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