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