Skip to content
Browse files

maven-site-plugin 3.0 patch as per ticket 3461365 at https://sourcefo…

  • Loading branch information...
1 parent 7da3fc0 commit ad292a7069a61828bc2ec7b6f8bd6531391800e8 Ben Alex committed Dec 23, 2011
Showing with 163 additions and 10 deletions.
  1. +30 −0 jacoco-maven-plugin/pom.xml
  2. +133 −10 jacoco-maven-plugin/src/org/jacoco/maven/ReportMojo.java
View
30 jacoco-maven-plugin/pom.xml
@@ -46,6 +46,36 @@
<artifactId>plexus-utils</artifactId>
<version>1.5.6</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.maven.reporting</groupId>
+ <artifactId>maven-reporting-api</artifactId>
+ <version>3.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.reporting</groupId>
+ <artifactId>maven-reporting-impl</artifactId>
+ <version>2.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.doxia</groupId>
+ <artifactId>doxia-core</artifactId>
+ <version>1.1.3</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.doxia</groupId>
+ <artifactId>doxia-sink-api</artifactId>
+ <version>1.1.3</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.doxia</groupId>
+ <artifactId>doxia-decoration-model</artifactId>
+ <version>1.1.3</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.doxia</groupId>
+ <artifactId>doxia-site-renderer</artifactId>
+ <version>1.1.3</version>
+ </dependency>
@Godin
Godin added a note Dec 25, 2011

