@Override public boolean execute(BuildCommand command, BuildSession buildSession) { File workingDirectory = buildSession.resolveRelativeDir(command.getWorkingDirectory()); String uploadPath = command.getStringArg("uploadPath"); String[] sources = command.getArrayArg("srcs"); ArrayList<File> allFiles = findMatchedSourceFiles(buildSession, workingDirectory, sources); if (allFiles.size() > 0) { File tempFolder = null; try { tempFolder = FileUtil.createTempFolder(); File testResultSource = new File(tempFolder, "result"); testResultSource.mkdirs(); UnitTestReportGenerator generator = new UnitTestReportGenerator(buildSession.getPublisher(), testResultSource); generator.generate(allFiles.toArray(new File[allFiles.size()]), uploadPath); } finally { if (tempFolder != null) { FileUtils.deleteQuietly(tempFolder); } } } else { String message = "No files were found in the Test Results folders"; buildSession.printlnWithPrefix(message); LOG.warn(message); } return true; }
@Override public boolean execute(BuildCommand command, BuildSession buildSession) { File dir = buildSession.resolveRelativeDir(command.getWorkingDirectory(), command.getStringArg("path")); String[] allowed = command.getArrayArg("allowed"); if (allowed.length == 0) { try { FileUtils.cleanDirectory(dir); } catch (IOException e) { return false; } } else { DirectoryCleaner cleaner = new DirectoryCleaner(dir, buildSession.processOutputStreamConsumer()); cleaner.allowed(allowed); cleaner.clean(); } return true; } }
@Override public boolean execute(BuildCommand command, BuildSession buildSession) { File workingDir = buildSession.resolveRelativeDir(command.getWorkingDirectory()); if (!workingDir.isDirectory()) { String message = "Working directory \"" + workingDir.getAbsolutePath() + "\" is not a directory!"; LOG.error(message); buildSession.println(message); return false; } String cmd = command.getStringArg("command"); String[] args = command.getArrayArg("args"); Map<String, String> secrets = buildSession.getSecretSubstitutions(); Set<String> leftSecrets = new HashSet<>(secrets.keySet()); CommandLine commandLine = createCommandLine(cmd, buildSession.getConsoleLogCharset()); for (String arg : args) { if(secrets.containsKey(arg)) { leftSecrets.remove(arg); commandLine.withArg(new SubstitutableCommandArgument(arg, secrets.get(arg))); } else { commandLine.withArg(arg); } } for (String secret: leftSecrets) { commandLine.withNonArgSecret(new SecretSubstitution(secret, secrets.get(secret))); } commandLine.withWorkingDir(workingDir); commandLine.withEnv(buildSession.getEnvs()); commandLine.withEnv(command.getCommandEnvVars()); return executeCommandLine(buildSession, commandLine, command.getExecInput()) == 0; }
@Test public void testGetArgs() { assertThat(new BuildCommand("foo", map("foo", new Gson().toJson(new String[]{"arg1", "arg2"}))).getArrayArg("foo"), is(new String[]{"arg1","arg2"})); assertThat(new BuildCommand("foo", map("foo", "true")).getBooleanArg("foo"), is(true)); assertThat(new BuildCommand("foo", map("foo", "true")).getBooleanArg("bar"), is(false)); assertThat(new BuildCommand("foo", map("foo", "bar")).getStringArg("foo"), is("bar")); }
@Test public void shouldGenerateCleanupCommandForRemovingJunkFoldersWhenCleanUpIsCalled_hasOneMaterialUseBaseFolderReturnsFalse() throws Exception { Materials materials = new Materials(); GitMaterial gitMaterial = new GitMaterial("http://some-url.com", "some-branch", "some-folder"); materials.add(gitMaterial); BuildCommand command = materials.cleanUpCommand("basedir"); assertThat(command.getName(), is("cleandir")); assertThat(command.getStringArg("path"), is("basedir")); assertThat(command.getArrayArg("allowed"), is(new String[]{"some-folder", "cruise-output"})); }