]> source.dussan.org Git - sonarqube.git/blob
86d7c3b7610de00a53ddeeba7aeaa14fb317d47a
[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.MergeBranchComponentUuids;
44 import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderImpl;
45 import org.sonar.server.computation.task.projectanalysis.duplication.CrossProjectDuplicationStatusHolderImpl;
46 import org.sonar.server.computation.task.projectanalysis.duplication.DuplicationMeasures;
47 import org.sonar.server.computation.task.projectanalysis.duplication.DuplicationRepositoryImpl;
48 import org.sonar.server.computation.task.projectanalysis.duplication.IntegrateCrossProjectDuplications;
49 import org.sonar.server.computation.task.projectanalysis.event.EventRepositoryImpl;
50 import org.sonar.server.computation.task.projectanalysis.filemove.FileSimilarityImpl;
51 import org.sonar.server.computation.task.projectanalysis.filemove.MutableMovedFilesRepositoryImpl;
52 import org.sonar.server.computation.task.projectanalysis.filemove.SourceSimilarityImpl;
53 import org.sonar.server.computation.task.projectanalysis.filesystem.ComputationTempFolderProvider;
54 import org.sonar.server.computation.task.projectanalysis.issue.BaseIssuesLoader;
55 import org.sonar.server.computation.task.projectanalysis.issue.CloseIssuesOnRemovedComponentsVisitor;
56 import org.sonar.server.computation.task.projectanalysis.issue.ComponentIssuesLoader;
57 import org.sonar.server.computation.task.projectanalysis.issue.ComponentIssuesRepositoryImpl;
58 import org.sonar.server.computation.task.projectanalysis.issue.ComponentsWithUnprocessedIssues;
59 import org.sonar.server.computation.task.projectanalysis.issue.DebtCalculator;
60 import org.sonar.server.computation.task.projectanalysis.issue.DefaultAssignee;
61 import org.sonar.server.computation.task.projectanalysis.issue.EffortAggregator;
62 import org.sonar.server.computation.task.projectanalysis.issue.IntegrateIssuesVisitor;
63 import org.sonar.server.computation.task.projectanalysis.issue.IssueAssigner;
64 import org.sonar.server.computation.task.projectanalysis.issue.IssueCache;
65 import org.sonar.server.computation.task.projectanalysis.issue.IssueCounter;
66 import org.sonar.server.computation.task.projectanalysis.issue.IssueCreationDateCalculator;
67 import org.sonar.server.computation.task.projectanalysis.issue.IssueLifecycle;
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.NewEffortCalculator;
76 import org.sonar.server.computation.task.projectanalysis.issue.RemoveProcessedComponentsVisitor;
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.webhook.WebhookModule;
120 import org.sonar.server.computation.task.step.ComputationStepExecutor;
121 import org.sonar.server.computation.task.step.ComputationSteps;
122 import org.sonar.server.computation.taskprocessor.MutableTaskResultHolderImpl;
123 import org.sonar.server.view.index.ViewIndex;
124
125 public final class ProjectAnalysisTaskContainerPopulator implements ContainerPopulator<TaskContainer> {
126   private static final ReportAnalysisComponentProvider[] NO_REPORT_ANALYSIS_COMPONENT_PROVIDERS = new ReportAnalysisComponentProvider[0];
127
128   private final CeTask task;
129   private final ReportAnalysisComponentProvider[] componentProviders;
130
131   public ProjectAnalysisTaskContainerPopulator(CeTask task, @Nullable ReportAnalysisComponentProvider[] componentProviders) {
132     this.task = task;
133     this.componentProviders = componentProviders == null ? NO_REPORT_ANALYSIS_COMPONENT_PROVIDERS : componentProviders;
134   }
135
136   @Override
137   public void populateContainer(TaskContainer container) {
138     ComputationSteps steps = new ReportComputationSteps(container);
139     container.add(SettingsLoader.class);
140     container.add(DefaultOrganizationLoader.class);
141     container.add(task);
142     container.add(steps);
143     container.addSingletons(componentClasses());
144     for (ReportAnalysisComponentProvider componentProvider : componentProviders) {
145       container.addSingletons(componentProvider.getComponents());
146     }
147     container.addSingletons(steps.orderedStepClasses());
148   }
149
150   /**
151    * List of all objects to be injected in the picocontainer dedicated to computation stack.
152    * Does not contain the steps declared in {@link ReportComputationSteps#orderedStepClasses()}.
153    */
154   private static List<Object> componentClasses() {
155     return Arrays.asList(
156       PostProjectAnalysisTasksExecutor.class,
157       ComputationStepExecutor.class,
158
159       // File System
160       new ComputationTempFolderProvider(),
161
162       MetricModule.class,
163
164       // holders
165       AnalysisMetadataHolderImpl.class,
166       CrossProjectDuplicationStatusHolderImpl.class,
167       BatchReportDirectoryHolderImpl.class,
168       TreeRootHolderImpl.class,
169       PeriodHolderImpl.class,
170       QualityGateHolderImpl.class,
171       QualityGateStatusHolderImpl.class,
172       RatingSettings.class,
173       ActiveRulesHolderImpl.class,
174       MeasureComputersHolderImpl.class,
175       MutableTaskResultHolderImpl.class,
176       BatchReportReaderImpl.class,
177       MergeBranchComponentUuids.class,
178
179       // repositories
180       LanguageRepositoryImpl.class,
181       MeasureRepositoryImpl.class,
182       EventRepositoryImpl.class,
183       ConfigurationRepositoryImpl.class,
184       DbIdsRepositoryImpl.class,
185       DisabledComponentsHolderImpl.class,
186       QualityGateServiceImpl.class,
187       EvaluationResultTextConverterImpl.class,
188       SourceLinesRepositoryImpl.class,
189       SourceHashRepositoryImpl.class,
190       ScmInfoRepositoryImpl.class,
191       ScmInfoDbLoader.class,
192       DuplicationRepositoryImpl.class,
193
194       // issues
195       RuleRepositoryImpl.class,
196       ScmAccountToUserLoader.class,
197       ScmAccountToUser.class,
198       IssueCache.class,
199       DefaultAssignee.class,
200       IssueVisitors.class,
201       IssueLifecycle.class,
202       ComponentsWithUnprocessedIssues.class,
203       ComponentIssuesRepositoryImpl.class,
204       IssueFilter.class,
205
206       // common rules
207       CommonRuleEngineImpl.class,
208       BranchCoverageRule.class,
209       LineCoverageRule.class,
210       CommentDensityRule.class,
211       DuplicatedBlockRule.class,
212       TestErrorRule.class,
213       SkippedTestRule.class,
214
215       // order is important: RuleTypeCopier must be the first one. And DebtAggregator must be before NewDebtAggregator (new debt requires
216       // debt)
217       RuleTypeCopier.class,
218       RuleTagsCopier.class,
219       IssueCreationDateCalculator.class,
220       DebtCalculator.class,
221       EffortAggregator.class,
222       NewEffortCalculator.class,
223       NewEffortAggregator.class,
224       IssueAssigner.class,
225       IssueCounter.class,
226       MovedIssueVisitor.class,
227       IssuesRepositoryVisitor.class,
228       RemoveProcessedComponentsVisitor.class,
229
230       // visitors : order is important, measure computers must be executed at the end in order to access to every measures / issues
231       LoadComponentUuidsHavingOpenIssuesVisitor.class,
232       IntegrateIssuesVisitor.class,
233       CloseIssuesOnRemovedComponentsVisitor.class,
234       MaintainabilityMeasuresVisitor.class,
235       NewMaintainabilityMeasuresVisitor.class,
236       ReliabilityAndSecurityRatingMeasuresVisitor.class,
237       NewReliabilityAndSecurityRatingMeasuresVisitor.class,
238       LastCommitVisitor.class,
239       MeasureComputersVisitor.class,
240
241       UpdateConflictResolver.class,
242       TrackerBaseInputFactory.class,
243       TrackerRawInputFactory.class,
244       TrackerMergeBranchInputFactory.class,
245       Tracker.class,
246       TrackerExecution.class,
247       ShortBranchTrackerExecution.class,
248       MergeBranchTrackerExecution.class,
249       ComponentIssuesLoader.class,
250       BaseIssuesLoader.class,
251       IssueTrackingDelegator.class,
252       BranchPersister.class,
253
254       // filemove
255       SourceSimilarityImpl.class,
256       FileSimilarityImpl.class,
257       MutableMovedFilesRepositoryImpl.class,
258
259       // duplication
260       IntegrateCrossProjectDuplications.class,
261       DuplicationMeasures.class,
262
263       // views
264       ViewIndex.class,
265
266       BranchLoader.class,
267       MeasureToMeasureDto.class,
268
269       // webhooks
270       WebhookModule.class);
271   }
272
273 }