maven-plugins/abbot/plugin.jelly

386 lines
16 KiB
XML

<?xml version="1.0"?>
<!--
/* ====================================================================
* Copyright 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.
* ====================================================================
*/
-->
<!--
========================================================================
Abbot plugin. Abbot is a GUI testing framework for AWT/Swing
applications.
========================================================================
-->
<project
xmlns:j="jelly:core"
xmlns:m="jelly:maven"
xmlns:x="jelly:xml"
xmlns:u="jelly:util"
xmlns:ant="jelly:ant"
xmlns:doc="doc"
xmlns:define="jelly:define"
xmlns:jsl="jelly:jsl">
<!--
========================================================================
Default goal. Execute the Abbot tests.
========================================================================
-->
<goal name="abbot" prereqs="abbot:test" description="Run the abbot tests"/>
<!--
========================================================================
Execute the Abbot tests by running the application locally.
========================================================================
-->
<goal name="abbot:test"
prereqs="abbot:check-env,abbot:prepare-filesystem,abbot:prepare-resources,java:compile,java:jar-resources"
description="Run the abbot tests">
<!-- Needed to define junit task -->
<taskdef name="junit"
classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask">
<classpath>
<pathelement location="${plugin.getDependencyPath('junit:junit')}"/>
</classpath>
</taskdef>
<!-- Just let JUnit execute the tests -->
<!-- IMPORTANT: We must fork the JUnit tests. Otherwise there are classpath
problems (the version of xerces in the Maven root CL seems to be the
cause). -->
<junit printSummary="${maven.abbot.printSummary}"
failureProperty="maven.test.failure" fork="true">
<!-- Sys properties -->
<setProperty name="dir" value="${maven.abbot.dir}" />
<sysproperty key="maven.abbot.src.dir" value="${maven.abbot.src.dir}"/>
<sysproperty key="basedir" value="${basedir}"/>
<u:tokenize var="listOfProperties" delim=" ">${maven.abbot.sysproperties}</u:tokenize>
<j:forEach var="someProperty" items="${listOfProperties}">
<sysproperty key="${someProperty}" value="${context.getVariable(someProperty)}"/>
</j:forEach>
<!-- JVM args -->
<u:tokenize var="listOfJvmArgs" delim=" ">${maven.abbot.jvmargs}</u:tokenize>
<j:forEach var="somejvmarg" items="${listOfJvmArgs}">
<jvmarg value="${somejvmarg}"/>
</j:forEach>
<!-- File format of test reports are defined here -->
<formatter type="xml"/>
<formatter type="${maven.abbot.format}" usefile="${maven.abbot.usefile}"/>
<!-- Classpath -->
<classpath>
<pathelement location="${plugin.dir}"/>
<pathelement location="${maven.build.dest}"/>
<pathelement location="${maven.test.dest}"/>
<j:forEach var="dep" items="${plugin.getDependencies()}">
<j:if test="${dep.getProperty('abbot.webstart')}">
<pathelement path="${plugin.getDependencyPath(dep.Id)}"/>
</j:if>
</j:forEach>
<j:forEach var="lib" items="${pom.artifacts}">
<pathelement path="${lib.path}"/>
</j:forEach>
</classpath>
<test name="${maven.abbot.include}" todir="${maven.abbot.reports.dir}"/>
</junit>
<!-- Junit exit status is stored in maven.test.failure. Whenever it is true
(and ignore flag is not) we must stop the build process -->
<j:if test="${maven.test.failure}">
<j:if test="${context.getVariable('maven.test.failure.ignore') != null}">
<fail message="There were test failures"/>
</j:if>
</j:if>
</goal>
<!--
========================================================================
Launch tests on a webstart application
========================================================================
-->
<goal name="abbot:test-webstart" prereqs="abbot:check-webstart-env,abbot:prepare-filesystem"
description="Launch tests on a webstart application">
<!-- First we get the remote jnlp -->
<get src="${maven.abbot.remotejnlp}"
dest="${maven.abbot.dest.dir}/${maven.abbot.webstart.jnlp.original}"/>
<!-- We make a jar with compiled main class -->
<!-- TODO: create this as part of the plugin creation and not as part of
its execution -->
<jar destfile="${maven.abbot.dest.jar.dir}/${maven.abbot.webstart.main.jar}"
basedir="${plugin.dir}" includes="**/*.class"/>
<!-- Iterating through dependencies, and signing them if they're not up-to-date -->
<j:if test="${context.getVariable('maven.abbot.sign')}">
<j:forEach var="dep" items="${plugin.getDependencies()}">
<j:if test="${dep.getProperty('abbot.webstart')}">
<j:set var="filename" value="${dep.GroupId}-${dep.ArtifactId}"/>
<j:set var="varname" value="abbot.signing.notrequired.${dep.id}"/>
<!-- Checking whether or not the dependency has to be signed -->
<uptodate property="${varname}"
srcfile="${plugin.getDependencyPath(dep.Id)}"
targetfile="${maven.abbot.dest.jar.dir}/${filename}.jar"/>
<!-- Keeping this debug trace a while to ensure that the up-to-date feature is working properly -->
<echo level="debug">${dep.id} is uptodate ? ${context.getVariable(varname) == true}</echo>
<!-- Signing the dependency only if it is not up-to-date or forced -->
<j:if test="${(context.getVariable(varname) != true)}">
<!-- Unsigning -->
<zip destfile="${maven.abbot.dest.jar.dir}/${filename}.jar">
<zipfileset src="${plugin.getDependencyPath(dep.id)}"
excludes="**/*.SF **/*.RSA **/*.DSA"/>
</zip>
<!-- Signing -->
<signjar jar="${maven.abbot.dest.jar.dir}/${filename}.jar"
keystore="${maven.abbot.sign.keystore}"
alias="${maven.abbot.sign.alias}"
storepass="${maven.abbot.sign.storepass}"/>
</j:if>
</j:if>
</j:forEach>
<!-- Also sign all user-specified extra jars to be added to the executing CP.
Note: The reason these jars are not passed as tagged dependencies is because
we need to be able to specify them from another plugin. -->
<u:tokenize var="customJars" delim=",">${maven.abbot.extrajars}</u:tokenize>
<j:forEach var="customJar" items="${customJars}">
<ant:basename property="jarname" file="${customJar}"/>
<copy todir="${maven.abbot.dest.jar.dir}" file="${customJar}"/>
<signjar jar="${maven.abbot.dest.jar.dir}/${jarname}"
keystore="${maven.abbot.sign.keystore}"
alias="${maven.abbot.sign.alias}"
storepass="${maven.abbot.sign.storepass}"/>
</j:forEach>
<!-- Jar containing abbot main class is signed -->
<!-- TODO: Only sign it if not already done instead of everytime -->
<signjar jar="${maven.abbot.dest.jar.dir}/${maven.abbot.webstart.main.jar}"
keystore="${maven.abbot.sign.keystore}"
alias="${maven.abbot.sign.alias}"
storepass="${maven.abbot.sign.storepass}"/>
</j:if>
<!-- Jnlp is modified so that local abbot libraries are referenced -->
<doc:jsl
input="${maven.abbot.dest.dir}/${maven.abbot.webstart.jnlp.original}"
output="${maven.abbot.webstart.jnlp.modified}"
outputDirectory="${maven.abbot.dest.dir}"
stylesheet="${plugin.resources}/jnlp.jsl"
outputMode="xml"
prettyPrint="true"/>
<!-- Java webstart is launched on local modified jnlp -->
<java classname="com.sun.javaws.Main" fork="true" failonerror="true">
<classpath>
<pathelement location="${maven.abbot.webstart.home}/javaws-l10n.jar"/>
<pathelement location="${maven.abbot.webstart.home}/javaws.jar"/>
</classpath>
<jvmarg value="-Djnlpx.home=${maven.abbot.webstart.home}"/>
<jvmarg value="-Djnlpx.heapsize=NULL,NULL"/>
<jvmarg value="-Djnlpx.jvm=${java.home}/bin/javaw.exe"/>
<jvmarg value="-Djnlpx.deployment.system.home=${maven.abbot.javaws.systemhome}"/>
<jvmarg value="-Djnlpx.deployment.user.home=${maven.abbot.javaws.userhome}"/>
<jvmarg value="-Djava.security.policy=${maven.abbot.webstart.home}/javaws.policy"/>
<jvmarg value="-DtrustProxy=true"/>
<arg value="${maven.abbot.dest.dir}/${maven.abbot.webstart.jnlp.modified}"/>
</java>
</goal>
<!--
========================================================================
Launch Abbot costello editor
========================================================================
-->
<goal name="abbot:editor" prereqs="abbot:check-env,abbot:prepare-filesystem"
description="Launch Abbot costello editor">
<!-- Launching abbot editor with abbot and jnlp dependencies as classpath -->
<java classname="abbot.editor.ScriptEditor" fork="true">
<classpath>
<!-- Abbot editor dependencies -->
<j:forEach var="dep" items="${plugin.getDependencies()}">
<j:if test="${dep.getProperty('abbot.editor')}">
<pathelement path="${plugin.getDependencyPath(dep.Id)}"/>
</j:if>
</j:forEach>
<path refid="maven.dependency.classpath"/>
</classpath>
</java>
</goal>
<!--
========================================================================
Launch Abbot costello editor on a webstart application
========================================================================
-->
<goal name="abbot:editor-webstart"
prereqs="abbot:check-webstart-env,abbot:prepare-filesystem"
description="Launch Abbot costello editor on a webstart application">
<!-- First we get the remote jnlp -->
<get src="${maven.abbot.remotejnlp}"
dest="${maven.abbot.dest.dir}/${maven.abbot.webstart.jnlp.original}"/>
<!-- Parsing jnlp file in order to copy all dependencies into local directory -->
<u:file var="inputFile" name="${maven.abbot.dest.dir}/${maven.abbot.webstart.jnlp.original}"/>
<x:parse var="parsedfile" xml="${inputFile}"/>
<x:set var="codebasename" select="string($parsedfile/jnlp/@codebase)"/>
<x:forEach var="jar" select="$parsedfile/jnlp/resources/jar">
<x:set var="jarname" select="string($jar/@href)"/>
<get src="${codebasename}/${jarname}" usetimestamp="true"
dest="${maven.abbot.dest.dir}/${jarname}"/>
</x:forEach>
<!-- Launching abbot editor with abbot and jnlp dependencies as classpath -->
<java classname="abbot.editor.ScriptEditor" fork="true">
<classpath>
<!-- Abbot editor dependencies -->
<j:forEach var="dep" items="${plugin.getDependencies()}">
<j:if test="${dep.getProperty('abbot.editor')}">
<pathelement path="${plugin.getDependencyPath(dep.Id)}"/>
</j:if>
</j:forEach>
<!-- Remote application dependencies -->
<x:forEach var="jar" select="$parsedfile/jnlp/resources/jar">
<x:set var="jarname" select="string($jar/@href)"/>
<pathelement path="${maven.abbot.dest.dir}/${jarname}"/>
</x:forEach>
<!-- Extra dependencies -->
<u:tokenize var="customJars" delim=",">${maven.abbot.extrajars}</u:tokenize>
<j:forEach var="customJar" items="${customJars}">
<pathelement location="${customjar}"/>
</j:forEach>
</classpath>
</java>
</goal>
<!--
========================================================================
Copy test resources to test directory (internal goal)
========================================================================
-->
<goal name="abbot:prepare-resources" prereqs="abbot:prepare-filesystem">
<j:if test="${pom.build.unitTest != null}">
<j:if test="${!pom.build.unitTest.resources.isEmpty()}">
<m:copy-resources
resources="${pom.build.unitTest.resources}"
todir="${maven.test.dest}"/>
</j:if>
</j:if>
</goal>
<!--
========================================================================
Create needed directories (internal goal)
========================================================================
-->
<goal name="abbot:prepare-filesystem">
<mkdir dir="${maven.test.dest}"/>
<mkdir dir="${maven.abbot.reports.dir}"/>
<mkdir dir="${maven.abbot.dest.dir}"/>
<mkdir dir="${maven.abbot.dest.jar.dir}"/>
</goal>
<!--
========================================================================
Checking environment (internal goal)
========================================================================
-->
<goal name="abbot:check-env">
<j:if test="${context.getVariable('java.awt.headless') == true}">
<fail message="Abbot plugin cannot be used in awt headless environment"/>
</j:if>
</goal>
<!--
========================================================================
Checking webstart environment (internal goal)
========================================================================
-->
<goal name="abbot:check-webstart-env" prereqs="abbot:check-env">
<u:file var="webstartHomeAsFile" name="${maven.abbot.webstart.home}"/>
<j:if test="${!webstartHomeAsFile.exists()}">
<fail>Webstart home directory not found at [${maven.abbot.webstart.home}]</fail>
</j:if>
<j:if test="${context.getVariable('maven.abbot.sign') == false}">
<fail>In the current version the Abbot plugin only works when signing jars</fail>
</j:if>
<j:if test="${context.getVariable('maven.abbot.remotejnlp') == null}">
<fail>Mandatory variable maven.abbot.remotejnlp is missing</fail>
</j:if>
<j:if test="${context.getVariable('maven.abbot.javaws.systemhome') == null}">
<fail>Mandatory variable maven.abbot.javaws.systemhome is missing</fail>
</j:if>
<j:if test="${context.getVariable('maven.abbot.javaws.userhome') == null}">
<fail>Mandatory variable maven.abbot.javaws.userhome is missing</fail>
</j:if>
</goal>
<!--
========================================================================
Dependency handle so that other plugins can load this plugin and its
properties. This is especially useful if another plugin needs to
modify one property of the Abbot plugin.
========================================================================
-->
<define:taglib uri="abbot">
<define:tag name="dependency-handle">
<!-- 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 abbot plugin</echo>
</define:tag>
</define:taglib>
</project>