]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3295 sonar.jacoco.excludes must exclude classes from coverage report
authorEvgeny Mandrikov <mandrikov@gmail.com>
Mon, 26 Mar 2012 19:27:05 +0000 (01:27 +0600)
committerEvgeny Mandrikov <mandrikov@gmail.com>
Mon, 26 Mar 2012 19:33:42 +0000 (01:33 +0600)
plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/AbstractAnalyzer.java
plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/JaCoCoItSensor.java
plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/JaCoCoSensor.java
plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/JacocoConfiguration.java

index 6ce0673318ed191d3a9c188092b3615fa49c5755..fd487ac1c8283b4ebe7e78036bbe81b86074bc9b 100644 (file)
 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);
 
 }
index ae19078aef7b66d34681ea44453d0535c8dc466d..a2bc48ebc2f77251a2f294b7c59341cffd024790 100644 (file)
@@ -58,7 +58,7 @@ public class JaCoCoItSensor implements Sensor {
     }
 
     @Override
-    protected String[] getExcludes(Project project) {
+    protected String getExcludes(Project project) {
       return configuration.getExcludes();
     }
 
index d40b17d5141b971a1dbfe7596e47c0e0ead28969..76b69f4001642fea54c9487c5f6120494b0a7b0c 100644 (file)
@@ -55,7 +55,7 @@ public class JaCoCoSensor implements Sensor, CoverageExtension {
     }
 
     @Override
-    protected String[] getExcludes(Project project) {
+    protected String getExcludes(Project project) {
       return configuration.getExcludes();
     }
 
index 986d6694ab66d72bfdd307835f722c33faf4dbd2..a650f49f7363c1c3386157c1832537ce73308fa9 100644 (file)
@@ -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);
   }
 
 }