maven-plugins/cactus/plugin.jelly
2003-01-31 00:28:32 +00:00

468 lines
17 KiB
XML

<?xml version="1.0"?>
<!--
=============================================================================
Cactus plugin for Maven.
=============================================================================
-->
<project xmlns:j="jelly:core"
xmlns:doc="doc"
xmlns:cactus="jelly:org.apache.maven.cactus.CactusTagLibrary" >
<!-- Import all the jelly scripts found in the plugin-resources/scripts
directory. They are jelly scripts to start/stop the different
containers. -->
<fileScanner var="scanner">
<fileset dir="${plugin.resources}/scripts/" includes="*.jelly"/>
</fileScanner>
<j:forEach var="script" items="${scanner.iterator()}">
<j:import inherit="true" file="${script.toString()}"/>
</j:forEach>
<!--
========================================================================
Initialization. Creates objects useful for several goals.
========================================================================
-->
<goal name="cactus:init" description="Creates objects useful for several goals">
<taskdef name="junit"
classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask"/>
<!-- Classpath containing all Cactus jars that are needed on Cactus
client side -->
<path id="cactus.classpath.clientside">
<path refid="maven.dependency.classpath"/>
<pathelement location="${maven.build.dest}"/>
<pathelement location="${maven.cactus.classes.dir}"/>
<pathelement location="${maven.cactus.build.resources.dir}"/>
<pathelement path="${plugin.getDependencyPath('junit')}"/>
<pathelement path="${plugin.getDependencyPath('cactus:cactus')}"/>
<pathelement path="${plugin.getDependencyPath('commons-httpclient')}"/>
<pathelement path="${plugin.getDependencyPath('commons-logging')}"/>
<pathelement path="${plugin.getDependencyPath('aspectj:aspectjrt')}"/>
<pathElement path="${plugin.getDependencyPath('httpunit')}"/>
<pathElement path="${plugin.getDependencyPath('nekohtml')}"/>
<!-- These 2 jars should not be needed but it won't work without
them -->
<pathelement path="${plugin.getDependencyPath('xml-apis')}"/>
<pathelement path="${plugin.getDependencyPath('xerces')}"/>
</path>
</goal>
<!--
========================================================================
Compile Cactus tests.
========================================================================
-->
<goal name="cactus:compile" prereqs="java:compile"
description="Compile Cactus tests">
<mkdir dir="${maven.cactus.build.dir}"/>
<mkdir dir="${maven.cactus.classes.dir}"/>
<javac
destdir="${maven.cactus.classes.dir}"
excludes="**/package.html"
debug="${maven.compile.debug}"
deprecation="${maven.compile.deprecation}"
optimize="${maven.compile.optimize}">
<classpath>
<pathelement path="${maven.build.dest}"/>
<path refid="maven.dependency.classpath"/>
<pathelement path="${plugin.getDependencyPath('cactus:cactus')}"/>
<pathelement path="${plugin.getDependencyPath('junit')}"/>
<pathElement path="${plugin.getDependencyPath('httpunit')}"/>
</classpath>
<src>
<path location="${maven.cactus.src.dir}"/>
</src>
</javac>
</goal>
<!--
========================================================================
Create the Cactus webapp (i.e. add Cactus related jars/config/test
classes to either the project war or the project webapp).
========================================================================
-->
<goal name="cactus:webapp" description="Create the Cactus webapp">
<attainGoal name="war:init"/> <!-- this seems required to setup the plugin context -->
<j:set var="maven.cactus.prewar.dir" value="${pom.getPluginContext('maven-war-plugin').getVariable('maven.war.build.dir')}"/>
<available file="${maven.cactus.prewar.dir}/${maven.final.name}.war"
property="maven.cactus.prewar.exists"/>
<j:choose>
<j:when test="${maven.cactus.prewar.exists}">
<!-- Expand the project war -->
<unwar src="${maven.cactus.prewar.dir}/${maven.final.name}.war"
dest="${maven.cactus.build.dir}/${pom.artifactId}"/>
<attainGoal name="cactus:webapp-update"/>
</j:when>
<j:otherwise>
<available file="${maven.cactus.prewar.dir}/${maven.final.name}/WEB-INF"
type="dir" property="maven.cactus.prewebapp.exists"/>
<j:choose>
<j:when test="${maven.cactus.prewebapp.exists}">
<copy todir="${maven.cactus.build.dir}/${pom.artifactId}">
<fileset dir="${maven.cactus.prewar.dir}/${maven.final.name}"/>
</copy>
<attainGoal name="cactus:webapp-update"/>
</j:when>
<j:otherwise>
<echo>
Either a war or a webapp must exist. Please call the War plugin
first.
</echo>
</j:otherwise>
</j:choose>
</j:otherwise>
</j:choose>
</goal>
<!--
========================================================================
Generate a web.xml which is the merge betweem the user project web.xml
and the webapp elements needed by Cactus.
========================================================================
-->
<goal name="cactus:merge-webxml"
description="Generate a web.xml which is the merge betweem the user project web.xml and the webapp elements needed by Cactus">
<j:set var="warWebXml"
value="${pom.getPluginContext('maven-war-plugin').getVariable('maven.war.webxml')}"/>
<available file="${warWebXml}"
property="maven.cactus.webxml.exists"/>
<j:choose>
<j:when test="${maven.cactus.webxml.exists}">
<j:set var="webxml" value="${warWebXml}"/>
</j:when>
<j:otherwise>
<j:set var="webxml" value="${maven.cactus.emptywebxml}"/>
</j:otherwise>
</j:choose>
<!-- FIXME: The Merge was done in DVSL. I removed it, but haven't been able to duplicate it with JSL.
You need to provide a Cactus'ed web.xml to use.
-->
<j:set var="cactuscheckwebxml" value="${maven.cactus.webxml}X"/>
<j:if test="${cactuscheckwebxml == 'X'}">
<fail message="You must provide in your project.properties a maven.cactus.webxml web.xml file to use."/>
</j:if>
<copy toFile="${maven.cactus.build.dir}/${pom.artifactId}/WEB-INF/web.xml" overwrite="true"
file="${maven.cactus.webxml}"/>
</goal>
<!--
========================================================================
Generate an expanded Cactus webapp from a project expanded webapp.
========================================================================
-->
<goal name="cactus:webapp-update" prereqs="cactus:compile"
description="Generate an expanded Cactus webapp from a project expanded webapp">
<!-- Copy Cactus configuration files -->
<copy todir="${maven.cactus.build.dir}/${pom.artifactId}"
file="${plugin.resources}/conf/web/jspRedirector.jsp"/>
<!-- Create the web.xml which is result of merging the project web.xml
and the elements needed by Cactus -->
<attainGoal name="cactus:merge-webxml"/>
<!-- Copy Cactus jars -->
<copy todir="${maven.cactus.build.dir}/${pom.artifactId}/WEB-INF/lib"
file="${plugin.getDependencyPath('cactus:cactus')}"/>
<copy todir="${maven.cactus.build.dir}/${pom.artifactId}/WEB-INF/lib"
file="${plugin.getDependencyPath('aspectj:aspectjrt')}"/>
<copy todir="${maven.cactus.build.dir}/${pom.artifactId}/WEB-INF/lib"
file="${plugin.getDependencyPath('commons-logging')}"/>
<copy todir="${maven.cactus.build.dir}/${pom.artifactId}/WEB-INF/lib"
file="${plugin.getDependencyPath('junit')}"/>
<copy todir="${maven.cactus.build.dir}/${pom.artifactId}/WEB-INF/lib"
file="${plugin.getDependencyPath('httpunit')}"/>
<!-- Copy Cactus tests -->
<copy todir="${maven.cactus.build.dir}/${pom.artifactId}/WEB-INF/classes">
<fileset dir="${maven.cactus.classes.dir}"/>
</copy>
</goal>
<!--
========================================================================
Test initialization.
========================================================================
-->
<goal name="cactus:test-init" description="Test initialization">
<path id="cactus.scanner.classpath">
<path refid="maven.dependency.classpath"/>
<pathElement location="${maven.build.dest}"/>
<pathElement location="${maven.cactus.classes.dir}"/>
<pathElement location="${plugin.getDependencyPath('cactus:cactus')}"/>
<pathElement location="${plugin.getDependencyPath('commons-logging')}"/>
<pathElement location="${plugin.getDependencyPath('junit')}"/>
<pathElement location="${plugin.getDependencyPath('commons-httpclient')}"/>
<pathElement location="${plugin.getDependencyPath('aspectj:aspectjrt')}"/>
<pathElement location="${plugin.getDependencyPath('httpunit')}"/>
<pathElement location="${plugin.getDependencyPath('nekohtml')}"/>
<j:forEach var="lib" items="${pom.dependencies}">
<pathElement location="${maven.repo.local}/${lib.artifactDirectory}/jars/${lib.artifact}"/>
</j:forEach>
</path>
<cactus:scanner var="cactusScanner" classpathref="cactus.scanner.classpath">
<fileset dir="${maven.cactus.classes.dir}">
<include name="${maven.cactus.test.fileset.include}"/>
<exclude name="${maven.cactus.test.fileset.exclude}"/>
</fileset>
</cactus:scanner>
</goal>
<!--
========================================================================
Start the Cactus tests using the <junit> Ant task with the JUnit
Text Test Runner.
========================================================================
-->
<goal name="cactus:test-text" prereqs="cactus:test-init,cactus:init"
description="Start the tests using the text runner">
<mkdir dir="${maven.cactus.test.reportsDirectory}"/>
<mkdir dir="${maven.cactus.build.resources.dir}"/>
<copy todir="${maven.cactus.build.resources.dir}"
file="${maven.cactus.configFile}" filtering="on">
<filterset>
<filter token="maven.cactus.port" value="${maven.cactus.port}"/>
</filterset>
</copy>
<junit printSummary="yes" fork="true" dir="${basedir}"
failureProperty="maven.cactus.test.failure">
<formatter type="xml"/>
<formatter type="plain" usefile="${maven.cactus.junit.usefile}"/>
<classpath refid="cactus.classpath.clientside"/>
<j:forEach var="test" items="${cactusScanner.iterator()}">
<test name="${test}" todir="${maven.cactus.test.reportsDirectory}"/>
</j:forEach>
</junit>
<j:if test="${maven.cactus.test.failure}">
<j:set var="cactusignore__" value="${maven.cactus.test.failure.ignore}X"/>
<j:if test="${cactusignore__ == 'X'}">
<fail message="There were test failures."/>
</j:if>
</j:if>
</goal>
<!--
========================================================================
Start the Cactus tests using the <junit> Ant task with the JUnit
Swing Test Runner.
========================================================================
-->
<goal name="cactus:test-swing" prereqs="cactus:test-init,cactus:init"
description="Start the tests using the swing runner">
<mkdir dir="${maven.cactus.build.resources.dir}"/>
<copy todir="${maven.cactus.build.resources.dir}"
file="${maven.cactus.configFile}" filtering="on">
<filterset>
<filter token="maven.cactus.port" value="${maven.cactus.port}"/>
</filterset>
</copy>
<!-- Copy the JUnit excluded.properties - This is needed because the
the Commons logging package need to be excluded from being loaded
by the special JUnit classloader. Otherwise, it fails. -->
<copy todir="${maven.cactus.build.resources.dir}/junit/runner"
file="${maven.cactus.testrunner.swing.excluded}"/>
<java classname="junit.swingui.TestRunner" fork="true" dir="${basedir}">
<j:forEach var="test" items="${cactusScanner.iterator()}">
<jvmarg value="-Dmaven.cactus.test.${test}"/>
</j:forEach>
<arg line="org.apache.maven.cactus.DynamicTestAll"/>
<classpath>
<path refid="cactus.classpath.clientside"/>
<pathelement location="${plugin.dir}"/>
</classpath>
</java>
</goal>
<!--
========================================================================
Generate Cactus test report (xdoc format). Run maven xdoc:transform
to then transform into HTML.
========================================================================
-->
<goal name="cactus:generate"
description="Generate HTML report">
<mkdir dir="${maven.cactus.test.reportsDirectory}"/>
<!-- Consolidate the reports into a single -->
<junitreport todir="${maven.cactus.test.reportsDirectory}">
<fileset dir="${maven.cactus.test.reportsDirectory}">
<include name="TEST-*.xml"/>
</fileset>
</junitreport>
<!-- copied from junit report plugin -->
<doc:jsl
input="${maven.build.dir}/TESTS-TestSuites.xml"
output="junit-report.xml"
stylesheet="${plugin.resources}/junit.jsl"
omitXmlDeclaration="true"
outputMode="xml"
prettyPrint="true"
/>
</goal>
<!--
========================================================================
Execute all Cactus tests using the 'maven.cactus.container'
variable.
========================================================================
-->
<goal name="cactus:test"
description="Execute all testcases">
<j:set var="container" value="${maven.cactus.container}X"/>
<j:choose>
<j:when test="${container != 'X'}">
<echo message="Attempting to run target: cactus:test-${maven.cactus.container}"/>
<!-- This should be the call, but I get JellyContext errors-->
<!--
<attainGoal name="cactus:test-${maven.cactus.container}"/>
-->
<!--
Therefore, we have this chunk of code lifted from tomcat.4x.jelly that
starts up the Tomcat engine in one thread. Because the <j:thread> tag seems to
generate errors as well, it blocks the thread.
You must then start another command line, call cactus:test again, and it
will run the actual tests. Nothing shuts down the original webserver thread.
If you use something besides Tomcat, you will need to change this section.
-->
<!-- Is Tomcat 4.x already started? -->
<condition property="tomcat4xstarted">
<socket server="localhost" port="${maven.cactus.port}"/>
</condition>
<j:choose>
<j:when test="${tomcat4xstarted == null}">
<attainGoal name="cactus:start-tomcat-4x"/>
</j:when>
<j:otherwise>
<!-- redeploy seems to fail. The copy doesn't happen. -->
<!-- <attainGoal name="cactus:redeploy-tomcat-4x"/>-->
</j:otherwise>
</j:choose>
<waitfor checkevery="500">
<http url="http://localhost:${maven.cactus.port}/test/ServletRedirector?Cactus_Service=RUN_TEST"/>
</waitfor>
<attainGoal name="cactus:test-${maven.cactus.testrunner}"/>
</j:when>
<j:otherwise>
<echo>
You must define the maven.cactus.container to run!
</echo>
</j:otherwise>
</j:choose>
</goal>
<!--
========================================================================
Execute a single Cactus test case defined using the 'Dmavencactustestcase'
variable.
NOTE: This assumes that the server was already started and that the
Cactus war has already been deployed.
========================================================================
-->
<goal name="cactus:single" prereqs="war:war,cactus:compile,cactus:init"
description="Execute a single test defined using the 'testcase' variable">
<j:choose>
<j:when test="${empty(mavencactustestcase)}">
<echo>
You must define the test case to run via -Dmavencactustestcase=classname
Example: maven -Dmavencactustestcase=MyTest cactus:single
</echo>
</j:when>
<j:otherwise>
<junit printSummary="yes" fork="true" dir="${basedir}"
failureProperty="maven.cactus.test.failure">
<formatter type="xml"/>
<formatter type="plain" usefile="${maven.cactus.junit.usefile}"/>
<classpath refid="cactus.classpath.clientside"/>
<test name="${mavencactustestcase}"
todir="${maven.cactus.test.reportsDirectory}"/>
</junit>
<j:if test="${maven.cactus.test.failure}">
<j:set var="cactusignore__"
value="${maven.cactus.test.failure.ignore}X"/>
<j:if test="${cactusignore__ == 'X'}">
<fail message="There were test failures."/>
</j:if>
</j:if>
</j:otherwise>
</j:choose>
</goal>
</project>