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) ); }
private BuildCommand cleanWorkingDir(String workingDir) { return compose( echo(format("[%s] Cleaning up working directory", GoConstants.PRODUCT_NAME)), exec("p4", "-d", workingDir, "clean").setCommandEnvVars(envVars()) ); } }
private BuildCommand resetWorkingCopy(String workingDir, Revision revision) { return compose( echo("[GIT] Reset working directory %s", workingDir), echo("[GIT] Updating working copy to revision %s", revision.getRevision()), cleanupUnversionedFiles(workingDir), resetHard(workingDir, revision), updateSubmodules(workingDir), cleanupUnversionedFiles(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)); }
@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"))); }
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 echoCommandAppendContentToConsole() { runBuild(echo("o1o2"), Passed); assertThat(console.asList(), is(Collections.singletonList("o1o2"))); }
@Override public void run() { buildSession.build(compose( execSleepScript(50), echo("build done"))); } });
@Override public void run() { buildSession.build(compose( echo("after sleep").setTest(execSleepScript(50)))); } });
@Test public void shouldNotFailBuildWhenTestCommandFail() { runBuild(echo("foo").setTest(fail("")), Passed); assertThat(statusReporter.singleResult(), is(Passed)); }
@Test public void shouldRunCommandWithRunIfFailedIfBuildIsFailed() { runBuild(compose( fail("force failure"), echo("on failure").runIf("failed")), Failed); assertThat(console.lastLine(), is("on failure")); }
@Override public void run() { buildSession.build(compose( compose(execSleepScript(50), echo("after sleep")) .setOnCancel(printSubProcessCount))); } });
@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)); } }