3 * Copyright (C) 2009-2019 SonarSource SA
4 * mailto:info 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.ce.task.projectanalysis.container;
22 import java.util.Arrays;
23 import java.util.List;
24 import javax.annotation.Nullable;
25 import org.sonar.ce.task.CeTask;
26 import org.sonar.ce.task.container.TaskContainer;
27 import org.sonar.ce.task.log.CeTaskMessagesImpl;
28 import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolderImpl;
29 import org.sonar.ce.task.projectanalysis.api.posttask.PostProjectAnalysisTasksExecutor;
30 import org.sonar.ce.task.projectanalysis.batch.BatchReportDirectoryHolderImpl;
31 import org.sonar.ce.task.projectanalysis.batch.BatchReportReaderImpl;
32 import org.sonar.ce.task.projectanalysis.component.BranchLoader;
33 import org.sonar.ce.task.projectanalysis.component.BranchPersisterImpl;
34 import org.sonar.ce.task.projectanalysis.component.ConfigurationRepositoryImpl;
35 import org.sonar.ce.task.projectanalysis.component.DbIdsRepositoryImpl;
36 import org.sonar.ce.task.projectanalysis.component.DisabledComponentsHolderImpl;
37 import org.sonar.ce.task.projectanalysis.component.MergeAndTargetBranchComponentUuids;
38 import org.sonar.ce.task.projectanalysis.component.ReportModulesPath;
39 import org.sonar.ce.task.projectanalysis.component.SiblingComponentsWithOpenIssues;
40 import org.sonar.ce.task.projectanalysis.component.TreeRootHolderImpl;
41 import org.sonar.ce.task.projectanalysis.dbmigration.DbMigrationModule;
42 import org.sonar.ce.task.projectanalysis.duplication.CrossProjectDuplicationStatusHolderImpl;
43 import org.sonar.ce.task.projectanalysis.duplication.DuplicationMeasures;
44 import org.sonar.ce.task.projectanalysis.duplication.DuplicationRepositoryImpl;
45 import org.sonar.ce.task.projectanalysis.duplication.IntegrateCrossProjectDuplications;
46 import org.sonar.ce.task.projectanalysis.event.EventRepositoryImpl;
47 import org.sonar.ce.task.projectanalysis.filemove.AddedFileRepositoryImpl;
48 import org.sonar.ce.task.projectanalysis.filemove.FileSimilarityImpl;
49 import org.sonar.ce.task.projectanalysis.filemove.MutableMovedFilesRepositoryImpl;
50 import org.sonar.ce.task.projectanalysis.filemove.ScoreMatrixDumperImpl;
51 import org.sonar.ce.task.projectanalysis.filemove.SourceSimilarityImpl;
52 import org.sonar.ce.task.projectanalysis.filesystem.ComputationTempFolderProvider;
53 import org.sonar.ce.task.projectanalysis.issue.BaseIssuesLoader;
54 import org.sonar.ce.task.projectanalysis.issue.CloseIssuesOnRemovedComponentsVisitor;
55 import org.sonar.ce.task.projectanalysis.issue.ClosedIssuesInputFactory;
56 import org.sonar.ce.task.projectanalysis.issue.ComponentIssuesLoader;
57 import org.sonar.ce.task.projectanalysis.issue.ComponentIssuesRepositoryImpl;
58 import org.sonar.ce.task.projectanalysis.issue.ComponentsWithUnprocessedIssues;
59 import org.sonar.ce.task.projectanalysis.issue.DebtCalculator;
60 import org.sonar.ce.task.projectanalysis.issue.DefaultAssignee;
61 import org.sonar.ce.task.projectanalysis.issue.EffortAggregator;
62 import org.sonar.ce.task.projectanalysis.issue.IntegrateIssuesVisitor;
63 import org.sonar.ce.task.projectanalysis.issue.IssueAssigner;
64 import org.sonar.ce.task.projectanalysis.issue.IssueCache;
65 import org.sonar.ce.task.projectanalysis.issue.IssueCounter;
66 import org.sonar.ce.task.projectanalysis.issue.IssueCreationDateCalculator;
67 import org.sonar.ce.task.projectanalysis.issue.IssueLifecycle;
68 import org.sonar.ce.task.projectanalysis.issue.IssueTrackingDelegator;
69 import org.sonar.ce.task.projectanalysis.issue.IssueVisitors;
70 import org.sonar.ce.task.projectanalysis.issue.IssuesRepositoryVisitor;
71 import org.sonar.ce.task.projectanalysis.issue.LoadComponentUuidsHavingOpenIssuesVisitor;
72 import org.sonar.ce.task.projectanalysis.issue.MergeBranchTrackerExecution;
73 import org.sonar.ce.task.projectanalysis.issue.MovedIssueVisitor;
74 import org.sonar.ce.task.projectanalysis.issue.NewEffortAggregator;
75 import org.sonar.ce.task.projectanalysis.issue.RemoveProcessedComponentsVisitor;
76 import org.sonar.ce.task.projectanalysis.issue.RuleRepositoryImpl;
77 import org.sonar.ce.task.projectanalysis.issue.RuleTagsCopier;
78 import org.sonar.ce.task.projectanalysis.issue.ScmAccountToUser;
79 import org.sonar.ce.task.projectanalysis.issue.ScmAccountToUserLoader;
80 import org.sonar.ce.task.projectanalysis.issue.SiblingsIssueMerger;
81 import org.sonar.ce.task.projectanalysis.issue.SiblingsIssuesLoader;
82 import org.sonar.ce.task.projectanalysis.issue.ShortBranchOrPullRequestTrackerExecution;
83 import org.sonar.ce.task.projectanalysis.issue.TrackerBaseInputFactory;
84 import org.sonar.ce.task.projectanalysis.issue.TrackerExecution;
85 import org.sonar.ce.task.projectanalysis.issue.TrackerMergeOrTargetBranchInputFactory;
86 import org.sonar.ce.task.projectanalysis.issue.TrackerRawInputFactory;
87 import org.sonar.ce.task.projectanalysis.issue.UpdateConflictResolver;
88 import org.sonar.ce.task.projectanalysis.issue.commonrule.BranchCoverageRule;
89 import org.sonar.ce.task.projectanalysis.issue.commonrule.CommentDensityRule;
90 import org.sonar.ce.task.projectanalysis.issue.commonrule.CommonRuleEngineImpl;
91 import org.sonar.ce.task.projectanalysis.issue.commonrule.DuplicatedBlockRule;
92 import org.sonar.ce.task.projectanalysis.issue.commonrule.LineCoverageRule;
93 import org.sonar.ce.task.projectanalysis.issue.commonrule.SkippedTestRule;
94 import org.sonar.ce.task.projectanalysis.issue.commonrule.TestErrorRule;
95 import org.sonar.ce.task.projectanalysis.issue.filter.IssueFilter;
96 import org.sonar.ce.task.projectanalysis.language.LanguageRepositoryImpl;
97 import org.sonar.ce.task.projectanalysis.measure.MeasureComputersHolderImpl;
98 import org.sonar.ce.task.projectanalysis.measure.MeasureComputersVisitor;
99 import org.sonar.ce.task.projectanalysis.measure.MeasureRepositoryImpl;
100 import org.sonar.ce.task.projectanalysis.measure.MeasureToMeasureDto;
101 import org.sonar.ce.task.projectanalysis.metric.MetricModule;
102 import org.sonar.ce.task.projectanalysis.notification.NotificationFactory;
103 import org.sonar.ce.task.projectanalysis.organization.DefaultOrganizationLoader;
104 import org.sonar.ce.task.projectanalysis.period.PeriodHolderImpl;
105 import org.sonar.ce.task.projectanalysis.qualitygate.EvaluationResultTextConverterImpl;
106 import org.sonar.ce.task.projectanalysis.qualitygate.QualityGateHolderImpl;
107 import org.sonar.ce.task.projectanalysis.qualitygate.QualityGateServiceImpl;
108 import org.sonar.ce.task.projectanalysis.qualitygate.QualityGateStatusHolderImpl;
109 import org.sonar.ce.task.projectanalysis.qualitymodel.MaintainabilityMeasuresVisitor;
110 import org.sonar.ce.task.projectanalysis.qualitymodel.NewMaintainabilityMeasuresVisitor;
111 import org.sonar.ce.task.projectanalysis.qualitymodel.NewReliabilityAndSecurityRatingMeasuresVisitor;
112 import org.sonar.ce.task.projectanalysis.qualitymodel.RatingSettings;
113 import org.sonar.ce.task.projectanalysis.qualitymodel.ReliabilityAndSecurityRatingMeasuresVisitor;
114 import org.sonar.ce.task.projectanalysis.qualityprofile.ActiveRulesHolderImpl;
115 import org.sonar.ce.task.projectanalysis.qualityprofile.QProfileStatusRepositoryImpl;
116 import org.sonar.ce.task.projectanalysis.scm.ScmInfoDbLoader;
117 import org.sonar.ce.task.projectanalysis.scm.ScmInfoRepositoryImpl;
118 import org.sonar.ce.task.projectanalysis.source.DbLineHashVersion;
119 import org.sonar.ce.task.projectanalysis.source.FileSourceDataComputer;
120 import org.sonar.ce.task.projectanalysis.source.FileSourceDataWarnings;
121 import org.sonar.ce.task.projectanalysis.source.LastCommitVisitor;
122 import org.sonar.ce.task.projectanalysis.source.NewLinesRepository;
123 import org.sonar.ce.task.projectanalysis.source.SignificantCodeRepository;
124 import org.sonar.ce.task.projectanalysis.source.SourceHashRepositoryImpl;
125 import org.sonar.ce.task.projectanalysis.source.SourceLineReadersFactory;
126 import org.sonar.ce.task.projectanalysis.source.SourceLinesDiffImpl;
127 import org.sonar.ce.task.projectanalysis.source.SourceLinesHashCache;
128 import org.sonar.ce.task.projectanalysis.source.SourceLinesHashRepositoryImpl;
129 import org.sonar.ce.task.projectanalysis.source.SourceLinesRepositoryImpl;
130 import org.sonar.ce.task.projectanalysis.step.ReportComputationSteps;
131 import org.sonar.ce.task.projectanalysis.step.SmallChangesetQualityGateSpecialCase;
132 import org.sonar.ce.task.projectanalysis.webhook.WebhookPostTask;
133 import org.sonar.ce.task.setting.SettingsLoader;
134 import org.sonar.ce.task.step.ComputationStepExecutor;
135 import org.sonar.ce.task.step.ComputationSteps;
136 import org.sonar.ce.task.taskprocessor.MutableTaskResultHolderImpl;
137 import org.sonar.core.issue.tracking.Tracker;
138 import org.sonar.core.platform.ContainerPopulator;
139 import org.sonar.server.view.index.ViewIndex;
141 public final class ProjectAnalysisTaskContainerPopulator implements ContainerPopulator<TaskContainer> {
142 private static final ReportAnalysisComponentProvider[] NO_REPORT_ANALYSIS_COMPONENT_PROVIDERS = new ReportAnalysisComponentProvider[0];
144 private final CeTask task;
145 private final ReportAnalysisComponentProvider[] componentProviders;
147 public ProjectAnalysisTaskContainerPopulator(CeTask task, @Nullable ReportAnalysisComponentProvider[] componentProviders) {
149 this.componentProviders = componentProviders == null ? NO_REPORT_ANALYSIS_COMPONENT_PROVIDERS : componentProviders;
153 public void populateContainer(TaskContainer container) {
154 ComputationSteps steps = new ReportComputationSteps(container);
155 container.add(SettingsLoader.class);
156 container.add(DefaultOrganizationLoader.class);
158 container.add(steps);
159 container.addSingletons(componentClasses());
160 for (ReportAnalysisComponentProvider componentProvider : componentProviders) {
161 container.addSingletons(componentProvider.getComponents());
163 container.addSingletons(steps.orderedStepClasses());
167 * List of all objects to be injected in the picocontainer dedicated to computation stack.
168 * Does not contain the steps declared in {@link ReportComputationSteps#orderedStepClasses()}.
170 private static List<Object> componentClasses() {
171 return Arrays.asList(
172 PostProjectAnalysisTasksExecutor.class,
173 ComputationStepExecutor.class,
176 CeTaskMessagesImpl.class,
177 FileSourceDataWarnings.class,
180 new ComputationTempFolderProvider(),
182 DbMigrationModule.class,
183 ReportModulesPath.class,
187 AnalysisMetadataHolderImpl.class,
188 CrossProjectDuplicationStatusHolderImpl.class,
189 BatchReportDirectoryHolderImpl.class,
190 TreeRootHolderImpl.class,
191 PeriodHolderImpl.class,
192 QualityGateHolderImpl.class,
193 QualityGateStatusHolderImpl.class,
194 RatingSettings.class,
195 ActiveRulesHolderImpl.class,
196 MeasureComputersHolderImpl.class,
197 MutableTaskResultHolderImpl.class,
198 BatchReportReaderImpl.class,
199 MergeAndTargetBranchComponentUuids.class,
200 SiblingComponentsWithOpenIssues.class,
203 LanguageRepositoryImpl.class,
204 MeasureRepositoryImpl.class,
205 EventRepositoryImpl.class,
206 ConfigurationRepositoryImpl.class,
207 DbIdsRepositoryImpl.class,
208 DisabledComponentsHolderImpl.class,
209 QualityGateServiceImpl.class,
210 EvaluationResultTextConverterImpl.class,
211 SourceLinesRepositoryImpl.class,
212 SourceHashRepositoryImpl.class,
213 SourceLinesDiffImpl.class,
214 ScmInfoRepositoryImpl.class,
215 ScmInfoDbLoader.class,
216 DuplicationRepositoryImpl.class,
217 SourceLinesHashRepositoryImpl.class,
218 DbLineHashVersion.class,
219 SignificantCodeRepository.class,
220 SourceLinesHashCache.class,
221 NewLinesRepository.class,
222 FileSourceDataComputer.class,
223 SourceLineReadersFactory.class,
224 QProfileStatusRepositoryImpl.class,
227 RuleRepositoryImpl.class,
228 ScmAccountToUserLoader.class,
229 ScmAccountToUser.class,
231 DefaultAssignee.class,
233 IssueLifecycle.class,
234 ComponentsWithUnprocessedIssues.class,
235 ComponentIssuesRepositoryImpl.class,
239 CommonRuleEngineImpl.class,
240 BranchCoverageRule.class,
241 LineCoverageRule.class,
242 CommentDensityRule.class,
243 DuplicatedBlockRule.class,
245 SkippedTestRule.class,
247 // order is important: RuleTypeCopier must be the first one. And DebtAggregator must be before NewDebtAggregator (new debt requires
249 RuleTagsCopier.class,
250 IssueCreationDateCalculator.class,
251 DebtCalculator.class,
252 EffortAggregator.class,
253 NewEffortAggregator.class,
256 MovedIssueVisitor.class,
257 IssuesRepositoryVisitor.class,
258 RemoveProcessedComponentsVisitor.class,
260 // visitors : order is important, measure computers must be executed at the end in order to access to every measures / issues
261 LoadComponentUuidsHavingOpenIssuesVisitor.class,
262 IntegrateIssuesVisitor.class,
263 CloseIssuesOnRemovedComponentsVisitor.class,
264 MaintainabilityMeasuresVisitor.class,
265 NewMaintainabilityMeasuresVisitor.class,
266 ReliabilityAndSecurityRatingMeasuresVisitor.class,
267 NewReliabilityAndSecurityRatingMeasuresVisitor.class,
268 LastCommitVisitor.class,
269 MeasureComputersVisitor.class,
271 UpdateConflictResolver.class,
272 TrackerBaseInputFactory.class,
273 TrackerRawInputFactory.class,
274 TrackerMergeOrTargetBranchInputFactory.class,
275 ClosedIssuesInputFactory.class,
277 TrackerExecution.class,
278 ShortBranchOrPullRequestTrackerExecution.class,
279 MergeBranchTrackerExecution.class,
280 ComponentIssuesLoader.class,
281 BaseIssuesLoader.class,
282 IssueTrackingDelegator.class,
283 BranchPersisterImpl.class,
284 SiblingsIssuesLoader.class,
285 SiblingsIssueMerger.class,
288 ScoreMatrixDumperImpl.class,
289 SourceSimilarityImpl.class,
290 FileSimilarityImpl.class,
291 MutableMovedFilesRepositoryImpl.class,
292 AddedFileRepositoryImpl.class,
295 IntegrateCrossProjectDuplications.class,
296 DuplicationMeasures.class,
302 MeasureToMeasureDto.class,
303 SmallChangesetQualityGateSpecialCase.class,
306 WebhookPostTask.class,
309 NotificationFactory.class);