public Task antTask() { if (isAntTask()) { return task; } return new AntTask(); }
@Before public void setup() throws Exception { antTask = new AntTask(); }
public static AntTask fromJSON(JsonReader jsonReader) { AntTask antTask = new AntTask(); if (jsonReader == null) { return antTask; } BaseTaskRepresenter.fromJSON(jsonReader, antTask); jsonReader.readStringIfPresent("working_directory", antTask::setWorkingDirectory); jsonReader.readStringIfPresent("build_file", antTask::setBuildFile); jsonReader.readStringIfPresent("target", antTask::setTarget); return antTask; } }
public static AntTask fromJSON(JsonReader jsonReader) { AntTask antTask = new AntTask(); if (jsonReader == null) { return antTask; } BaseTaskRepresenter.fromJSON(jsonReader, antTask); jsonReader.readStringIfPresent("working_directory", antTask::setWorkingDirectory); jsonReader.readStringIfPresent("build_file", antTask::setBuildFile); jsonReader.readStringIfPresent("target", antTask::setTarget); return antTask; } }
@Test public void antTaskShouldNormalizeBuildFile() throws Exception { AntTask task = new AntTask(); task.setBuildFile("pavan\\build.xml"); assertThat(task.arguments(), containsString("\"pavan/build.xml\"")); }
@Test public void shouldSetConfigAttributesForBuiltinTask() throws Exception { HashMap attributes = new HashMap(); attributes.put(Tasks.TASK_OPTIONS, "ant"); attributes.put("ant", antTaskAttribs("build.xml", "test", "foo")); TaskFactory taskFactory = mock(TaskFactory.class); AntTask antTask = new AntTask(); when(taskFactory.taskInstanceFor(antTask.getTaskType())).thenReturn(antTask); Tasks tasks = new Tasks(); Tasks spy = spy(tasks); spy.setConfigAttributes(attributes, taskFactory); assertThat(spy.size(), is(1)); assertThat(spy.get(0), is(antTask("build.xml", "test", "foo"))); }
private AntTask antTask(final String buildFile, final String target, final String workingDir) { AntTask antTask = new AntTask(); antTask.setBuildFile(buildFile); antTask.setWorkingDirectory(workingDir); antTask.setTarget(target); return antTask; }
@Test public void shouldOfferAllTasksToVisitors() throws Exception { CruiseConfig config = createCruiseConfig(); Task task1 = new ExecTask("ls", "-a", ""); Task task2 = new AntTask(); setupJobWithTasks(config, task1, task2); final List<Task> tasksVisited = new ArrayList<>(); config.accept(new TaskConfigVisitor() { public void visit(PipelineConfig pipelineConfig, StageConfig stageConfig, JobConfig jobConfig, Task task) { tasksVisited.add(task); } }); assertThat(tasksVisited.size(), is(2)); assertThat(tasksVisited.get(0), is(task1)); assertThat(tasksVisited.get(1), is(task2)); }
@Test public void shouldGiveArgumentsIncludingBuildfileAndTarget(){ AntTask task = new AntTask(); task.setBuildFile("build/build.xml"); task.setTarget("compile"); assertThat(task.arguments(), is("-f \"build/build.xml\" compile")); } }
@Test public void shouldReturnEmptyTasks() throws Exception { AntTask antTask1 = new AntTask(); FetchTask fetchArtifact = new FetchTask(); Tasks tasks = new Tasks(antTask1, fetchArtifact); Tasks finds = tasks.findByType(NantTask.class); assertThat(finds.size(), is(0)); }
@Test public void shouldReturnTheOnCancelOptionBasedOnWhatTheOnCancelTaskIs() { assertThat(new OnCancelConfig().onCancelOption(), is("")); assertThat(new OnCancelConfig(new ExecTask()).onCancelOption(), is("Custom Command")); assertThat(new OnCancelConfig(new AntTask()).onCancelOption(), is("Ant")); assertThat(new OnCancelConfig(new RakeTask()).onCancelOption(), is("Rake")); }
private static void addTask(JobConfig jobConfig) { jobConfig.setVariables(EnvironmentVariablesConfigMother.environmentVariables()); AntTask task = new AntTask(); task.setBuildFile("build-file"); task.setTarget("target"); task.setWorkingDirectory("working-directory"); jobConfig.addTask(task); }
@Test public void shouldReturnFalseWhenPluggableTaskIsComparedWithAnyOtherTask() { PluginConfiguration pluginConfiguration = new PluginConfiguration("test-plugin-1", "1.0"); PluggableTask pluggableTask = new PluggableTask(pluginConfiguration, new Configuration()); AntTask antTask = new AntTask(); assertFalse(pluggableTask.hasSameTypeAs(antTask)); }
@Test public void shouldValidateTree(){ String pipelineName = "p1"; PipelineConfig pipelineConfig = GoConfigMother.configWithPipelines(pipelineName).pipelineConfigByName(new CaseInsensitiveString(pipelineName)); StageConfig stageConfig = pipelineConfig.getStages().get(0); JobConfig jobConfig = stageConfig.getJobs().get(0); AbstractTask execTask = new ExecTask("ls", "-la", "42"); AntTask antTask = new AntTask(); antTask.setWorkingDirectory("/abc"); execTask.setCancelTask(antTask); PipelineConfigSaveValidationContext context = PipelineConfigSaveValidationContext.forChain(true, "group", pipelineConfig, stageConfig, jobConfig); assertThat(execTask.validateTree(context), is(false)); assertThat(antTask.errors().isEmpty(), is(false)); assertThat(antTask.errors().get(AntTask.WORKING_DIRECTORY).size(), is(1)); assertThat(antTask.errors().get(AntTask.WORKING_DIRECTORY).contains("Task of job 'job' in stage 'stage' of pipeline 'p1' has path '/abc' which is outside the working directory."), is(true)); }
@Test public void shouldGetAllFetchTasks() { PipelineConfig pipelineConfig = PipelineConfigMother.createPipelineConfig("foo bar", "stage1", "job1"); FetchTask firstFetch = new FetchTask(); JobConfig firstJob = pipelineConfig.getFirstStageConfig().getJobs().get(0); firstJob.addTask(firstFetch); firstJob.addTask(new AntTask()); JobConfig secondJob = new JobConfig(); secondJob.addTask(new ExecTask()); FetchTask secondFetch = new FetchTask(); secondJob.addTask(secondFetch); pipelineConfig.add(new StageConfig(new CaseInsensitiveString("stage-2"), new JobConfigs(secondJob))); List<FetchTask> fetchTasks = pipelineConfig.getFetchTasks(); assertThat(fetchTasks.size(), is(2)); assertThat(fetchTasks.contains(firstFetch), is(true)); assertThat(fetchTasks.contains(secondFetch), is(true)); }
@Test public void shouldErrorOutIfWorkingDirectoryIsOutsideTheCurrentWorkingDirectoryForTemplates() { CruiseConfig config = GoConfigMother.configWithPipelines("pipeline-blah"); BuildTask task = new AntTask(); task.setWorkingDirectory("/blah"); StageConfig stageConfig = StageConfigMother.manualStage("manualStage"); stageConfig.getJobs().get(0).addTask(task); PipelineTemplateConfig template = new PipelineTemplateConfig(new CaseInsensitiveString("some-template"), stageConfig); config.addTemplate(template); List<ConfigErrors> errors = config.validateAfterPreprocess(); assertThat(errors.size(), is(1)); String message = "Task of job 'default' in stage 'manualStage' of template 'some-template' has path '/blah' which is outside the working directory."; assertThat(task.errors().on(BuildTask.WORKING_DIRECTORY), is(message)); } }
@Test public void shouldNotSetTasksIfNoTasksGiven() throws Exception { config = new JobConfig(); AntTask task = new AntTask(); task.setTarget("hello"); config.addTask(task); config.setConfigAttributes(m()); AntTask taskAfterUpdate = (AntTask) config.getTasks().get(0); assertThat(taskAfterUpdate.getTarget(), is("hello")); assertThat(config.getTasks().size(), is(1)); config.setConfigAttributes(m(JobConfig.TASKS, null)); assertThat(config.getTasks().size(), is(0)); }
public static StageConfig stageWithTasks(String stageName) { JobConfig job = new JobConfig("job"); job.addTask(new ExecTask("ls", "-la", "pwd")); job.addTask(new AntTask()); return new StageConfig(new CaseInsensitiveString(stageName), new JobConfigs(job)); }
@Test public void shouldRegisterViewEnginesForAllTasks() { assertReturnsAppropriateViewModelForInbuiltTasks(registry, new AntTask(), "ant"); assertReturnsAppropriateViewModelForInbuiltTasks(registry, new ExecTask(), "exec"); assertReturnsAppropriateViewModelForInbuiltTasks(registry, new FetchTask(), "fetch"); assertReturnsAppropriateViewModelForInbuiltTasks(registry, new RakeTask(), "rake"); assertReturnsAppropriateViewModelForInbuiltTasks(registry, new NantTask(), "nant"); }
private StageConfig getStageConfig(String stageName, String jobName) { JobConfig jobConfig = new JobConfig(new CaseInsensitiveString(jobName)); jobConfig.addTask(new AntTask()); jobConfig.addTask(new ExecTask("command", "", "workingDir")); jobConfig.artifactConfigs().add(new BuildArtifactConfig("src", "dest")); jobConfig.addVariable("env1", "val1"); jobConfig.addResourceConfig("powerful"); JobConfigs jobConfigs = new JobConfigs(jobConfig); return new StageConfig(new CaseInsensitiveString(stageName), jobConfigs); }