Search in sources :

Example 1 with Task

use of com.thoughtworks.go.domain.Task in project gocd by gocd.

the class PipelineConfigErrorCopier method copyErrors.

static void copyErrors(PipelineConfig from, PipelineConfig to) {
    copy(from, to);
    copyCollectionErrors(from.materialConfigs(), to.materialConfigs());
    copyCollectionErrors(from.getVariables(), to.getVariables());
    copyCollectionErrors(from.getParams(), to.getParams());
    copy(from.getTrackingTool(), to.getTrackingTool());
    copy(from.getTimer(), to.getTimer());
    for (StageConfig toStage : to.getStages()) {
        StageConfig fromStage = from.findBy(toStage.name());
        copy(fromStage, toStage);
        copyCollectionErrors(fromStage.getVariables(), toStage.getVariables());
        copy(fromStage.getApproval(), toStage.getApproval());
        copyCollectionErrors(fromStage.getApproval().getAuthConfig(), toStage.getApproval().getAuthConfig());
        for (JobConfig toJob : toStage.getJobs()) {
            JobConfig fromJob = fromStage.jobConfigByConfigName(toJob.name());
            copy(fromJob, toJob);
            copyCollectionErrors(fromJob.getTasks(), toJob.getTasks());
            copyCollectionErrors(fromJob.artifactConfigs(), toJob.artifactConfigs());
            copyCollectionErrors(fromJob.getTabs(), toJob.getTabs());
            copyCollectionErrors(fromJob.getProperties(), toJob.getProperties());
            copyCollectionErrors(fromJob.getVariables(), toJob.getVariables());
            Tasks toTasks = toJob.getTasks();
            Tasks fromTasks = fromJob.getTasks();
            copyCollectionErrors(fromTasks, toTasks);
            for (int i = 0; i < toTasks.size(); i++) {
                Task fromTask = fromTasks.get(i);
                Task toTask = toTasks.get(i);
                copy(fromTask, toTask);
                copyCollectionErrors(fromTask.getConditions(), toTask.getConditions());
                if (toTask instanceof ExecTask) {
                    copyCollectionErrors(((ExecTask) fromTask).getArgList(), ((ExecTask) toTask).getArgList());
                }
            }
        }
    }
}
Also used : Task(com.thoughtworks.go.domain.Task)

Example 2 with Task

use of com.thoughtworks.go.domain.Task in project gocd by gocd.

the class BuilderFactoryTest method shouldFailIfCalledWithSomeRandomTypeOfTask.

@Test
public void shouldFailIfCalledWithSomeRandomTypeOfTask() {
    Task task = someRandomNonStandardTask();
    try {
        Pipeline pipeline = PipelineMother.pipeline("pipeline1", StageMother.custom("stage1"));
        builderFactory.builderFor(task, pipeline, pipelineResolver);
    } catch (RuntimeException e) {
        assertThat(e.getMessage(), is("Unexpected type of task: " + task.getClass()));
    }
}
Also used : Task(com.thoughtworks.go.domain.Task) KillAllChildProcessTask(com.thoughtworks.go.domain.KillAllChildProcessTask) NullTask(com.thoughtworks.go.domain.NullTask) PluggableTask(com.thoughtworks.go.config.pluggabletask.PluggableTask) Pipeline(com.thoughtworks.go.domain.Pipeline) Test(org.junit.Test)

Example 3 with Task

use of com.thoughtworks.go.domain.Task in project gocd by gocd.

the class TaskViewServiceTest method shouldNotGetViewModelForPluggableFetchArtifactTaskWhenToggleIsOff.

@Test
public void shouldNotGetViewModelForPluggableFetchArtifactTaskWhenToggleIsOff() {
    List<Class<? extends Task>> taskClasses = taskImplementations();
    taskClasses.add(FetchPluggableArtifactTask.class);
    when(featureToggleService.isToggleOn(Toggles.ARTIFACT_EXTENSION_KEY)).thenReturn(false);
    when(registry.implementersOf(Task.class)).thenReturn(taskClasses);
    when(registry.getViewModelFor(new FetchPluggableArtifactTask(), "new")).thenReturn(viewModel(new FetchPluggableArtifactTask()));
    when(registry.getViewModelFor(new ExecTask(), "new")).thenReturn(new TaskViewModel(new ExecTask(), ""));
    List<PluggableViewModel> taskViewModels = taskViewService.getTaskViewModels();
    assertThat(taskViewModels.size(), is(3));
    assertThat(taskViewModels, hasItem((PluggableViewModel) new TaskViewModel(new ExecTask(), "")));
    assertThat(taskViewModels.indexOf(viewModel(new FetchPluggableArtifactTask())), is(-1));
}
Also used : ExecTask(com.thoughtworks.go.config.ExecTask) Task(com.thoughtworks.go.domain.Task) FetchTask(com.thoughtworks.go.config.FetchTask) AntTask(com.thoughtworks.go.config.AntTask) FetchPluggableArtifactTask(com.thoughtworks.go.config.FetchPluggableArtifactTask) PluggableTask(com.thoughtworks.go.config.pluggabletask.PluggableTask) TaskViewModel(com.thoughtworks.go.presentation.TaskViewModel) ExecTask(com.thoughtworks.go.config.ExecTask) PluggableViewModel(com.thoughtworks.go.plugins.presentation.PluggableViewModel) FetchPluggableArtifactTask(com.thoughtworks.go.config.FetchPluggableArtifactTask) Test(org.junit.Test)

