maven-plugins/jcoverage/plugin.jelly
evenisse 2d8af3aa9a Fixed tests execution when artifact contains properties.
- Remove deprecated APIs.


git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@115792 13f79535-47bb-0310-9956-ffa450edef68
2004-07-11 15:19:33 +00:00

246 lines
9.7 KiB
XML

<?xml version="1.0"?>
<!--
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-->
<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:pathelement path="${plugin.getDependencyPath('xerces:xercesImpl')}"/>
<ant:pathelement path="${plugin.getDependencyPath('xerces:xmlParserAPIs')}"/>
</ant:path>
<ant:taskdef classpath="${plugin.getDependencyPath('jcoverage')}" resource="tasks.properties" />
<maven:get plugin="maven-xdoc-plugin" property="maven.docs.dest" var="docsDest"/>
<j:set var="jcoverageDocs" value="${docsDest}/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}"/>
<maven:get plugin="maven-test-plugin" property="maven.junit.fork" var="oldfork"/>
<!-- reset the maven.build.dest for the test plugin to find the instrumented classes -->
<maven:set plugin="maven-java-plugin" property="maven.build.dest" value="${instrumented}"/>
<maven:set plugin="maven-test-plugin" property="maven.build.dest" value="${instrumented}"/>
<!--
set the maven.junit.fork property
-->
<maven:set plugin="maven-test-plugin" property="maven.junit.fork" value="${fork}"/>
<ant:mkdir dir="${jcoverageDocs}" />
<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:exclude name="${maven.jcoverage.instrumentation.excludes}" />
</ant:fileset>
<ant:classpath>
<ant:path refid="jcoverage.classpath"/>
</ant:classpath>
</instrument>
<ant:copy todir="${maven.jcoverage.instrumentation}">
<ant:fileset dir="${maven.build.dest}">
<ant:exclude name="**/*.class" />
<ant:exclude name="${maven.jcoverage.instrumentation.excludes}" />
</ant:fileset>
</ant:copy>
</j:catch>
<j:if test="${ex != null}">
<log:error>${ex}</log:error>
<ant:fail message="${ex}" />
</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:choose>
<j:when test="${unitTestSourcesPresent == 'true'}">
<j:catch var="ex">
<j:set var="sourceDir" value="${context.getAntProject().getReferences().get('maven.compile.src.set')}" />
<u:tokenize var="sourceDirList" delim="${path.separator}">${sourceDir}</u:tokenize>
<j:if test="${size(sourceDirList) != 1}">
<!-- Copy multiple source directories to one: jcoverage doesn't handle multiple source directories -->
<echo>Copying ${size(sourceDirList)} source directories into one for jcoverage</echo>
<j:set var="sourceDir" value="${maven.jcoverage.dir}/sources" />
<ant:copy todir="${sourceDir}">
<j:forEach var="dir" items="${sourceDirList}">
<ant:fileset dir="${dir}" />
</j:forEach>
</ant:copy>
</j:if>
<j:set var="template" value="${maven.jcoverage.report.template}"/>
<j:choose>
<j:when test="${template == 'jcoverage'}">
<report srcdir="${sourceDir}" destdir="${jcoverageDocs}">
<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="${sourceDir}" destdir="${maven.jcoverage.dir}" format="xml">
<ant:classpath>
<ant:path refid="jcoverage.classpath"/>
</ant:classpath>
</report>
<j:set var="stylesheet" value="${maven.jcoverage.report.stylesheet}"/>
<ant:copy file="${stylesheet}" tofile="${jcoverageDocs}/style.css"/>
<jcoverage:report
dataFile="${maven.jcoverage.dir}/coverage.xml"
outputDir="${jcoverageDocs}"/>
</j:otherwise>
</j:choose>
<!--
restore the maven.junit.fork property
-->
<maven:set plugin="maven-java-plugin" property="maven.junit.fork" value="${oldfork}"/>
<!--
restore the maven.build.dest property
-->
<maven:set plugin="maven-java-plugin" property="maven.build.dest" value="${oldBuildDest}"/>
<maven:set plugin="maven-test-plugin" property="maven.build.dest" value="${oldBuildDest}"/>
</j:catch>
<j:if test="${ex != null}">
<log:error>${ex}</log:error>
<ant:fail message="${ex}" />
</j:if>
</j:when>
<j:otherwise>
<ant:echo>No tests to run JCoverage on.</ant:echo>
</j:otherwise>
</j:choose>
</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>
</project>