use of org.sonar.ce.taskprocessor.CeTaskProcessor in project sonarqube by SonarSource.
the class CeWorkerCallableImpl method executeTask.
private void executeTask(CeTask task) {
ceLogging.initForTask(task);
Profiler ceProfiler = startActivityProfiler(task);
CeActivityDto.Status status = CeActivityDto.Status.FAILED;
CeTaskResult taskResult = null;
Throwable error = null;
try {
// TODO delegate the message to the related task processor, according to task type
Optional<CeTaskProcessor> taskProcessor = taskProcessorRepository.getForCeTask(task);
if (taskProcessor.isPresent()) {
taskResult = taskProcessor.get().process(task);
status = CeActivityDto.Status.SUCCESS;
} else {
LOG.error("No CeTaskProcessor is defined for task of type {}. Plugin configuration may have changed", task.getType());
status = CeActivityDto.Status.FAILED;
}
} catch (Throwable e) {
LOG.error(format("Failed to execute task %s", task.getUuid()), e);
error = e;
} finally {
finalizeTask(task, ceProfiler, status, taskResult, error);
}
}
use of org.sonar.ce.taskprocessor.CeTaskProcessor in project sonarqube by SonarSource.
the class CeTaskProcessorRepositoryImplTest method getForTask_returns_TaskProcessor_based_on_CeTask_type_only.
@Test
public void getForTask_returns_TaskProcessor_based_on_CeTask_type_only() {
CeTaskProcessor taskProcessor = createCeTaskProcessor(SOME_CE_TASK_TYPE);
CeTaskProcessorRepositoryImpl underTest = new CeTaskProcessorRepositoryImpl(new CeTaskProcessor[] { taskProcessor });
assertThat(underTest.getForCeTask(createCeTask(SOME_CE_TASK_TYPE, SOME_COMPONENT_KEY)).get()).isSameAs(taskProcessor);
assertThat(underTest.getForCeTask(createCeTask(SOME_CE_TASK_TYPE, SOME_COMPONENT_KEY + "2")).get()).isSameAs(taskProcessor);
}
use of org.sonar.ce.taskprocessor.CeTaskProcessor in project sonarqube by SonarSource.
the class CeTaskProcessorRepositoryImplTest method getForTask_returns_TaskProcessor_even_if_it_is_not_specific.
@Test
public void getForTask_returns_TaskProcessor_even_if_it_is_not_specific() {
CeTaskProcessor taskProcessor = createCeTaskProcessor(SOME_CE_TASK_TYPE + "_1", SOME_CE_TASK_TYPE, SOME_CE_TASK_TYPE + "_3");
CeTaskProcessorRepositoryImpl underTest = new CeTaskProcessorRepositoryImpl(new CeTaskProcessor[] { taskProcessor });
assertThat(underTest.getForCeTask(createCeTask(SOME_CE_TASK_TYPE, SOME_COMPONENT_KEY)).get()).isSameAs(taskProcessor);
}
use of org.sonar.ce.taskprocessor.CeTaskProcessor in project sonarqube by SonarSource.
the class CeTaskProcessorRepositoryRule method getForCeTask.
@Override
public Optional<CeTaskProcessor> getForCeTask(CeTask ceTask) {
CeTaskProcessor taskProcessor = index.get(ceTask.getType());
checkState(taskProcessor != null, "CeTaskProcessor was not set in rule for task %s", ceTask);
return taskProcessor instanceof NoCeTaskProcessor ? Optional.<CeTaskProcessor>absent() : Optional.of(taskProcessor);
}
Aggregations