]> source.dussan.org Git - sonarqube.git/blob
7785c691bd2a865508c83efa10727226719d5b81
[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     LogScannerContextStep.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     NewDuplicationMeasuresStep.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
111     // notifications are sent at the end, so that webapp displays up-to-date information
112     SendIssueNotificationsStep.class,
113
114     PublishTaskResultStep.class);
115
116   private final TaskContainer taskContainer;
117
118   public ReportComputationSteps(TaskContainer taskContainer) {
119     super(taskContainer);
120     this.taskContainer = taskContainer;
121   }
122
123   /**
124    * List of all {@link ComputationStep},
125    * ordered by execution sequence.
126    */
127   @Override
128   public List<Class<? extends ComputationStep>> orderedStepClasses() {
129     return from(STEPS)
130       .filter(new AllowPersistDevelopersStepIfDevCockpitPluginInstalled(taskContainer))
131       .toList();
132   }
133
134   private static class AllowPersistDevelopersStepIfDevCockpitPluginInstalled implements Predicate<Class<? extends ComputationStep>> {
135     private final boolean devCockpitIsInstalled;
136
137     private AllowPersistDevelopersStepIfDevCockpitPluginInstalled(TaskContainer taskContainer) {
138       this.devCockpitIsInstalled = isDevCockpitInstalled(taskContainer);
139     }
140
141     private static boolean isDevCockpitInstalled(TaskContainer taskContainer) {
142       List<ComponentAdapter<PersistDevelopersDelegate>> componentAdapters = taskContainer.getPicoContainer().getComponentAdapters(PersistDevelopersDelegate.class);
143       return !componentAdapters.isEmpty();
144     }
145
146     @Override
147     public boolean apply(@Nonnull Class<? extends ComputationStep> input) {
148       return devCockpitIsInstalled || !input.equals(PersistDevelopersStep.class);
149     }
150   }
151
152 }