I've figured out a way to test archetypes with Ant, but it's not quite as
clean as I'd like. In my archetypes directory, I have a common-test.xml[1]
file that gets called from the archetype using the antrun-plugin:
The following works:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.1</version>
<configuration>
<tasks>
<ant antfile="test.xml"/>
</tasks>
</configuration>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
If test.xml has:
<?xml version="1.0" encoding="UTF-8"?>
<project name="integration-test" basedir="." default="test">
<!-- Import macrodefs for running Maven to create archetypes and run
integration tests -->
<import file="../common-test.xml"/>
<target name="test" description="Tests that 'mvn integration-test' works
with archetype">
<test archetype="appfuse-basic-jsf" name="basicjsf"
version="1.0-m3-SNAPSHOT"/>
</target>
</project>
Is it possible to move the contents from test.xml into the pom.xml itself?
When I try to use the following, it fails with a NPE:
<tasks>
<import file="../common-test.xml"/>
<test archetype="appfuse-basic-jsf"
name="basicjsf"
version="1.0-m3-SNAPSHOT"/>
</tasks>
Error:
Embedded error: java.lang.NullPointerException
[INFO]
------------------------------------------------------------------------
[INFO] Trace
org.apache.maven.lifecycle.LifecycleExecutionException: Error executing ant
tasks
at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:559)
at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:475)
at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:454)
at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:306)
at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:273)
at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:140)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:322)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:115)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:256)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at
org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
at
org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: org.apache.maven.plugin.MojoExecutionException: Error executing
ant tasks
at
org.apache.maven.plugin.antrun.AbstractAntMojo.executeTasks(AbstractAntMojo.java:114)
at
org.apache.maven.plugin.antrun.AntRunMojo.execute(AntRunMojo.java:83)
at
org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:412)
at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:534)
... 16 more
Caused by: java.lang.NullPointerException
at org.apache.tools.ant.Task.perform(Task.java:373)
at org.apache.tools.ant.Target.execute(Target.java:341)
at
org.apache.maven.plugin.antrun.AbstractAntMojo.executeTasks(AbstractAntMojo.java:108)
... 19 more
Caused by: java.lang.NullPointerException
at
org.apache.tools.ant.taskdefs.ImportTask.execute(ImportTask.java:96)
at
org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
at org.apache.tools.ant.Task.perform(Task.java:364)
... 21 more
Does the antrun plugin support imports?
Is this the best way to test archetypes?
Thanks,
Matt
[1] common-test.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!-- This file is imported in the archetype pom.xml files for integration
tests -->
<project>
<macrodef name="test">
<attribute name="name"/>
<attribute name="archetype"/>
<attribute name="version"/>
<sequential>
<delete dir="target/@{name}"/>
<maven dir="target" name="@{name}" archetype="@{archetype}"
version="@{version}" />
<maven dir="target/@{name}" command="integration-test"/>
</sequential>
</macrodef>
<macrodef name="maven">
<attribute name="dir" default="${basedir}"/>
<attribute name="name" default=""/>
<attribute name="archetype" default=""/>
<attribute name="version" default=""/>
<attribute name="command" default="archetype:create
-DarchetypeGroupId=org.appfuse [EMAIL PROTECTED]
-DremoteRepositories=http://static.appfuse.org/repository
[EMAIL PROTECTED] -DgroupId=com.mycompany
[EMAIL PROTECTED]"/>
<sequential>
<exec dir="@{dir}" executable="mvn.bat" os="Windows XP">
<arg line="@{command}"/>
</exec>
<exec dir="@{dir}" executable="mvn" os="Mac OS X">
<arg line="@{command}"/>
</exec>
<exec dir="@{dir}" executable="mvn" os="Linux">
<arg line="@{command}"/>
</exec>
</sequential>
</macrodef>
</project>
--
View this message in context:
http://www.nabble.com/Testing-archetypes-with-Ant-tf3167091s177.html#a8785598
Sent from the Maven - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]