]> source.dussan.org Git - sonarqube.git/blob
b2cad5537cb939332451efb874f387208f0cccf6
[sonarqube.git] /
1 /*
2  * SonarQube
3  * Copyright (C) 2009-2023 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.ce.task.projectanalysis.container;
21
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.AnalysisFromSonarQube94Visitor;
29 import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolderImpl;
30 import org.sonar.ce.task.projectanalysis.api.posttask.PostProjectAnalysisTasksExecutor;
31 import org.sonar.ce.task.projectanalysis.batch.BatchReportDirectoryHolderImpl;
32 import org.sonar.ce.task.projectanalysis.batch.BatchReportReaderImpl;
33 import org.sonar.ce.task.projectanalysis.component.BranchLoader;
34 import org.sonar.ce.task.projectanalysis.component.BranchPersisterImpl;
35 import org.sonar.ce.task.projectanalysis.component.ConfigurationRepositoryImpl;
36 import org.sonar.ce.task.projectanalysis.component.DisabledComponentsHolderImpl;
37 import org.sonar.ce.task.projectanalysis.component.FileStatusesImpl;
38 import org.sonar.ce.task.projectanalysis.component.PreviousSourceHashRepositoryImpl;
39 import org.sonar.ce.task.projectanalysis.component.ProjectPersister;
40 import org.sonar.ce.task.projectanalysis.component.ReferenceBranchComponentUuids;
41 import org.sonar.ce.task.projectanalysis.component.SiblingComponentsWithOpenIssues;
42 import org.sonar.ce.task.projectanalysis.component.TreeRootHolderImpl;
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.ComputeLocationHashesVisitor;
61 import org.sonar.ce.task.projectanalysis.issue.DebtCalculator;
62 import org.sonar.ce.task.projectanalysis.issue.DefaultAssignee;
63 import org.sonar.ce.task.projectanalysis.issue.EffortAggregator;
64 import org.sonar.ce.task.projectanalysis.issue.IntegrateIssuesVisitor;
65 import org.sonar.ce.task.projectanalysis.issue.IssueAssigner;
66 import org.sonar.ce.task.projectanalysis.issue.IssueChangesToDeleteRepository;
67 import org.sonar.ce.task.projectanalysis.issue.IssueCounter;
68 import org.sonar.ce.task.projectanalysis.issue.IssueCreationDateCalculator;
69 import org.sonar.ce.task.projectanalysis.issue.IssueLifecycle;
70 import org.sonar.ce.task.projectanalysis.issue.IssueOnReferenceBranchVisitor;
71 import org.sonar.ce.task.projectanalysis.issue.IssueTrackingDelegator;
72 import org.sonar.ce.task.projectanalysis.issue.IssueVisitors;
73 import org.sonar.ce.task.projectanalysis.issue.IssuesRepositoryVisitor;
74 import org.sonar.ce.task.projectanalysis.issue.LoadComponentUuidsHavingOpenIssuesVisitor;
75 import org.sonar.ce.task.projectanalysis.issue.MovedIssueVisitor;
76 import org.sonar.ce.task.projectanalysis.issue.NewEffortAggregator;
77 import org.sonar.ce.task.projectanalysis.issue.NewIssueClassifier;
78 import org.sonar.ce.task.projectanalysis.issue.ProtoIssueCache;
79 import org.sonar.ce.task.projectanalysis.issue.PullRequestSourceBranchMerger;
80 import org.sonar.ce.task.projectanalysis.issue.PullRequestTrackerExecution;
81 import org.sonar.ce.task.projectanalysis.issue.ReferenceBranchTrackerExecution;
82 import org.sonar.ce.task.projectanalysis.issue.RemoveProcessedComponentsVisitor;
83 import org.sonar.ce.task.projectanalysis.issue.RuleRepositoryImpl;
84 import org.sonar.ce.task.projectanalysis.issue.RuleTagsCopier;
85 import org.sonar.ce.task.projectanalysis.issue.ScmAccountToUser;
86 import org.sonar.ce.task.projectanalysis.issue.ScmAccountToUserLoader;
87 import org.sonar.ce.task.projectanalysis.issue.SiblingsIssueMerger;
88 import org.sonar.ce.task.projectanalysis.issue.SiblingsIssuesLoader;
89 import org.sonar.ce.task.projectanalysis.issue.SourceBranchComponentUuids;
90 import org.sonar.ce.task.projectanalysis.issue.TargetBranchComponentUuids;
91 import org.sonar.ce.task.projectanalysis.issue.TrackerBaseInputFactory;
92 import org.sonar.ce.task.projectanalysis.issue.TrackerExecution;
93 import org.sonar.ce.task.projectanalysis.issue.TrackerRawInputFactory;
94 import org.sonar.ce.task.projectanalysis.issue.TrackerReferenceBranchInputFactory;
95 import org.sonar.ce.task.projectanalysis.issue.TrackerSourceBranchInputFactory;
96 import org.sonar.ce.task.projectanalysis.issue.TrackerTargetBranchInputFactory;
97 import org.sonar.ce.task.projectanalysis.issue.UpdateConflictResolver;
98 import org.sonar.ce.task.projectanalysis.issue.commonrule.BranchCoverageRule;
99 import org.sonar.ce.task.projectanalysis.issue.commonrule.CommentDensityRule;
100 import org.sonar.ce.task.projectanalysis.issue.commonrule.CommonRuleEngineImpl;
101 import org.sonar.ce.task.projectanalysis.issue.commonrule.DuplicatedBlockRule;
102 import org.sonar.ce.task.projectanalysis.issue.commonrule.LineCoverageRule;
103 import org.sonar.ce.task.projectanalysis.issue.commonrule.SkippedTestRule;
104 import org.sonar.ce.task.projectanalysis.issue.commonrule.TestErrorRule;
105 import org.sonar.ce.task.projectanalysis.issue.filter.IssueFilter;
106 import org.sonar.ce.task.projectanalysis.language.LanguageRepositoryImpl;
107 import org.sonar.ce.task.projectanalysis.locations.flow.FlowGenerator;
108 import org.sonar.ce.task.projectanalysis.measure.MeasureComputersHolderImpl;
109 import org.sonar.ce.task.projectanalysis.measure.MeasureComputersVisitor;
110 import org.sonar.ce.task.projectanalysis.measure.MeasureRepositoryImpl;
111 import org.sonar.ce.task.projectanalysis.measure.MeasureToMeasureDto;
112 import org.sonar.ce.task.projectanalysis.metric.MetricModule;
113 import org.sonar.ce.task.projectanalysis.notification.NotificationFactory;
114 import org.sonar.ce.task.projectanalysis.period.NewCodePeriodResolver;
115 import org.sonar.ce.task.projectanalysis.period.NewCodeReferenceBranchComponentUuids;
116 import org.sonar.ce.task.projectanalysis.period.PeriodHolderImpl;
117 import org.sonar.ce.task.projectanalysis.pushevent.PushEventFactory;
118 import org.sonar.ce.task.projectanalysis.qualitygate.EvaluationResultTextConverterImpl;
119 import org.sonar.ce.task.projectanalysis.qualitygate.QualityGateHolderImpl;
120 import org.sonar.ce.task.projectanalysis.qualitygate.QualityGateServiceImpl;
121 import org.sonar.ce.task.projectanalysis.qualitygate.QualityGateStatusHolderImpl;
122 import org.sonar.ce.task.projectanalysis.qualitymodel.MaintainabilityMeasuresVisitor;
123 import org.sonar.ce.task.projectanalysis.qualitymodel.NewMaintainabilityMeasuresVisitor;
124 import org.sonar.ce.task.projectanalysis.qualitymodel.NewReliabilityAndSecurityRatingMeasuresVisitor;
125 import org.sonar.ce.task.projectanalysis.qualitymodel.NewSecurityReviewMeasuresVisitor;
126 import org.sonar.ce.task.projectanalysis.qualitymodel.RatingSettings;
127 import org.sonar.ce.task.projectanalysis.qualitymodel.ReliabilityAndSecurityRatingMeasuresVisitor;
128 import org.sonar.ce.task.projectanalysis.qualitymodel.SecurityReviewMeasuresVisitor;
129 import org.sonar.ce.task.projectanalysis.qualityprofile.ActiveRulesHolderImpl;
130 import org.sonar.ce.task.projectanalysis.qualityprofile.QProfileStatusRepositoryImpl;
131 import org.sonar.ce.task.projectanalysis.scm.ScmInfoDbLoader;
132 import org.sonar.ce.task.projectanalysis.scm.ScmInfoRepositoryImpl;
133 import org.sonar.ce.task.projectanalysis.source.DbLineHashVersion;
134 import org.sonar.ce.task.projectanalysis.source.FileSourceDataComputer;
135 import org.sonar.ce.task.projectanalysis.source.FileSourceDataWarnings;
136 import org.sonar.ce.task.projectanalysis.source.LastCommitVisitor;
137 import org.sonar.ce.task.projectanalysis.source.NewLinesRepository;
138 import org.sonar.ce.task.projectanalysis.source.SignificantCodeRepository;
139 import org.sonar.ce.task.projectanalysis.source.SourceHashRepositoryImpl;
140 import org.sonar.ce.task.projectanalysis.source.SourceLineReadersFactory;
141 import org.sonar.ce.task.projectanalysis.source.SourceLinesDiffImpl;
142 import org.sonar.ce.task.projectanalysis.source.SourceLinesHashCache;
143 import org.sonar.ce.task.projectanalysis.source.SourceLinesHashRepositoryImpl;
144 import org.sonar.ce.task.projectanalysis.source.SourceLinesRepositoryImpl;
145 import org.sonar.ce.task.projectanalysis.step.ReportComputationSteps;
146 import org.sonar.ce.task.projectanalysis.step.SmallChangesetQualityGateSpecialCase;
147 import org.sonar.ce.task.projectanalysis.webhook.WebhookPostTask;
148 import org.sonar.ce.task.setting.SettingsLoader;
149 import org.sonar.ce.task.step.ComputationStepExecutor;
150 import org.sonar.ce.task.step.ComputationSteps;
151 import org.sonar.ce.task.taskprocessor.MutableTaskResultHolderImpl;
152 import org.sonar.core.issue.tracking.Tracker;
153 import org.sonar.core.platform.ContainerPopulator;
154 import org.sonar.server.issue.TaintChecker;
155 import org.sonar.server.setting.ProjectConfigurationLoaderImpl;
156 import org.sonar.server.view.index.ViewIndex;
157
158 public final class ProjectAnalysisTaskContainerPopulator implements ContainerPopulator<TaskContainer> {
159   private static final ReportAnalysisComponentProvider[] NO_REPORT_ANALYSIS_COMPONENT_PROVIDERS = new ReportAnalysisComponentProvider[0];
160
161   private final CeTask task;
162   private final ReportAnalysisComponentProvider[] componentProviders;
163
164   public ProjectAnalysisTaskContainerPopulator(CeTask task, @Nullable ReportAnalysisComponentProvider[] componentProviders) {
165     this.task = task;
166     this.componentProviders = componentProviders == null ? NO_REPORT_ANALYSIS_COMPONENT_PROVIDERS : componentProviders;
167   }
168
169   @Override
170   public void populateContainer(TaskContainer container) {
171     ComputationSteps steps = new ReportComputationSteps(container);
172     container.add(SettingsLoader.class);
173     container.add(task);
174     container.add(steps);
175     container.add(componentClasses());
176     for (ReportAnalysisComponentProvider componentProvider : componentProviders) {
177       container.add(componentProvider.getComponents());
178     }
179     container.add(steps.orderedStepClasses());
180   }
181
182   /**
183    * List of all objects to be injected in the ioc container dedicated to computation stack.
184    * Does not contain the steps declared in {@link ReportComputationSteps#orderedStepClasses()}.
185    */
186   private static List<Object> componentClasses() {
187     return Arrays.asList(
188       ProjectConfigurationLoaderImpl.class,
189
190       PostProjectAnalysisTasksExecutor.class,
191       ComputationStepExecutor.class,
192
193       // messages/warnings
194       CeTaskMessagesImpl.class,
195       FileSourceDataWarnings.class,
196
197       // File System
198       new ComputationTempFolderProvider(),
199
200       FileStatusesImpl.class,
201       new MetricModule(),
202
203       // holders
204       AnalysisMetadataHolderImpl.class,
205       CrossProjectDuplicationStatusHolderImpl.class,
206       BatchReportDirectoryHolderImpl.class,
207       TreeRootHolderImpl.class,
208       PeriodHolderImpl.class,
209       QualityGateHolderImpl.class,
210       QualityGateStatusHolderImpl.class,
211       RatingSettings.class,
212       ActiveRulesHolderImpl.class,
213       MeasureComputersHolderImpl.class,
214       MutableTaskResultHolderImpl.class,
215       BatchReportReaderImpl.class,
216       ReferenceBranchComponentUuids.class,
217       NewCodeReferenceBranchComponentUuids.class,
218       SiblingComponentsWithOpenIssues.class,
219
220       // repositories
221       PreviousSourceHashRepositoryImpl.class,
222       LanguageRepositoryImpl.class,
223       MeasureRepositoryImpl.class,
224       EventRepositoryImpl.class,
225       ConfigurationRepositoryImpl.class,
226       DisabledComponentsHolderImpl.class,
227       QualityGateServiceImpl.class,
228       EvaluationResultTextConverterImpl.class,
229       SourceLinesRepositoryImpl.class,
230       SourceHashRepositoryImpl.class,
231       SourceLinesDiffImpl.class,
232       ScmInfoRepositoryImpl.class,
233       ScmInfoDbLoader.class,
234       DuplicationRepositoryImpl.class,
235       SourceLinesHashRepositoryImpl.class,
236       DbLineHashVersion.class,
237       SignificantCodeRepository.class,
238       SourceLinesHashCache.class,
239       NewLinesRepository.class,
240       FileSourceDataComputer.class,
241       SourceLineReadersFactory.class,
242       QProfileStatusRepositoryImpl.class,
243       IssueChangesToDeleteRepository.class,
244
245       // issues
246       RuleRepositoryImpl.class,
247       ScmAccountToUserLoader.class,
248       ScmAccountToUser.class,
249       ProtoIssueCache.class,
250       DefaultAssignee.class,
251       IssueVisitors.class,
252       IssueLifecycle.class,
253       NewIssueClassifier.class,
254       ComponentsWithUnprocessedIssues.class,
255       ComponentIssuesRepositoryImpl.class,
256       IssueFilter.class,
257
258       FlowGenerator.class,
259       // push events
260       PushEventFactory.class,
261
262       // common rules
263       CommonRuleEngineImpl.class,
264       BranchCoverageRule.class,
265       LineCoverageRule.class,
266       CommentDensityRule.class,
267       DuplicatedBlockRule.class,
268       TestErrorRule.class,
269       SkippedTestRule.class,
270
271       // order is important: RuleTypeCopier must be the first one. And DebtAggregator must be before NewDebtAggregator (new debt requires
272       // debt)
273       RuleTagsCopier.class,
274       IssueCreationDateCalculator.class,
275       ComputeLocationHashesVisitor.class,
276       DebtCalculator.class,
277       EffortAggregator.class,
278       NewEffortAggregator.class,
279       IssueAssigner.class,
280       IssueCounter.class,
281       MovedIssueVisitor.class,
282       IssuesRepositoryVisitor.class,
283       RemoveProcessedComponentsVisitor.class,
284       IssueOnReferenceBranchVisitor.class,
285
286       // visitors : order is important, measure computers must be executed at the end in order to access to every measures / issues
287       AnalysisFromSonarQube94Visitor.class,
288       LoadComponentUuidsHavingOpenIssuesVisitor.class,
289       IntegrateIssuesVisitor.class,
290       TaintChecker.class,
291       CloseIssuesOnRemovedComponentsVisitor.class,
292       MaintainabilityMeasuresVisitor.class,
293       NewMaintainabilityMeasuresVisitor.class,
294       ReliabilityAndSecurityRatingMeasuresVisitor.class,
295       NewReliabilityAndSecurityRatingMeasuresVisitor.class,
296       SecurityReviewMeasuresVisitor.class,
297       NewSecurityReviewMeasuresVisitor.class,
298       LastCommitVisitor.class,
299       MeasureComputersVisitor.class,
300       TargetBranchComponentUuids.class,
301       UpdateConflictResolver.class,
302       TrackerBaseInputFactory.class,
303       TrackerTargetBranchInputFactory.class,
304       TrackerRawInputFactory.class,
305       TrackerReferenceBranchInputFactory.class,
306       TrackerSourceBranchInputFactory.class,
307       SourceBranchComponentUuids.class,
308       ClosedIssuesInputFactory.class,
309       Tracker.class,
310       TrackerExecution.class,
311       PullRequestTrackerExecution.class,
312       PullRequestSourceBranchMerger.class,
313       ReferenceBranchTrackerExecution.class,
314       ComponentIssuesLoader.class,
315       BaseIssuesLoader.class,
316       IssueTrackingDelegator.class,
317       BranchPersisterImpl.class,
318       ProjectPersister.class,
319       SiblingsIssuesLoader.class,
320       SiblingsIssueMerger.class,
321       NewCodePeriodResolver.class,
322
323       // filemove
324       ScoreMatrixDumperImpl.class,
325       SourceSimilarityImpl.class,
326       FileSimilarityImpl.class,
327       MutableMovedFilesRepositoryImpl.class,
328       AddedFileRepositoryImpl.class,
329
330       // duplication
331       IntegrateCrossProjectDuplications.class,
332       DuplicationMeasures.class,
333
334       // views
335       ViewIndex.class,
336
337       BranchLoader.class,
338       MeasureToMeasureDto.class,
339       SmallChangesetQualityGateSpecialCase.class,
340
341       // webhooks
342       WebhookPostTask.class,
343
344       // notifications
345       NotificationFactory.class);
346   }
347
348 }