]> source.dussan.org Git - sonarqube.git/blob
55c66df8e5c53ca668ce428890db369cdeffd21d
[sonarqube.git] /
1 /*
2  * SonarQube
3  * Copyright (C) 2009-2016 SonarSource SA
4  * mailto:contact AT sonarsource DOT com
5  *
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.
10  *
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.
15  *
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.
19  */
20 package org.sonar.server.computation.task.projectanalysis.step;
21
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;
31
32 import static com.google.common.collect.FluentIterable.from;
33
34 /**
35  * Ordered list of steps classes and instances to be executed for batch processing
36  */
37 public class ReportComputationSteps extends AbstractComputationSteps {
38
39   private static final List<Class<? extends ComputationStep>> STEPS = Arrays.asList(
40     ExtractReportStep.class,
41     PersistScannerContextStep.class,
42     GenerateAnalysisUuid.class,
43
44     // Builds Component tree
45     LoadReportAnalysisMetadataHolderStep.class,
46     BuildComponentTreeStep.class,
47     ValidateProjectStep.class,
48
49     LoadQualityProfilesStep.class,
50
51     // load project related stuffs
52     LoadQualityGateStep.class,
53     LoadPeriodsStep.class,
54     FileMoveDetectionStep.class,
55
56     // load duplications related stuff
57     LoadDuplicationsFromReportStep.class,
58     LoadCrossProjectDuplicationsRepositoryStep.class,
59
60     // data computation
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,
72
73     LoadMeasureComputersStep.class,
74     ExecuteVisitorsStep.class,
75
76     // Must be executed after computation of all measures
77     ComputeMeasureVariationsStep.class,
78
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,
85
86     // Must be executed after computation of quality gate measure
87     QualityGateEventsStep.class,
88
89     // Persist data
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,
101
102     UpdateQualityProfilesLastUsedDateStep.class,
103     IndexComponentsStep.class,
104     PurgeDatastoresStep.class,
105     ApplyPermissionsStep.class,
106
107     // ES indexing is done after all db changes
108     IndexIssuesStep.class,
109     IndexTestsStep.class,
110     IndexProjectMeasuresStep.class,
111
112     // notifications are sent at the end, so that webapp displays up-to-date information
113     SendIssueNotificationsStep.class,
114
115     PublishTaskResultStep.class);
116
117   private final TaskContainer taskContainer;
118
119   public ReportComputationSteps(TaskContainer taskContainer) {
120     super(taskContainer);
121     this.taskContainer = taskContainer;
122   }
123
124   /**
125    * List of all {@link ComputationStep},
126    * ordered by execution sequence.
127    */
128   @Override
129   public List<Class<? extends ComputationStep>> orderedStepClasses() {
130     return from(STEPS)
131       .filter(new AllowPersistDevelopersStepIfDevCockpitPluginInstalled(taskContainer))
132       .toList();
133   }
134
135   private static class AllowPersistDevelopersStepIfDevCockpitPluginInstalled implements Predicate<Class<? extends ComputationStep>> {
136     private final boolean devCockpitIsInstalled;
137
138     private AllowPersistDevelopersStepIfDevCockpitPluginInstalled(TaskContainer taskContainer) {
139       this.devCockpitIsInstalled = isDevCockpitInstalled(taskContainer);
140     }
141
142     private static boolean isDevCockpitInstalled(TaskContainer taskContainer) {
143       List<ComponentAdapter<PersistDevelopersDelegate>> componentAdapters = taskContainer.getPicoContainer().getComponentAdapters(PersistDevelopersDelegate.class);
144       return !componentAdapters.isEmpty();
145     }
146
147     @Override
148     public boolean apply(@Nonnull Class<? extends ComputationStep> input) {
149       return devCockpitIsInstalled || !input.equals(PersistDevelopersStep.class);
150     }
151   }
152
153 }