]> source.dussan.org Git - sonarqube.git/commitdiff
add AbstractComputationSteps 643/head
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Fri, 20 Nov 2015 09:00:21 +0000 (10:00 +0100)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Fri, 20 Nov 2015 10:12:30 +0000 (11:12 +0100)
reduce duplication of code logic in implementations of ComputationSteps accross SQ and CE tasks in plugins

server/sonar-server/src/main/java/org/sonar/server/computation/step/AbstractComputationSteps.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/computation/step/ReportComputationSteps.java

diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/AbstractComputationSteps.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/AbstractComputationSteps.java
new file mode 100644 (file)
index 0000000..c77d99b
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * 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.collect.Iterables;
+import javax.annotation.Nonnull;
+import org.sonar.core.platform.ContainerPopulator;
+
+/**
+ * Abstract implementation of {@link ComputationStep} which provides the implementation of {@link ComputationSteps#instances()}
+ * based on a {@link org.sonar.core.platform.ContainerPopulator.Container}.
+ */
+public abstract class AbstractComputationSteps implements ComputationSteps {
+  private final ContainerPopulator.Container container;
+
+  protected AbstractComputationSteps(ContainerPopulator.Container container) {
+    this.container = container;
+  }
+
+  @Override
+  public Iterable<ComputationStep> instances() {
+    return Iterables.transform(orderedStepClasses(), new Function<Class<? extends ComputationStep>, ComputationStep>() {
+      @Override
+      public ComputationStep apply(@Nonnull Class<? extends ComputationStep> input) {
+        ComputationStep computationStepType = container.getComponentByType(input);
+        if (computationStepType == null) {
+          throw new IllegalStateException(String.format("Component not found: %s", input));
+        }
+        return computationStepType;
+      }
+    });
+  }
+}
index d6b8424b1f4139494e7715be6cfa987e425b69d3..d7595b90b9cced64a47c3a271e773567e144d564 100644 (file)
@@ -19,9 +19,7 @@
  */
 package org.sonar.server.computation.step;
 
-import com.google.common.base.Function;
 import com.google.common.base.Predicate;
-import com.google.common.collect.Iterables;
 import java.util.Arrays;
 import java.util.List;
 import javax.annotation.Nonnull;
@@ -33,7 +31,7 @@ import static com.google.common.collect.FluentIterable.from;
 /**
  * Ordered list of steps classes and instances to be executed for batch processing
  */
-public class ReportComputationSteps implements ComputationSteps {
+public class ReportComputationSteps extends AbstractComputationSteps {
 
   private static final List<Class<? extends ComputationStep>> STEPS = Arrays.asList(
     ExtractReportStep.class,
@@ -111,6 +109,7 @@ public class ReportComputationSteps implements ComputationSteps {
   private final ComputeEngineContainer computeEngineContainer;
 
   public ReportComputationSteps(ComputeEngineContainer computeEngineContainer) {
+    super(computeEngineContainer);
     this.computeEngineContainer = computeEngineContainer;
   }
 
@@ -125,30 +124,13 @@ public class ReportComputationSteps implements ComputationSteps {
       .toList();
   }
 
-  @Override
-  public Iterable<ComputationStep> instances() {
-    return Iterables.transform(orderedStepClasses(), new Function<Class<? extends ComputationStep>, ComputationStep>() {
-      @Override
-      public ComputationStep apply(@Nonnull Class<? extends ComputationStep> input) {
-        ComputationStep computationStepType = computeEngineContainer.getComponentByType(input);
-        if (computationStepType == null) {
-          throw new IllegalStateException(String.format("Component not found: %s", input));
-        }
-        return computationStepType;
-      }
-    });
-  }
-
   private class AllowPersistDevelopersStepIfDevCockpitPluginInstalled implements Predicate<Class<? extends ComputationStep>> {
 
     private final boolean devCockpitIsInstalled = computeEngineContainer.getComponentByType(DevCockpitBridge.class) != null;
 
     @Override
     public boolean apply(@Nonnull Class<? extends ComputationStep> input) {
-      if (devCockpitIsInstalled) {
-        return true;
-      }
-      return !input.equals(PersistDevelopersStep.class);
+      return devCockpitIsInstalled || !input.equals(PersistDevelopersStep.class);
     }
   }