Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add maven parameter to control which reports to generate (#1175)
Co-authored-by: troosan <antoine.de.troostembergh@gmail.com> Co-authored-by: Marc R. Hoffmann <hoffmann@mountainminds.com>
- Loading branch information
Showing
11 changed files
with
229 additions
and
53 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
jacoco-maven-plugin.test/it/it-report-select-formats/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright (c) 2009, 2021 Mountainminds GmbH & Co. KG and Contributors | ||
This program and the accompanying materials are made available under | ||
the terms of the Eclipse Public License 2.0 which is available at | ||
http://www.eclipse.org/legal/epl-2.0 | ||
SPDX-License-Identifier: EPL-2.0 | ||
Contributors: | ||
Marc R. Hoffmann - initial API and implementation | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>jacoco</groupId> | ||
<artifactId>setup-parent</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>it-report-select-formats</artifactId> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>@project.groupId@</groupId> | ||
<artifactId>jacoco-maven-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>prepare-agent</goal> | ||
</goals> | ||
</execution> | ||
<execution> | ||
<id>report</id> | ||
<goals> | ||
<goal>report</goal> | ||
</goals> | ||
<configuration> | ||
<formats> | ||
<format>XML</format> | ||
<format>CSV</format> | ||
</formats> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
15 changes: 15 additions & 0 deletions
15
jacoco-maven-plugin.test/it/it-report-select-formats/src/main/java/Example.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2009, 2021 Mountainminds GmbH & Co. KG and Contributors | ||
* This program and the accompanying materials are made available under | ||
* the terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Marc R. Hoffmann - initial API and implementation | ||
* | ||
*******************************************************************************/ | ||
public class Example { | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
jacoco-maven-plugin.test/it/it-report-select-formats/src/test/java/ExampleTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2009, 2021 Mountainminds GmbH & Co. KG and Contributors | ||
* This program and the accompanying materials are made available under | ||
* the terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Marc R. Hoffmann - initial API and implementation | ||
* | ||
*******************************************************************************/ | ||
import org.junit.Test; | ||
|
||
public class ExampleTest { | ||
|
||
@Test | ||
public void test() { | ||
new Example(); | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
jacoco-maven-plugin.test/it/it-report-select-formats/verify.bsh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2009, 2021 Mountainminds GmbH & Co. KG and Contributors | ||
* This program and the accompanying materials are made available under | ||
* the terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Marc R. Hoffmann - initial API and implementation | ||
* | ||
*******************************************************************************/ | ||
import java.io.*; | ||
|
||
File htmlReportFile = new File( basedir, "target/site/jacoco/index.html" ); | ||
if ( htmlReportFile.isFile() ) { | ||
throw new RuntimeException( "Unexpected HTML report was created" ); | ||
} | ||
|
||
File xmlReportFile = new File( basedir, "target/site/jacoco/jacoco.xml" ); | ||
if ( !xmlReportFile.isFile() ) { | ||
throw new RuntimeException( "XML report was not created" ); | ||
} | ||
|
||
File csvReportFile = new File( basedir, "target/site/jacoco/jacoco.csv" ); | ||
if ( !csvReportFile.isFile() ) { | ||
throw new RuntimeException( "CSV report was not created" ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
jacoco-maven-plugin/src/org/jacoco/maven/ReportFormat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2009, 2021 Mountainminds GmbH & Co. KG and Contributors | ||
* This program and the accompanying materials are made available under | ||
* the terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Marc R. Hoffmann - initial API and implementation | ||
* | ||
*******************************************************************************/ | ||
package org.jacoco.maven; | ||
|
||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.util.Locale; | ||
|
||
import org.jacoco.report.FileMultiReportOutput; | ||
import org.jacoco.report.IReportVisitor; | ||
import org.jacoco.report.csv.CSVFormatter; | ||
import org.jacoco.report.html.HTMLFormatter; | ||
import org.jacoco.report.xml.XMLFormatter; | ||
|
||
/** | ||
* Configurable output formats for the report goals. | ||
*/ | ||
public enum ReportFormat { | ||
|
||
/** | ||
* Multi-page html report. | ||
*/ | ||
HTML() { | ||
@Override | ||
IReportVisitor createVisitor(final AbstractReportMojo mojo, | ||
final Locale locale) throws IOException { | ||
final HTMLFormatter htmlFormatter = new HTMLFormatter(); | ||
htmlFormatter.setOutputEncoding(mojo.outputEncoding); | ||
htmlFormatter.setLocale(locale); | ||
if (mojo.footer != null) { | ||
htmlFormatter.setFooterText(mojo.footer); | ||
} | ||
return htmlFormatter.createVisitor( | ||
new FileMultiReportOutput(mojo.getOutputDirectory())); | ||
} | ||
}, | ||
|
||
/** | ||
* Single-file XML report. | ||
*/ | ||
XML() { | ||
@Override | ||
IReportVisitor createVisitor(final AbstractReportMojo mojo, | ||
final Locale locale) throws IOException { | ||
final XMLFormatter xml = new XMLFormatter(); | ||
xml.setOutputEncoding(mojo.outputEncoding); | ||
return xml.createVisitor(new FileOutputStream( | ||
new File(mojo.getOutputDirectory(), "jacoco.xml"))); | ||
} | ||
}, | ||
|
||
/** | ||
* Single-file CSV report. | ||
*/ | ||
CSV() { | ||
@Override | ||
IReportVisitor createVisitor(final AbstractReportMojo mojo, | ||
final Locale locale) throws IOException { | ||
final CSVFormatter csv = new CSVFormatter(); | ||
csv.setOutputEncoding(mojo.outputEncoding); | ||
return csv.createVisitor(new FileOutputStream( | ||
new File(mojo.getOutputDirectory(), "jacoco.csv"))); | ||
} | ||
}; | ||
|
||
abstract IReportVisitor createVisitor(AbstractReportMojo mojo, | ||
final Locale locale) throws IOException; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters