]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6730 Replace ComponentVisitors and inject directly ComponentVisitor in CE container
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 1 Sep 2015 14:55:22 +0000 (16:55 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 2 Sep 2015 12:28:19 +0000 (14:28 +0200)
server/sonar-server/src/main/java/org/sonar/server/computation/container/ReportComputeEngineContainerPopulator.java
server/sonar-server/src/main/java/org/sonar/server/computation/step/ComponentVisitors.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/computation/step/ExecuteVisitorsStep.java
server/sonar-server/src/test/java/org/sonar/server/computation/step/ExecuteVisitorsStepTest.java

index 664a04ace8260fa7eec7049c45f64c8afcda7772..7c1e502aff4a391259f7f9402eec3881a7ca1d0a 100644 (file)
@@ -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 (file)
index b3d92cc..0000000
+++ /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;
-      }
-    });
-  }
-
-}
index 31137c5f607e5e28d6b53d1663675b02279e23ab..0e87f65419cd6b2f54b8b52c7cd06485aff0cfcf 100644 (file)
 
 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
index c886445384afe13c84146d15b100ce4bdd8ab093..83289966607c3c66f71e366339b3f7ceec646fe3 100644 (file)
@@ -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));