bear.plugins.misc.ReleasesPlugin Maven / Gradle / Ivy
package bear.plugins.misc;
import bear.context.AbstractContext;
import bear.context.Fun;
import bear.core.GlobalContext;
import bear.core.SessionContext;
import bear.plugins.Plugin;
import bear.session.DynamicVariable;
import bear.task.*;
import com.google.common.base.Optional;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import java.util.TimeZone;
import static bear.session.BearVariables.joinPath;
import static bear.session.Variables.*;
/**
* @author Andrey Chaschev [email protected]
*/
public class ReleasesPlugin extends Plugin {
public static final DateTimeZone GMT = DateTimeZone.forTimeZone(TimeZone.getTimeZone("GMT"));
public static final DateTimeFormatter RELEASE_FORMATTER = DateTimeFormat.forPattern("yyyyMMdd.HHmmss");
public final DynamicVariable pendingRelease = undefined();
// not present when: there is no activation for pending release OR when there is no release
public final DynamicVariable> activatedRelease = dynamic(new Fun>() {
@Override
public Optional apply(AbstractContext $) {
return $.var(session).getCurrentRelease();
}
});
public final DynamicVariable> rollbackToRelease = undefined();
public final DynamicVariable
dirName = newVar("releases"),
currentDirName = newVar("current"),
releaseName = dynamic(new Fun() {
@Override
public String apply(AbstractContext $) {
return RELEASE_FORMATTER.print(new DateTime()) + ".GMT";
}
}).memoizeIn(GlobalContext.class),
pendingName = newVar("pending_"),
pendingReleaseName = concat("pending_", releaseName),
path = joinPath(bear.applicationPath, dirName),
releasesJsonPath = joinPath(path, "releases.json"),
currentReleaseLinkPath = joinPath(path, currentDirName),
releasePath = joinPath(path, releaseName),
pendingReleasePath = concat(path, "/pending_", releaseName);
public final DynamicVariable
keepXReleases = newVar(5);
public final DynamicVariable
cleanPending = newVar(true),
manualRollback = newVar(false);
public final DynamicVariable session = dynamic(new Fun() {
@Override
public Releases apply(SessionContext $) {
return $.wire(new Releases($, ReleasesPlugin.this)).load();
}
}).memoizeIn(SessionContext.class);
public ReleasesPlugin(GlobalContext global) {
super(global);
}
@Override
public InstallationTaskDef extends InstallationTask> getInstall() {
return new InstallationTaskDef(new NamedSupplier
© 2015 - 2024 Weber Informatics LLC | Privacy Policy