]> source.dussan.org Git - sonarqube.git/blob
2b7096ffad586816fa1183d5c117b30ff97fe618
[sonarqube.git] /
1 /*
2  * SonarQube
3  * Copyright (C) 2009-2017 SonarSource SA
4  * mailto:info 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.container;
21
22 import java.util.Arrays;
23 import java.util.List;
24 import javax.annotation.Nullable;
25 import org.sonar.ce.organization.DefaultOrganizationLoader;
26 import org.sonar.ce.queue.CeTask;
27 import org.sonar.ce.settings.SettingsLoader;
28 import org.sonar.core.issue.tracking.Tracker;
29 import org.sonar.core.platform.ContainerPopulator;
30 import org.sonar.plugin.ce.ReportAnalysisComponentProvider;
31 import org.sonar.server.computation.task.container.TaskContainer;
32 import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetadataHolderImpl;
33 import org.sonar.server.computation.task.projectanalysis.api.posttask.PostProjectAnalysisTasksExecutor;
34 import org.sonar.server.computation.task.projectanalysis.batch.BatchReportDirectoryHolderImpl;
35 import org.sonar.server.computation.task.projectanalysis.batch.BatchReportReaderImpl;
36 import org.sonar.server.computation.task.projectanalysis.component.DbIdsRepositoryImpl;
37 import org.sonar.server.computation.task.projectanalysis.component.DisabledComponentsHolderImpl;
38 import org.sonar.server.computation.task.projectanalysis.component.SettingsRepositoryImpl;
39 import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderImpl;
40 import org.sonar.server.computation.task.projectanalysis.duplication.CrossProjectDuplicationStatusHolderImpl;
41 import org.sonar.server.computation.task.projectanalysis.duplication.DuplicationRepositoryImpl;
42 import org.sonar.server.computation.task.projectanalysis.duplication.IntegrateCrossProjectDuplications;
43 import org.sonar.server.computation.task.projectanalysis.event.EventRepositoryImpl;
44 import org.sonar.server.computation.task.projectanalysis.filemove.FileSimilarityImpl;
45 import org.sonar.server.computation.task.projectanalysis.filemove.MutableMovedFilesRepositoryImpl;
46 import org.sonar.server.computation.task.projectanalysis.filemove.SourceSimilarityImpl;
47 import org.sonar.server.computation.task.projectanalysis.filesystem.ComputationTempFolderProvider;
48 import org.sonar.server.computation.task.projectanalysis.issue.BaseIssuesLoader;
49 import org.sonar.server.computation.task.projectanalysis.issue.CloseIssuesOnRemovedComponentsVisitor;
50 import org.sonar.server.computation.task.projectanalysis.issue.ComponentIssuesRepositoryImpl;
51 import org.sonar.server.computation.task.projectanalysis.issue.ComponentsWithUnprocessedIssues;
52 import org.sonar.server.computation.task.projectanalysis.issue.DebtCalculator;
53 import org.sonar.server.computation.task.projectanalysis.issue.DefaultAssignee;
54 import org.sonar.server.computation.task.projectanalysis.issue.EffortAggregator;
55 import org.sonar.server.computation.task.projectanalysis.issue.IntegrateIssuesVisitor;
56 import org.sonar.server.computation.task.projectanalysis.issue.IssueAssigner;
57 import org.sonar.server.computation.task.projectanalysis.issue.IssueCache;
58 import org.sonar.server.computation.task.projectanalysis.issue.IssueCounter;
59 import org.sonar.server.computation.task.projectanalysis.issue.IssueCreationDateCalculator;
60 import org.sonar.server.computation.task.projectanalysis.issue.IssueLifecycle;
61 import org.sonar.server.computation.task.projectanalysis.issue.IssueVisitors;
62 import org.sonar.server.computation.task.projectanalysis.issue.LoadComponentUuidsHavingOpenIssuesVisitor;
63 import org.sonar.server.computation.task.projectanalysis.issue.MovedIssueVisitor;
64 import org.sonar.server.computation.task.projectanalysis.issue.NewEffortAggregator;
65 import org.sonar.server.computation.task.projectanalysis.issue.NewEffortCalculator;
66 import org.sonar.server.computation.task.projectanalysis.issue.RuleRepositoryImpl;
67 import org.sonar.server.computation.task.projectanalysis.issue.RuleTagsCopier;
68 import org.sonar.server.computation.task.projectanalysis.issue.RuleTypeCopier;
69 import org.sonar.server.computation.task.projectanalysis.issue.ScmAccountToUser;
70 import org.sonar.server.computation.task.projectanalysis.issue.ScmAccountToUserLoader;
71 import org.sonar.server.computation.task.projectanalysis.issue.TrackerBaseInputFactory;
72 import org.sonar.server.computation.task.projectanalysis.issue.TrackerExecution;
73 import org.sonar.server.computation.task.projectanalysis.issue.TrackerRawInputFactory;
74 import org.sonar.server.computation.task.projectanalysis.issue.UpdateConflictResolver;
75 import org.sonar.server.computation.task.projectanalysis.issue.commonrule.BranchCoverageRule;
76 import org.sonar.server.computation.task.projectanalysis.issue.commonrule.CommentDensityRule;
77 import org.sonar.server.computation.task.projectanalysis.issue.commonrule.CommonRuleEngineImpl;
78 import org.sonar.server.computation.task.projectanalysis.issue.commonrule.DuplicatedBlockRule;
79 import org.sonar.server.computation.task.projectanalysis.issue.commonrule.LineCoverageRule;
80 import org.sonar.server.computation.task.projectanalysis.issue.commonrule.SkippedTestRule;
81 import org.sonar.server.computation.task.projectanalysis.issue.commonrule.TestErrorRule;
82 import org.sonar.server.computation.task.projectanalysis.issue.filter.IssueFilter;
83 import org.sonar.server.computation.task.projectanalysis.language.LanguageRepositoryImpl;
84 import org.sonar.server.computation.task.projectanalysis.measure.MeasureComputersHolderImpl;
85 import org.sonar.server.computation.task.projectanalysis.measure.MeasureComputersVisitor;
86 import org.sonar.server.computation.task.projectanalysis.measure.MeasureRepositoryImpl;
87 import org.sonar.server.computation.task.projectanalysis.measure.MeasureToMeasureDto;
88 import org.sonar.server.computation.task.projectanalysis.metric.MetricModule;
89 import org.sonar.server.computation.task.projectanalysis.period.PeriodHolderImpl;
90 import org.sonar.server.computation.task.projectanalysis.qualitygate.EvaluationResultTextConverterImpl;
91 import org.sonar.server.computation.task.projectanalysis.qualitygate.QualityGateHolderImpl;
92 import org.sonar.server.computation.task.projectanalysis.qualitygate.QualityGateServiceImpl;
93 import org.sonar.server.computation.task.projectanalysis.qualitygate.QualityGateStatusHolderImpl;
94 import org.sonar.server.computation.task.projectanalysis.qualitymodel.MaintainabilityMeasuresVisitor;
95 import org.sonar.server.computation.task.projectanalysis.qualitymodel.NewMaintainabilityMeasuresVisitor;
96 import org.sonar.server.computation.task.projectanalysis.qualitymodel.NewReliabilityAndSecurityRatingMeasuresVisitor;
97 import org.sonar.server.computation.task.projectanalysis.qualitymodel.RatingSettings;
98 import org.sonar.server.computation.task.projectanalysis.qualitymodel.ReliabilityAndSecurityRatingMeasuresVisitor;
99 import org.sonar.server.computation.task.projectanalysis.qualityprofile.ActiveRulesHolderImpl;
100 import org.sonar.server.computation.task.projectanalysis.scm.ScmInfoRepositoryImpl;
101 import org.sonar.server.computation.task.projectanalysis.source.LastCommitVisitor;
102 import org.sonar.server.computation.task.projectanalysis.source.SourceHashRepositoryImpl;
103 import org.sonar.server.computation.task.projectanalysis.source.SourceLinesRepositoryImpl;
104 import org.sonar.server.computation.task.projectanalysis.step.ReportComputationSteps;
105 import org.sonar.server.computation.task.projectanalysis.webhook.WebhookModule;
106 import org.sonar.server.computation.task.step.ComputationStepExecutor;
107 import org.sonar.server.computation.task.step.ComputationSteps;
108 import org.sonar.server.computation.taskprocessor.MutableTaskResultHolderImpl;
109 import org.sonar.server.view.index.ViewIndex;
110
111 public final class ProjectAnalysisTaskContainerPopulator implements ContainerPopulator<TaskContainer> {
112   private static final ReportAnalysisComponentProvider[] NO_REPORT_ANALYSIS_COMPONENT_PROVIDERS = new ReportAnalysisComponentProvider[0];
113
114   private final CeTask task;
115   private final ReportAnalysisComponentProvider[] componentProviders;
116
117   public ProjectAnalysisTaskContainerPopulator(CeTask task, @Nullable ReportAnalysisComponentProvider[] componentProviders) {
118     this.task = task;
119     this.componentProviders = componentProviders == null ? NO_REPORT_ANALYSIS_COMPONENT_PROVIDERS : componentProviders;
120   }
121
122   @Override
123   public void populateContainer(TaskContainer container) {
124     ComputationSteps steps = new ReportComputationSteps(container);
125     container.add(SettingsLoader.class);
126     container.add(DefaultOrganizationLoader.class);
127     container.add(task);
128     container.add(steps);
129     container.addSingletons(componentClasses());
130     for (ReportAnalysisComponentProvider componentProvider : componentProviders) {
131       container.addSingletons(componentProvider.getComponents());
132     }
133     container.addSingletons(steps.orderedStepClasses());
134   }
135
136   /**
137    * List of all objects to be injected in the picocontainer dedicated to computation stack.
138    * Does not contain the steps declared in {@link ReportComputationSteps#orderedStepClasses()}.
139    */
140   private static List<Object> componentClasses() {
141     return Arrays.asList(
142       PostProjectAnalysisTasksExecutor.class,
143       ComputationStepExecutor.class,
144
145       // File System
146       new ComputationTempFolderProvider(),
147
148       MetricModule.class,
149
150       // holders
151       AnalysisMetadataHolderImpl.class,
152       CrossProjectDuplicationStatusHolderImpl.class,
153       BatchReportDirectoryHolderImpl.class,
154       TreeRootHolderImpl.class,
155       PeriodHolderImpl.class,
156       QualityGateHolderImpl.class,
157       QualityGateStatusHolderImpl.class,
158       RatingSettings.class,
159       ActiveRulesHolderImpl.class,
160       MeasureComputersHolderImpl.class,
161       MutableTaskResultHolderImpl.class,
162
163       BatchReportReaderImpl.class,
164
165       // repositories
166       LanguageRepositoryImpl.class,
167       MeasureRepositoryImpl.class,
168       EventRepositoryImpl.class,
169       SettingsRepositoryImpl.class,
170       DbIdsRepositoryImpl.class,
171       DisabledComponentsHolderImpl.class,
172       QualityGateServiceImpl.class,
173       EvaluationResultTextConverterImpl.class,
174       SourceLinesRepositoryImpl.class,
175       SourceHashRepositoryImpl.class,
176       ScmInfoRepositoryImpl.class,
177       DuplicationRepositoryImpl.class,
178
179       // issues
180       RuleRepositoryImpl.class,
181       ScmAccountToUserLoader.class,
182       ScmAccountToUser.class,
183       IssueCache.class,
184       DefaultAssignee.class,
185       IssueVisitors.class,
186       IssueLifecycle.class,
187       ComponentsWithUnprocessedIssues.class,
188       ComponentIssuesRepositoryImpl.class,
189       IssueFilter.class,
190
191       // common rules
192       CommonRuleEngineImpl.class,
193       BranchCoverageRule.class,
194       LineCoverageRule.class,
195       CommentDensityRule.class,
196       DuplicatedBlockRule.class,
197       TestErrorRule.class,
198       SkippedTestRule.class,
199
200       // order is important: RuleTypeCopier must be the first one. And DebtAggregator must be before NewDebtAggregator (new debt requires
201       // debt)
202       RuleTypeCopier.class,
203       RuleTagsCopier.class,
204       IssueCreationDateCalculator.class,
205       DebtCalculator.class,
206       EffortAggregator.class,
207       NewEffortCalculator.class,
208       NewEffortAggregator.class,
209       IssueAssigner.class,
210       IssueCounter.class,
211       MovedIssueVisitor.class,
212
213       // visitors : order is important, measure computers must be executed at the end in order to access to every measures / issues
214       LoadComponentUuidsHavingOpenIssuesVisitor.class,
215       IntegrateIssuesVisitor.class,
216       CloseIssuesOnRemovedComponentsVisitor.class,
217       MaintainabilityMeasuresVisitor.class,
218       NewMaintainabilityMeasuresVisitor.class,
219       ReliabilityAndSecurityRatingMeasuresVisitor.class,
220       NewReliabilityAndSecurityRatingMeasuresVisitor.class,
221       LastCommitVisitor.class,
222       MeasureComputersVisitor.class,
223
224       UpdateConflictResolver.class,
225       TrackerBaseInputFactory.class,
226       TrackerRawInputFactory.class,
227       Tracker.class,
228       TrackerExecution.class,
229       BaseIssuesLoader.class,
230
231       // filemove
232       SourceSimilarityImpl.class,
233       FileSimilarityImpl.class,
234       MutableMovedFilesRepositoryImpl.class,
235
236       // duplication
237       IntegrateCrossProjectDuplications.class,
238
239       // views
240       ViewIndex.class,
241
242       MeasureToMeasureDto.class,
243
244       // webhooks
245       WebhookModule.class);
246   }
247
248 }