Skip to content

Commit

Permalink
Add parameter to include the current project in the aggregated report (
Browse files Browse the repository at this point in the history
  • Loading branch information
lion7 committed Jun 27, 2022
1 parent 9852a8c commit af33753
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
<dataFileExclude>target/child2.coverage</dataFileExclude>
</dataFileExcludes>
<outputDirectory>target/jacoco-aggregate-customization</outputDirectory>
<includeCurrentProject>true</includeCurrentProject>
</configuration>
</execution>
</executions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,10 @@ File reportChild2 = new File( basedir, "report/target/jacoco-aggregate-customiza
if ( !reportChild2.isFile() ) {
throw new RuntimeException( "Report for child2 was not created." );
}

// Test customization of includeCurrentProject

File reportReport = new File( basedir, "report/target/jacoco-aggregate-customization/report/index.html" );
if ( !reportReport.isFile() ) {
throw new RuntimeException( "Report for report was not created." );
}
30 changes: 23 additions & 7 deletions jacoco-maven-plugin/src/org/jacoco/maven/ReportAggregateMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@
* <p>
* Creates a structured code coverage report (HTML, XML, and CSV) from multiple
* projects within reactor. The report is created from all modules this project
* depends on. From those projects class and source files as well as JaCoCo
* execution data files will be collected. In addition execution data is
* collected from the project itself. This also allows to create coverage
* reports when tests are in separate projects than the code under test, for
* example in case of integration tests.
* depends on, and optionally this project itself. From those projects class and
* source files as well as JaCoCo execution data files will be collected. In
* addition execution data is collected from the project itself. This also
* allows to create coverage reports when tests are in separate projects than
* the code under test, for example in case of integration tests.
* </p>
*
* <p>
Expand Down Expand Up @@ -82,6 +82,13 @@ public class ReportAggregateMojo extends AbstractReportMojo {
@Parameter(defaultValue = "${project.reporting.outputDirectory}/jacoco-aggregate")
private File outputDirectory;

/**
* Include this project in the report. If true then this projects class and
* source files as well as JaCoCo execution data files will be collected.
*/
@Parameter(defaultValue = "false")
private boolean includeCurrentProject;

/**
* The projects in the reactor.
*/
Expand Down Expand Up @@ -131,14 +138,23 @@ File getOutputDirectory() {
void createReport(final IReportGroupVisitor visitor,
final ReportSupport support) throws IOException {
final IReportGroupVisitor group = visitor.visitGroup(title);
if (includeCurrentProject) {
processProject(support, group, project);
}
for (final MavenProject dependency : findDependencies(
Artifact.SCOPE_COMPILE, Artifact.SCOPE_RUNTIME,
Artifact.SCOPE_PROVIDED)) {
support.processProject(group, dependency.getArtifactId(),
dependency, getIncludes(), getExcludes(), sourceEncoding);
processProject(support, group, dependency);
}
}

private void processProject(final ReportSupport support,
final IReportGroupVisitor group, final MavenProject project)
throws IOException {
support.processProject(group, project.getArtifactId(), project,
getIncludes(), getExcludes(), sourceEncoding);
}

public File getReportOutputDirectory() {
return outputDirectory;
}
Expand Down
7 changes: 7 additions & 0 deletions org.jacoco.doc/docroot/doc/changes.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ <h1>Change History</h1>

<h2>Snapshot Build @qualified.bundle.version@ (@build.date@)</h2>

<h3>New Features</h3>
<ul>
<li>Add parameter to include the current project in the <code>report-aggregate</code>
Maven goal
(GitHub <a href="https://github.com/jacoco/jacoco/issues/1007">#1007</a>).</li>
</ul>

<h3>Non-functional Changes</h3>
<ul>
<li>Experimental support for Java 20 class files
Expand Down

0 comments on commit af33753

Please sign in to comment.