From 26883aeba7ecb1f6f7b499ae754a376ee40f4404 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Wed, 18 May 2016 10:56:11 +0200 Subject: [PATCH] Fix quality flaws --- .../computation/measure/api/MeasureImpl.java | 8 +++----- .../qualitymodel/QualityModelMeasuresVisitor.java | 10 ---------- .../java/org/sonar/server/platform/ServerImpl.java | 5 ----- .../org/sonar/server/qualitygate/QualityGates.java | 14 +++++++------- .../computation/measure/api/MeasureImplTest.java | 4 ++-- 5 files changed, 12 insertions(+), 29 deletions(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/measure/api/MeasureImpl.java b/server/sonar-server/src/main/java/org/sonar/server/computation/measure/api/MeasureImpl.java index b2d3cf71d5e..f22793b5554 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/measure/api/MeasureImpl.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/measure/api/MeasureImpl.java @@ -19,9 +19,8 @@ */ package org.sonar.server.computation.measure.api; -import com.google.common.collect.ImmutableSet; +import java.util.EnumSet; import java.util.Locale; -import java.util.Set; import javax.annotation.concurrent.Immutable; import org.sonar.api.ce.measure.Measure; @@ -36,7 +35,7 @@ import static org.sonar.server.computation.measure.Measure.ValueType.STRING; @Immutable public class MeasureImpl implements Measure { - private static final Set ALLOWED_VALUE_TYPES = ImmutableSet.of(INT, LONG, DOUBLE, STRING, BOOLEAN); + private static final EnumSet ALLOWED_VALUE_TYPES = EnumSet.of(INT, LONG, DOUBLE, STRING, BOOLEAN); private final org.sonar.server.computation.measure.Measure measure; @@ -79,8 +78,7 @@ public class MeasureImpl implements Measure { checkState(measure.getValueType() == expected, String.format( "Value can not be converted to %s because current value type is a %s", expected.toString().toLowerCase(Locale.US), - measure.getValueType() - )); + measure.getValueType())); } @Override diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/qualitymodel/QualityModelMeasuresVisitor.java b/server/sonar-server/src/main/java/org/sonar/server/computation/qualitymodel/QualityModelMeasuresVisitor.java index 1aa60869226..a6bd2569c06 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/qualitymodel/QualityModelMeasuresVisitor.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/qualitymodel/QualityModelMeasuresVisitor.java @@ -22,8 +22,6 @@ package org.sonar.server.computation.qualitymodel; import com.google.common.base.Optional; import org.sonar.api.ce.measure.Issue; import org.sonar.api.measures.CoreMetrics; -import org.sonar.api.rule.Severity; -import org.sonar.api.utils.Duration; import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; import org.sonar.server.computation.component.Component; @@ -270,14 +268,6 @@ public class QualityModelMeasuresVisitor extends PathAwareVisitorAdapter conditions, Metric metric, @Nullable final Integer period) { + private static void checkConditionDoesNotAlreadyExistOnSameMetricAndPeriod(Collection conditions, Metric metric, @Nullable final Integer period) { if (conditions.isEmpty()) { return; } @@ -302,7 +302,7 @@ public class QualityGates { } } - private void checkPeriod(Metric metric, @Nullable Integer period, Errors errors) { + private static void checkPeriod(Metric metric, @Nullable Integer period, Errors errors) { if (period == null) { errors.check(!metric.getKey().startsWith("new_"), "A period must be selected for differential metrics."); } else { @@ -310,24 +310,24 @@ public class QualityGates { } } - private void checkThresholds(@Nullable String warningThreshold, @Nullable String errorThreshold, Errors errors) { + private static void checkThresholds(@Nullable String warningThreshold, @Nullable String errorThreshold, Errors errors) { errors.check(warningThreshold != null || errorThreshold != null, "At least one threshold (warning, error) must be set."); } - private void checkOperator(Metric metric, String operator, Errors errors) { + private static void checkOperator(Metric metric, String operator, Errors errors) { errors .check(QualityGateConditionDto.isOperatorAllowed(operator, metric.getType()), format("Operator %s is not allowed for metric type %s.", operator, metric.getType())); } - private void validateMetric(Metric metric, Errors errors) { + private static void validateMetric(Metric metric, Errors errors) { errors.check(isAlertable(metric), format("Metric '%s' cannot be used to define a condition.", metric.getKey())); } - private boolean isAvailableForInit(Metric metric) { + private static boolean isAvailableForInit(Metric metric) { return !metric.isDataType() && !CoreMetrics.ALERT_STATUS.equals(metric) && ValueType.RATING != metric.getType(); } - private boolean isAlertable(Metric metric) { + private static boolean isAlertable(Metric metric) { return isAvailableForInit(metric) && BooleanUtils.isFalse(metric.isHidden()); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/measure/api/MeasureImplTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/measure/api/MeasureImplTest.java index 7b0f46ce1de..c78082b3164 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/measure/api/MeasureImplTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/measure/api/MeasureImplTest.java @@ -109,7 +109,7 @@ public class MeasureImplTest { @Test public void fail_with_ISE_when_creating_measure_with_no_value() throws Exception { thrown.expect(IllegalStateException.class); - thrown.expectMessage("Only following types are allowed [INT, LONG, DOUBLE, STRING, BOOLEAN]"); + thrown.expectMessage("Only following types are allowed [BOOLEAN, INT, LONG, DOUBLE, STRING]"); new MeasureImpl(Measure.newMeasureBuilder().createNoValue()); } @@ -117,7 +117,7 @@ public class MeasureImplTest { @Test public void fail_with_ISE_when_creating_measure_with_not_allowed_value() throws Exception { thrown.expect(IllegalStateException.class); - thrown.expectMessage("Only following types are allowed [INT, LONG, DOUBLE, STRING, BOOLEAN]"); + thrown.expectMessage("Only following types are allowed [BOOLEAN, INT, LONG, DOUBLE, STRING]"); new MeasureImpl(Measure.newMeasureBuilder().create(Measure.Level.ERROR)); } -- 2.39.5