maven-plugins/jcoverage/plugin.jelly
2003-09-09 16:18:40 +00:00

207 lines
7.6 KiB
XML

<?xml version="1.0"?>
<project
xmlns:j="jelly:core"
xmlns:ant="jelly:ant"
xmlns:log="jelly:log"
xmlns:maven="jelly:maven"
xmlns:define="jelly:define"
xmlns:jcoverage="jcoverage"
xmlns:u="jelly:util"
xmlns:doc="doc">
<define:taglib uri="jcoverage">
<define:jellybean
name="report"
className="org.apache.maven.jcoveragereport.CoverageReportGenerator"
method="execute"
/>
</define:taglib>
<!-- global definitions -->
<ant:path id="jcoverage.classpath">
<ant:pathelement path="${plugin.getDependencyPath('bcel')}"/>
<ant:pathelement path="${plugin.getDependencyPath('urbanophile:java-getopt')}"/>
<ant:pathelement path="${plugin.getDependencyPath('log4j')}"/>
<ant:pathelement path="${plugin.getDependencyPath('jcoverage')}"/>
<ant:pathelement path="${plugin.getDependencyPath('oro')}"/>
<ant:pathelement path="${plugin.getDependencyPath('junit')}"/>
</ant:path>
<ant:taskdef classpath="${plugin.getDependencyPath('jcoverage')}" resource="tasks.properties" />
<j:set var="maven.coverage.dir"
value="${pom.getPluginContext('maven-xdoc-plugin').getVariable('maven.docs.dest')}/jcoverage" />
<!-- ================================================================== -->
<!-- J C O V E R A G E R E P O R T D E -/R E G I S T R A T I O N -->
<!-- ================================================================== -->
<goal name="maven-jcoverage-plugin:register"
description="Register the maven-jcoverage-plugin.">
<j:if test="${sourcesPresent == 'true'}">
<doc:registerReport
name="JCoverage"
pluginName="maven-jcoverage-plugin"
link="jcoverage/index"
description="JCoverage test coverage report." />
</j:if>
</goal>
<goal name="maven-jcoverage-plugin:deregister"
description="Deregister the jcoverage plugin">
<j:if test="${sourcesPresent == 'true'}">
<doc:deregisterReport name="JCoverage" />
</j:if>
</goal>
<!-- ================================================================== -->
<!-- D E F A U L T R E P O R T -->
<!-- ================================================================== -->
<goal name="maven-jcoverage-plugin:report"
description="Run the default report (html).">
<attainGoal name="jcoverage:html-report" />
</goal>
<!-- ================================================================== -->
<!-- I N S T R U M E N T A T I O N -->
<!-- ================================================================== -->
<goal name="jcoverage:on" description="perform the coverage analysis"
prereqs="java:compile">
<j:catch var="ex">
<j:set var="instrumented" value="${maven.jcoverage.instrumentation}"/>
<j:set var="oldBuildDest" value="${maven.build.dest}"/>
<j:set var="fork" value="${maven.jcoverage.junit.fork}"/>
<j:set var="oldfork" value="${pom.getPluginContext('maven-test-plugin').getVariable('maven.junit.fork')}"/>
<!-- reset the maven.build.dest for the test plugin to find the instrumented classes -->
${pom.getPluginContext('maven-test-plugin').setVariable('maven.build.dest', instrumented)}
<!--
set the maven.junit.fork property
-->
${pom.getPluginContext('maven-test-plugin').setVariable('maven.junit.fork', fork)}
<ant:mkdir dir="${maven.coverage.dir}" />
<ant:mkdir dir="${maven.jcoverage.database.dir}" />
<ant:mkdir dir="${maven.jcoverage.instrumentation}" />
<log:info>instrumenting the class-files...</log:info>
<maven:addPath id="maven.dependency.classpath" refid="jcoverage.classpath"/>
<maven:addPath id="maven.dependency.classpath" refid="${pom.getDependencyClasspath()}"/>
<instrument todir="${maven.jcoverage.instrumentation}">
<ant:fileset dir="${maven.build.dest}">
<ant:include name="**/*.class" />
</ant:fileset>
<ant:classpath>
<ant:path refid="jcoverage.classpath"/>
</ant:classpath>
</instrument>
</j:catch>
<j:if test="${ex != null}">
<log:error>${ex}</log:error>
<ant:fail message="${ex}" />
</j:if>
<j:if test="${!pom.build.resources.isEmpty()}">
<maven:copy-resources
resources="${pom.build.resources}"
todir="${maven.jcoverage.instrumentation}"/>
</j:if>
</goal>
<!-- ================================================================== -->
<!-- D E F A U L T G O A L -->
<!-- ================================================================== -->
<goal name="jcoverage"
description="Generate HTML test coverage reports with JCoverage"
prereqs="jcoverage:html-report"
/>
<!-- ================================================================== -->
<!-- R E P O R T G O A L -->
<!-- ================================================================== -->
<goal name="jcoverage:html-report"
description="Generate HTML test coverage reports with JCoverage"
prereqs="jcoverage:on,test:test">
<j:catch var="ex">
<j:set var="template" value="${maven.jcoverage.report.template}"/>
<j:choose>
<j:when test="${template == 'jcoverage'}">
<report srcdir="${pom.build.sourceDirectory}" destdir="${maven.coverage.dir}">
<ant:classpath>
<ant:path refid="jcoverage.classpath"/>
</ant:classpath>
</report>
<log:info>jcoverage reports have been generated.</log:info>
<log:info>The HTML report is ${maven.build.coverage.dir}/index.html</log:info>
</j:when>
<j:otherwise>
<report srcdir="${pom.build.sourceDirectory}" destdir="${maven.jcoverage.dir}"
format="xml">
<ant:classpath>
<ant:path refid="jcoverage.classpath"/>
</ant:classpath>
</report>
<ant:copy file="${plugin.resources}/style.css" todir="${maven.coverage.dir}"/>
<jcoverage:report
dataFile="${maven.jcoverage.dir}/coverage.xml"
outputDir="${maven.coverage.dir}"/>
</j:otherwise>
</j:choose>
<!--
restore the maven.junit.fork property
-->
${pom.getPluginContext('maven-test-plugin').setVariable('maven.junit.fork', oldfork)}
<!--
restore the maven.build.dest property
-->
${pom.getPluginContext('maven-test-plugin').setVariable('maven.build.dest', oldBuildDest)}
</j:catch>
<j:if test="${ex != null}">
<log:error>${ex}</log:error>
<ant:fail message="${ex}" />
</j:if>
</goal>
<!-- ================================================================== -->
<!-- M E R G E G O A L -->
<!-- ================================================================== -->
<goal name="jcoverage:merge"
description="Merge two or more instrumentation files into one">
<java classname="com.jcoverage.tool.merge.Main">
<u:tokenize var="listOfinput" delim=",">${maven.jcoverage.merge.instrumentedFiles}</u:tokenize>
<j:forEach var="instrumentedFile" items="${listOfinput}">
<arg line="-i ${instrumentedFile}"/>
</j:forEach>
<arg line="-o ${maven.jcoverage.merge.outputDir}"/>
<classpath>
<path refid="jcoverage.classpath"/>
</classpath>
</java>
</goal>
<postGoal name="clean:clean">
<ant:delete file="${basedir}/jcoverage.ser" quiet="true" failonerror="false"/>
</postGoal>
</project>