3 * Copyright (C) 2009-2016 SonarSource SA
4 * mailto:contact 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.server.computation.task.projectanalysis.step;
22 import com.google.common.base.Predicate;
23 import java.util.Arrays;
24 import java.util.List;
25 import javax.annotation.Nonnull;
26 import org.picocontainer.ComponentAdapter;
27 import org.sonar.server.computation.task.container.TaskContainer;
28 import org.sonar.server.computation.task.projectanalysis.api.developer.PersistDevelopersDelegate;
29 import org.sonar.server.computation.task.projectanalysis.filemove.FileMoveDetectionStep;
30 import org.sonar.server.computation.task.step.ComputationStep;
32 import static com.google.common.collect.FluentIterable.from;
35 * Ordered list of steps classes and instances to be executed for batch processing
37 public class ReportComputationSteps extends AbstractComputationSteps {
39 private static final List<Class<? extends ComputationStep>> STEPS = Arrays.asList(
40 ExtractReportStep.class,
41 PersistScannerContextStep.class,
42 GenerateAnalysisUuid.class,
44 // Builds Component tree
45 LoadReportAnalysisMetadataHolderStep.class,
46 BuildComponentTreeStep.class,
47 ValidateProjectStep.class,
49 LoadQualityProfilesStep.class,
51 // load project related stuffs
52 LoadQualityGateStep.class,
53 LoadPeriodsStep.class,
54 FileMoveDetectionStep.class,
56 // load duplications related stuff
57 LoadDuplicationsFromReportStep.class,
58 LoadCrossProjectDuplicationsRepositoryStep.class,
61 SizeMeasuresStep.class,
62 NewCoverageMeasuresStep.class,
63 CoverageMeasuresStep.class,
64 CommentMeasuresStep.class,
65 CustomMeasuresCopyStep.class,
66 DuplicationMeasuresStep.class,
67 DuplicationDataMeasuresStep.class,
68 NewSizeMeasuresStep.class,
69 LanguageDistributionMeasuresStep.class,
70 UnitTestMeasuresStep.class,
71 ComplexityMeasuresStep.class,
73 LoadMeasureComputersStep.class,
74 ExecuteVisitorsStep.class,
76 // Must be executed after computation of all measures
77 ComputeMeasureVariationsStep.class,
79 // Must be executed after computation of differential measures
80 QualityGateMeasuresStep.class,
81 // Must be executed after computation of language distribution
82 ComputeQProfileMeasureStep.class,
83 // Must be executed after computation of quality profile measure
84 QualityProfileEventsStep.class,
86 // Must be executed after computation of quality gate measure
87 QualityGateEventsStep.class,
90 PersistComponentsStep.class,
91 PersistAnalysisStep.class,
92 PersistDevelopersStep.class,
93 PersistMeasuresStep.class,
94 PersistIssuesStep.class,
95 PersistProjectLinksStep.class,
96 PersistEventsStep.class,
97 PersistFileSourcesStep.class,
98 PersistTestsStep.class,
99 PersistCrossProjectDuplicationIndexStep.class,
100 EnableAnalysisStep.class,
102 UpdateQualityProfilesLastUsedDateStep.class,
103 IndexComponentsStep.class,
104 PurgeDatastoresStep.class,
105 ApplyPermissionsStep.class,
107 // ES indexing is done after all db changes
108 IndexIssuesStep.class,
109 IndexTestsStep.class,
110 IndexProjectMeasuresStep.class,
112 // notifications are sent at the end, so that webapp displays up-to-date information
113 SendIssueNotificationsStep.class,
115 PublishTaskResultStep.class);
117 private final TaskContainer taskContainer;
119 public ReportComputationSteps(TaskContainer taskContainer) {
120 super(taskContainer);
121 this.taskContainer = taskContainer;
125 * List of all {@link ComputationStep},
126 * ordered by execution sequence.
129 public List<Class<? extends ComputationStep>> orderedStepClasses() {
131 .filter(new AllowPersistDevelopersStepIfDevCockpitPluginInstalled(taskContainer))
135 private static class AllowPersistDevelopersStepIfDevCockpitPluginInstalled implements Predicate<Class<? extends ComputationStep>> {
136 private final boolean devCockpitIsInstalled;
138 private AllowPersistDevelopersStepIfDevCockpitPluginInstalled(TaskContainer taskContainer) {
139 this.devCockpitIsInstalled = isDevCockpitInstalled(taskContainer);
142 private static boolean isDevCockpitInstalled(TaskContainer taskContainer) {
143 List<ComponentAdapter<PersistDevelopersDelegate>> componentAdapters = taskContainer.getPicoContainer().getComponentAdapters(PersistDevelopersDelegate.class);
144 return !componentAdapters.isEmpty();
148 public boolean apply(@Nonnull Class<? extends ComputationStep> input) {
149 return devCockpitIsInstalled || !input.equals(PersistDevelopersStep.class);