Seems that all dependencies except "maven-reporting-api" and "maven-reporting-impl" are useless.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
<dependency>
<groupId>org.jacoco</groupId>
View
143 jacoco-maven-plugin/src/org/jacoco/maven/ReportMojo.java
@@ -11,10 +11,20 @@
*******************************************************************************/
package org.jacoco.maven;
-import java.io.*;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
import java.util.ArrayList;
import java.util.List;
+import java.util.Locale;
+import org.apache.maven.doxia.siterenderer.Renderer;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.reporting.AbstractMavenReport;
+import org.apache.maven.reporting.MavenReportException;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.StringUtils;
import org.jacoco.core.analysis.Analyzer;
@@ -24,7 +34,11 @@
import org.jacoco.core.data.ExecutionDataReader;
import org.jacoco.core.data.ExecutionDataStore;
import org.jacoco.core.data.SessionInfoStore;
-import org.jacoco.report.*;
+import org.jacoco.report.FileMultiReportOutput;
+import org.jacoco.report.IReportGroupVisitor;
+import org.jacoco.report.IReportVisitor;
+import org.jacoco.report.ISourceFileLocator;
+import org.jacoco.report.MultiReportVisitor;
import org.jacoco.report.csv.CSVFormatter;
import org.jacoco.report.html.HTMLFormatter;
import org.jacoco.report.xml.XMLFormatter;
@@ -36,7 +50,85 @@
* @goal report
* @requiresProject true
*/
-public class ReportMojo extends AbstractJacocoMojo {
+public class ReportMojo extends AbstractMavenReport {
+
+ /**
+ * Maven project.
+ *
+ * @parameter expression="${project}"
+ * @readonly
+ */
+ private MavenProject project;
+
+ /**
+ * A list of class files to include in instrumentation/analysis/reports. May
+ * use wildcard characters (* and ?). When not specified - everything will
+ * be included.
+ *
+ * @parameter expression="${jacoco.includes}"
+ */
+ private List<String> includes;
+
+ /**
+ * A list of class files to exclude from instrumentation/analysis/reports.
+ * May use wildcard characters (* and ?).
+ *
+ * @parameter expression="${jacoco.excludes}"
+ */
+ private List<String> excludes;
+
+ /**
+ * Flag used to suppress execution.
+ *
+ * @parameter expression="${jacoco.skip}" default-value="false"
+ */
+ private boolean skip;
+
+ /**
+ * <i>Maven Internal</i>: The Doxia Site Renderer.
+ *
+ * @component
+ */
+ private Renderer siteRenderer;
+
+ /**
+ * @see org.apache.maven.reporting.AbstractMavenReport#canGenerateReport()
+ */
+ public boolean canGenerateReport() {
@Godin
Godin added a note Dec 25, 2011

In fact I think that would be better to really determine that report can be generated, i.e. data file exists and can be read.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ if ("pom".equals(project.getPackaging())) {
+ getLog().info(
+ "Skipping JaCoCo for project with packaging type 'pom'");
+ return false;
+ }
+ if (skip) {
+ getLog().info("Skipping JaCoCo execution");
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * @see org.apache.maven.reporting.AbstractMavenReport#isExternalReport()
+ */
+ public boolean isExternalReport()
+ {
+ return true;
+ }
+
+ /**
+ * @return Maven project
+ */
+ protected final MavenProject getProject() {
+ return project;
+ }
+
+ protected List<String> getIncludes() {
+ return includes;
+ }
+
+ protected List<String> getExcludes() {
+ return excludes;
+ }
/**
* Output directory for the reports.
@@ -72,8 +164,7 @@
private ExecutionDataStore executionDataStore;
- @Override
- protected void executeMojo() {
+ protected void executeReport(Locale locale) throws MavenReportException {
try {
loadExecutionData();
} catch (final IOException e) {
@@ -93,6 +184,31 @@ protected void executeMojo() {
}
}
+ @Override
+ public String getOutputName() {
+ return "jacoco/index";
+ }
+
+ @Override
+ public String getName(Locale locale) {
+ return "JaCoCo";
+ }
+
+ @Override
+ public String getDescription(Locale locale) {
+ return "JaCoCo Test Coverage Report.";
+ }
+
+ @Override
+ protected Renderer getSiteRenderer() {
+ return siteRenderer;
+ }
+
+ @Override
+ protected String getOutputDirectory() {
+ return outputDirectory.getAbsolutePath();
+ }
+
private void loadExecutionData() throws IOException {
sessionInfoStore = new SessionInfoStore();
executionDataStore = new ExecutionDataStore();
@@ -144,25 +260,31 @@ private IBundleCoverage createBundle() throws IOException {
private IReportVisitor createVisitor() throws IOException {
final List<IReportVisitor> visitors = new ArrayList<IReportVisitor>();
-
- outputDirectory.mkdirs();
+
+ File effectiveOutputDirectory = getReportOutputDirectory();
+ if (!effectiveOutputDirectory.getName().equals("jacoco")) {
@Godin
Godin added a note Dec 25, 2011

This condition implies that in case of following configuration

<plugin>
  <groupId>org.jacoco</groupId>
  <artifactId>jacoco-maven-plugin</artifactId>
  <executions>
    <execution>
      <id>report</id>
      <phase>prepare-package</phase>
      <goals>
        <goal>report</goal>
      </goals>
      <configuration>
        <outputDirectory>target/coverage</outputDirectory>
      </configuration>
    </execution>
  </executions>
</plugin>

report would be generated in directory "target/coverage/jacoco", whereas expected "target/coverage".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ effectiveOutputDirectory = new File(effectiveOutputDirectory, "jacoco");
+ }
+
+ getLog().debug("Effective output directory: " + effectiveOutputDirectory.getCanonicalPath());
+ effectiveOutputDirectory.mkdirs();
final XMLFormatter xmlFormatter = new XMLFormatter();
xmlFormatter.setOutputEncoding(outputEncoding);
visitors.add(xmlFormatter.createVisitor(new FileOutputStream(new File(
- outputDirectory, "jacoco.xml"))));
+ effectiveOutputDirectory, "jacoco.xml"))));
final CSVFormatter formatter = new CSVFormatter();
formatter.setOutputEncoding(outputEncoding);
visitors.add(formatter.createVisitor(new FileOutputStream(new File(
- outputDirectory, "jacoco.csv"))));
+ effectiveOutputDirectory, "jacoco.csv"))));
final HTMLFormatter htmlFormatter = new HTMLFormatter();
// formatter.setFooterText(footer);
htmlFormatter.setOutputEncoding(outputEncoding);
// formatter.setLocale(locale);
visitors.add(htmlFormatter.createVisitor(new FileMultiReportOutput(
- outputDirectory)));
+ effectiveOutputDirectory)));
return new MultiReportVisitor(visitors);
}
@@ -217,6 +339,7 @@ private File resolvePath(final String path) {
return result;
}
+ @SuppressWarnings("unchecked")
protected List<File> getFilesToAnalyze(File rootDir) throws IOException {
final String includes;
if (getIncludes() != null && !getIncludes().isEmpty()) {

2 comments on commit ad292a7

@Godin
Godin commented on ad292a7 Dec 25, 2011

This patch does not allow to use report as a standalone Mojo, which is indicated by failure of integration tests :

The following builds failed:
*  it-report-without-debug/pom.xml
*  it-includes-excludes/pom.xml
*  it-multi-module/pom.xml
*  it-report-without-dump/pom.xml

thus introduces regression.

@Godin
Godin commented on ad292a7 Dec 25, 2011

FYI: patch was reworked and applied (including integration test) - https://sourceforge.net/apps/trac/eclemma/changeset/1551
And snapshot version has been deployed https://oss.sonatype.org/content/repositories/snapshots/org/jacoco/
So this feature definitely will be a part of next JaCoCo release.

Please sign in to comment.
Something went wrong with that request. Please try again.