From 06befb09bee0e992d6d584137a6a70eddbf23a94 Mon Sep 17 00:00:00 2001 From: "Marc R. Hoffmann" Date: Mon, 20 Jan 2014 17:25:54 +0100 Subject: Log warning in Maven report goal if execution data does not match. --- .../src/org/jacoco/maven/AbstractReportMojo.java | 2 +- .../src/org/jacoco/maven/BundleCreator.java | 36 ++++++++++++++++++++-- .../src/org/jacoco/maven/CheckMojo.java | 15 ++++----- 3 files changed, 43 insertions(+), 10 deletions(-) (limited to 'jacoco-maven-plugin/src/org/jacoco') 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 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 must use implementation hints for - * rule and limit when using Maven 2, with Maven 3 you - * do not need to specify the attributes. + * rule and limit when using Maven 2, with Maven 3 you do + * not need to specify the attributes. *

* *

@@ -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); -- cgit v1.2.3