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