diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2015-08-26 17:15:54 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2015-08-31 09:49:15 +0200 |
commit | a2a6a50c88c58a0af3daa52e39e76d362078f547 (patch) | |
tree | fd8646f94efc6bac96d3e7ebc9fce0e68d643bcd /sonar-plugin-api/src | |
parent | aeccf8fba38eed49136826020d80cf7e0cef9bc6 (diff) | |
download | sonarqube-a2a6a50c88c58a0af3daa52e39e76d362078f547.tar.gz sonarqube-a2a6a50c88c58a0af3daa52e39e76d362078f547.zip |
SONAR-6730 Measure computer should allowed no Input metrics
For instance, when a measure computer needs only issues to compute measures, it won't declare any input metrics
Diffstat (limited to 'sonar-plugin-api/src')
-rw-r--r-- | sonar-plugin-api/src/main/java/org/sonar/api/ce/measure/MeasureComputer.java | 19 | ||||
-rw-r--r-- | sonar-plugin-api/src/test/java/org/sonar/api/test/ce/measure/MeasureComputerImpl.java | 41 |
2 files changed, 37 insertions, 23 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/ce/measure/MeasureComputer.java b/sonar-plugin-api/src/main/java/org/sonar/api/ce/measure/MeasureComputer.java index 32d5d90e469..d62851006a6 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/ce/measure/MeasureComputer.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/ce/measure/MeasureComputer.java @@ -48,24 +48,29 @@ public interface MeasureComputer { interface MeasureComputerBuilder { /** - * @throws IllegalStateException if there's not at least one input metrics - */ + * Input metrics can be empty (for instance when only issues are needed) + * @throws NullPointerException if inputMetrics is null + * @throws NullPointerException if the metrics contains a {@code null} + * */ MeasureComputerBuilder setInputMetrics(String... inputMetrics); /** - * @throws IllegalStateException if there's not at least one output metrics + * @throws IllegalArgumentException if there's not at least one output metrics + * @throws NullPointerException if the metrics contains a {@code null} */ MeasureComputerBuilder setOutputMetrics(String... outMetrics); /** - * @throws IllegalStateException if there's no implementation + * @throws NullPointerException if there's no implementation */ MeasureComputerBuilder setImplementation(Implementation impl); /** - * @throws IllegalStateException if there's not at least one input metrics - * @throws IllegalStateException if there's not at least one output metrics - * @throws IllegalStateException if there's no implementation + * @throws NullPointerException if inputMetrics is null + * @throws NullPointerException if inputs metrics contains a {@code null} + * @throws IllegalArgumentException if there's not at least one output metrics + * @throws NullPointerException if outputs metrics contains a {@code null} + * @throws NullPointerException if there's no implementation */ MeasureComputer build(); } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/test/ce/measure/MeasureComputerImpl.java b/sonar-plugin-api/src/test/java/org/sonar/api/test/ce/measure/MeasureComputerImpl.java index 653499c6efe..b661247a517 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/test/ce/measure/MeasureComputerImpl.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/test/ce/measure/MeasureComputerImpl.java @@ -22,9 +22,11 @@ package org.sonar.api.test.ce.measure; import com.google.common.collect.ImmutableSet; import java.util.Set; +import javax.annotation.Nullable; import org.sonar.api.ce.measure.MeasureComputer; import static com.google.common.base.Preconditions.checkArgument; +import static java.util.Objects.requireNonNull; public class MeasureComputerImpl implements MeasureComputer { @@ -64,49 +66,56 @@ public class MeasureComputerImpl implements MeasureComputer { public static class MeasureComputerBuilderImpl implements MeasureComputerBuilder { - private String[] inputMetricKeys; + private String[] inputMetricKeys = new String[] {}; private String[] outputMetrics; private Implementation measureComputerImplementation; @Override public MeasureComputerBuilder setInputMetrics(String... inputMetrics) { - this.inputMetricKeys = inputMetrics; - checkInputMetricKeys(); + this.inputMetricKeys = validateInputMetricKeys(inputMetrics); return this; } @Override public MeasureComputerBuilder setOutputMetrics(String... outputMetrics) { - this.outputMetrics = outputMetrics; - checkOutputMetricKeys(); + this.outputMetrics = validateOutputMetricKeys(outputMetrics); return this; } @Override public MeasureComputerBuilder setImplementation(Implementation impl) { - this.measureComputerImplementation = impl; - checkImplementation(); + this.measureComputerImplementation = validateImplementation(impl); return this; } @Override public MeasureComputer build() { - checkInputMetricKeys(); - checkOutputMetricKeys(); - checkImplementation(); + validateInputMetricKeys(this.inputMetricKeys); + validateOutputMetricKeys(this.outputMetrics); + validateImplementation(this.measureComputerImplementation); return new MeasureComputerImpl(this); } - private void checkInputMetricKeys(){ - checkArgument(this.inputMetricKeys != null && inputMetricKeys.length > 0, "At least one input metrics must be defined"); + private static String[] validateInputMetricKeys(@Nullable String[] inputMetrics) { + requireNonNull(inputMetrics, "Input metrics cannot be null"); + checkNotNull(inputMetrics); + return inputMetrics; } - private void checkOutputMetricKeys(){ - checkArgument(this.outputMetrics != null && outputMetrics.length > 0, "At least one output metrics must be defined"); + private static String[] validateOutputMetricKeys(@Nullable String[] outputMetrics) { + checkArgument(outputMetrics != null && outputMetrics.length > 0, "At least one output metric must be defined"); + checkNotNull(outputMetrics); + return outputMetrics; } - private void checkImplementation(){ - checkArgument(this.measureComputerImplementation != null, "The implementation is missing"); + private static Implementation validateImplementation(Implementation impl) { + return requireNonNull(impl, "The implementation is missing"); + } + } + + private static void checkNotNull(String[] metrics){ + for (String metric : metrics) { + requireNonNull(metric, "Null metric is not allowed"); } } } |