Example 4 with Task

use of com.thoughtworks.go.domain.Task in project gocd by gocd.

the class TaskViewServiceTest method shouldGetViewModelsOnlyForBuiltInTasks_WhenThereAreNoExistingPlugins.

@Test
public void shouldGetViewModelsOnlyForBuiltInTasks_WhenThereAreNoExistingPlugins() throws Exception {
    List<Class<? extends Task>> taskClasses = taskImplementations();
    taskClasses.add(PluggableTask.class);
    when(registry.implementersOf(Task.class)).thenReturn(taskClasses);
    when(registry.getViewModelFor(new AntTask(), "new")).thenReturn(viewModel(new AntTask()));
    when(registry.getViewModelFor(new ExecTask(), "new")).thenReturn(new TaskViewModel(new ExecTask(), ""));
    List<PluggableViewModel> taskViewModels = taskViewService.getTaskViewModels();
    assertThat(taskViewModels.size(), is(3));
    assertThat(taskViewModels, hasItem((PluggableViewModel) viewModel(new AntTask())));
    assertThat(taskViewModels, hasItem((PluggableViewModel) new TaskViewModel(new ExecTask(), "")));
}
Also used : ExecTask(com.thoughtworks.go.config.ExecTask) Task(com.thoughtworks.go.domain.Task) FetchTask(com.thoughtworks.go.config.FetchTask) AntTask(com.thoughtworks.go.config.AntTask) FetchPluggableArtifactTask(com.thoughtworks.go.config.FetchPluggableArtifactTask) PluggableTask(com.thoughtworks.go.config.pluggabletask.PluggableTask) TaskViewModel(com.thoughtworks.go.presentation.TaskViewModel) ExecTask(com.thoughtworks.go.config.ExecTask) AntTask(com.thoughtworks.go.config.AntTask) PluggableViewModel(com.thoughtworks.go.plugins.presentation.PluggableViewModel) Test(org.junit.Test)

Example 5 with Task

use of com.thoughtworks.go.domain.Task in project gocd by gocd.

the class TaskViewServiceTest method shouldThrowAnExceptionIfTheTaskOfGivenTypeIsNotFound.

@Test
public void shouldThrowAnExceptionIfTheTaskOfGivenTypeIsNotFound() {
    ConfigElementImplementationRegistry registry = this.registry;
    List<Class<? extends Task>> taskClasses = new ArrayList<>();
    taskClasses.add(AntTask.class);
    when(registry.implementersOf(Task.class)).thenReturn(taskClasses);
    TaskViewService service = new TaskViewService(registry, mock(PluginManager.class));
    try {
        service.taskInstanceFor("Unknown");
        fail("Should have failed since the given task is not available in the registry");
    } catch (RuntimeException e) {
        assertThat(e.getMessage(), is("Could not find any task of type: Unknown"));
    }
}
Also used : PluginManager(com.thoughtworks.go.plugin.infra.PluginManager) ExecTask(com.thoughtworks.go.config.ExecTask) Task(com.thoughtworks.go.domain.Task) FetchTask(com.thoughtworks.go.config.FetchTask) AntTask(com.thoughtworks.go.config.AntTask) FetchPluggableArtifactTask(com.thoughtworks.go.config.FetchPluggableArtifactTask) PluggableTask(com.thoughtworks.go.config.pluggabletask.PluggableTask) ConfigElementImplementationRegistry(com.thoughtworks.go.config.registry.ConfigElementImplementationRegistry) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

Task (com.thoughtworks.go.domain.Task)15 Test (org.junit.Test)9 PluggableTask (com.thoughtworks.go.config.pluggabletask.PluggableTask)8 ExecTask (com.thoughtworks.go.config.ExecTask)6 AntTask (com.thoughtworks.go.config.AntTask)5 FetchPluggableArtifactTask (com.thoughtworks.go.config.FetchPluggableArtifactTask)5 FetchTask (com.thoughtworks.go.config.FetchTask)5 PluggableViewModel (com.thoughtworks.go.plugins.presentation.PluggableViewModel)4 TaskViewModel (com.thoughtworks.go.presentation.TaskViewModel)4 KillAllChildProcessTask (com.thoughtworks.go.domain.KillAllChildProcessTask)2 NullTask (com.thoughtworks.go.domain.NullTask)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 Cloner (com.rits.cloning.Cloner)1 BuildTask (com.thoughtworks.go.config.BuildTask)1 Tasks (com.thoughtworks.go.config.Tasks)1 ConfigElementImplementationRegistry (com.thoughtworks.go.config.registry.ConfigElementImplementationRegistry)1 Pipeline (com.thoughtworks.go.domain.Pipeline)1 Builder (com.thoughtworks.go.domain.builder.Builder)1