diff options
author | Marc R. Hoffmann <hoffmann@mountainminds.com> | 2014-01-17 16:44:27 +0100 |
---|---|---|
committer | Marc R. Hoffmann <hoffmann@mountainminds.com> | 2014-01-20 17:04:01 +0100 |
commit | 817ef2a33158818cadb6a5df3b51b1e4fdec0338 (patch) | |
tree | 025fcf58a63d0c29e486bda9667d015e9bf158bb | |
parent | 60c33d63e75c1b0a5da9bd58be1f0b5434240220 (diff) | |
download | jacoco-817ef2a33158818cadb6a5df3b51b1e4fdec0338.tar.gz |
Log warning in Ant report task if execution data does not match.
-rw-r--r-- | org.jacoco.ant.test/src/org/jacoco/ant/ReportTaskTest.xml | 36 | ||||
-rw-r--r-- | org.jacoco.ant.test/src/org/jacoco/ant/data/nomatch.exec | bin | 0 -> 42 bytes | |||
-rw-r--r-- | org.jacoco.ant/src/org/jacoco/ant/ReportTask.java | 27 |
3 files changed, 49 insertions, 14 deletions
diff --git a/org.jacoco.ant.test/src/org/jacoco/ant/ReportTaskTest.xml b/org.jacoco.ant.test/src/org/jacoco/ant/ReportTaskTest.xml index bed8b2f0..04ab9802 100644 --- a/org.jacoco.ant.test/src/org/jacoco/ant/ReportTaskTest.xml +++ b/org.jacoco.ant.test/src/org/jacoco/ant/ReportTaskTest.xml @@ -117,6 +117,24 @@ </jacoco:report> <au:assertLogDoesntContain level="warn" text="source code annotation"/> </target> + + <target name="testReportWithNoMatch"> + <property name="nomatch.file" location="${basedir}/data/nomatch.exec"/> + <jacoco:report> + <executiondata> + <file file="${nomatch.file}"/> + </executiondata> + <structure name="root"> + <classfiles> + <path location="${org.jacoco.ant.reportTaskTest.classes.dir}"/> + </classfiles> + </structure> + </jacoco:report> + <au:assertLogContains level="warn" text="Classes in bundle 'root' do no match with execution data."/> + <au:assertLogContains level="warn" text="For report generation the same class files must be used as at runtime."/> + <au:assertLogContains level="warn" text="Execution data for class org/jacoco/ant/TestTarget does not match."/> + </target> + <!-- HTML Output --> @@ -220,7 +238,7 @@ <sourcefiles encoding="UTF-8"> <fileset dir="${org.jacoco.ant.reportTaskTest.sources.dir}" /> </sourcefiles> - </structure> + </structure> <html destdir="${temp.dir}"/> </jacoco:report> @@ -239,7 +257,7 @@ <sourcefiles encoding="UTF-8" tabwidth="13"> <fileset dir="${org.jacoco.ant.reportTaskTest.sources.dir}" /> </sourcefiles> - </structure> + </structure> <html destdir="${temp.dir}"/> </jacoco:report> @@ -287,7 +305,7 @@ <sourcefiles encoding="UTF-8"> <fileset dir="${org.jacoco.ant.reportTaskTest.sources.dir}" /> </sourcefiles> - </structure> + </structure> <html destdir="${temp.dir}"/> </jacoco:report> @@ -304,7 +322,7 @@ <sourcefiles encoding="UTF-8"> <dirset dir="${org.jacoco.ant.reportTaskTest.sources.dir}/.." includes="src" /> </sourcefiles> - </structure> + </structure> <html destdir="${temp.dir}"/> </jacoco:report> @@ -323,7 +341,7 @@ <sourcefiles encoding="UTF-16"> <fileset dir="${temp.dir}" /> </sourcefiles> - </structure> + </structure> <html destdir="${temp.dir}"/> </jacoco:report> @@ -342,7 +360,7 @@ <sourcefiles encoding="UTF-8"> <fileset dir="${org.jacoco.ant.reportTaskTest.sources.dir}" /> </sourcefiles> - </structure> + </structure> <html destdir="${temp.dir}" locale="gr"/> </jacoco:report> @@ -423,7 +441,7 @@ <sourcefiles encoding="UTF-8"> <fileset dir="${org.jacoco.ant.reportTaskTest.sources.dir}" /> </sourcefiles> - </structure> + </structure> <check> <rule element="CLASS"> <limit counter="METHOD" value="MISSEDCOUNT" maximum="100"/> @@ -442,7 +460,7 @@ <sourcefiles encoding="UTF-8"> <fileset dir="${org.jacoco.ant.reportTaskTest.sources.dir}" /> </sourcefiles> - </structure> + </structure> <check> <rule element="BUNDLE"> <limit counter="INSTRUCTION" value="COVEREDRATIO" minimum="0.90"/> @@ -462,7 +480,7 @@ <sourcefiles encoding="UTF-8"> <fileset dir="${org.jacoco.ant.reportTaskTest.sources.dir}" /> </sourcefiles> - </structure> + </structure> <check failonviolation="false" violationsproperty="violation"> <rule element="BUNDLE"> <limit counter="METHOD" value="COVEREDRATIO" minimum="0.50"/> diff --git a/org.jacoco.ant.test/src/org/jacoco/ant/data/nomatch.exec b/org.jacoco.ant.test/src/org/jacoco/ant/data/nomatch.exec Binary files differnew file mode 100644 index 00000000..ef7d62ae --- /dev/null +++ b/org.jacoco.ant.test/src/org/jacoco/ant/data/nomatch.exec diff --git a/org.jacoco.ant/src/org/jacoco/ant/ReportTask.java b/org.jacoco.ant/src/org/jacoco/ant/ReportTask.java index ba58894a..90bad95d 100644 --- a/org.jacoco.ant/src/org/jacoco/ant/ReportTask.java +++ b/org.jacoco.ant/src/org/jacoco/ant/ReportTask.java @@ -18,6 +18,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; +import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.Locale; @@ -32,6 +33,7 @@ import org.apache.tools.ant.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.analysis.ICoverageNode; import org.jacoco.core.data.ExecutionDataStore; import org.jacoco.core.data.SessionInfoStore; @@ -543,9 +545,6 @@ public class ReportTask extends Task { } } else { final IBundleCoverage bundle = createBundle(group); - log(format("Writing group \"%s\" with %s classes", - bundle.getName(), - Integer.valueOf(bundle.getClassCounter().getTotalCount()))); final SourceFilesElement sourcefiles = group.sourcefiles; final AntResourcesLocator locator = new AntResourcesLocator( sourcefiles.encoding, sourcefiles.tabWidth); @@ -571,14 +570,32 @@ public class ReportTask extends Task { in.close(); } } - return builder.getBundle(group.name); + final IBundleCoverage bundle = builder.getBundle(group.name); + logBundleInfo(bundle, builder.getNoMatchClasses()); + return bundle; + } + + private void logBundleInfo(final IBundleCoverage bundle, + final Collection<IClassCoverage> nomatch) { + log(format("Writing bundle '%s' with %s classes", bundle.getName(), + Integer.valueOf(bundle.getClassCounter().getTotalCount()))); + if (!nomatch.isEmpty()) { + log(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()), Project.MSG_WARN); + for (final IClassCoverage c : nomatch) { + log(format("Execution data for class %s does not match.", + c.getName()), Project.MSG_WARN); + } + } } private void checkForMissingDebugInformation(final ICoverageNode node) { if (node.getClassCounter().getTotalCount() > 0 && node.getLineCounter().getTotalCount() == 0) { log(format( - "To enable source code annotation class files for bundle '%s' have to be compiled with debug information", + "To enable source code annotation class files for bundle '%s' have to be compiled with debug information.", node.getName()), Project.MSG_WARN); } } |