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