diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2018-07-20 21:14:05 +0200 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2018-07-30 20:21:23 +0200 |
commit | 5f995384b08be67cdd11a52485b38cf7099bd113 (patch) | |
tree | e6d913a39ba5108a969a16afbab98926e070bb36 /sonar-scanner-engine | |
parent | c6a19fae1b693f8048c9e91fda4136682ef966fb (diff) | |
download | sonarqube-5f995384b08be67cdd11a52485b38cf7099bd113.tar.gz sonarqube-5f995384b08be67cdd11a52485b38cf7099bd113.zip |
SONAR-11064 drop metric comment_lines_data
Diffstat (limited to 'sonar-scanner-engine')
3 files changed, 14 insertions, 12 deletions
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<Integer, Object> optimizeStorage(String metricKey, Map<Integer, Object> 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<String> 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.<String>findByKey(BRANCHES_METRIC_KEY)).thenReturn(branchesMetric); when(metricFinder.<String>findByKey(CoreMetrics.NCLOC_DATA_KEY)).thenReturn(CoreMetrics.NCLOC_DATA); when(metricFinder.<String>findByKey(CoreMetrics.EXECUTABLE_LINES_DATA_KEY)).thenReturn(CoreMetrics.EXECUTABLE_LINES_DATA); - when(metricFinder.<String>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 |