From 42356b8ce08fb663ee975173ebb14ae7b7b691ca Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Wed, 29 Mar 2017 16:57:45 +0200 Subject: [PATCH] SONAR-9050 Stop using column project_measures.description --- .../measure/BestValueOptimization.java | 3 +- .../task/projectanalysis/measure/Measure.java | 40 ++++-------------- .../measure/MeasureToMeasureDto.java | 1 - .../measure/BestValueOptimizationTest.java | 8 ++-- .../measure/MeasureAssert.java | 42 ------------------- .../measure/MeasureRepoEntry.java | 1 - .../projectanalysis/measure/MeasureTest.java | 6 --- .../insert-from-index-result.xml | 1 - .../insert-from-report-result.xml | 1 - .../java/org/sonar/db/measure/MeasureDto.java | 12 ------ .../org/sonar/db/measure/MeasureMapper.xml | 2 - .../org/sonar/db/measure/MeasureDaoTest.java | 3 +- .../measure/MeasureDaoTest/insert-result.xml | 1 - 13 files changed, 13 insertions(+), 108 deletions(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/measure/BestValueOptimization.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/measure/BestValueOptimization.java index 38db43da28d..bce3c7c57a7 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/measure/BestValueOptimization.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/measure/BestValueOptimization.java @@ -57,8 +57,7 @@ public class BestValueOptimization implements Predicate { } private boolean isBestValueOptimized(Measure measure) { - return measure.getDescription() == null - && measure.getData() == null + return measure.getData() == null && !measure.hasQualityGateStatus() && hasNoVariation(measure, metric.getBestValue()) && (measure.getValueType() == NO_VALUE || isBestValue(measure, metric.getBestValue())); diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/measure/Measure.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/measure/Measure.java index b5b704b1292..eda72c35a86 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/measure/Measure.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/measure/Measure.java @@ -76,21 +76,18 @@ public final class Measure { @CheckForNull private final Level dataLevel; @CheckForNull - private final String description; - @CheckForNull private final QualityGateStatus qualityGateStatus; @CheckForNull private final Double variation; private Measure(ValueType valueType, @Nullable Developer developer, @Nullable Double value, @Nullable String data, @Nullable Level dataLevel, - @Nullable String description, @Nullable QualityGateStatus qualityGateStatus, @Nullable Double variation) { + @Nullable QualityGateStatus qualityGateStatus, @Nullable Double variation) { this.valueType = valueType; this.developer = developer; this.value = value; this.data = data; this.dataLevel = dataLevel; - this.description = description; this.qualityGateStatus = qualityGateStatus; this.variation = variation; } @@ -105,7 +102,6 @@ public final class Measure { public static final class NewMeasureBuilder { private Developer developer; - private String description; private QualityGateStatus qualityGateStatus; private Double variation; @@ -118,16 +114,6 @@ public final class Measure { return this; } - /** - * Sets the description of the measure - * - * @throws NullPointerException if the specified argument is {@code null} - */ - public NewMeasureBuilder setDescription(String description) { - this.description = requireNonNull(description, "description can not be set to null"); - return this; - } - public NewMeasureBuilder setQualityGateStatus(QualityGateStatus qualityGateStatus) { this.qualityGateStatus = requireNonNull(qualityGateStatus, "QualityGateStatus can not be set to null"); return this; @@ -139,7 +125,7 @@ public final class Measure { } public Measure create(boolean value, @Nullable String data) { - return new Measure(ValueType.BOOLEAN, developer, value ? 1.0d : 0.0d, data, null, description, qualityGateStatus, variation); + return new Measure(ValueType.BOOLEAN, developer, value ? 1.0d : 0.0d, data, null, qualityGateStatus, variation); } public Measure create(boolean value) { @@ -147,7 +133,7 @@ public final class Measure { } public Measure create(int value, @Nullable String data) { - return new Measure(ValueType.INT, developer, (double) value, data, null, description, qualityGateStatus, variation); + return new Measure(ValueType.INT, developer, (double) value, data, null, qualityGateStatus, variation); } public Measure create(int value) { @@ -155,7 +141,7 @@ public final class Measure { } public Measure create(long value, @Nullable String data) { - return new Measure(ValueType.LONG, developer, (double) value, data, null, description, qualityGateStatus, variation); + return new Measure(ValueType.LONG, developer, (double) value, data, null, qualityGateStatus, variation); } public Measure create(long value) { @@ -165,7 +151,7 @@ public final class Measure { public Measure create(double value, int decimalScale, @Nullable String data) { checkArgument(!Double.isNaN(value), "NaN is not allowed as a Measure value"); double scaledValue = scale(value, decimalScale); - return new Measure(ValueType.DOUBLE, developer, scaledValue, data, null, description, qualityGateStatus, variation); + return new Measure(ValueType.DOUBLE, developer, scaledValue, data, null, qualityGateStatus, variation); } public Measure create(double value, int decimalScale) { @@ -173,15 +159,15 @@ public final class Measure { } public Measure create(String value) { - return new Measure(ValueType.STRING, developer, null, requireNonNull(value), null, description, qualityGateStatus, variation); + return new Measure(ValueType.STRING, developer, null, requireNonNull(value), null, qualityGateStatus, variation); } public Measure create(Level level) { - return new Measure(ValueType.LEVEL, developer, null, null, requireNonNull(level), description, qualityGateStatus, variation); + return new Measure(ValueType.LEVEL, developer, null, null, requireNonNull(level), qualityGateStatus, variation); } public Measure createNoValue() { - return new Measure(ValueType.NO_VALUE, developer, null, null, null, description, qualityGateStatus, variation); + return new Measure(ValueType.NO_VALUE, developer, null, null, null, qualityGateStatus, variation); } private static double scale(double value, int decimalScale) { @@ -229,7 +215,6 @@ public final class Measure { public Measure create() { return new Measure(source.valueType, source.developer, source.value, source.data, source.dataLevel, - source.description, source.qualityGateStatus == null ? qualityGateStatus : source.qualityGateStatus, source.variation == null ? variation : source.variation); } @@ -362,14 +347,6 @@ public final class Measure { return variation; } - /** - * The optional description of the measure. Relevant for manual measures. - */ - @CheckForNull - public String getDescription() { - return description; - } - /** * a Metric is equal to another Metric if it has the same ruleId/characteristicId paar (both being potentially * {@code null} but only one of them can be non {@code null}). @@ -401,7 +378,6 @@ public final class Measure { .add("dataLevel", dataLevel) .add("qualityGateStatus", qualityGateStatus) .add("variations", variation) - .add("description", description) .toString(); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/measure/MeasureToMeasureDto.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/measure/MeasureToMeasureDto.java index e3802667148..cc1935fe7b2 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/measure/MeasureToMeasureDto.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/measure/MeasureToMeasureDto.java @@ -54,7 +54,6 @@ public class MeasureToMeasureDto { if (developer != null) { out.setDeveloperId(dbIdsRepository.getDeveloperId(developer)); } - out.setDescription(measure.getDescription()); out.setValue(valueAsDouble(measure)); out.setData(data(measure)); return out; diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/measure/BestValueOptimizationTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/measure/BestValueOptimizationTest.java index 0d3c0a1ecb6..6ad0fbe2841 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/measure/BestValueOptimizationTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/measure/BestValueOptimizationTest.java @@ -40,17 +40,15 @@ public class BestValueOptimizationTest { private static final MetricImpl METRIC_BOOLEAN_TRUE = createMetric(Metric.MetricType.BOOL, 1d); private static final double SOME_EMPTY_VARIATIONS = 0d; - public static Measure.NewMeasureBuilder[] builders_of_non_bestValueOptimized_measures() { + private static Measure.NewMeasureBuilder[] builders_of_non_bestValueOptimized_measures() { QualityGateStatus someQualityGateStatus = new QualityGateStatus(Measure.Level.ERROR, null); double someVariations = 2d; - String someDescription = "desc"; return new Measure.NewMeasureBuilder[] { newMeasureBuilder().setQualityGateStatus(someQualityGateStatus), newMeasureBuilder().setQualityGateStatus(someQualityGateStatus).setVariation(someVariations), newMeasureBuilder().setVariation(someVariations), - newMeasureBuilder().setQualityGateStatus(someQualityGateStatus).setDescription(someDescription), - newMeasureBuilder().setDescription(someDescription), - newMeasureBuilder().setQualityGateStatus(someQualityGateStatus).setVariation(someVariations).setDescription(someDescription), + newMeasureBuilder().setQualityGateStatus(someQualityGateStatus), + newMeasureBuilder().setQualityGateStatus(someQualityGateStatus).setVariation(someVariations), }; } diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/measure/MeasureAssert.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/measure/MeasureAssert.java index ff1c3f85397..c3627b09435 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/measure/MeasureAssert.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/measure/MeasureAssert.java @@ -179,37 +179,6 @@ public class MeasureAssert extends AbstractAssert { return this; } - public MeasureAssert hasDescription(String expected) { - isNotNull(); - - if (!Objects.equals(actual.getDescription(), expected)) { - failWithMessage("Expected description of Measure to be <%s> but was <%s>", expected, actual.getDescription()); - } - - return this; - } - - public MeasureAssert hasNoDescription() { - isNotNull(); - - if (actual.getDescription() != null) { - failWithMessage("Expected Measure to have no description but it was <%s>", actual.getDescription()); - } - - return this; - } - - public MeasureAssert hasNoQualityGateStatus() { - isNotNull(); - hasQualityGateStatus(); - - if (actual.hasQualityGateStatus()) { - failWithMessage("Expected Measure to have no QualityGateStatus but it did"); - } - - return this; - } - public MeasureAssert hasQualityGateLevel(Measure.Level expected) { isNotNull(); hasQualityGateStatus(); @@ -232,17 +201,6 @@ public class MeasureAssert extends AbstractAssert { return this; } - public MeasureAssert hasNoQualityGateText() { - isNotNull(); - hasQualityGateStatus(); - - if (actual.getQualityGateStatus().getText() == null) { - failWithMessage("Expected Measure to have no QualityGate Test but was <%s>", actual.getQualityGateStatus().getText()); - } - - return this; - } - private void hasQualityGateStatus() { if (!actual.hasQualityGateStatus()) { failWithMessage("Expected Measure to have a QualityGateStatus but it did not"); diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/measure/MeasureRepoEntry.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/measure/MeasureRepoEntry.java index 50e5a779a7b..1169a73becb 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/measure/MeasureRepoEntry.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/measure/MeasureRepoEntry.java @@ -77,7 +77,6 @@ public final class MeasureRepoEntry { && equalsByValue(measure, measure1) && equalsByVariation(measure, measure1) && equalsByQualityGateStatus(measure, measure1) - && Objects.equals(measure.getDescription(), measure1.getDescription()) && Objects.equals(measure.getData(), measure1.getData()); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/measure/MeasureTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/measure/MeasureTest.java index 472dedde38b..4b9a3d21cd8 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/measure/MeasureTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/measure/MeasureTest.java @@ -251,11 +251,6 @@ public class MeasureTest { newMeasureBuilder().setQualityGateStatus(null); } - @Test(expected = NullPointerException.class) - public void newMeasureBuilder_setDescription_throws_NPE_if_arg_is_null() { - newMeasureBuilder().setDescription(null); - } - @Test(expected = NullPointerException.class) public void updateMeasureBuilder_setQualityGateStatus_throws_NPE_if_arg_is_null() { Measure.updatedMeasureBuilder(newMeasureBuilder().createNoValue()).setQualityGateStatus(null); @@ -279,7 +274,6 @@ public class MeasureTest { Measure newMeasure = Measure.updatedMeasureBuilder(measure).create(); assertThat(newMeasure.getValueType()).isEqualTo(measure.getValueType()); - assertThat(newMeasure.getDescription()).isEqualTo(measure.getDescription()); assertThat(newMeasure.hasQualityGateStatus()).isEqualTo(measure.hasQualityGateStatus()); assertThat(newMeasure.hasVariation()).isEqualTo(measure.hasVariation()); } diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/task/projectanalysis/step/PersistNumberOfDaysSinceLastCommitStepTest/insert-from-index-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/task/projectanalysis/step/PersistNumberOfDaysSinceLastCommitStepTest/insert-from-index-result.xml index bebfa323a9f..2c86ebdd19b 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/computation/task/projectanalysis/step/PersistNumberOfDaysSinceLastCommitStepTest/insert-from-index-result.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/task/projectanalysis/step/PersistNumberOfDaysSinceLastCommitStepTest/insert-from-index-result.xml @@ -12,6 +12,5 @@ variation_value_5="[null]" alert_status="[null]" alert_text="[null]" - description="[null]" person_id="[null]"/> diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/task/projectanalysis/step/PersistNumberOfDaysSinceLastCommitStepTest/insert-from-report-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/task/projectanalysis/step/PersistNumberOfDaysSinceLastCommitStepTest/insert-from-report-result.xml index 2ade50f852e..35e08d7568a 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/computation/task/projectanalysis/step/PersistNumberOfDaysSinceLastCommitStepTest/insert-from-report-result.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/task/projectanalysis/step/PersistNumberOfDaysSinceLastCommitStepTest/insert-from-report-result.xml @@ -12,6 +12,5 @@ variation_value_5="[null]" alert_status="[null]" alert_text="[null]" - description="[null]" person_id="[null]"/> diff --git a/sonar-db/src/main/java/org/sonar/db/measure/MeasureDto.java b/sonar-db/src/main/java/org/sonar/db/measure/MeasureDto.java index b7e1d4e7310..fbf5fae3594 100644 --- a/sonar-db/src/main/java/org/sonar/db/measure/MeasureDto.java +++ b/sonar-db/src/main/java/org/sonar/db/measure/MeasureDto.java @@ -33,7 +33,6 @@ public class MeasureDto { private Double variation; private String alertStatus; private String alertText; - private String description; private String componentUuid; private String analysisUuid; private int metricId; @@ -111,16 +110,6 @@ public class MeasureDto { return this; } - @CheckForNull - public String getDescription() { - return description; - } - - public MeasureDto setDescription(@Nullable String description) { - this.description = description; - return this; - } - public int getMetricId() { return metricId; } @@ -158,7 +147,6 @@ public class MeasureDto { .add("variation", variation) .add("alertStatus", alertStatus) .add("alertText", alertText) - .add("description", description) .add("componentUuid", componentUuid) .add("analysisUuid", analysisUuid) .add("metricId", metricId) diff --git a/sonar-db/src/main/resources/org/sonar/db/measure/MeasureMapper.xml b/sonar-db/src/main/resources/org/sonar/db/measure/MeasureMapper.xml index 7db0a207c83..6b2f932796f 100644 --- a/sonar-db/src/main/resources/org/sonar/db/measure/MeasureMapper.xml +++ b/sonar-db/src/main/resources/org/sonar/db/measure/MeasureMapper.xml @@ -179,7 +179,6 @@ text_value, alert_status, alert_text, - description, person_id, variation_value_1, measure_data) @@ -191,7 +190,6 @@ #{textValue, jdbcType=VARCHAR}, #{alertStatus, jdbcType=VARCHAR}, #{alertText, jdbcType=VARCHAR}, - #{description, jdbcType=VARCHAR}, #{developerId, jdbcType=INTEGER}, #{variation, jdbcType=DOUBLE}, #{dataValue, jdbcType=BINARY} diff --git a/sonar-db/src/test/java/org/sonar/db/measure/MeasureDaoTest.java b/sonar-db/src/test/java/org/sonar/db/measure/MeasureDaoTest.java index 26930dcc6f9..f57ad192613 100644 --- a/sonar-db/src/test/java/org/sonar/db/measure/MeasureDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/measure/MeasureDaoTest.java @@ -89,8 +89,7 @@ public class MeasureDaoTest { .setData("data") .setVariation(1d) .setAlertStatus("alert") - .setAlertText("alert-text") - .setDescription("measure-description"); + .setAlertText("alert-text"); underTest.insert(db.getSession(), inserted); db.commit(); diff --git a/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/insert-result.xml b/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/insert-result.xml index 7d63f40cee4..692539f175b 100644 --- a/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/insert-result.xml +++ b/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/insert-result.xml @@ -15,6 +15,5 @@ variation_value_5="5.0" alert_status="alert" alert_text="alert-text" - description="measure-description" /> -- 2.39.5