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 maven parameter to control which reports to generate #1175

Merged
merged 9 commits into from May 1, 2021
42 changes: 39 additions & 3 deletions jacoco-maven-plugin/src/org/jacoco/maven/AbstractReportMojo.java
Expand Up @@ -12,6 +12,7 @@
*******************************************************************************/
package org.jacoco.maven;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Locale;
Expand All @@ -33,12 +34,23 @@
public abstract class AbstractReportMojo extends AbstractMojo
implements MavenMultiPageReport {

static final String REPORT_XML = "XML";
marchof marked this conversation as resolved.
Show resolved Hide resolved
static final String REPORT_HTML = "HTML";
static final String REPORT_CSV = "CSV";

/**
* Encoding of the generated reports.
*/
@Parameter(property = "project.reporting.outputEncoding", defaultValue = "UTF-8")
String outputEncoding;

/**
* A list of report formats to generate. Supported formats are HTML, XML and
* CSV. Defaults to all formats if no values are given
*/
@Parameter
List<String> formats;

/**
* Name of the root node HTML report pages.
*
Expand Down Expand Up @@ -140,6 +152,8 @@ public boolean canGenerateReport() {

abstract boolean canGenerateReportRegardingClassesDirectory();

abstract File getOutputDirectory();

public void generate(
@SuppressWarnings("deprecation") final org.codehaus.doxia.sink.Sink sink,
final Locale locale) throws MavenReportException {
Expand Down Expand Up @@ -186,12 +200,34 @@ private void executeReport(final Locale locale)
}
}

private void addFormatters(final ReportSupport support, final Locale locale)
throws IOException {
if (formats == null || formats.isEmpty()) {
marchof marked this conversation as resolved.
Show resolved Hide resolved
support.addAllFormatters(getOutputDirectory(), outputEncoding,
footer, locale);
} else {
getOutputDirectory().mkdirs();
marchof marked this conversation as resolved.
Show resolved Hide resolved
if (formats.contains(REPORT_CSV)) {
support.addCsvFormatter(
new File(getOutputDirectory(), "jacoco.csv"),
outputEncoding);
}
if (formats.contains(REPORT_XML)) {
support.addXmlFormatter(
new File(getOutputDirectory(), "jacoco.xml"),
outputEncoding);
}
if (formats.contains(REPORT_HTML)) {
support.addHtmlFormatter(getOutputDirectory(), outputEncoding,
footer, locale);
}
}

}

abstract void loadExecutionData(final ReportSupport support)
throws IOException;

abstract void addFormatters(final ReportSupport support,
final Locale locale) throws IOException;

abstract void createReport(final IReportGroupVisitor visitor,
final ReportSupport support) throws IOException;

Expand Down
Expand Up @@ -123,10 +123,8 @@ private void loadExecutionData(final ReportSupport support,
}

@Override
void addFormatters(final ReportSupport support, final Locale locale)
throws IOException {
support.addAllFormatters(outputDirectory, outputEncoding, footer,
locale);
File getOutputDirectory() {
return outputDirectory;
}

@Override
Expand Down
6 changes: 2 additions & 4 deletions jacoco-maven-plugin/src/org/jacoco/maven/ReportITMojo.java
Expand Up @@ -67,10 +67,8 @@ void loadExecutionData(final ReportSupport support) throws IOException {
}

@Override
void addFormatters(final ReportSupport support, final Locale locale)
throws IOException {
support.addAllFormatters(outputDirectory, outputEncoding, footer,
locale);
File getOutputDirectory() {
return outputDirectory;
}

@Override
Expand Down
6 changes: 2 additions & 4 deletions jacoco-maven-plugin/src/org/jacoco/maven/ReportMojo.java
Expand Up @@ -62,10 +62,8 @@ void loadExecutionData(final ReportSupport support) throws IOException {
}

@Override
void addFormatters(final ReportSupport support, final Locale locale)
throws IOException {
support.addAllFormatters(outputDirectory, outputEncoding, footer,
locale);
File getOutputDirectory() {
return outputDirectory;
}

@Override
Expand Down