From 5f995384b08be67cdd11a52485b38cf7099bd113 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Fri, 20 Jul 2018 21:14:05 +0200 Subject: SONAR-11064 drop metric comment_lines_data --- .../main/java/org/sonar/scanner/DefaultFileLinesContext.java | 12 +++++------- .../java/org/sonar/scanner/sensor/DefaultSensorStorage.java | 9 +++++++++ .../java/org/sonar/scanner/DefaultFileLinesContextTest.java | 5 ----- 3 files changed, 14 insertions(+), 12 deletions(-) (limited to 'sonar-scanner-engine') diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/DefaultFileLinesContext.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/DefaultFileLinesContext.java index b71a4adbebd..c59cd57f7db 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/DefaultFileLinesContext.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/DefaultFileLinesContext.java @@ -19,12 +19,12 @@ */ package org.sonar.scanner; -import static java.util.stream.Collectors.toMap; - +import com.google.common.base.MoreObjects; +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableMap; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; - import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.measure.MetricFinder; import org.sonar.api.batch.sensor.SensorContext; @@ -35,9 +35,7 @@ import org.sonar.api.utils.KeyValueFormat; import org.sonar.api.utils.KeyValueFormat.Converter; import org.sonar.scanner.scan.measure.MeasureCache; -import com.google.common.base.MoreObjects; -import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableMap; +import static java.util.stream.Collectors.toMap; public class DefaultFileLinesContext implements FileLinesContext { private final SensorContext context; @@ -117,7 +115,7 @@ public class DefaultFileLinesContext implements FileLinesContext { private static Map optimizeStorage(String metricKey, Map lines) { // SONAR-7464 Don't store 0 because this is default value anyway - if (CoreMetrics.NCLOC_DATA_KEY.equals(metricKey) || CoreMetrics.COMMENT_LINES_DATA_KEY.equals(metricKey) || CoreMetrics.EXECUTABLE_LINES_DATA_KEY.equals(metricKey)) { + if (CoreMetrics.NCLOC_DATA_KEY.equals(metricKey) || CoreMetrics.EXECUTABLE_LINES_DATA_KEY.equals(metricKey)) { return lines.entrySet().stream() .filter(entry -> !entry.getValue().equals(0)) .collect(toMap(Entry::getKey, Entry::getValue)); diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultSensorStorage.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultSensorStorage.java index c798dcca98d..538ca0d7de4 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultSensorStorage.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultSensorStorage.java @@ -69,6 +69,7 @@ import org.sonar.scanner.scan.measure.MeasureCache; import static java.util.stream.Collectors.toList; import static org.sonar.api.measures.CoreMetrics.BRANCH_COVERAGE; import static org.sonar.api.measures.CoreMetrics.COMMENTED_OUT_CODE_LINES_KEY; +import static org.sonar.api.measures.CoreMetrics.COMMENT_LINES_DATA_KEY; import static org.sonar.api.measures.CoreMetrics.CONDITIONS_BY_LINE; import static org.sonar.api.measures.CoreMetrics.CONDITIONS_TO_COVER; import static org.sonar.api.measures.CoreMetrics.COVERAGE; @@ -117,7 +118,15 @@ public class DefaultSensorStorage implements SensorStorage { private static final Logger LOG = Loggers.get(DefaultSensorStorage.class); + /** + * The metrics that can be computed by analyzers but that are + * filtered from analysis reports. That allows analyzers to continue + * providing measures that are supported only by older versions. + * + * The metrics in this list should not be declared in {@link ScannerMetrics#ALLOWED_CORE_METRICS}. + */ private static final List DEPRECATED_METRICS_KEYS = Arrays.asList( + COMMENT_LINES_DATA_KEY, DEPENDENCY_MATRIX_KEY, DIRECTORY_CYCLES_KEY, DIRECTORY_EDGES_WEIGHT_KEY, diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/DefaultFileLinesContextTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/DefaultFileLinesContextTest.java index 245702a0252..c4521bb6c31 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/DefaultFileLinesContextTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/DefaultFileLinesContextTest.java @@ -38,7 +38,6 @@ import static org.hamcrest.CoreMatchers.nullValue; import static org.junit.Assert.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import static org.sonar.api.measures.CoreMetrics.COMMENT_LINES_DATA_KEY; import static org.sonar.api.measures.CoreMetrics.EXECUTABLE_LINES_DATA_KEY; import static org.sonar.api.measures.CoreMetrics.NCLOC_DATA_KEY; @@ -77,7 +76,6 @@ public class DefaultFileLinesContextTest { when(metricFinder.findByKey(BRANCHES_METRIC_KEY)).thenReturn(branchesMetric); when(metricFinder.findByKey(CoreMetrics.NCLOC_DATA_KEY)).thenReturn(CoreMetrics.NCLOC_DATA); when(metricFinder.findByKey(CoreMetrics.EXECUTABLE_LINES_DATA_KEY)).thenReturn(CoreMetrics.EXECUTABLE_LINES_DATA); - when(metricFinder.findByKey(CoreMetrics.COMMENT_LINES_DATA_KEY)).thenReturn(CoreMetrics.COMMENT_LINES_DATA); measureCache = mock(MeasureCache.class); fileLineMeasures = new DefaultFileLinesContext(sensorContextTester, new TestInputFileBuilder("foo", "src/foo.php").initMetadata("Foo\nbar\nbiz").build(), metricFinder, measureCache); @@ -112,13 +110,10 @@ public class DefaultFileLinesContextTest { fileLineMeasures.setIntValue(NCLOC_DATA_KEY, 2, 1); fileLineMeasures.setIntValue(EXECUTABLE_LINES_DATA_KEY, 1, 0); fileLineMeasures.setIntValue(EXECUTABLE_LINES_DATA_KEY, 2, 1); - fileLineMeasures.setIntValue(COMMENT_LINES_DATA_KEY, 1, 0); - fileLineMeasures.setIntValue(COMMENT_LINES_DATA_KEY, 2, 1); fileLineMeasures.save(); assertThat(sensorContextTester.measure("foo:src/foo.php", NCLOC_DATA_KEY).value()).isEqualTo("2=1"); assertThat(sensorContextTester.measure("foo:src/foo.php", EXECUTABLE_LINES_DATA_KEY).value()).isEqualTo("2=1"); - assertThat(sensorContextTester.measure("foo:src/foo.php", COMMENT_LINES_DATA_KEY).value()).isEqualTo("2=1"); } @Test -- cgit v1.2.3