]> source.dussan.org Git - sonarqube.git/blob
a68aa9e53403e72dce2ec3c58e53cce99fa3827f
[sonarqube.git] /
1 /*
2  * SonarQube
3  * Copyright (C) 2009-2017 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.server.computation.task.projectanalysis.container;
21
22 import java.util.Arrays;
23 import java.util.List;
24 import javax.annotation.Nullable;
25 import org.sonar.ce.organization.DefaultOrganizationLoader;
26 import org.sonar.ce.queue.CeTask;
27 import org.sonar.ce.settings.SettingsLoader;
28 import org.sonar.core.issue.tracking.Tracker;
29 import org.sonar.core.platform.ContainerPopulator;
30 import org.sonar.plugin.ce.ReportAnalysisComponentProvider;
31 import org.sonar.server.computation.task.container.TaskContainer;
32 import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetadataHolderImpl;
33 import org.sonar.server.computation.task.projectanalysis.api.posttask.PostProjectAnalysisTasksExecutor;
34 import org.sonar.server.computation.task.projectanalysis.batch.BatchReportDirectoryHolderImpl;
35 import org.sonar.server.computation.task.projectanalysis.batch.BatchReportReaderImpl;
36 import org.sonar.server.computation.task.projectanalysis.component.BranchLoader;
37 import org.sonar.server.computation.task.projectanalysis.component.BranchPersister;
38 import org.sonar.server.computation.task.projectanalysis.component.ConfigurationRepositoryImpl;
39 import org.sonar.server.computation.task.projectanalysis.component.DbIdsRepositoryImpl;
40 import org.sonar.server.computation.task.projectanalysis.component.DisabledComponentsHolderImpl;
41 import org.sonar.server.computation.task.projectanalysis.component.MergeBranchComponentUuids;
42 import org.sonar.server.computation.task.projectanalysis.component.ShortBranchComponentsWithIssues;
43 import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderImpl;
44 import org.sonar.server.computation.task.projectanalysis.duplication.CrossProjectDuplicationStatusHolderImpl;
45 import org.sonar.server.computation.task.projectanalysis.duplication.DuplicationMeasures;
46 import org.sonar.server.computation.task.projectanalysis.duplication.DuplicationRepositoryImpl;
47 import org.sonar.server.computation.task.projectanalysis.duplication.IntegrateCrossProjectDuplications;
48 import org.sonar.server.computation.task.projectanalysis.event.EventRepositoryImpl;
49 import org.sonar.server.computation.task.projectanalysis.filemove.FileSimilarityImpl;
50 import org.sonar.server.computation.task.projectanalysis.filemove.MutableMovedFilesRepositoryImpl;
51 import org.sonar.server.computation.task.projectanalysis.filemove.SourceSimilarityImpl;
52 import org.sonar.server.computation.task.projectanalysis.filesystem.ComputationTempFolderProvider;
53 import org.sonar.server.computation.task.projectanalysis.issue.BaseIssuesLoader;
54 import org.sonar.server.computation.task.projectanalysis.issue.CloseIssuesOnRemovedComponentsVisitor;
55 import org.sonar.server.computation.task.projectanalysis.issue.ComponentIssuesLoader;
56 import org.sonar.server.computation.task.projectanalysis.issue.ComponentIssuesRepositoryImpl;
57 import org.sonar.server.computation.task.projectanalysis.issue.ComponentsWithUnprocessedIssues;
58 import org.sonar.server.computation.task.projectanalysis.issue.DebtCalculator;
59 import org.sonar.server.computation.task.projectanalysis.issue.DefaultAssignee;
60 import org.sonar.server.computation.task.projectanalysis.issue.EffortAggregator;
61 import org.sonar.server.computation.task.projectanalysis.issue.IntegrateIssuesVisitor;
62 import org.sonar.server.computation.task.projectanalysis.issue.IssueAssigner;
63 import org.sonar.server.computation.task.projectanalysis.issue.IssueCache;
64 import org.sonar.server.computation.task.projectanalysis.issue.IssueCounter;
65 import org.sonar.server.computation.task.projectanalysis.issue.IssueCreationDateCalculator;
66 import org.sonar.server.computation.task.projectanalysis.issue.IssueLifecycle;
67 import org.sonar.server.computation.task.projectanalysis.issue.ShortBranchIssueMerger;
68 import org.sonar.server.computation.task.projectanalysis.issue.IssueTrackingDelegator;
69 import org.sonar.server.computation.task.projectanalysis.issue.IssueVisitors;
70 import org.sonar.server.computation.task.projectanalysis.issue.IssuesRepositoryVisitor;
71 import org.sonar.server.computation.task.projectanalysis.issue.LoadComponentUuidsHavingOpenIssuesVisitor;
72 import org.sonar.server.computation.task.projectanalysis.issue.MergeBranchTrackerExecution;
73 import org.sonar.server.computation.task.projectanalysis.issue.MovedIssueVisitor;
74 import org.sonar.server.computation.task.projectanalysis.issue.NewEffortAggregator;
75 import org.sonar.server.computation.task.projectanalysis.issue.RemoveProcessedComponentsVisitor;
76 import org.sonar.server.computation.task.projectanalysis.issue.ShortBranchIssuesLoader;
77 import org.sonar.server.computation.task.projectanalysis.issue.RuleRepositoryImpl;
78 import org.sonar.server.computation.task.projectanalysis.issue.RuleTagsCopier;
79 import org.sonar.server.computation.task.projectanalysis.issue.RuleTypeCopier;
80 import org.sonar.server.computation.task.projectanalysis.issue.ScmAccountToUser;
81 import org.sonar.server.computation.task.projectanalysis.issue.ScmAccountToUserLoader;
82 import org.sonar.server.computation.task.projectanalysis.issue.ShortBranchTrackerExecution;
83 import org.sonar.server.computation.task.projectanalysis.issue.TrackerBaseInputFactory;
84 import org.sonar.server.computation.task.projectanalysis.issue.TrackerExecution;
85 import org.sonar.server.computation.task.projectanalysis.issue.TrackerMergeBranchInputFactory;
86 import org.sonar.server.computation.task.projectanalysis.issue.TrackerRawInputFactory;
87 import org.sonar.server.computation.task.projectanalysis.issue.UpdateConflictResolver;
88 import org.sonar.server.computation.task.projectanalysis.issue.commonrule.BranchCoverageRule;
89 import org.sonar.server.computation.task.projectanalysis.issue.commonrule.CommentDensityRule;
90 import org.sonar.server.computation.task.projectanalysis.issue.commonrule.CommonRuleEngineImpl;
91 import org.sonar.server.computation.task.projectanalysis.issue.commonrule.DuplicatedBlockRule;
92 import org.sonar.server.computation.task.projectanalysis.issue.commonrule.LineCoverageRule;
93 import org.sonar.server.computation.task.projectanalysis.issue.commonrule.SkippedTestRule;
94 import org.sonar.server.computation.task.projectanalysis.issue.commonrule.TestErrorRule;
95 import org.sonar.server.computation.task.projectanalysis.issue.filter.IssueFilter;
96 import org.sonar.server.computation.task.projectanalysis.language.LanguageRepositoryImpl;
97 import org.sonar.server.computation.task.projectanalysis.measure.MeasureComputersHolderImpl;
98 import org.sonar.server.computation.task.projectanalysis.measure.MeasureComputersVisitor;
99 import org.sonar.server.computation.task.projectanalysis.measure.MeasureRepositoryImpl;
100 import org.sonar.server.computation.task.projectanalysis.measure.MeasureToMeasureDto;
101 import org.sonar.server.computation.task.projectanalysis.metric.MetricModule;
102 import org.sonar.server.computation.task.projectanalysis.period.PeriodHolderImpl;
103 import org.sonar.server.computation.task.projectanalysis.qualitygate.EvaluationResultTextConverterImpl;
104 import org.sonar.server.computation.task.projectanalysis.qualitygate.QualityGateHolderImpl;
105 import org.sonar.server.computation.task.projectanalysis.qualitygate.QualityGateServiceImpl;
106 import org.sonar.server.computation.task.projectanalysis.qualitygate.QualityGateStatusHolderImpl;
107 import org.sonar.server.computation.task.projectanalysis.qualitymodel.MaintainabilityMeasuresVisitor;
108 import org.sonar.server.computation.task.projectanalysis.qualitymodel.NewMaintainabilityMeasuresVisitor;
109 import org.sonar.server.computation.task.projectanalysis.qualitymodel.NewReliabilityAndSecurityRatingMeasuresVisitor;
110 import org.sonar.server.computation.task.projectanalysis.qualitymodel.RatingSettings;
111 import org.sonar.server.computation.task.projectanalysis.qualitymodel.ReliabilityAndSecurityRatingMeasuresVisitor;
112 import org.sonar.server.computation.task.projectanalysis.qualityprofile.ActiveRulesHolderImpl;
113 import org.sonar.server.computation.task.projectanalysis.scm.ScmInfoDbLoader;
114 import org.sonar.server.computation.task.projectanalysis.scm.ScmInfoRepositoryImpl;
115 import org.sonar.server.computation.task.projectanalysis.source.LastCommitVisitor;
116 import org.sonar.server.computation.task.projectanalysis.source.SourceHashRepositoryImpl;
117 import org.sonar.server.computation.task.projectanalysis.source.SourceLinesRepositoryImpl;
118 import org.sonar.server.computation.task.projectanalysis.step.ReportComputationSteps;
119 import org.sonar.server.computation.task.projectanalysis.step.SmallChangesetQualityGateSpecialCase;
120 import org.sonar.server.computation.task.projectanalysis.webhook.WebhookPostTask;
121 import org.sonar.server.computation.task.step.ComputationStepExecutor;
122 import org.sonar.server.computation.task.step.ComputationSteps;
123 import org.sonar.server.computation.taskprocessor.MutableTaskResultHolderImpl;
124 import org.sonar.server.view.index.ViewIndex;
125 import org.sonar.server.webhook.WebhookModule;
126
127 public final class ProjectAnalysisTaskContainerPopulator implements ContainerPopulator<TaskContainer> {
128   private static final ReportAnalysisComponentProvider[] NO_REPORT_ANALYSIS_COMPONENT_PROVIDERS = new ReportAnalysisComponentProvider[0];
129
130   private final CeTask task;
131   private final ReportAnalysisComponentProvider[] componentProviders;
132
133   public ProjectAnalysisTaskContainerPopulator(CeTask task, @Nullable ReportAnalysisComponentProvider[] componentProviders) {
134     this.task = task;
135     this.componentProviders = componentProviders == null ? NO_REPORT_ANALYSIS_COMPONENT_PROVIDERS : componentProviders;
136   }
137
138   @Override
139   public void populateContainer(TaskContainer container) {
140     ComputationSteps steps = new ReportComputationSteps(container);
141     container.add(SettingsLoader.class);
142     container.add(DefaultOrganizationLoader.class);
143     container.add(task);
144     container.add(steps);
145     container.addSingletons(componentClasses());
146     for (ReportAnalysisComponentProvider componentProvider : componentProviders) {
147       container.addSingletons(componentProvider.getComponents());
148     }
149     container.addSingletons(steps.orderedStepClasses());
150   }
151
152   /**
153    * List of all objects to be injected in the picocontainer dedicated to computation stack.
154    * Does not contain the steps declared in {@link ReportComputationSteps#orderedStepClasses()}.
155    */
156   private static List<Object> componentClasses() {
157     return Arrays.asList(
158       PostProjectAnalysisTasksExecutor.class,
159       ComputationStepExecutor.class,
160
161       // File System
162       new ComputationTempFolderProvider(),
163
164       MetricModule.class,
165
166       // holders
167       AnalysisMetadataHolderImpl.class,
168       CrossProjectDuplicationStatusHolderImpl.class,
169       BatchReportDirectoryHolderImpl.class,
170       TreeRootHolderImpl.class,
171       PeriodHolderImpl.class,
172       QualityGateHolderImpl.class,
173       QualityGateStatusHolderImpl.class,
174       RatingSettings.class,
175       ActiveRulesHolderImpl.class,
176       MeasureComputersHolderImpl.class,
177       MutableTaskResultHolderImpl.class,
178       BatchReportReaderImpl.class,
179       MergeBranchComponentUuids.class,
180       ShortBranchComponentsWithIssues.class,
181
182       // repositories
183       LanguageRepositoryImpl.class,
184       MeasureRepositoryImpl.class,
185       EventRepositoryImpl.class,
186       ConfigurationRepositoryImpl.class,
187       DbIdsRepositoryImpl.class,
188       DisabledComponentsHolderImpl.class,
189       QualityGateServiceImpl.class,
190       EvaluationResultTextConverterImpl.class,
191       SourceLinesRepositoryImpl.class,
192       SourceHashRepositoryImpl.class,
193       ScmInfoRepositoryImpl.class,
194       ScmInfoDbLoader.class,
195       DuplicationRepositoryImpl.class,
196
197       // issues
198       RuleRepositoryImpl.class,
199       ScmAccountToUserLoader.class,
200       ScmAccountToUser.class,
201       IssueCache.class,
202       DefaultAssignee.class,
203       IssueVisitors.class,
204       IssueLifecycle.class,
205       ComponentsWithUnprocessedIssues.class,
206       ComponentIssuesRepositoryImpl.class,
207       IssueFilter.class,
208
209       // common rules
210       CommonRuleEngineImpl.class,
211       BranchCoverageRule.class,
212       LineCoverageRule.class,
213       CommentDensityRule.class,
214       DuplicatedBlockRule.class,
215       TestErrorRule.class,
216       SkippedTestRule.class,
217
218       // order is important: RuleTypeCopier must be the first one. And DebtAggregator must be before NewDebtAggregator (new debt requires
219       // debt)
220       RuleTypeCopier.class,
221       RuleTagsCopier.class,
222       IssueCreationDateCalculator.class,
223       DebtCalculator.class,
224       EffortAggregator.class,
225       NewEffortAggregator.class,
226       IssueAssigner.class,
227       IssueCounter.class,
228       MovedIssueVisitor.class,
229       IssuesRepositoryVisitor.class,
230       RemoveProcessedComponentsVisitor.class,
231
232       // visitors : order is important, measure computers must be executed at the end in order to access to every measures / issues
233       LoadComponentUuidsHavingOpenIssuesVisitor.class,
234       IntegrateIssuesVisitor.class,
235       CloseIssuesOnRemovedComponentsVisitor.class,
236       MaintainabilityMeasuresVisitor.class,
237       NewMaintainabilityMeasuresVisitor.class,
238       ReliabilityAndSecurityRatingMeasuresVisitor.class,
239       NewReliabilityAndSecurityRatingMeasuresVisitor.class,
240       LastCommitVisitor.class,
241       MeasureComputersVisitor.class,
242
243       UpdateConflictResolver.class,
244       TrackerBaseInputFactory.class,
245       TrackerRawInputFactory.class,
246       TrackerMergeBranchInputFactory.class,
247       Tracker.class,
248       TrackerExecution.class,
249       ShortBranchTrackerExecution.class,
250       MergeBranchTrackerExecution.class,
251       ComponentIssuesLoader.class,
252       BaseIssuesLoader.class,
253       IssueTrackingDelegator.class,
254       BranchPersister.class,
255       ShortBranchIssuesLoader.class,
256       ShortBranchIssueMerger.class,
257
258       // filemove
259       SourceSimilarityImpl.class,
260       FileSimilarityImpl.class,
261       MutableMovedFilesRepositoryImpl.class,
262
263       // duplication
264       IntegrateCrossProjectDuplications.class,
265       DuplicationMeasures.class,
266
267       // views
268       ViewIndex.class,
269
270       BranchLoader.class,
271       MeasureToMeasureDto.class,
272       SmallChangesetQualityGateSpecialCase.class,
273
274       // webhooks
275       WebhookModule.class,
276       WebhookPostTask.class);
277   }
278
279 }