aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api/src/main/java
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2017-07-31 16:15:44 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2017-08-04 14:58:16 +0200
commit6cedf507a95545611c31813a427f43291beeadfc (patch)
treea509e266abbf44baa523e2a19566ccb249389666 /sonar-plugin-api/src/main/java
parent75e47ba5a19b3d4ab901d2ed7a180714b141d580 (diff)
downloadsonarqube-6cedf507a95545611c31813a427f43291beeadfc.tar.gz
sonarqube-6cedf507a95545611c31813a427f43291beeadfc.zip
SONAR-9557 Fix coverage exclusions for global sensors
Diffstat (limited to 'sonar-plugin-api/src/main/java')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputFile.java29
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/TestInputFileBuilder.java2
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/coverage/internal/DefaultCoverage.java15
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/SensorContextTester.java2
4 files changed, 33 insertions, 15 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputFile.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputFile.java
index 4312c634c04..3fe157a43e2 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputFile.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputFile.java
@@ -54,7 +54,8 @@ public class DefaultInputFile extends DefaultInputComponent implements InputFile
private Status status;
private Charset charset;
private Metadata metadata;
- private boolean publish;
+ private boolean published;
+ private boolean excludedForCoverage;
public DefaultInputFile(DefaultIndexedFile indexedFile, Consumer<DefaultInputFile> metadataGenerator) {
this(indexedFile, metadataGenerator, null);
@@ -66,7 +67,8 @@ public class DefaultInputFile extends DefaultInputComponent implements InputFile
this.indexedFile = indexedFile;
this.metadataGenerator = metadataGenerator;
this.metadata = null;
- this.publish = false;
+ this.published = false;
+ this.excludedForCoverage = false;
this.contents = contents;
}
@@ -100,19 +102,22 @@ public class DefaultInputFile extends DefaultInputComponent implements InputFile
}
}
- /**
- * @since 6.3
- */
- public DefaultInputFile setPublish(boolean publish) {
- this.publish = publish;
+ public DefaultInputFile setPublished(boolean published) {
+ this.published = published;
return this;
}
- /**
- * @since 6.3
- */
- public boolean publish() {
- return publish;
+ public boolean isPublished() {
+ return published;
+ }
+
+ public DefaultInputFile setExcludedForCoverage(boolean excludedForCoverage) {
+ this.excludedForCoverage = excludedForCoverage;
+ return this;
+ }
+
+ public boolean isExcludedForCoverage() {
+ return excludedForCoverage;
}
@Override
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/TestInputFileBuilder.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/TestInputFileBuilder.java
index c06e1ec4c30..df2bc17d5fa 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/TestInputFileBuilder.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/TestInputFileBuilder.java
@@ -198,7 +198,7 @@ public class TestInputFileBuilder {
contents);
inputFile.setStatus(status);
inputFile.setCharset(charset);
- inputFile.setPublish(publish);
+ inputFile.setPublished(publish);
return inputFile;
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/coverage/internal/DefaultCoverage.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/coverage/internal/DefaultCoverage.java
index c99f2ab7de6..04625256a65 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/coverage/internal/DefaultCoverage.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/coverage/internal/DefaultCoverage.java
@@ -24,6 +24,7 @@ import java.util.SortedMap;
import java.util.TreeMap;
import javax.annotation.Nullable;
import org.sonar.api.batch.fs.InputFile;
+import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.batch.sensor.coverage.CoverageType;
import org.sonar.api.batch.sensor.coverage.NewCoverage;
import org.sonar.api.batch.sensor.internal.DefaultStorable;
@@ -74,6 +75,9 @@ public class DefaultCoverage extends DefaultStorable implements NewCoverage {
@Override
public NewCoverage lineHits(int line, int hits) {
validateFile();
+ if (isExcluded()) {
+ return this;
+ }
validateLine(line);
if (!hitsByLine.containsKey(line)) {
@@ -97,6 +101,9 @@ public class DefaultCoverage extends DefaultStorable implements NewCoverage {
@Override
public NewCoverage conditions(int line, int conditions, int coveredConditions) {
validateFile();
+ if (isExcluded()) {
+ return this;
+ }
validateLine(line);
if (conditions > 0 && !conditionsByLine.containsKey(line)) {
@@ -139,7 +146,13 @@ public class DefaultCoverage extends DefaultStorable implements NewCoverage {
@Override
public void doSave() {
validateFile();
- storage.store(this);
+ if (!isExcluded()) {
+ storage.store(this);
+ }
+ }
+
+ private boolean isExcluded() {
+ return ((DefaultInputFile) inputFile).isExcludedForCoverage();
}
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/SensorContextTester.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/SensorContextTester.java
index edfa3645112..7e9dc824d16 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/SensorContextTester.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/SensorContextTester.java
@@ -352,6 +352,6 @@ public class SensorContextTester implements SensorContext {
@Override
public void markForPublishing(InputFile inputFile) {
DefaultInputFile file = (DefaultInputFile) inputFile;
- file.setPublish(true);
+ file.setPublished(true);
}
}