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