maven-plugins/test/plugin.jelly

561 lines
24 KiB
XML

<?xml version="1.0"?>
<!--
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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:maven="jelly:maven"
xmlns:u="jelly:util"
xmlns:define="jelly:define" xmlns:ant="jelly:ant">
<goal name="test"
description="Test the application"
prereqs="test:test"/>
<goal name="test:prepare-filesystem"
description="Create the needed directory structure">
<mkdir dir="${maven.test.dest}"/>
<mkdir dir="${maven.test.reportsDirectory}"/>
</goal>
<goal name="test:compile"
description="Compile the TestCases and TestSuites"
prereqs="java:compile,java:jar-resources,test:prepare-filesystem,test:test-resources">
<j:set var="maven.test.searchdir" value="${maven.test.dest}"/>
<j:if test="${context.getVariable('maven.test.search.classdir') == null}">
<j:set var="maven.test.searchdir" value="${pom.build.unitTestSourceDirectory}"/>
</j:if>
<ant:path id="_searchdir" location="${maven.test.searchdir}"/>
<maven:addPath id="maven.test.compile.src.set" refid="_searchdir"/>
<pathconvert pathsep="${path.separator}" property="_testSrcDirs" refid="maven.test.compile.src.set"/>
<u:tokenize var="_listOfTestSrcDirs" delim="${path.separator}">${_testSrcDirs}</u:tokenize>
<j:if test="${unitTestSourcesPresent == 'true' and context.getVariable('maven.test.skip') != 'true'}">
<javac
destdir="${maven.test.dest}"
excludes="**/package.html"
debug="${maven.compile.debug}"
deprecation="${maven.compile.deprecation}"
optimize="${maven.compile.optimize}">
<j:if test="${context.getVariable('maven.test.source') != null}">
<setProperty name="source" value="${maven.test.source}" />
</j:if>
<classpath>
<pathelement path="${maven.test.dest}"/>
<pathelement path="${maven.build.dest}"/>
<path refid="maven.dependency.classpath"/>
<pathelement path="${plugin.getDependencyPath('junit')}"/>
<j:if test="${!context.getVariable('maven.junit.fork').toString().trim().equalsIgnoreCase('no') and !context.getVariable('maven.test.excludeXmlApis').toString().trim().equalsIgnoreCase('yes') }">
<pathelement location="${plugin.getDependencyPath('xml-apis:xml-apis')}"/>
<pathelement location="${plugin.getDependencyPath('xerces:xercesImpl')}"/>
<pathelement location="${plugin.getDependencyPath('xml-resolver:xml-resolver')}"/>
</j:if>
</classpath>
<src>
<path refid="maven.test.compile.src.set"/>
</src>
<!--
|
| Source Modifications.
|
-->
<j:forEach var="sm" items="${pom.build.sourceModifications}">
<ant:available property="testClassPresent" classname="${sm.className}"/>
<j:if test="${testClassPresent != 'true'}">
<j:forEach var="exclude" items="${sm.excludes}">
<ant:exclude name="${exclude}"/>
</j:forEach>
<j:forEach var="include" items="${sm.includes}">
<ant:include name="${include}"/>
</j:forEach>
</j:if>
</j:forEach>
<j:if test="${context.getVariable('maven.test.compile.compilerargs') != null}">
<compilerarg line="${maven.test.compile.compilerargs}" />
</j:if>
<j:if test="${context.getVariable('maven.test.compile.memoryMaximumSize') != null}">
<setProperty name="memoryMaximumSize" value="${maven.test.compile.memoryMaximumSize}" />
</j:if>
<j:if test="${context.getVariable('maven.test.compile.encoding') != null}">
<setProperty name="encoding" value="${maven.test.compile.encoding}" />
</j:if>
<j:if test="${context.getVariable('maven.test.compile.executable') != null}">
<setProperty name="executable" value="${maven.test.compile.executable}" />
</j:if>
<j:if test="${context.getVariable('maven.test.compile.fork') != null}">
<setProperty name="fork" value="${maven.test.compile.fork}" />
</j:if>
<j:if test="${context.getVariable('maven.test.compile.source') != null}">
<setProperty name="source" value="${maven.test.compile.source}" />
</j:if>
<j:if test="${context.getVariable('maven.test.compile.target') != null}">
<ant:setProperty name="target" value="${maven.test.compile.target}" />
</j:if>
<j:if test="${context.getVariable('maven.test.compile.verbose') != null}">
<setProperty name="verbose" value="${maven.test.compile.verbose}" />
</j:if>
</javac>
</j:if>
<j:if test="${!unitTestSourcesPresent}">
<echo>No test source files to compile.</echo>
</j:if>
</goal>
<goal name="test:test"
description="Test the application">
<j:if test="${unitTestSourcesPresent == 'true' and context.getVariable('maven.test.skip') != 'true'}">
<attainGoal name="test:compile"/>
<taskdef
name="junit"
classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask"
/>
<j:set var="_haltonfailure" value="no"/>
<j:if test="${context.getVariable('maven.test.failure.ignore') != 'true'}">
<j:set var="_haltonfailure" value="yes"/>
</j:if>
<j:set var="_haltonerror" value="no"/>
<j:if test="${context.getVariable('maven.test.error.ignore') != 'true'}">
<j:set var="_haltonerror" value="yes"/>
</j:if>
<junit printSummary="${maven.junit.printSummary}"
haltonfailure="${_haltonfailure}"
haltonerror="${_haltonerror}"
failureProperty="maven.test.failure"
fork="${maven.junit.fork}"
forkmode="${maven.junit.forkmode}">
<setProperty name="showoutput" value="${maven.debugOn}" />
<j:if test="${context.getVariable('maven.junit.jvm') != null}">
<setProperty name="jvm" value="${maven.junit.jvm}" />
</j:if>
<j:if test="${context.getVariable('maven.junit.timeout') != null}">
<setProperty name="timeout" value="${maven.junit.timeout}" />
</j:if>
<j:if test="${!context.getVariable('maven.junit.fork').toString().trim().equalsIgnoreCase('no')}">
<setProperty name="dir" value="${maven.junit.dir}" />
</j:if>
<sysproperty key="basedir" value="${basedir}"/>
<u:tokenize var="listOfProperties" delim=" ">${maven.junit.sysproperties}</u:tokenize>
<j:forEach var="someProperty" items="${listOfProperties}">
<sysproperty key="${someProperty}" value="${context.getVariable(someProperty)}"/>
</j:forEach>
<u:tokenize var="listOfEnv" delim=" ">${maven.junit.envvars}</u:tokenize>
<j:forEach var="someEnv" items="${listOfEnv}">
<env key="${someEnv}" value="${context.getVariable(someEnv)}"/>
</j:forEach>
<u:tokenize var="listOfJvmArgs" delim=" ">${maven.junit.jvmargs}</u:tokenize>
<j:forEach var="somejvmarg" items="${listOfJvmArgs}">
<jvmarg value="${somejvmarg}"/>
</j:forEach>
<formatter type="xml"/>
<formatter type="${maven.junit.format}" usefile="${maven.junit.usefile}"/>
<classpath>
<pathelement location="${maven.test.dest}"/>
<pathelement location="${maven.build.dest}"/>
<path refid="maven.dependency.classpath"/>
<pathelement path="${plugin.getDependencyPath('junit')}"/>
<j:if test="${!context.getVariable('maven.junit.fork').toString().trim().equalsIgnoreCase('no') and !context.getVariable('maven.test.excludeXmlApis').toString().trim().equalsIgnoreCase('yes') }">
<pathelement location="${plugin.getDependencyPath('xml-apis:xml-apis')}"/>
<pathelement location="${plugin.getDependencyPath('xerces:xercesImpl')}"/>
<pathelement location="${plugin.getDependencyPath('xml-resolver:xml-resolver')}"/>
</j:if>
<j:if test="${not empty(context.getVariable('maven.test.classpath'))}">
<pathelement path="${maven.test.classpath}"/>
</j:if>
</classpath>
<batchtest todir="${maven.test.reportsDirectory}">
<j:forEach var="srcDir" items="${_listOfTestSrcDirs}">
<fileset dir="${srcDir}">
<j:forEach var="pat" items="${pom.build.unitTest.includes}">
<include name="${pat}"/>
</j:forEach>
<j:forEach var="pat" items="${pom.build.unitTest.excludes}">
<exclude name="${pat}"/>
</j:forEach>
<!-- KEEP ALL ABSTRACT TESTS FROM BEING RUN! -->
<exclude name="**/*AbstractTestCase.java"/>
</fileset>
</j:forEach>
</batchtest>
</junit>
<j:set var="_testfailure" value="${maven.test.failure}"/>
<j:if test="${_testfailure}">
<j:if test="${context.getVariable('maven.test.haltafterfailure') != 'false'}">
<ant:fail>There were test failures!</ant:fail>
</j:if>
<echo>
==========================================================
WARNING: There were test failures!
==========================================================
</echo>
</j:if>
</j:if>
<j:if test="${!unitTestSourcesPresent}">
<echo>No tests to run.</echo>
</j:if>
</goal>
<goal name="test:ui"
description="Starts the Swing TestRunner front end"
prereqs="test:compile">
<java classname="junit.swingui.TestRunner" fork="yes">
<sysproperty key="basedir" value="${basedir}"/>
<u:tokenize var="listOfProperties" delim=" ">${maven.junit.sysproperties}</u:tokenize>
<j:forEach var="someProperty" items="${listOfProperties}">
<sysproperty key="${someProperty}" value="${context.getVariable(someProperty)}"/>
</j:forEach>
<u:tokenize var="listOfEnv" delim=" ">${maven.junit.envvars}</u:tokenize>
<j:forEach var="someEnv" items="${listOfEnv}">
<env key="${someEnv}" value="${context.getVariable(someEnv)}"/>
</j:forEach>
<u:tokenize var="listOfJvmArgs" delim=" ">${maven.junit.jvmargs}</u:tokenize>
<j:forEach var="somejvmarg" items="${listOfJvmArgs}">
<jvmarg value="${somejvmarg}"/>
</j:forEach>
<classpath>
<pathelement location="${maven.test.dest}"/>
<pathelement location="${maven.build.dest}"/>
<path refid="maven.dependency.classpath"/>
<pathelement path="${plugin.getDependencyPath('junit')}"/>
<j:if test="${!context.getVariable('maven.junit.fork').toString().trim().equalsIgnoreCase('no') and !context.getVariable('maven.test.excludeXmlApis').toString().trim().equalsIgnoreCase('yes') }">
<pathelement location="${plugin.getDependencyPath('xml-apis:xml-apis')}"/>
<pathelement location="${plugin.getDependencyPath('xerces:xercesImpl')}"/>
<pathelement location="${plugin.getDependencyPath('xml-resolver:xml-resolver')}"/>
</j:if>
<j:if test="${not empty(context.getVariable('maven.test.classpath'))}">
<pathelement path="${maven.test.classpath}"/>
</j:if>
</classpath>
<arg value="-noloading"/>
</java>
</goal>
<goal name="test:single"
description="Execute a single test defined using the 'testcase' variable">
<j:if test="${unitTestSourcesPresent == 'true'}">
<j:choose>
<j:when test="${empty(testcase)}">
<echo>
You must define the test case to run via -Dtestcase=classname
Example: maven -Dtestcase=MyTest test:single
</echo>
</j:when>
<j:otherwise>
<!-- Make sure test classes are compiled -->
<j:set var="testSkipOld" value="${maven.test.skip}"/>
<j:set var="maven.test.skip" scope="parent" value="false"/>
<attainGoal name="test:compile"/>
<j:set var="maven.test.skip" scope="parent" value="${testSkipOld}"/>
<taskdef
name="junit"
classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask"
/>
<j:set var="_haltonfailure" value="no"/>
<j:if test="${context.getVariable('maven.test.failure.ignore') != 'true'}">
<j:set var="_haltonfailure" value="yes"/>
</j:if>
<j:set var="_haltonerror" value="no"/>
<j:if test="${context.getVariable('maven.test.error.ignore') != 'true'}">
<j:set var="_haltonerror" value="yes"/>
</j:if>
<junit printSummary="${maven.junit.printSummary}"
haltonfailure="${_haltonfailure}"
haltonerror="${_haltonerror}"
failureProperty="maven.test.failure"
fork="${maven.junit.fork}"
dir="${maven.junit.dir}"
forkmode="${maven.junit.forkmode}">
<setProperty name="showoutput" value="${maven.debugOn}" />
<j:if test="${context.getVariable('maven.junit.jvm') != null}">
<setProperty name="jvm" value="${maven.junit.jvm}" />
</j:if>
<j:if test="${context.getVariable('maven.junit.timeout') != null}">
<setProperty name="timeout" value="${maven.junit.timeout}" />
</j:if>
<sysproperty key="basedir" value="${basedir}"/>
<u:tokenize var="listOfProperties" delim=" ">${maven.junit.sysproperties}</u:tokenize>
<j:forEach var="someProperty" items="${listOfProperties}">
<sysproperty key="${someProperty}" value="${context.getVariable(someProperty)}"/>
</j:forEach>
<u:tokenize var="listOfEnv" delim=" ">${maven.junit.envvars}</u:tokenize>
<j:forEach var="someEnv" items="${listOfEnv}">
<env key="${someEnv}" value="${context.getVariable(someEnv)}"/>
</j:forEach>
<u:tokenize var="listOfJvmArgs" delim=" ">${maven.junit.jvmargs}</u:tokenize>
<j:forEach var="somejvmarg" items="${listOfJvmArgs}">
<jvmarg value="${somejvmarg}"/>
</j:forEach>
<formatter type="xml"/>
<formatter type="${maven.junit.format}" usefile="${maven.junit.usefile}"/>
<classpath>
<pathelement location="${maven.test.dest}"/>
<pathelement location="${maven.build.dest}"/>
<path refid="maven.dependency.classpath"/>
<pathelement path="${plugin.getDependencyPath('junit')}"/>
<j:if test="${!context.getVariable('maven.junit.fork').toString().trim().equalsIgnoreCase('no') and !context.getVariable('maven.test.excludeXmlApis').toString().trim().equalsIgnoreCase('yes') }">
<pathelement location="${plugin.getDependencyPath('xml-apis:xml-apis')}"/>
<pathelement location="${plugin.getDependencyPath('xerces:xercesImpl')}"/>
<pathelement location="${plugin.getDependencyPath('xml-resolver:xml-resolver')}"/>
</j:if>
<j:if test="${not empty(context.getVariable('maven.test.classpath'))}">
<pathelement path="${maven.test.classpath}"/>
</j:if>
</classpath>
<test name="${testcase}" todir="${maven.test.reportsDirectory}"/>
</junit>
<j:set var="_testfailure" value="${maven.test.failure}"/>
<j:if test="${_testfailure}">
<j:if test="${context.getVariable('maven.test.haltafterfailure') != 'false'}">
<ant:fail>There were test failures!</ant:fail>
</j:if>
<echo>
==========================================================
WARNING: There were test failures!
==========================================================
</echo>
</j:if>
</j:otherwise>
</j:choose>
</j:if>
<j:if test="${!unitTestSourcesPresent}">
<echo>No tests to run.</echo>
</j:if>
</goal>
<goal name="test:match"
description="Execute all the tests matching the given 'testmatch' variable"
prereqs="test:compile">
<j:if test="${unitTestSourcesPresent == 'true'}">
<j:if test="${context.getVariable('testmatch') != null}">
<echo>[deprecated] testmatch property is deprecated, please use testmatchpattern instead</echo>
<j:set var="testmatchpattern" value="**/${testmatch}.*"/>
</j:if>
<j:choose>
<j:when test="${empty(testmatchpattern)}">
<echo>
You must define the test case to run via -Dtestmatchpattern=pattern
Example: maven -Dtestmatchpattern=*Foo* test:match
</echo>
</j:when>
<j:otherwise>
<taskdef
name="junit"
classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask"
/>
<echo>Searching directory ${maven.test.searchdir}</echo>
<j:set var="_haltonfailure" value="no"/>
<j:if test="${context.getVariable('maven.test.failure.ignore') != 'true'}">
<j:set var="_haltonfailure" value="yes"/>
</j:if>
<j:set var="_haltonerror" value="no"/>
<j:if test="${context.getVariable('maven.test.error.ignore') != 'true'}">
<j:set var="_haltonerror" value="yes"/>
</j:if>
<junit printSummary="${maven.junit.printSummary}"
haltonfailure="${_haltonfailure}"
haltonerror="${_haltonerror}"
failureProperty="maven.test.failure"
fork="${maven.junit.fork}"
dir="${maven.junit.dir}"
forkmode="${maven.junit.forkmode}">
<setProperty name="showoutput" value="${maven.debugOn}" />
<j:if test="${context.getVariable('maven.junit.jvm') != null}">
<setProperty name="jvm" value="${maven.junit.jvm}" />
</j:if>
<j:if test="${context.getVariable('maven.junit.timeout') != null}">
<setProperty name="timeout" value="${maven.junit.timeout}" />
</j:if>
<sysproperty key="basedir" value="${basedir}"/>
<u:tokenize var="listOfProperties" delim=" ">${maven.junit.sysproperties}</u:tokenize>
<j:forEach var="someProperty" items="${listOfProperties}">
<sysproperty key="${someProperty}" value="${context.getVariable(someProperty)}"/>
</j:forEach>
<u:tokenize var="listOfEnv" delim=" ">${maven.junit.envvars}</u:tokenize>
<j:forEach var="someEnv" items="${listOfEnv}">
<env key="${someEnv}" value="${context.getVariable(someEnv)}"/>
</j:forEach>
<u:tokenize var="listOfJvmArgs" delim=" ">${maven.junit.jvmargs}</u:tokenize>
<j:forEach var="somejvmarg" items="${listOfJvmArgs}">
<jvmarg value="${somejvmarg}"/>
</j:forEach>
<formatter type="xml"/>
<formatter type="${maven.junit.format}" usefile="${maven.junit.usefile}"/>
<classpath>
<pathelement location="${maven.test.dest}"/>
<pathelement location="${maven.build.dest}"/>
<path refid="maven.dependency.classpath"/>
<pathelement path="${plugin.getDependencyPath('junit')}"/>
<j:if test="${!context.getVariable('maven.junit.fork').toString().trim().equalsIgnoreCase('no') and !context.getVariable('maven.test.excludeXmlApis').toString().trim().equalsIgnoreCase('yes') }">
<pathelement location="${plugin.getDependencyPath('xml-apis:xml-apis')}"/>
<pathelement location="${plugin.getDependencyPath('xerces:xercesImpl')}"/>
<pathelement location="${plugin.getDependencyPath('xml-resolver:xml-resolver')}"/>
</j:if>
<j:if test="${not empty(context.getVariable('maven.test.classpath'))}">
<pathelement path="${maven.test.classpath}"/>
</j:if>
</classpath>
<batchtest todir="${maven.test.reportsDirectory}">
<j:forEach var="srcDir" items="${_listOfTestSrcDirs}">
<fileset dir="${srcDir}">
<!-- includes -->
<u:tokenize var="includeItems" delim=",">${testmatchpattern}</u:tokenize>
<j:forEach var="include" items="${includeItems}">
<include name="${include}"/>
</j:forEach>
<!-- excludes -->
<j:if test="${context.getVariable('testnotmatchpattern') != null}">
<u:tokenize var="excludeItems" delim=",">${testnotmatchpattern}</u:tokenize>
<j:forEach var="exclude" items="${excludeItems}">
<exclude name="${exclude}"/>
</j:forEach>
</j:if>
</fileset>
</j:forEach>
</batchtest>
</junit>
<j:set var="_testfailure" value="${maven.test.failure}"/>
<j:if test="${_testfailure}">
<j:if test="${context.getVariable('maven.test.haltafterfailure') != 'false'}">
<ant:fail>There were test failures!</ant:fail>
</j:if>
<echo>
==========================================================
WARNING: There were test failures!
==========================================================
</echo>
</j:if>
</j:otherwise>
</j:choose>
</j:if>
<j:if test="${!unitTestSourcesPresent}">
<echo>No tests to run.</echo>
</j:if>
</goal>
<goal name="test:single-test"
description="[deprecated] please use the test:single goal instead">
<echo>[deprecated] please use the test:single goal instead</echo>
<attainGoal name="test:single"/>
</goal>
<goal name="test:match-test"
description="[deprecated] please use the test:match goal instead">
<echo>[deprecated] please use the test:match goal instead</echo>
<attainGoal name="test:match"/>
</goal>
<!-- ================================================================== -->
<!-- T E S T R E S O U R C E S -->
<!-- ================================================================== -->
<goal name="test:test-resources"
description="Copy any resources that must be present for run tests"
prereqs="test:prepare-filesystem">
<j:if test="${unitTestSourcesPresent == 'true' and context.getVariable('maven.test.skip') != 'true'}">
<j:if test="${pom.build.unitTest != null}">
<j:if test="${!pom.build.unitTest.resources.isEmpty()}">
<maven:copy-resources
resources="${pom.build.unitTest.resources}"
todir="${maven.test.dest}"
/>
</j:if>
</j:if>
</j:if>
</goal>
<define:taglib uri="test">
<define:tag name="dependency-handle">
<!-- XXX Use this tag to allow this plugin to be loaded into another -->
<echo>DEPRECATED: the use of dependency-handle is deprecated. Please use maven:get/set to modify properties of the test plugin</echo>
</define:tag>
</define:taglib>
</project>