public BuildCommand setWorkingDirectoryRecursively(String workingDirectory) { this.setWorkingDirectory(workingDirectory); for (BuildCommand subCommand : subCommands) { subCommand.setWorkingDirectoryRecursively(workingDirectory); } return this; }
@Override public BuildCommand buildCommand() { BuildCommand exec = BuildCommand.exec(this.command, args); if (workingDir != null) { exec.setWorkingDirectory(workingDir.getPath()); } return exec; } }
private BuildCommand info(String workingDir) { return exec("svn", "info", "--non-interactive").setWorkingDirectory(workingDir); }
@Override public BuildCommand buildCommand() { String[] argsArray = CommandLine.translateCommandLine(args); BuildCommand exec = BuildCommand.exec(command, argsArray); if (workingDir != null) { exec.setWorkingDirectory(workingDir.getPath()); } return exec; } }
private BuildCommand fetchRemote(String workingDir) { return compose( echo("[GIT] Fetching changes"), exec("git", "fetch", "origin", "--prune").setWorkingDirectory(workingDir), exec("git", "gc", "--auto").setWorkingDirectory(workingDir)); }
private BuildCommand resetHard(String workingDir, Revision revision) { return exec("git", "reset", "--hard", revision.getRevision()) .setWorkingDirectory(workingDir); }
private BuildCommand pull(String workingDir) { return exec("hg", "pull", "-b", material.getBranch(), "--config", String.format("paths.default=%s", material.getUrl())). setWorkingDirectory(workingDir); }
private BuildCommand generateTestReport() { List<String> srcs = new ArrayList<>(); for (ArtifactPlan ap : assignment.getArtifactPlans()) { if (ap.getArtifactPlanType() == ArtifactPlanType.unit) { srcs.add(ap.getSrc()); } } return srcs.isEmpty() ? noop() : BuildCommand.generateTestReport(srcs, "testoutput").setWorkingDirectory(workingDirectory()); }
private BuildCommand isBranchChanged(String workDir) { return test("-neq", material.getBranch(), exec("hg", "branch").setWorkingDirectory(workDir)); }
private BuildCommand isBranchChanged(String workDir) { return test("-neq", material.branchWithDefault(), exec("git", "rev-parse", "--abbrev-ref", "HEAD").setWorkingDirectory(workDir)); }
private BuildCommand isRepoUrlChanged(String workDir) { return test("-neq", material.getUrlArgument().forCommandline(), exec("git", "config", "remote.origin.url").setWorkingDirectory(workDir)); }
@Test public void mkdirWithWorkingDir() { runBuild(mkdirs("foo").setWorkingDirectory("bar"), Passed); assertThat(new File(sandbox, "bar/foo").isDirectory(), is(true)); assertThat(new File(sandbox, "foo").isDirectory(), is(false)); }
private BuildCommand harvestProperties() { List<ArtifactPropertiesGenerator> generators = assignment.getPropertyGenerators(); List<BuildCommand> commands = new ArrayList<>(); for (ArtifactPropertiesGenerator generator : generators) { BuildCommand command = BuildCommand.generateProperty(generator.getName(), generator.getSrc(), generator.getXpath()).setWorkingDirectory(workingDirectory()); commands.add(command); } return BuildCommand.compose( reportAction("Start to create properties"), BuildCommand.compose(commands)); }
private BuildCommand isRepoUrlChanged(String workDir) { return test("-neq", new MaterialUrl(material.getHgUrlArgument().defaultRemoteUrl()).getUrl(), exec("hg", "showconfig", "paths.default").setWorkingDirectory(workDir)); }
@Test public void cleanDirWithAllowsAndWorkingDir() throws IOException { runBuild(mkdirs("bar/foo/baz"), Passed); runBuild(mkdirs("bar/foo2"), Passed); assertTrue(new File(sandbox, "bar/foo/file1").createNewFile()); assertTrue(new File(sandbox, "bar/file2").createNewFile()); assertTrue(new File(sandbox, "file3").createNewFile()); runBuild(cleandir("", "file2", "foo2").setWorkingDirectory("bar"), Passed); assertThat(new File(sandbox, "bar").isDirectory(), is(true)); assertThat(new File(sandbox, "file3").exists(), is(true)); assertThat(new File(sandbox, "bar").listFiles(), arrayContainingInAnyOrder(new File(sandbox, "bar/file2"), new File(sandbox, "bar/foo2"))); }
private BuildCommand uploadArtifacts() { List<BuildCommand> commands = new ArrayList<>(); for (ArtifactPlan ap : assignment.getArtifactPlans()) { commands.add(uploadArtifact(ap.getSrc(), ap.getDest(), ap.getArtifactPlanType().isTest()) .setWorkingDirectory(workingDirectory())); } return BuildCommand.compose( reportAction("Start to upload"), BuildCommand.compose(commands), generateTestReport()); }
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)); }
@Test public void uploadSingleFileArtifact() throws Exception { File targetFile = new File(sandbox, "foo"); assertTrue(targetFile.createNewFile()); runBuild(uploadArtifact("foo", "foo-dest", false).setWorkingDirectory(sandbox.getPath()), Passed); assertThat(artifactsRepository.getFileUploaded().size(), is(1)); assertThat(artifactsRepository.getFileUploaded().get(0).file, is(targetFile)); assertThat(artifactsRepository.getFileUploaded().get(0).destPath, is("foo-dest")); assertThat(artifactsRepository.getFileUploaded().get(0).buildId, is("build1")); }
private BuildCommand execTfsCheckout(TfsMaterial material, Revision revision, String workingDir) { Map<String, String> properties = map( "type", "tfs", "username", material.getUserName(), "password", material.getPassword(), "domain", material.getDomain(), "projectPath", material.getProjectPath(), "url", material.getUrl(), "revision", revision.getRevision()); return plugin(properties).setWorkingDirectory(workingDir); } }
@Test public void execShouldFailIfWorkingDirectoryNotExists() { runBuild(exec("echo", "should not show").setWorkingDirectory("not-exists"), Failed); assertThat(console.lineCount(), is(1)); assertThat(console.firstLine(), containsString("not-exists\" is not a directory!")); }