diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2017-07-24 16:03:02 +0200 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2017-08-07 11:44:06 +0200 |
commit | 62c163c5b6e4d42117a8ba08dcadbfb27a7a27c5 (patch) | |
tree | 07c7c3188182272c39364afd91405377ce02f1ec /sonar-scanner-engine/src/main/java/org | |
parent | 94f2c5e8e859ff49d7a68d50d13b5b4f402ef28e (diff) | |
download | sonarqube-62c163c5b6e4d42117a8ba08dcadbfb27a7a27c5.tar.gz sonarqube-62c163c5b6e4d42117a8ba08dcadbfb27a7a27c5.zip |
SONAR-9600 Disable "force coverage to zero" in incremental mode
Diffstat (limited to 'sonar-scanner-engine/src/main/java/org')
-rw-r--r-- | sonar-scanner-engine/src/main/java/org/sonar/scanner/source/ZeroCoverageSensor.java | 34 |
1 files changed, 15 insertions, 19 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/source/ZeroCoverageSensor.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/source/ZeroCoverageSensor.java index 5732f0bacae..e788a597f51 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/source/ZeroCoverageSensor.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/source/ZeroCoverageSensor.java @@ -22,8 +22,8 @@ package org.sonar.scanner.source; import com.google.common.collect.Sets; import java.util.Map; import java.util.Set; -import java.util.function.Function; import java.util.stream.StreamSupport; +import org.sonar.api.batch.AnalysisMode; import org.sonar.api.batch.Phase; import org.sonar.api.batch.fs.FileSystem; import org.sonar.api.batch.fs.InputFile; @@ -38,30 +38,23 @@ import org.sonar.api.batch.sensor.coverage.NewCoverage; import org.sonar.api.batch.sensor.measure.internal.DefaultMeasure; import org.sonar.api.measures.CoreMetrics; import org.sonar.api.utils.KeyValueFormat; -import org.sonar.core.util.stream.MoreCollectors; +import org.sonar.api.utils.log.Logger; +import org.sonar.api.utils.log.Loggers; import org.sonar.scanner.scan.measure.MeasureCache; +import static org.sonar.core.util.stream.MoreCollectors.toSet; + @Phase(name = Phase.Name.POST) public final class ZeroCoverageSensor implements Sensor { - private static final class MeasureToMetricKey implements Function<DefaultMeasure<?>, String> { - @Override - public String apply(DefaultMeasure<?> input) { - return input.metric().key(); - } - } - - private static final class MetricToKey implements Function<Metric, String> { - @Override - public String apply(Metric input) { - return input.key(); - } - } + private static final Logger LOG = Loggers.get(ZeroCoverageSensor.class); private final MeasureCache measureCache; + private final AnalysisMode mode; - public ZeroCoverageSensor(MeasureCache measureCache) { + public ZeroCoverageSensor(MeasureCache measureCache, AnalysisMode mode) { this.measureCache = measureCache; + this.mode = mode; } @Override @@ -72,6 +65,10 @@ public final class ZeroCoverageSensor implements Sensor { @Override public void execute(final SensorContext context) { + if (mode.isIncremental()) { + LOG.debug("Incremental mode: not forcing coverage to zero"); + return; + } FileSystem fs = context.fileSystem(); for (InputFile f : fs.inputFiles(fs.predicates().hasType(Type.MAIN))) { if (((DefaultInputFile) f).isExcludedForCoverage()) { @@ -100,9 +97,8 @@ public final class ZeroCoverageSensor implements Sensor { private boolean isCoverageMeasuresAlreadyDefined(InputFile f) { Set<String> metricKeys = StreamSupport.stream(measureCache.byComponentKey(f.key()).spliterator(), false) - .map(new MeasureToMetricKey()).collect(MoreCollectors.toSet()); - Function<Metric, String> metricToKey = new MetricToKey(); - Set<String> allCoverageMetricKeys = CoverageType.UNIT.allMetrics().stream().map(metricToKey).collect(MoreCollectors.toSet()); + .map(m -> m.metric().key()).collect(toSet()); + Set<String> allCoverageMetricKeys = CoverageType.UNIT.allMetrics().stream().map(Metric::key).collect(toSet()); return !Sets.intersection(metricKeys, allCoverageMetricKeys).isEmpty(); } |