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 parameter to include the current project in the aggregated report #1007

Merged
merged 5 commits into from
Jun 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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) {
lion7 marked this conversation as resolved.
Show resolved Hide resolved
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