Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add exclusions support to cli #1581

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.codehaus.plexus.util.IOUtil;
import org.jacoco.core.instr.Instrumenter;
import org.jacoco.core.runtime.OfflineInstrumentationAccessGenerator;
import org.jacoco.report.FileFilter;

/**
* Performs offline instrumentation. Note that after execution of test you must
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.jacoco.report.FileFilter;
import org.jacoco.report.IReportGroupVisitor;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.jacoco.core.analysis.IBundleCoverage;
import org.jacoco.core.analysis.IClassCoverage;
import org.jacoco.core.tools.ExecFileLoader;
import org.jacoco.report.FileFilter;
import org.jacoco.report.IReportGroupVisitor;
import org.jacoco.report.IReportVisitor;
import org.jacoco.report.ISourceFileLocator;
Expand Down
13 changes: 12 additions & 1 deletion org.jacoco.cli/src/org/jacoco/cli/internal/commands/Report.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.jacoco.core.data.ExecutionDataStore;
import org.jacoco.core.tools.ExecFileLoader;
import org.jacoco.report.DirectorySourceFileLocator;
import org.jacoco.report.FileFilter;
import org.jacoco.report.FileMultiReportOutput;
import org.jacoco.report.IReportVisitor;
import org.jacoco.report.ISourceFileLocator;
Expand All @@ -48,6 +49,9 @@ public class Report extends Command {
@Argument(usage = "list of JaCoCo *.exec files to read", metaVar = "<execfiles>")
List<File> execfiles = new ArrayList<File>();

@Option(name = "--exclusions", usage = "pattern to excludes, e.g. **/*DTO.class", metaVar = "<pattern>")
List<String> exclusions = new ArrayList<String>();

@Option(name = "--classfiles", usage = "location of Java class files", metaVar = "<path>", required = true)
List<File> classfiles = new ArrayList<File>();

Expand Down Expand Up @@ -106,8 +110,15 @@ private IBundleCoverage analyze(final ExecutionDataStore data,
final PrintWriter out) throws IOException {
final CoverageBuilder builder = new CoverageBuilder();
final Analyzer analyzer = new Analyzer(data, builder);
final FileFilter fileFilter = new FileFilter(null, exclusions);
for (final File f : classfiles) {
analyzer.analyzeAll(f);
if (!f.isDirectory()) {
analyzer.analyzeAll(f);
continue;
}
for (final File filtered : fileFilter.getFiles(f)) {
analyzer.analyzeAll(filtered);
}
}
printNoMatchWarning(builder.getNoMatchClasses(), out);
return builder.getBundle(name);
Expand Down
5 changes: 5 additions & 0 deletions org.jacoco.report/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
<groupId>${project.groupId}</groupId>
<artifactId>org.jacoco.core</artifactId>
</dependency>
<dependency>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really, we don't want to have that dependency outside the Maven plugin. Why should any user of our library get an dependeny on the Maven framework?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the exiting filtering in core we use our own class WildcardMatcher, maybe this works here.

<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>3.0.24</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Kyle Lieber - implementation of CheckMojo
*
*******************************************************************************/
package org.jacoco.maven;
package org.jacoco.report;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -92,10 +92,9 @@ public String getExcludes() {

private String buildPattern(final List<String> patterns,
final String defaultPattern) {
String pattern = defaultPattern;
if (patterns != null && !patterns.isEmpty()) {
pattern = StringUtils.join(patterns.iterator(), ",");
if (patterns == null || patterns.isEmpty()) {
return defaultPattern;
}
return pattern;
return StringUtils.join(patterns.iterator(), ",");
}
}