3 * Copyright (C) 2009-2020 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.ProjectPersister;
38 import org.sonar.ce.task.projectanalysis.component.ReferenceBranchComponentUuids;
39 import org.sonar.ce.task.projectanalysis.component.ReportModulesPath;
40 import org.sonar.ce.task.projectanalysis.component.SiblingComponentsWithOpenIssues;
41 import org.sonar.ce.task.projectanalysis.component.TreeRootHolderImpl;
42 import org.sonar.ce.task.projectanalysis.dbmigration.DbMigrationModule;
43 import org.sonar.ce.task.projectanalysis.duplication.CrossProjectDuplicationStatusHolderImpl;
44 import org.sonar.ce.task.projectanalysis.duplication.DuplicationMeasures;
45 import org.sonar.ce.task.projectanalysis.duplication.DuplicationRepositoryImpl;
46 import org.sonar.ce.task.projectanalysis.duplication.IntegrateCrossProjectDuplications;
47 import org.sonar.ce.task.projectanalysis.event.EventRepositoryImpl;
48 import org.sonar.ce.task.projectanalysis.filemove.AddedFileRepositoryImpl;
49 import org.sonar.ce.task.projectanalysis.filemove.FileSimilarityImpl;
50 import org.sonar.ce.task.projectanalysis.filemove.MutableMovedFilesRepositoryImpl;
51 import org.sonar.ce.task.projectanalysis.filemove.ScoreMatrixDumperImpl;
52 import org.sonar.ce.task.projectanalysis.filemove.SourceSimilarityImpl;
53 import org.sonar.ce.task.projectanalysis.filesystem.ComputationTempFolderProvider;
54 import org.sonar.ce.task.projectanalysis.issue.BaseIssuesLoader;
55 import org.sonar.ce.task.projectanalysis.issue.CloseIssuesOnRemovedComponentsVisitor;
56 import org.sonar.ce.task.projectanalysis.issue.ClosedIssuesInputFactory;
57 import org.sonar.ce.task.projectanalysis.issue.ComponentIssuesLoader;
58 import org.sonar.ce.task.projectanalysis.issue.ComponentIssuesRepositoryImpl;
59 import org.sonar.ce.task.projectanalysis.issue.ComponentsWithUnprocessedIssues;
60 import org.sonar.ce.task.projectanalysis.issue.DebtCalculator;
61 import org.sonar.ce.task.projectanalysis.issue.DefaultAssignee;
62 import org.sonar.ce.task.projectanalysis.issue.EffortAggregator;
63 import org.sonar.ce.task.projectanalysis.issue.IntegrateIssuesVisitor;
64 import org.sonar.ce.task.projectanalysis.issue.IssueAssigner;
65 import org.sonar.ce.task.projectanalysis.issue.IssueCache;
66 import org.sonar.ce.task.projectanalysis.issue.IssueCounter;
67 import org.sonar.ce.task.projectanalysis.issue.IssueCreationDateCalculator;
68 import org.sonar.ce.task.projectanalysis.issue.IssueLifecycle;
69 import org.sonar.ce.task.projectanalysis.issue.IssueTrackingDelegator;
70 import org.sonar.ce.task.projectanalysis.issue.IssueVisitors;
71 import org.sonar.ce.task.projectanalysis.issue.IssuesRepositoryVisitor;
72 import org.sonar.ce.task.projectanalysis.issue.LoadComponentUuidsHavingOpenIssuesVisitor;
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.PullRequestTrackerExecution;
76 import org.sonar.ce.task.projectanalysis.issue.ReferenceBranchTrackerExecution;
77 import org.sonar.ce.task.projectanalysis.issue.RemoveProcessedComponentsVisitor;
78 import org.sonar.ce.task.projectanalysis.issue.RuleRepositoryImpl;
79 import org.sonar.ce.task.projectanalysis.issue.RuleTagsCopier;
80 import org.sonar.ce.task.projectanalysis.issue.ScmAccountToUser;
81 import org.sonar.ce.task.projectanalysis.issue.ScmAccountToUserLoader;
82 import org.sonar.ce.task.projectanalysis.issue.SiblingsIssueMerger;
83 import org.sonar.ce.task.projectanalysis.issue.SiblingsIssuesLoader;
84 import org.sonar.ce.task.projectanalysis.issue.TrackerBaseInputFactory;
85 import org.sonar.ce.task.projectanalysis.issue.TrackerExecution;
86 import org.sonar.ce.task.projectanalysis.issue.TrackerRawInputFactory;
87 import org.sonar.ce.task.projectanalysis.issue.TrackerReferenceBranchInputFactory;
88 import org.sonar.ce.task.projectanalysis.issue.UpdateConflictResolver;
89 import org.sonar.ce.task.projectanalysis.issue.commonrule.BranchCoverageRule;
90 import org.sonar.ce.task.projectanalysis.issue.commonrule.CommentDensityRule;
91 import org.sonar.ce.task.projectanalysis.issue.commonrule.CommonRuleEngineImpl;
92 import org.sonar.ce.task.projectanalysis.issue.commonrule.DuplicatedBlockRule;
93 import org.sonar.ce.task.projectanalysis.issue.commonrule.LineCoverageRule;
94 import org.sonar.ce.task.projectanalysis.issue.commonrule.SkippedTestRule;
95 import org.sonar.ce.task.projectanalysis.issue.commonrule.TestErrorRule;
96 import org.sonar.ce.task.projectanalysis.issue.filter.IssueFilter;
97 import org.sonar.ce.task.projectanalysis.language.LanguageRepositoryImpl;
98 import org.sonar.ce.task.projectanalysis.measure.MeasureComputersHolderImpl;
99 import org.sonar.ce.task.projectanalysis.measure.MeasureComputersVisitor;
100 import org.sonar.ce.task.projectanalysis.measure.MeasureRepositoryImpl;
101 import org.sonar.ce.task.projectanalysis.measure.MeasureToMeasureDto;
102 import org.sonar.ce.task.projectanalysis.metric.MetricModule;
103 import org.sonar.ce.task.projectanalysis.notification.NotificationFactory;
104 import org.sonar.ce.task.projectanalysis.organization.DefaultOrganizationLoader;
105 import org.sonar.ce.task.projectanalysis.period.NewCodePeriodResolver;
106 import org.sonar.ce.task.projectanalysis.period.PeriodHolderImpl;
107 import org.sonar.ce.task.projectanalysis.qualitygate.EvaluationResultTextConverterImpl;
108 import org.sonar.ce.task.projectanalysis.qualitygate.QualityGateHolderImpl;
109 import org.sonar.ce.task.projectanalysis.qualitygate.QualityGateServiceImpl;
110 import org.sonar.ce.task.projectanalysis.qualitygate.QualityGateStatusHolderImpl;
111 import org.sonar.ce.task.projectanalysis.qualitymodel.MaintainabilityMeasuresVisitor;
112 import org.sonar.ce.task.projectanalysis.qualitymodel.NewMaintainabilityMeasuresVisitor;
113 import org.sonar.ce.task.projectanalysis.qualitymodel.NewReliabilityAndSecurityRatingMeasuresVisitor;
114 import org.sonar.ce.task.projectanalysis.qualitymodel.NewSecurityReviewMeasuresVisitor;
115 import org.sonar.ce.task.projectanalysis.qualitymodel.RatingSettings;
116 import org.sonar.ce.task.projectanalysis.qualitymodel.ReliabilityAndSecurityRatingMeasuresVisitor;
117 import org.sonar.ce.task.projectanalysis.qualitymodel.SecurityReviewMeasuresVisitor;
118 import org.sonar.ce.task.projectanalysis.qualityprofile.ActiveRulesHolderImpl;
119 import org.sonar.ce.task.projectanalysis.qualityprofile.QProfileStatusRepositoryImpl;
120 import org.sonar.ce.task.projectanalysis.scm.ScmInfoDbLoader;
121 import org.sonar.ce.task.projectanalysis.scm.ScmInfoRepositoryImpl;
122 import org.sonar.ce.task.projectanalysis.source.DbLineHashVersion;
123 import org.sonar.ce.task.projectanalysis.source.FileSourceDataComputer;
124 import org.sonar.ce.task.projectanalysis.source.FileSourceDataWarnings;
125 import org.sonar.ce.task.projectanalysis.source.LastCommitVisitor;
126 import org.sonar.ce.task.projectanalysis.source.NewLinesRepository;
127 import org.sonar.ce.task.projectanalysis.source.SignificantCodeRepository;
128 import org.sonar.ce.task.projectanalysis.source.SourceHashRepositoryImpl;
129 import org.sonar.ce.task.projectanalysis.source.SourceLineReadersFactory;
130 import org.sonar.ce.task.projectanalysis.source.SourceLinesDiffImpl;
131 import org.sonar.ce.task.projectanalysis.source.SourceLinesHashCache;
132 import org.sonar.ce.task.projectanalysis.source.SourceLinesHashRepositoryImpl;
133 import org.sonar.ce.task.projectanalysis.source.SourceLinesRepositoryImpl;
134 import org.sonar.ce.task.projectanalysis.step.ReportComputationSteps;
135 import org.sonar.ce.task.projectanalysis.step.SmallChangesetQualityGateSpecialCase;
136 import org.sonar.ce.task.projectanalysis.webhook.WebhookPostTask;
137 import org.sonar.ce.task.setting.SettingsLoader;
138 import org.sonar.ce.task.step.ComputationStepExecutor;
139 import org.sonar.ce.task.step.ComputationSteps;
140 import org.sonar.ce.task.taskprocessor.MutableTaskResultHolderImpl;
141 import org.sonar.core.issue.tracking.Tracker;
142 import org.sonar.core.platform.ContainerPopulator;
143 import org.sonar.server.view.index.ViewIndex;
145 public final class ProjectAnalysisTaskContainerPopulator implements ContainerPopulator<TaskContainer> {
146 private static final ReportAnalysisComponentProvider[] NO_REPORT_ANALYSIS_COMPONENT_PROVIDERS = new ReportAnalysisComponentProvider[0];
148 private final CeTask task;
149 private final ReportAnalysisComponentProvider[] componentProviders;
151 public ProjectAnalysisTaskContainerPopulator(CeTask task, @Nullable ReportAnalysisComponentProvider[] componentProviders) {
153 this.componentProviders = componentProviders == null ? NO_REPORT_ANALYSIS_COMPONENT_PROVIDERS : componentProviders;
157 public void populateContainer(TaskContainer container) {
158 ComputationSteps steps = new ReportComputationSteps(container);
159 container.add(SettingsLoader.class);
160 container.add(DefaultOrganizationLoader.class);
162 container.add(steps);
163 container.addSingletons(componentClasses());
164 for (ReportAnalysisComponentProvider componentProvider : componentProviders) {
165 container.addSingletons(componentProvider.getComponents());
167 container.addSingletons(steps.orderedStepClasses());
171 * List of all objects to be injected in the picocontainer dedicated to computation stack.
172 * Does not contain the steps declared in {@link ReportComputationSteps#orderedStepClasses()}.
174 private static List<Object> componentClasses() {
175 return Arrays.asList(
176 PostProjectAnalysisTasksExecutor.class,
177 ComputationStepExecutor.class,
180 CeTaskMessagesImpl.class,
181 FileSourceDataWarnings.class,
184 new ComputationTempFolderProvider(),
186 DbMigrationModule.class,
187 ReportModulesPath.class,
191 AnalysisMetadataHolderImpl.class,
192 CrossProjectDuplicationStatusHolderImpl.class,
193 BatchReportDirectoryHolderImpl.class,
194 TreeRootHolderImpl.class,
195 PeriodHolderImpl.class,
196 QualityGateHolderImpl.class,
197 QualityGateStatusHolderImpl.class,
198 RatingSettings.class,
199 ActiveRulesHolderImpl.class,
200 MeasureComputersHolderImpl.class,
201 MutableTaskResultHolderImpl.class,
202 BatchReportReaderImpl.class,
203 ReferenceBranchComponentUuids.class,
204 SiblingComponentsWithOpenIssues.class,
207 LanguageRepositoryImpl.class,
208 MeasureRepositoryImpl.class,
209 EventRepositoryImpl.class,
210 ConfigurationRepositoryImpl.class,
211 DbIdsRepositoryImpl.class,
212 DisabledComponentsHolderImpl.class,
213 QualityGateServiceImpl.class,
214 EvaluationResultTextConverterImpl.class,
215 SourceLinesRepositoryImpl.class,
216 SourceHashRepositoryImpl.class,
217 SourceLinesDiffImpl.class,
218 ScmInfoRepositoryImpl.class,
219 ScmInfoDbLoader.class,
220 DuplicationRepositoryImpl.class,
221 SourceLinesHashRepositoryImpl.class,
222 DbLineHashVersion.class,
223 SignificantCodeRepository.class,
224 SourceLinesHashCache.class,
225 NewLinesRepository.class,
226 FileSourceDataComputer.class,
227 SourceLineReadersFactory.class,
228 QProfileStatusRepositoryImpl.class,
231 RuleRepositoryImpl.class,
232 ScmAccountToUserLoader.class,
233 ScmAccountToUser.class,
235 DefaultAssignee.class,
237 IssueLifecycle.class,
238 ComponentsWithUnprocessedIssues.class,
239 ComponentIssuesRepositoryImpl.class,
243 CommonRuleEngineImpl.class,
244 BranchCoverageRule.class,
245 LineCoverageRule.class,
246 CommentDensityRule.class,
247 DuplicatedBlockRule.class,
249 SkippedTestRule.class,
251 // order is important: RuleTypeCopier must be the first one. And DebtAggregator must be before NewDebtAggregator (new debt requires
253 RuleTagsCopier.class,
254 IssueCreationDateCalculator.class,
255 DebtCalculator.class,
256 EffortAggregator.class,
257 NewEffortAggregator.class,
260 MovedIssueVisitor.class,
261 IssuesRepositoryVisitor.class,
262 RemoveProcessedComponentsVisitor.class,
264 // visitors : order is important, measure computers must be executed at the end in order to access to every measures / issues
265 LoadComponentUuidsHavingOpenIssuesVisitor.class,
266 IntegrateIssuesVisitor.class,
267 CloseIssuesOnRemovedComponentsVisitor.class,
268 MaintainabilityMeasuresVisitor.class,
269 NewMaintainabilityMeasuresVisitor.class,
270 ReliabilityAndSecurityRatingMeasuresVisitor.class,
271 NewReliabilityAndSecurityRatingMeasuresVisitor.class,
272 SecurityReviewMeasuresVisitor.class,
273 NewSecurityReviewMeasuresVisitor.class,
274 LastCommitVisitor.class,
275 MeasureComputersVisitor.class,
277 UpdateConflictResolver.class,
278 TrackerBaseInputFactory.class,
279 TrackerRawInputFactory.class,
280 TrackerReferenceBranchInputFactory.class,
281 ClosedIssuesInputFactory.class,
283 TrackerExecution.class,
284 PullRequestTrackerExecution.class,
285 ReferenceBranchTrackerExecution.class,
286 ComponentIssuesLoader.class,
287 BaseIssuesLoader.class,
288 IssueTrackingDelegator.class,
289 BranchPersisterImpl.class,
290 ProjectPersister.class,
291 SiblingsIssuesLoader.class,
292 SiblingsIssueMerger.class,
293 NewCodePeriodResolver.class,
296 ScoreMatrixDumperImpl.class,
297 SourceSimilarityImpl.class,
298 FileSimilarityImpl.class,
299 MutableMovedFilesRepositoryImpl.class,
300 AddedFileRepositoryImpl.class,
303 IntegrateCrossProjectDuplications.class,
304 DuplicationMeasures.class,
310 MeasureToMeasureDto.class,
311 SmallChangesetQualityGateSpecialCase.class,
314 WebhookPostTask.class,
317 NotificationFactory.class);