private BuildCommand unshallowIfNeeded(String workingDir, Revision revision, Integer[] steps) { if (steps.length == 0) { return noop(); } int depth = steps[0]; return compose( compose( echo("[GIT] Unshallowing repository with depth %d", depth), exec("git", "fetch", "origin", format("--depth=%d", depth)).setWorkingDirectory(workingDir), unshallowIfNeeded(workingDir, revision, Arrays.copyOfRange(steps, 1, steps.length)) ).setTest(revisionNotExists(workingDir, revision)) ).setTest(isShallow(workingDir)); }
private BuildCommand fetchRemote(String workingDir) { return compose( echo("[GIT] Fetching changes"), exec("git", "fetch", "origin", "--prune").setWorkingDirectory(workingDir), exec("git", "gc", "--auto").setWorkingDirectory(workingDir)); }
public BuildCommand setWorkingDirectoryRecursively(String workingDirectory) { this.setWorkingDirectory(workingDirectory); for (BuildCommand subCommand : subCommands) { subCommand.setWorkingDirectoryRecursively(workingDirectory); } return this; }
private BuildCommand info(String workingDir) { return exec("svn", "info", "--non-interactive").setWorkingDirectory(workingDir); }
private BuildCommand isBranchChanged(String workDir) { return test("-neq", material.getBranch(), exec("hg", "branch").setWorkingDirectory(workDir)); }
private BuildCommand cleanupUnversionedFiles(String workingDir) { return compose( echo("[GIT] Cleaning all unversioned files in working copy"), exec("git", "submodule", "foreach", "--recursive", "git", "clean", "-fdd") .setTest(hasSubmodules(workingDir)), exec("git", "clean", "-dff")) .setWorkingDirectoryRecursively(workingDir); }
@Test public void shouldRunCommandWithRunIfAnyRegardlessOfBuildResult() { runBuild(compose( echo("foo"), echo("on passing").runIf("any"), fail("force failure"), echo("on failure").runIf("any")), Failed); assertThat(console.asList(), is(Arrays.asList("foo", "on passing", "force failure", "on failure"))); }
public BuildCommand updateTo(String baseDir, RevisionContext revisionContext) { Revision revision = revisionContext.getLatestRevision(); String workingDir = material.workingdir(new File(baseDir)).getPath(); UrlArgument url = material.getUrlArgument(); return compose( echoWithPrefix(format("Start updating %s at revision %s from %s", material.updatingTarget(), revision.getRevision(), url.forDisplay())), secret(url.forCommandline(), url.forDisplay()), secret(material.getPassword(), "*********************"), cleanupAndUpdate(workingDir, revision).setTest(shouldDoCleanupAndUpdate(workingDir)), freshCheckout(workingDir, revision).setTest(isNotRepository(workingDir)), freshCheckout(workingDir, revision).setTest(test("-nd", workingDir)), freshCheckout(workingDir, revision).setTest(repoUrlChanged(workingDir)), echoWithPrefix(format("Done.\n")) ); }
@Test public void encodeDecode() { BuildCommand bc = BuildCommand.compose(new BuildCommand("bar1", map("arg1", "1", "arg2", "2")), BuildCommand.compose(new BuildCommand("barz"))); bc.setRunIfConfig("any"); bc.setTest(new BuildCommand("t", map("k1", "v1"))); bc.setOnCancel(BuildCommand.compose(BuildCommand.echo("foo"), BuildCommand.echo("bar"))); assertThat(MessageEncoding.decodeData(MessageEncoding.encodeData(bc), BuildCommand.class), is(bc)); } }
private BuildCommand runSingleBuilder(Builder builder) { String runIfConfig = builder.resolvedRunIfConfig().toString(); return BuildCommand.compose( echoWithPrefix("Current job status: passed"), echoWithPrefix("Current job status: failed").runIf("failed"), echoWithPrefix("Task: %s", builder.getDescription()).runIf(runIfConfig), builder.buildCommand() .runIf(runIfConfig) .setOnCancel(runCancelTask(builder.getCancelBuilder()))).runIf(runIfConfig); }
private BuildCommand cleanWorkingDir(String workingDir) { return compose( echo(format("[%s] Cleaning up working directory", GoConstants.PRODUCT_NAME)), exec("p4", "-d", workingDir, "clean").setCommandEnvVars(envVars()) ); } }
public BuildCommand updateTo(String baseDir, RevisionContext revisionContext) { Revision revision = revisionContext.getLatestRevision(); String workingDir = material.workingdir(new File(baseDir)).getPath(); UrlArgument url = material.getUrlArgument(); return compose( secret(url.forCommandline(), url.forDisplay()), echoWithPrefix("Start updating %s at revision %s from %s", material.updatingTarget(), revision.getRevision(), url.forDisplay()), cloneIfNeeded(workingDir), pull(workingDir), update(workingDir, revision), echoWithPrefix("Done.\n")); }
private BuildCommand cleanupAndUpdate(String workingDir, Revision revision) { return compose( echo("[SVN] Cleaning up working directory %s", workingDir), exec("svn", "cleanup", workingDir), exec("svn", "revert", "--recursive", workingDir), echo("[SVN] Updating working copy to revision %s", revision.getRevision()), update(workingDir, revision) ); }
@Override public void run() { buildSession.build(compose( compose( execSleepScript(50).setOnCancel(echo("exec canceled")), echo("after sleep")) .setOnCancel(echo("inner oncancel")) ).setOnCancel(echo("outter oncancel"))); } });
private BuildCommand runCancelTask(Builder cancelBuilder) { if (cancelBuilder == null) { return null; } return BuildCommand.compose( echoWithPrefix("Cancel task: %s", cancelBuilder.getDescription()), cancelBuilder.buildCommand(), echoWithPrefix("Task is cancelled")); }