From 2d407aeb481218fdcf9cdc498008942d92252f04 Mon Sep 17 00:00:00 2001 From: Evgeny Mandrikov Date: Tue, 27 Mar 2012 01:27:05 +0600 Subject: [PATCH] SONAR-3295 sonar.jacoco.excludes must exclude classes from coverage report --- .../plugins/jacoco/AbstractAnalyzer.java | 19 ++++++++----------- .../sonar/plugins/jacoco/JaCoCoItSensor.java | 2 +- .../sonar/plugins/jacoco/JaCoCoSensor.java | 2 +- .../plugins/jacoco/JacocoConfiguration.java | 5 ++--- 4 files changed, 12 insertions(+), 16 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 6ce0673318e..fd487ac1c82 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 @@ -20,18 +20,19 @@ package org.sonar.plugins.jacoco; import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Strings; import org.apache.commons.lang.StringUtils; import org.jacoco.core.analysis.*; import org.jacoco.core.data.ExecutionDataReader; import org.jacoco.core.data.ExecutionDataStore; import org.jacoco.core.data.SessionInfoStore; +import org.jacoco.core.runtime.WildcardMatcher; import org.sonar.api.batch.SensorContext; import org.sonar.api.measures.CoverageMeasuresBuilder; 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; @@ -51,7 +52,8 @@ public abstract class AbstractAnalyzer { } String path = getReportPath(project); File jacocoExecutionData = project.getFileSystem().resolvePath(path); - WildcardPattern[] excludes = WildcardPattern.create(getExcludes(project)); + + WildcardMatcher excludes = new WildcardMatcher(Strings.nullToEmpty(getExcludes(project))); try { readExecutionData(jacocoExecutionData, buildOutputDir, context, excludes); } catch (IOException e) { @@ -59,7 +61,7 @@ public abstract class AbstractAnalyzer { } } - public final void readExecutionData(File jacocoExecutionData, File buildOutputDir, SensorContext context, WildcardPattern[] excludes) throws IOException { + public final void readExecutionData(File jacocoExecutionData, File buildOutputDir, SensorContext context, WildcardMatcher excludes) throws IOException { SessionInfoStore sessionInfoStore = new SessionInfoStore(); ExecutionDataStore executionDataStore = new ExecutionDataStore(); @@ -93,14 +95,9 @@ public abstract class AbstractAnalyzer { } } - private static boolean isExcluded(ISourceFileCoverage coverage, WildcardPattern[] excludes) { + private static boolean isExcluded(ISourceFileCoverage coverage, WildcardMatcher excludesMatcher) { String name = coverage.getPackageName() + "/" + coverage.getName(); - for (WildcardPattern pattern : excludes) { - if (pattern.match(name)) { - return true; - } - } - return false; + return excludesMatcher.matches(name); } @VisibleForTesting @@ -163,6 +160,6 @@ public abstract class AbstractAnalyzer { protected abstract String getReportPath(Project project); - protected abstract String[] getExcludes(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 ae19078aef7..a2bc48ebc2f 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,7 +58,7 @@ public class JaCoCoItSensor implements Sensor { } @Override - protected String[] getExcludes(Project project) { + protected String getExcludes(Project project) { return configuration.getExcludes(); } 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 d40b17d5141..76b69f40016 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,7 +55,7 @@ public class JaCoCoSensor implements Sensor, CoverageExtension { } @Override - protected String[] getExcludes(Project project) { + protected String getExcludes(Project project) { return configuration.getExcludes(); } 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 986d6694ab6..a650f49f736 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 @@ -145,9 +145,8 @@ public class JacocoConfiguration implements BatchExtension { return settings.getStringArray(ANT_TARGETS_PROPERTY); } - public String[] getExcludes() { - String values = settings.getString(EXCLUDES_PROPERTY); - return StringUtils.split(values, ':'); + public String getExcludes() { + return settings.getString(EXCLUDES_PROPERTY); } } -- 2.39.5