Author: markt Date: Mon Nov 4 09:18:59 2013 New Revision: 1538534 URL: http://svn.apache.org/r1538534 Log: Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=52323 Add support for code coverage with Cobertura (disabled by default) when running the unit tests
Modified: tomcat/tc7.0.x/trunk/ (props changed) tomcat/tc7.0.x/trunk/build.properties.default tomcat/tc7.0.x/trunk/build.xml tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Propchange: tomcat/tc7.0.x/trunk/ ------------------------------------------------------------------------------ Merged /tomcat/trunk:r1538533 Modified: tomcat/tc7.0.x/trunk/build.properties.default URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/build.properties.default?rev=1538534&r1=1538533&r2=1538534&view=diff ============================================================================== --- tomcat/tc7.0.x/trunk/build.properties.default (original) +++ tomcat/tc7.0.x/trunk/build.properties.default Mon Nov 4 09:18:59 2013 @@ -43,6 +43,9 @@ test.haltonfailure=false # Activate AccessLog during testing test.accesslog=false +# Note the Cobertura code coverage tool is GPLv2 licensed +test.cobertura=false + # Workaround against http://bugs.sun.com/view_bug.do?bug_id=6202721 test.jvmarg.egd=-Djava.security.egd=file:/dev/./urandom @@ -207,3 +210,9 @@ dojo-js.home=${base.path}/dojo-release-1 dojo-js.loc=http://download.dojotoolkit.org/release-1.1.1/dojo-release-1.1.1.tar.gz dojo-js.jar=${dojo-js.home}/dojo/dojo.js +# ----- Cobertura code coverage tool ----- +cobertura.version=2.0.3 +cobertura.home=${base.path}/cobertura-${cobertura.version} +cobertura.jar=${cobertura.home}/cobertura-${cobertura.version}.jar +cobertura.lib=${cobertura.home}/lib +cobertura.loc=${base-sf.loc}/cobertura/cobertura-2.0.3-bin.tar.gz Modified: tomcat/tc7.0.x/trunk/build.xml URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/build.xml?rev=1538534&r1=1538533&r2=1538534&view=diff ============================================================================== --- tomcat/tc7.0.x/trunk/build.xml (original) +++ tomcat/tc7.0.x/trunk/build.xml Mon Nov 4 09:18:59 2013 @@ -165,6 +165,13 @@ <property name="test.name" value="**/Test*.java"/> <property name="test.formatter" value="-Dorg.apache.juli.formatter=java.util.logging.SimpleFormatter"/> + <!-- Cobertura code coverage settings --> + <property name="cobertura.out" value="${tomcat.build}/coverage"/> + <property name="cobertura.datafile" value="${cobertura.out}/cobertura.ser"/> + <property name="tomcat.classes.cobertura" value="${tomcat.classes}-cobertura"/> + <property name="cobertura.report.format" value="html"/> + + <!-- Include .gitignore in src distributions. --> <!-- .git and .gitignore are in defaultexcludes since Ant 1.8.2 --> <defaultexcludes add="**/.git" /> @@ -190,6 +197,13 @@ <path refid="tomcat.classpath" /> </path> + <path id="cobertura.classpath"> + <fileset dir="${cobertura.home}"> + <include name="cobertura-${cobertura.version}.jar" /> + <include name="lib/**/*.jar" /> + </fileset> + </path> + <path id="tomcat.webservices.classpath"> <path refid="tomcat.classpath" /> <fileset dir="${tomcat.extras}/webservices"> @@ -1232,25 +1246,25 @@ <property name="junit.formatter.extension" value=".txt" /> <target name="test" description="Runs the JUnit test cases" - depends="test-init1,test-init2,test-bio,test-nio,test-apr" > + depends="test-init1,test-init2,test-bio,test-nio,test-apr,cobertura-report" > <fail if="test.result.error" message='Some tests completed with an Error. See ${tomcat.build}/logs for details, search for "FAILED".' /> <fail if="test.result.failure" message='Some tests completed with a Failure. See ${tomcat.build}/logs for details, search for "FAILED".' /> </target> <target name="test-bio" description="Runs the JUnit test cases for BIO. Does not stop on errors." - depends="test-compile,deploy" if="${execute.test.bio}"> + depends="test-init,test-compile,deploy,cobertura-instrument" if="${execute.test.bio}"> <runtests protocol="org.apache.coyote.http11.Http11Protocol" extension=".BIO" /> </target> <target name="test-nio" description="Runs the JUnit test cases for NIO. Does not stop on errors." - depends="test-compile,deploy" if="${execute.test.nio}"> + depends="test-init,test-compile,deploy,cobertura-instrument" if="${execute.test.nio}"> <runtests protocol="org.apache.coyote.http11.Http11NioProtocol" extension=".NIO" /> </target> <target name="test-apr" description="Runs the JUnit test cases for APR. Does not stop on errors." - depends="test-compile,deploy,test-apr-exists" + depends="test-init,test-compile,deploy,test-apr-exists,cobertura-instrument" if="${apr.exists}"> <runtests protocol="org.apache.coyote.http11.Http11AprProtocol" extension=".APR" /> @@ -1269,6 +1283,13 @@ <property name="java.bin.path" value=""/> </target> + <target name="test-init" > + <!-- This directory needs to exist even if it is empty otherwise the --> + <!-- use of the cobertura.classpath class path when running the unit --> + <!-- triggers an error. --> + <mkdir dir="${cobertura.home}" /> + </target> + <macrodef name="runtests" description="Runs the unit tests using the specified connector. Does not stop on errors, but sets 'test.result.error' and 'test.result.failure' properties."> @@ -1289,12 +1310,17 @@ <jvmarg value="${test.formatter}"/> <jvmarg value="-Dapple.awt.UIElement=true"/> + <!-- The Cobertura instrumented classes must appear first on the classpath --> + <classpath location="${tomcat.classes.cobertura}" /> <classpath refid="tomcat.test.classpath" /> + <classpath refid="cobertura.classpath"/> <sysproperty key="tomcat.test.temp" value="${test.temp}" /> <sysproperty key="tomcat.test.tomcatbuild" value="${tomcat.build}" /> <sysproperty key="tomcat.test.protocol" value="@{protocol}" /> <sysproperty key="tomcat.test.accesslog" value="${test.accesslog}" /> + <!-- File for Cobertura to write coverage results to --> + <sysproperty key="net.sourceforge.cobertura.datafile" file="${cobertura.datafile}" /> <formatter type="${junit.formatter.type}" usefile="${junit.formatter.usefile}" @@ -1321,6 +1347,40 @@ </sequential> </macrodef> + <target name="cobertura-instrument" depends="compile,download-cobertura" + if="${test.cobertura}" + description="Adds Cobertura instrumentation to the compiled bytecode"> + + <taskdef classpathref="cobertura.classpath" resource="tasks.properties" /> + + <cobertura-instrument datafile="${cobertura.datafile}" + todir="${tomcat.classes.cobertura}"> + <fileset dir="${tomcat.classes}"> + <include name="**/*.class"/> + <exclude name="**/ClassLoaderLogManager.class"/> + <exclude name="**/ClassLoaderLogManager*.class"/> + <exclude name="**/FileHandler.class"/> + <exclude name="**/AsyncFileHandler.class"/> + <exclude name="**/AsyncFileHandler*.class"/> + <exclude name="**/OneLineFormatter.class"/> + <exclude name="**/OneLineFormatter*.class"/> + <exclude name="**/DateFormatCache.class"/> + <exclude name="**/DateFormatCache*.class"/> + </fileset> + <auxClasspath path="${jdt.jar}" /> + </cobertura-instrument> + + </target> + + <target name="cobertura-report" if="${test.cobertura}" + depends="test-bio,test-nio,test-apr" + description="Creates report from gathered Cobertura results"> + + <cobertura-report srcdir="${basedir}/java" destdir="${cobertura.out}" + datafile="${cobertura.datafile}" + format="${cobertura.report.format}"/> + </target> + <target name="extras-prepare" > <mkdir dir="${tomcat.extras}"/> <mkdir dir="${tomcat.extras.sources}"/> @@ -2591,6 +2651,16 @@ Apache Tomcat ${version} native binaries </target> + <target name="download-cobertura" + description="Download the Cobertura code coverage tool" > + + <antcall target="downloadgz"> + <param name="sourcefile" value="${cobertura.loc}"/> + <param name="destfile" value="${cobertura.jar}"/> + </antcall> + + </target> + <target name="download-dist" description="Download additional components for a distribution" > Modified: tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1538534&r1=1538533&r2=1538534&view=diff ============================================================================== --- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original) +++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Mon Nov 4 09:18:59 2013 @@ -184,6 +184,14 @@ </update> </changelog> </subsection> + <subsection name="Other"> + <changelog> + <add> + Add support for the Cobertura code coverage tool when running the unit + tests. Based on a patch by mhasko. (markt) + </add> + </changelog> + </subsection> </section> <section name="Tomcat 7.0.47 (violetagg)" rtext="2013-10-24"> <subsection name="Coyote"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org