aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorEvgeny Mandrikov <mandrikov@gmail.com>2012-03-25 03:00:37 +0600
committerEvgeny Mandrikov <mandrikov@gmail.com>2012-03-25 03:43:49 +0600
commitcf3eaf5efb2b200607689c8978c872c84e8ae794 (patch)
treebdb416260fc60320724cc0732a217e94e1a67a56 /plugins
parente8cdc53a9e7b329abe80622bb7a36320d1dc3bd8 (diff)
downloadsonarqube-cf3eaf5efb2b200607689c8978c872c84e8ae794.tar.gz
sonarqube-cf3eaf5efb2b200607689c8978c872c84e8ae794.zip
SONAR-3295 sonar.jacoco.excludes must exclude classes from coverage report
Diffstat (limited to 'plugins')
-rw-r--r--plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/AbstractAnalyzer.java24
-rw-r--r--plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/JaCoCoItSensor.java5
-rw-r--r--plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/JaCoCoSensor.java5
-rw-r--r--plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/JacocoConfiguration.java6
4 files changed, 37 insertions, 3 deletions
diff --git a/plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/AbstractAnalyzer.java b/plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/AbstractAnalyzer.java
index 5042d506bcb..6ce0673318e 100644
--- a/plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/AbstractAnalyzer.java
+++ b/plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/AbstractAnalyzer.java
@@ -19,6 +19,7 @@
*/
package org.sonar.plugins.jacoco;
+import com.google.common.annotations.VisibleForTesting;
import org.apache.commons.lang.StringUtils;
import org.jacoco.core.analysis.*;
import org.jacoco.core.data.ExecutionDataReader;
@@ -30,6 +31,7 @@ import org.sonar.api.measures.Measure;
import org.sonar.api.resources.JavaFile;
import org.sonar.api.resources.Project;
import org.sonar.api.utils.SonarException;
+import org.sonar.api.utils.WildcardPattern;
import java.io.File;
import java.io.FileInputStream;
@@ -49,14 +51,15 @@ public abstract class AbstractAnalyzer {
}
String path = getReportPath(project);
File jacocoExecutionData = project.getFileSystem().resolvePath(path);
+ WildcardPattern[] excludes = WildcardPattern.create(getExcludes(project));
try {
- readExecutionData(jacocoExecutionData, buildOutputDir, context);
+ readExecutionData(jacocoExecutionData, buildOutputDir, context, excludes);
} catch (IOException e) {
throw new SonarException(e);
}
}
- public final void readExecutionData(File jacocoExecutionData, File buildOutputDir, SensorContext context) throws IOException {
+ public final void readExecutionData(File jacocoExecutionData, File buildOutputDir, SensorContext context, WildcardPattern[] excludes) throws IOException {
SessionInfoStore sessionInfoStore = new SessionInfoStore();
ExecutionDataStore executionDataStore = new ExecutionDataStore();
@@ -79,7 +82,9 @@ public abstract class AbstractAnalyzer {
JavaFile resource = getResource(coverage);
// Do not save measures on resource which doesn't exist in the context
if (context.getResource(resource) != null) {
- analyzeFile(resource, coverage, context);
+ if (!isExcluded(coverage, excludes)) {
+ analyzeFile(resource, coverage, context);
+ }
analyzedResources++;
}
}
@@ -88,6 +93,17 @@ public abstract class AbstractAnalyzer {
}
}
+ private static boolean isExcluded(ISourceFileCoverage coverage, WildcardPattern[] excludes) {
+ String name = coverage.getPackageName() + "/" + coverage.getName();
+ for (WildcardPattern pattern : excludes) {
+ if (pattern.match(name)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @VisibleForTesting
static JavaFile getResource(ISourceFileCoverage coverage) {
String packageName = StringUtils.replaceChars(coverage.getPackageName(), '/', '.');
String fileName = StringUtils.substringBeforeLast(coverage.getName(), ".");
@@ -147,4 +163,6 @@ public abstract class AbstractAnalyzer {
protected abstract String getReportPath(Project project);
+ protected abstract String[] getExcludes(Project project);
+
}
diff --git a/plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/JaCoCoItSensor.java b/plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/JaCoCoItSensor.java
index 37cc58a21e0..ae19078aef7 100644
--- a/plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/JaCoCoItSensor.java
+++ b/plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/JaCoCoItSensor.java
@@ -58,6 +58,11 @@ public class JaCoCoItSensor implements Sensor {
}
@Override
+ protected String[] getExcludes(Project project) {
+ return configuration.getExcludes();
+ }
+
+ @Override
protected void saveMeasures(SensorContext context, JavaFile resource, Collection<Measure> measures) {
for (Measure measure : measures) {
Measure itMeasure = convertForIT(measure);
diff --git a/plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/JaCoCoSensor.java b/plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/JaCoCoSensor.java
index 63671d43515..d40b17d5141 100644
--- a/plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/JaCoCoSensor.java
+++ b/plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/JaCoCoSensor.java
@@ -55,6 +55,11 @@ public class JaCoCoSensor implements Sensor, CoverageExtension {
}
@Override
+ protected String[] getExcludes(Project project) {
+ return configuration.getExcludes();
+ }
+
+ @Override
protected void saveMeasures(SensorContext context, JavaFile resource, Collection<Measure> measures) {
for (Measure measure : measures) {
context.saveMeasure(resource, measure);
diff --git a/plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/JacocoConfiguration.java b/plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/JacocoConfiguration.java
index ea442494987..986d6694ab6 100644
--- a/plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/JacocoConfiguration.java
+++ b/plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/JacocoConfiguration.java
@@ -144,4 +144,10 @@ public class JacocoConfiguration implements BatchExtension {
public String[] getAntTargets() {
return settings.getStringArray(ANT_TARGETS_PROPERTY);
}
+
+ public String[] getExcludes() {
+ String values = settings.getString(EXCLUDES_PROPERTY);
+ return StringUtils.split(values, ':');
+ }
+
}