3 * Copyright (C) 2009-2020 SonarSource SA
4 * mailto:info AT sonarsource DOT com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package org.sonar.ce.task.projectanalysis.taskprocessor;
22 import com.google.common.collect.ImmutableSet;
23 import java.util.Collections;
24 import java.util.List;
26 import javax.annotation.CheckForNull;
27 import org.sonar.ce.task.CeTask;
28 import org.sonar.ce.task.CeTaskResult;
29 import org.sonar.ce.task.container.TaskContainer;
30 import org.sonar.ce.task.container.TaskContainerImpl;
31 import org.sonar.ce.task.projectanalysis.step.AbstractComputationSteps;
32 import org.sonar.ce.task.step.ComputationStep;
33 import org.sonar.ce.task.step.ComputationStepExecutor;
34 import org.sonar.ce.task.taskprocessor.CeTaskProcessor;
35 import org.sonar.core.platform.ComponentContainer;
36 import org.sonar.core.platform.ContainerPopulator;
38 import static org.sonar.db.ce.CeTaskTypes.BRANCH_ISSUE_SYNC;
40 public class IssueSyncTaskProcessor implements CeTaskProcessor {
41 private static final Set<String> HANDLED_TYPES = ImmutableSet.of(BRANCH_ISSUE_SYNC);
43 private final ComponentContainer ceEngineContainer;
45 public IssueSyncTaskProcessor(ComponentContainer ceEngineContainer) {
46 this.ceEngineContainer = ceEngineContainer;
50 public Set<String> getHandledCeTaskTypes() {
56 public CeTaskResult process(CeTask task) {
57 try (TaskContainer container = new TaskContainerImpl(ceEngineContainer, newContainerPopulator(task))) {
59 container.getComponentByType(ComputationStepExecutor.class).execute();
64 static ContainerPopulator<TaskContainer> newContainerPopulator(CeTask task) {
65 return taskContainer -> {
66 taskContainer.add(task);
67 taskContainer.add(IndexIssuesStep.class);
68 taskContainer.add(new SyncComputationSteps(taskContainer));
69 taskContainer.add(ComputationStepExecutor.class);
73 public static final class SyncComputationSteps extends AbstractComputationSteps {
75 public SyncComputationSteps(ContainerPopulator.Container container) {
80 public List<Class<? extends ComputationStep>> orderedStepClasses() {
81 return Collections.singletonList(IndexIssuesStep.class);