diff options
2 files changed, 54 insertions, 21 deletions
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 index 00000000000..c77d99b3724 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/step/AbstractComputationSteps.java @@ -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; + } + }); + } +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/ReportComputationSteps.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/ReportComputationSteps.java index d6b8424b1f4..d7595b90b9c 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/step/ReportComputationSteps.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/step/ReportComputationSteps.java @@ -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); } } |