import org.sonar.server.computation.debt.DebtModelHolderImpl;
import org.sonar.server.computation.event.EventRepositoryImpl;
import org.sonar.server.computation.issue.BaseIssuesLoader;
+import org.sonar.server.computation.issue.CloseIssuesOnRemovedComponentsVisitor;
import org.sonar.server.computation.issue.ComponentIssuesRepositoryImpl;
import org.sonar.server.computation.issue.ComponentsWithUnprocessedIssues;
import org.sonar.server.computation.issue.DebtAggregator;
import org.sonar.server.computation.issue.DebtCalculator;
import org.sonar.server.computation.issue.DefaultAssignee;
+import org.sonar.server.computation.issue.IntegrateIssuesVisitor;
import org.sonar.server.computation.issue.IssueAssigner;
import org.sonar.server.computation.issue.IssueCache;
import org.sonar.server.computation.issue.IssueCounter;
import org.sonar.server.computation.issue.IssueLifecycle;
import org.sonar.server.computation.issue.IssueVisitors;
+import org.sonar.server.computation.issue.LoadComponentUuidsHavingOpenIssuesVisitor;
import org.sonar.server.computation.issue.NewDebtAggregator;
import org.sonar.server.computation.issue.NewDebtCalculator;
import org.sonar.server.computation.issue.RuleCacheLoader;
import org.sonar.server.computation.issue.commonrule.TestErrorRule;
import org.sonar.server.computation.language.LanguageRepositoryImpl;
import org.sonar.server.computation.measure.MeasureComputersHolderImpl;
+import org.sonar.server.computation.measure.MeasureComputersVisitor;
import org.sonar.server.computation.measure.MeasureRepositoryImpl;
import org.sonar.server.computation.metric.MetricModule;
import org.sonar.server.computation.period.PeriodsHolderImpl;
import org.sonar.server.computation.qualitygate.QualityGateHolderImpl;
import org.sonar.server.computation.qualitygate.QualityGateServiceImpl;
import org.sonar.server.computation.qualityprofile.ActiveRulesHolderImpl;
+import org.sonar.server.computation.sqale.SqaleMeasuresVisitor;
import org.sonar.server.computation.sqale.SqaleRatingSettings;
-import org.sonar.server.computation.step.ComponentVisitors;
import org.sonar.server.computation.step.ComputationSteps;
import org.sonar.server.computation.step.ReportComputationSteps;
import org.sonar.server.view.index.ViewIndex;
@Override
public void populateContainer(ComputeEngineContainer container) {
ComputationSteps steps = new ReportComputationSteps(container);
- ComponentVisitors visitors = new ComponentVisitors(container);
container.add(item);
container.add(steps);
- container.add(visitors);
container.addSingletons(componentClasses());
container.addSingletons(steps.orderedStepClasses());
- container.addSingletons(visitors.orderedClasses());
}
/**
RuleTagsCopier.class,
IssueCounter.class,
+ // visitors : order is important, measure computers must be executed at the end in order to access to every measures / issues
+ LoadComponentUuidsHavingOpenIssuesVisitor.class,
+ IntegrateIssuesVisitor.class,
+ CloseIssuesOnRemovedComponentsVisitor.class,
+ SqaleMeasuresVisitor.class,
+ MeasureComputersVisitor.class,
+
UpdateConflictResolver.class,
TrackerBaseInputFactory.class,
TrackerRawInputFactory.class,
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.computation.step;
-
-import com.google.common.base.Function;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Iterables;
-import java.util.List;
-import javax.annotation.Nonnull;
-import org.sonar.server.computation.component.ComponentVisitor;
-import org.sonar.server.computation.container.ComputeEngineContainer;
-import org.sonar.server.computation.issue.CloseIssuesOnRemovedComponentsVisitor;
-import org.sonar.server.computation.issue.IntegrateIssuesVisitor;
-import org.sonar.server.computation.issue.LoadComponentUuidsHavingOpenIssuesVisitor;
-import org.sonar.server.computation.measure.MeasureComputersVisitor;
-import org.sonar.server.computation.sqale.SqaleMeasuresVisitor;
-
-/**
- * Ordered list of component visitors to be executed by {@link ExecuteVisitorsStep}
- */
-public class ComponentVisitors {
-
- private static final List<Class<? extends ComponentVisitor>> ORDERED_VISITOR_CLASSES = ImmutableList.of(
- LoadComponentUuidsHavingOpenIssuesVisitor.class,
- IntegrateIssuesVisitor.class,
- CloseIssuesOnRemovedComponentsVisitor.class,
-
- SqaleMeasuresVisitor.class,
-
- // Must be after all other visitors as it requires measures computed by previous visitors
- MeasureComputersVisitor.class
- );
-
- /**
- * List of all {@link ComponentVisitor}, ordered by execution sequence.
- */
- public List<Class<? extends ComponentVisitor>> orderedClasses() {
- return ORDERED_VISITOR_CLASSES;
- }
-
- private final ComputeEngineContainer computeEngineContainer;
-
- public ComponentVisitors(ComputeEngineContainer computeEngineContainer) {
- this.computeEngineContainer = computeEngineContainer;
- }
-
- public Iterable<ComponentVisitor> instances() {
- return Iterables.transform(orderedClasses(), new Function<Class<? extends ComponentVisitor>, ComponentVisitor>() {
- @Override
- public ComponentVisitor apply(@Nonnull Class<? extends ComponentVisitor> input) {
- ComponentVisitor componentVisitor = computeEngineContainer.getComponentByType(input);
- Preconditions.checkState(componentVisitor != null, String.format("Visitor not found: %s", input));
- return componentVisitor;
- }
- });
- }
-
-}
package org.sonar.server.computation.step;
+import java.util.List;
import org.sonar.server.computation.component.ComponentVisitor;
import org.sonar.server.computation.component.TreeRootHolder;
import org.sonar.server.computation.component.VisitorsCrawler;
public class ExecuteVisitorsStep implements ComputationStep {
private final TreeRootHolder treeRootHolder;
- private final Iterable<ComponentVisitor> visitors;
+ private final List<ComponentVisitor> visitors;
- public ExecuteVisitorsStep(TreeRootHolder treeRootHolder, ComponentVisitors visitors) {
+ public ExecuteVisitorsStep(TreeRootHolder treeRootHolder, List<ComponentVisitor> visitors) {
this.treeRootHolder = treeRootHolder;
- this.visitors = visitors.instances();
+ this.visitors = visitors;
}
@Override
import org.sonar.server.computation.metric.MetricRepositoryRule;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
import static org.sonar.api.measures.CoreMetrics.NCLOC;
import static org.sonar.api.measures.CoreMetrics.NCLOC_KEY;
import static org.sonar.server.computation.component.Component.Type.DIRECTORY;
).build());
}
- ComponentVisitors visitors = mock(ComponentVisitors.class);
-
@Test
public void execute_with_type_aware_visitor() throws Exception {
- when(visitors.instances()).thenReturn(Arrays.<ComponentVisitor>asList(new TestTypeAwareVisitor()));
- ExecuteVisitorsStep underStep = new ExecuteVisitorsStep(treeRootHolder, visitors);
+ ExecuteVisitorsStep underStep = new ExecuteVisitorsStep(treeRootHolder, Arrays.<ComponentVisitor>asList(new TestTypeAwareVisitor()));
measureRepository.addRawMeasure(FILE_1_REF, NCLOC_KEY, newMeasureBuilder().create(1));
measureRepository.addRawMeasure(FILE_2_REF, NCLOC_KEY, newMeasureBuilder().create(2));
@Test
public void execute_with_path_aware_visitor() throws Exception {
- when(visitors.instances()).thenReturn(Arrays.<ComponentVisitor>asList(new TestPathAwareVisitor()));
- ExecuteVisitorsStep underStep = new ExecuteVisitorsStep(treeRootHolder, visitors);
+ ExecuteVisitorsStep underStep = new ExecuteVisitorsStep(treeRootHolder, Arrays.<ComponentVisitor>asList(new TestPathAwareVisitor()));
measureRepository.addRawMeasure(FILE_1_REF, NCLOC_KEY, newMeasureBuilder().create(1));
measureRepository.addRawMeasure(FILE_2_REF, NCLOC_KEY, newMeasureBuilder().create(1));