3 * Copyright (C) 2009-2017 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.server.computation.task.projectanalysis.container;
22 import java.util.Arrays;
23 import java.util.List;
25 import javax.annotation.Nullable;
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.MovedIssueVisitor;
71 import org.sonar.server.computation.task.projectanalysis.issue.NewEffortAggregator;
72 import org.sonar.server.computation.task.projectanalysis.issue.NewEffortCalculator;
73 import org.sonar.server.computation.task.projectanalysis.issue.RemoveProcessedComponentsVisitor;
74 import org.sonar.server.computation.task.projectanalysis.issue.RuleRepositoryImpl;
75 import org.sonar.server.computation.task.projectanalysis.issue.RuleTagsCopier;
76 import org.sonar.server.computation.task.projectanalysis.issue.RuleTypeCopier;
77 import org.sonar.server.computation.task.projectanalysis.issue.ScmAccountToUser;
78 import org.sonar.server.computation.task.projectanalysis.issue.ScmAccountToUserLoader;
79 import org.sonar.server.computation.task.projectanalysis.issue.ShortBranchTrackerExecution;
80 import org.sonar.server.computation.task.projectanalysis.issue.TrackerBaseInputFactory;
81 import org.sonar.server.computation.task.projectanalysis.issue.TrackerExecution;
82 import org.sonar.server.computation.task.projectanalysis.issue.TrackerMergeBranchInputFactory;
83 import org.sonar.server.computation.task.projectanalysis.issue.TrackerRawInputFactory;
84 import org.sonar.server.computation.task.projectanalysis.issue.UpdateConflictResolver;
85 import org.sonar.server.computation.task.projectanalysis.issue.commonrule.BranchCoverageRule;
86 import org.sonar.server.computation.task.projectanalysis.issue.commonrule.CommentDensityRule;
87 import org.sonar.server.computation.task.projectanalysis.issue.commonrule.CommonRuleEngineImpl;
88 import org.sonar.server.computation.task.projectanalysis.issue.commonrule.DuplicatedBlockRule;
89 import org.sonar.server.computation.task.projectanalysis.issue.commonrule.LineCoverageRule;
90 import org.sonar.server.computation.task.projectanalysis.issue.commonrule.SkippedTestRule;
91 import org.sonar.server.computation.task.projectanalysis.issue.commonrule.TestErrorRule;
92 import org.sonar.server.computation.task.projectanalysis.issue.filter.IssueFilter;
93 import org.sonar.server.computation.task.projectanalysis.language.LanguageRepositoryImpl;
94 import org.sonar.server.computation.task.projectanalysis.measure.MeasureComputersHolderImpl;
95 import org.sonar.server.computation.task.projectanalysis.measure.MeasureComputersVisitor;
96 import org.sonar.server.computation.task.projectanalysis.measure.MeasureRepositoryImpl;
97 import org.sonar.server.computation.task.projectanalysis.measure.MeasureToMeasureDto;
98 import org.sonar.server.computation.task.projectanalysis.metric.MetricModule;
99 import org.sonar.server.computation.task.projectanalysis.period.PeriodHolderImpl;
100 import org.sonar.server.computation.task.projectanalysis.qualitygate.EvaluationResultTextConverterImpl;
101 import org.sonar.server.computation.task.projectanalysis.qualitygate.QualityGateHolderImpl;
102 import org.sonar.server.computation.task.projectanalysis.qualitygate.QualityGateServiceImpl;
103 import org.sonar.server.computation.task.projectanalysis.qualitygate.QualityGateStatusHolderImpl;
104 import org.sonar.server.computation.task.projectanalysis.qualitymodel.MaintainabilityMeasuresVisitor;
105 import org.sonar.server.computation.task.projectanalysis.qualitymodel.NewMaintainabilityMeasuresVisitor;
106 import org.sonar.server.computation.task.projectanalysis.qualitymodel.NewReliabilityAndSecurityRatingMeasuresVisitor;
107 import org.sonar.server.computation.task.projectanalysis.qualitymodel.RatingSettings;
108 import org.sonar.server.computation.task.projectanalysis.qualitymodel.ReliabilityAndSecurityRatingMeasuresVisitor;
109 import org.sonar.server.computation.task.projectanalysis.qualityprofile.ActiveRulesHolderImpl;
110 import org.sonar.server.computation.task.projectanalysis.scm.ScmInfoRepositoryImpl;
111 import org.sonar.server.computation.task.projectanalysis.source.LastCommitVisitor;
112 import org.sonar.server.computation.task.projectanalysis.source.SourceHashRepositoryImpl;
113 import org.sonar.server.computation.task.projectanalysis.source.SourceLinesRepositoryImpl;
114 import org.sonar.server.computation.task.projectanalysis.step.ReportComputationSteps;
115 import org.sonar.server.computation.task.projectanalysis.webhook.WebhookModule;
116 import org.sonar.server.computation.task.step.ComputationStepExecutor;
117 import org.sonar.server.computation.task.step.ComputationSteps;
118 import org.sonar.server.computation.taskprocessor.MutableTaskResultHolderImpl;
119 import org.sonar.server.view.index.ViewIndex;
121 public final class ProjectAnalysisTaskContainerPopulator implements ContainerPopulator<TaskContainer> {
122 private static final ReportAnalysisComponentProvider[] NO_REPORT_ANALYSIS_COMPONENT_PROVIDERS = new ReportAnalysisComponentProvider[0];
124 private final CeTask task;
125 private final ReportAnalysisComponentProvider[] componentProviders;
127 public ProjectAnalysisTaskContainerPopulator(CeTask task, @Nullable ReportAnalysisComponentProvider[] componentProviders) {
129 this.componentProviders = componentProviders == null ? NO_REPORT_ANALYSIS_COMPONENT_PROVIDERS : componentProviders;
133 public void populateContainer(TaskContainer container) {
134 ComputationSteps steps = new ReportComputationSteps(container);
135 container.add(SettingsLoader.class);
136 container.add(DefaultOrganizationLoader.class);
138 container.add(steps);
139 container.addSingletons(componentClasses());
140 for (ReportAnalysisComponentProvider componentProvider : componentProviders) {
141 container.addSingletons(componentProvider.getComponents());
143 container.addSingletons(steps.orderedStepClasses());
147 * List of all objects to be injected in the picocontainer dedicated to computation stack.
148 * Does not contain the steps declared in {@link ReportComputationSteps#orderedStepClasses()}.
150 private static List<Object> componentClasses() {
151 return Arrays.asList(
152 PostProjectAnalysisTasksExecutor.class,
153 ComputationStepExecutor.class,
156 new ComputationTempFolderProvider(),
161 AnalysisMetadataHolderImpl.class,
162 CrossProjectDuplicationStatusHolderImpl.class,
163 BatchReportDirectoryHolderImpl.class,
164 TreeRootHolderImpl.class,
165 PeriodHolderImpl.class,
166 QualityGateHolderImpl.class,
167 QualityGateStatusHolderImpl.class,
168 RatingSettings.class,
169 ActiveRulesHolderImpl.class,
170 MeasureComputersHolderImpl.class,
171 MutableTaskResultHolderImpl.class,
172 BatchReportReaderImpl.class,
175 LanguageRepositoryImpl.class,
176 MeasureRepositoryImpl.class,
177 EventRepositoryImpl.class,
178 ConfigurationRepositoryImpl.class,
179 DbIdsRepositoryImpl.class,
180 DisabledComponentsHolderImpl.class,
181 QualityGateServiceImpl.class,
182 EvaluationResultTextConverterImpl.class,
183 SourceLinesRepositoryImpl.class,
184 SourceHashRepositoryImpl.class,
185 ScmInfoRepositoryImpl.class,
186 DuplicationRepositoryImpl.class,
189 RuleRepositoryImpl.class,
190 ScmAccountToUserLoader.class,
191 ScmAccountToUser.class,
193 DefaultAssignee.class,
195 IssueLifecycle.class,
196 ComponentsWithUnprocessedIssues.class,
197 ComponentIssuesRepositoryImpl.class,
201 CommonRuleEngineImpl.class,
202 BranchCoverageRule.class,
203 LineCoverageRule.class,
204 CommentDensityRule.class,
205 DuplicatedBlockRule.class,
207 SkippedTestRule.class,
209 // order is important: RuleTypeCopier must be the first one. And DebtAggregator must be before NewDebtAggregator (new debt requires
211 RuleTypeCopier.class,
212 RuleTagsCopier.class,
213 IssueCreationDateCalculator.class,
214 DebtCalculator.class,
215 EffortAggregator.class,
216 NewEffortCalculator.class,
217 NewEffortAggregator.class,
220 MovedIssueVisitor.class,
221 IssuesRepositoryVisitor.class,
222 RemoveProcessedComponentsVisitor.class,
224 // visitors : order is important, measure computers must be executed at the end in order to access to every measures / issues
225 LoadComponentUuidsHavingOpenIssuesVisitor.class,
226 IntegrateIssuesVisitor.class,
227 CloseIssuesOnRemovedComponentsVisitor.class,
228 MaintainabilityMeasuresVisitor.class,
229 NewMaintainabilityMeasuresVisitor.class,
230 ReliabilityAndSecurityRatingMeasuresVisitor.class,
231 NewReliabilityAndSecurityRatingMeasuresVisitor.class,
232 LastCommitVisitor.class,
233 MeasureComputersVisitor.class,
235 UpdateConflictResolver.class,
236 TrackerBaseInputFactory.class,
237 TrackerRawInputFactory.class,
238 TrackerMergeBranchInputFactory.class,
240 TrackerExecution.class,
241 ShortBranchTrackerExecution.class,
242 ComponentIssuesLoader.class,
243 BaseIssuesLoader.class,
244 IssueTrackingDelegator.class,
247 SourceSimilarityImpl.class,
248 FileSimilarityImpl.class,
249 MutableMovedFilesRepositoryImpl.class,
252 IntegrateCrossProjectDuplications.class,
253 DuplicationMeasures.class,
259 MeasureToMeasureDto.class,
262 WebhookModule.class);