aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2015-09-01 16:55:22 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2015-09-02 14:28:19 +0200
commit65ebf5ecc8b06a5a3992d326d0fc5ddda38175fd (patch)
treed8adb6f0f857bcf2fc871dfd1814b7c975004f21
parent32428f49443f18796d73237b892117e171c1f5af (diff)
downloadsonarqube-65ebf5ecc8b06a5a3992d326d0fc5ddda38175fd.tar.gz
sonarqube-65ebf5ecc8b06a5a3992d326d0fc5ddda38175fd.zip
SONAR-6730 Replace ComponentVisitors and inject directly ComponentVisitor in CE container
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/container/ReportComputeEngineContainerPopulator.java16
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/step/ComponentVisitors.java77
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/step/ExecuteVisitorsStep.java7
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/step/ExecuteVisitorsStepTest.java10
4 files changed, 18 insertions, 92 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/container/ReportComputeEngineContainerPopulator.java b/server/sonar-server/src/main/java/org/sonar/server/computation/container/ReportComputeEngineContainerPopulator.java
index 664a04ace82..7c1e502aff4 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/container/ReportComputeEngineContainerPopulator.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/container/ReportComputeEngineContainerPopulator.java
@@ -36,16 +36,19 @@ import org.sonar.server.computation.component.SettingsRepositoryImpl;
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;
@@ -66,6 +69,7 @@ import org.sonar.server.computation.issue.commonrule.SkippedTestRule;
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;
@@ -73,8 +77,8 @@ import org.sonar.server.computation.qualitygate.EvaluationResultTextConverterImp
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;
@@ -89,13 +93,10 @@ public final class ReportComputeEngineContainerPopulator implements ContainerPop
@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());
}
/**
@@ -162,6 +163,13 @@ public final class ReportComputeEngineContainerPopulator implements ContainerPop
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,
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/ComponentVisitors.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/ComponentVisitors.java
deleted file mode 100644
index b3d92cc8273..00000000000
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/step/ComponentVisitors.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * 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;
- }
- });
- }
-
-}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/ExecuteVisitorsStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/ExecuteVisitorsStep.java
index 31137c5f607..0e87f65419c 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/step/ExecuteVisitorsStep.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/step/ExecuteVisitorsStep.java
@@ -20,17 +20,18 @@
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
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/ExecuteVisitorsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/ExecuteVisitorsStepTest.java
index c886445384a..83289966607 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/ExecuteVisitorsStepTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/ExecuteVisitorsStepTest.java
@@ -36,8 +36,6 @@ import org.sonar.server.computation.metric.MetricImpl;
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;
@@ -84,12 +82,9 @@ public class ExecuteVisitorsStepTest {
).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));
@@ -108,8 +103,7 @@ public class ExecuteVisitorsStepTest {
@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));