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;
}
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) {
}
}
- 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();
}
}
- 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
protected abstract String getReportPath(Project project);
- protected abstract String[] getExcludes(Project project);
+ protected abstract String getExcludes(Project project);
}