aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc R. Hoffmann <hoffmann@mountainminds.com>2014-01-20 17:25:54 +0100
committerMarc R. Hoffmann <hoffmann@mountainminds.com>2014-01-20 17:25:54 +0100
commit06befb09bee0e992d6d584137a6a70eddbf23a94 (patch)
tree0447ca0c19378dfcbecb901369d9d9ce8ae78e0e
parent817ef2a33158818cadb6a5df3b51b1e4fdec0338 (diff)
downloadjacoco-06befb09bee0e992d6d584137a6a70eddbf23a94.tar.gz
Log warning in Maven report goal if execution data does not match.
-rw-r--r--jacoco-maven-plugin.test/it/it-report-nomatch/nomatch.execbin0 -> 24 bytes
-rw-r--r--jacoco-maven-plugin.test/it/it-report-nomatch/pom.xml44
-rw-r--r--jacoco-maven-plugin.test/it/it-report-nomatch/src/main/java/Example.java14
-rw-r--r--jacoco-maven-plugin.test/it/it-report-nomatch/verify.bsh24
-rw-r--r--jacoco-maven-plugin/src/org/jacoco/maven/AbstractReportMojo.java2
-rw-r--r--jacoco-maven-plugin/src/org/jacoco/maven/BundleCreator.java36
-rw-r--r--jacoco-maven-plugin/src/org/jacoco/maven/CheckMojo.java15
7 files changed, 125 insertions, 10 deletions
diff --git a/jacoco-maven-plugin.test/it/it-report-nomatch/nomatch.exec b/jacoco-maven-plugin.test/it/it-report-nomatch/nomatch.exec
new file mode 100644
index 00000000..31cad96f
--- /dev/null
+++ b/jacoco-maven-plugin.test/it/it-report-nomatch/nomatch.exec
Binary files differ
diff --git a/jacoco-maven-plugin.test/it/it-report-nomatch/pom.xml b/jacoco-maven-plugin.test/it/it-report-nomatch/pom.xml
new file mode 100644
index 00000000..73b6a096
--- /dev/null
+++ b/jacoco-maven-plugin.test/it/it-report-nomatch/pom.xml
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright (c) 2009, 2014 Mountainminds GmbH & Co. KG and Contributors
+ All rights reserved. This program and the accompanying materials
+ are made available under the terms of the Eclipse Public License v1.0
+ which accompanies this distribution, and is available at
+ http://www.eclipse.org/legal/epl-v10.html
+
+ Contributors:
+ Evgeny Mandrikov - 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-nomatch</artifactId>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>@project.groupId@</groupId>
+ <artifactId>jacoco-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>report</id>
+ <phase>prepare-package</phase>
+ <goals>
+ <goal>report</goal>
+ </goals>
+ <configuration>
+ <dataFile>nomatch.exec</dataFile>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/jacoco-maven-plugin.test/it/it-report-nomatch/src/main/java/Example.java b/jacoco-maven-plugin.test/it/it-report-nomatch/src/main/java/Example.java
new file mode 100644
index 00000000..5d2c1392
--- /dev/null
+++ b/jacoco-maven-plugin.test/it/it-report-nomatch/src/main/java/Example.java
@@ -0,0 +1,14 @@
+/*******************************************************************************
+ * Copyright (c) 2009, 2014 Mountainminds GmbH & Co. KG and Contributors
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Marc R. Hoffmann - initial API and implementation
+ *
+ *******************************************************************************/
+public class Example {
+
+}
diff --git a/jacoco-maven-plugin.test/it/it-report-nomatch/verify.bsh b/jacoco-maven-plugin.test/it/it-report-nomatch/verify.bsh
new file mode 100644
index 00000000..e45c9ad7
--- /dev/null
+++ b/jacoco-maven-plugin.test/it/it-report-nomatch/verify.bsh
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * Copyright (c) 2009, 2014 Mountainminds GmbH & Co. KG and Contributors
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Evgeny Mandrikov - initial API and implementation
+ *
+ *******************************************************************************/
+import java.io.*;
+import org.codehaus.plexus.util.*;
+
+String buildLog = FileUtils.fileRead( new File( basedir, "build.log" ) );
+if ( buildLog.indexOf( "Classes in bundle 'it-report-nomatch' do no match with execution data." ) < 0 ) {
+ throw new RuntimeException( "Warning 1 was not printed" );
+}
+if ( buildLog.indexOf( "For report generation the same class files must be used as at runtime." ) < 0 ) {
+ throw new RuntimeException( "Warning 2 was not printed" );
+}
+if ( buildLog.indexOf( "Execution data for class Example does not match." ) < 0 ) {
+ throw new RuntimeException( "Warning 3 was not printed" );
+}
diff --git a/jacoco-maven-plugin/src/org/jacoco/maven/AbstractReportMojo.java b/jacoco-maven-plugin/src/org/jacoco/maven/AbstractReportMojo.java
index ac735c17..4c694aa8 100644
--- a/jacoco-maven-plugin/src/org/jacoco/maven/AbstractReportMojo.java
+++ b/jacoco-maven-plugin/src/org/jacoco/maven/AbstractReportMojo.java
@@ -215,7 +215,7 @@ public abstract class AbstractReportMojo extends AbstractMavenReport {
final FileFilter fileFilter = new FileFilter(this.getIncludes(),
this.getExcludes());
final BundleCreator creator = new BundleCreator(this.getProject(),
- fileFilter);
+ fileFilter, getLog());
final IBundleCoverage bundle = creator.createBundle(executionDataStore);
final SourceFileCollection locator = new SourceFileCollection(
getCompileSourceRoots(), sourceEncoding);
diff --git a/jacoco-maven-plugin/src/org/jacoco/maven/BundleCreator.java b/jacoco-maven-plugin/src/org/jacoco/maven/BundleCreator.java
index 3088399f..e20c4aef 100644
--- a/jacoco-maven-plugin/src/org/jacoco/maven/BundleCreator.java
+++ b/jacoco-maven-plugin/src/org/jacoco/maven/BundleCreator.java
@@ -12,15 +12,20 @@
*******************************************************************************/
package org.jacoco.maven;
+import static java.lang.String.format;
+
import java.io.File;
import java.io.IOException;
+import java.util.Collection;
import java.util.List;
+import org.apache.maven.plugin.logging.Log;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.FileUtils;
import org.jacoco.core.analysis.Analyzer;
import org.jacoco.core.analysis.CoverageBuilder;
import org.jacoco.core.analysis.IBundleCoverage;
+import org.jacoco.core.analysis.IClassCoverage;
import org.jacoco.core.data.ExecutionDataStore;
/**
@@ -30,6 +35,7 @@ public final class BundleCreator {
private final MavenProject project;
private final FileFilter fileFilter;
+ private final Log log;
/**
* Construct a new BundleCreator given the MavenProject and FileFilter.
@@ -38,10 +44,14 @@ public final class BundleCreator {
* the MavenProject
* @param fileFilter
* the FileFilter
+ * @param log
+ * for log output
*/
- public BundleCreator(final MavenProject project, final FileFilter fileFilter) {
+ public BundleCreator(final MavenProject project,
+ final FileFilter fileFilter, final Log log) {
this.project = project;
this.fileFilter = fileFilter;
+ this.log = log;
}
/**
@@ -68,6 +78,28 @@ public final class BundleCreator {
analyzer.analyzeAll(file);
}
- return builder.getBundle(this.project.getName());
+ final IBundleCoverage bundle = builder
+ .getBundle(this.project.getName());
+ logBundleInfo(bundle, builder.getNoMatchClasses());
+
+ return bundle;
+ }
+
+ private void logBundleInfo(final IBundleCoverage bundle,
+ final Collection<IClassCoverage> nomatch) {
+ log.info(format("Analyzed bundle '%s' with %s classes",
+ bundle.getName(),
+ Integer.valueOf(bundle.getClassCounter().getTotalCount())));
+ if (!nomatch.isEmpty()) {
+ log.warn(format(
+ "Classes in bundle '%s' do no match with execution data. "
+ + "For report generation the same class files must be used as at runtime.",
+ bundle.getName()));
+ for (final IClassCoverage c : nomatch) {
+ log.warn(format("Execution data for class %s does not match.",
+ c.getName()));
+ }
+ }
}
+
}
diff --git a/jacoco-maven-plugin/src/org/jacoco/maven/CheckMojo.java b/jacoco-maven-plugin/src/org/jacoco/maven/CheckMojo.java
index 94779c6a..f5f9a55a 100644
--- a/jacoco-maven-plugin/src/org/jacoco/maven/CheckMojo.java
+++ b/jacoco-maven-plugin/src/org/jacoco/maven/CheckMojo.java
@@ -54,10 +54,10 @@ public class CheckMojo extends AbstractJacocoMojo implements IViolationsOutput {
* If a limit refers to a ratio the range is from 0.0 to 1.0 where the
* number of decimal places will also determine the precision in error
* messages.
- *
+ *
* Note that you <b>must</b> use <tt>implementation</tt> hints for
- * <tt>rule</tt> and <tt>limit</tt> when using Maven 2, with Maven 3 you
- * do not need to specify the attributes.
+ * <tt>rule</tt> and <tt>limit</tt> when using Maven 2, with Maven 3 you do
+ * not need to specify the attributes.
* </p>
*
* <p>
@@ -137,11 +137,12 @@ public class CheckMojo extends AbstractJacocoMojo implements IViolationsOutput {
getLog().info(MSG_SKIPPING + dataFile);
return false;
}
- final File classesDirectory = new File(getProject().getBuild().getOutputDirectory());
+ final File classesDirectory = new File(getProject().getBuild()
+ .getOutputDirectory());
if (!classesDirectory.exists()) {
getLog().info(
- "Skipping JaCoCo execution due to missing classes directory:" +
- classesDirectory);
+ "Skipping JaCoCo execution due to missing classes directory:"
+ + classesDirectory);
return false;
}
return true;
@@ -189,7 +190,7 @@ public class CheckMojo extends AbstractJacocoMojo implements IViolationsOutput {
final FileFilter fileFilter = new FileFilter(this.getIncludes(),
this.getExcludes());
final BundleCreator creator = new BundleCreator(getProject(),
- fileFilter);
+ fileFilter, getLog());
try {
final ExecutionDataStore executionData = loadExecutionData();
return creator.createBundle(executionData);