aboutsummaryrefslogtreecommitdiff
path: root/jacoco-maven-plugin/src/org/jacoco
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 /jacoco-maven-plugin/src/org/jacoco
parent817ef2a33158818cadb6a5df3b51b1e4fdec0338 (diff)
downloadjacoco-06befb09bee0e992d6d584137a6a70eddbf23a94.tar.gz
Log warning in Maven report goal if execution data does not match.
Diffstat (limited to 'jacoco-maven-plugin/src/org/jacoco')
-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
3 files changed, 43 insertions, 10 deletions
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);