You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by mraible <ma...@raibledesigns.com> on 2007/02/03 19:58:28 UTC

Testing archetypes with Ant

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 -DarchetypeArtifactId=@{archetype}
-DremoteRepositories=http://static.appfuse.org/repository
-DarchetypeVersion=@{version} -DgroupId=com.mycompany
-DartifactId=@{name}"/>
        
        <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: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Testing archetypes with Ant

Posted by mraible <ma...@raibledesigns.com>.
I finally got everything working, but I'm also experiencing a strange side
effect. The common-test.xml[1] script is called from each archetype's
pom.xml:

    <profiles>
        <profile>
            <id>integration-test</id>
            <activation>
                <property>
                    <name>!maven.test.skip</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <version>1.1</version>
                        <configuration>
                            <tasks>
                                <ant antfile="../common-test.xml" dir=".">
                                    <property name="archetype"
value="${pom.artifactId}"/>
                                    <property name="version"
value="${pom.version}"/>
                                </ant>
                            </tasks>
                        </configuration>
                        <executions>
                            <execution>
                                <phase>integration-test</phase>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

However, there's something in these archetype tests that causes downstream
antrun executions to fail. This no longer works:

                    <plugin>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <version>1.1</version>
                        <configuration>
                            <tasks>
                                <taskdef
resource="webtest_base_relaxed.taskdef">
                                    <classpath
refid="maven.test.classpath"/>
                                </taskdef>

AFAICT, the classpath is somehow getting messed up by the archetype Ant
execution.  If I comment out the archetype tests, the above taskdef works. 
Strangely enough, the archetype tests create archetypes and run integration
tests with the same <taskdef> and it works fine.  Do I need to fork the JVM
or something to get this to work?  Has anyone else experienced antrun
executions causing issues with other antrun executions?

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 name="common-test" default="test">

    <property name="version" value="${version}"/>
    <property name="archetype" value="${archetype}"/>
    <property name="test.dir" value="${basedir}/target/test-archetype"/>

    <target name="test" description="Tests that 'mvn integration-test' works
with archetype">
        <echo message="Creating archetype '${archetype}', version
'${version}'"/>
        <test archetype="${archetype}" version="${version}"/>
    </target>

    <macrodef name="test">
        <attribute name="archetype"/>
        <attribute name="version"/>
        
        <sequential>
            <delete dir="${test.dir}"/>
            <mkdir dir="${test.dir}"/>
            <maven dir="${basedir}" command="install
-Dmaven.test.skip=true"/>
            <maven dir="${test.dir}" archetype="@{archetype}"
version="@{version}" />
            <maven dir="${test.dir}/archetype" command="integration-test"/>
        </sequential>
    </macrodef>
    
    <macrodef name="maven">
        <attribute name="dir"/>
        <attribute name="name" default=""/>
        <attribute name="archetype" default=""/>
        <attribute name="version" default=""/>
        <attribute name="command" default="archetype:create
-DarchetypeGroupId=org.appfuse -DarchetypeArtifactId=@{archetype}
-DarchetypeVersion=@{version} -DgroupId=com.mycompany
-DartifactId=archetype"/>
        
        <sequential>
            <exec dir="@{dir}" executable="mvn.bat" os="Windows XP"
failonerror="true">
                <arg line="@{command}"/>
            </exec>
            <exec dir="@{dir}" executable="mvn" os="Mac OS X"
failonerror="true">
                <arg line="@{command}"/>
            </exec>
            <exec dir="@{dir}" executable="mvn" os="Linux"
failonerror="true">
                <arg line="@{command}"/>
            </exec>
        </sequential>
    </macrodef>
</project>

-- 
View this message in context: http://www.nabble.com/Testing-archetypes-with-Ant-tf3167091s177.html#a8810296
Sent from the Maven - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Testing archetypes with Ant

Posted by mraible <ma...@raibledesigns.com>.
Hmmm, this might not work as good as I thought it did.  It seems when the
antrun plugin fails during integration testing, the antrun plugin running
the tests doesn't catch and report the failure.  Any idea how to fix this?

     [exec] [ERROR] BUILD ERROR
     [exec] [INFO]
------------------------------------------------------------------------
     [exec] [INFO] Error executing ant tasks

     [exec] Embedded error: The following error occurred while executing
this line:
     [exec]
/Users/mraible/Work/appfuse-2.0/archetypes/appfuse-basic-spring/target/basicspring/src/test/resources/web-tests.xml:23:
Canoo Webtest: R_1454.
     [exec] Test failed.
     [exec] Test step steps
(/Users/mraible/Work/appfuse-2.0/archetypes/appfuse-basic-spring/target/basicspring/src/test/resources/web-tests.xml:25:
) null failed with message "Step[invoke "get Login Page" (1/6)]: HTTP error
400, at: invoke"
     [exec] [INFO]
------------------------------------------------------------------------
     [exec] [INFO] For more information, run Maven with the -e switch
     [exec] [INFO]
------------------------------------------------------------------------
     [exec] [INFO] Total time: 22 seconds
     [exec] [INFO] Finished at: Sat Feb 03 12:41:58 MST 2007
     [exec] [INFO] Final Memory: 22M/508M
     [exec] [INFO]
------------------------------------------------------------------------
     [exec] Result: 1
[INFO] Executed tasks
[INFO] [install:install]
[INFO] Installing
/Users/mraible/Work/appfuse-2.0/archetypes/appfuse-basic-spring/target/appfuse-basic-spring-1.0-m3-SNAPSHOT.jar
to
/Users/mraible/.m2/repository/org/appfuse/appfuse-basic-spring/1.0-m3-SNAPSHOT/appfuse-basic-spring-1.0-m3-SNAPSHOT.jar
[INFO]
------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO]
------------------------------------------------------------------------
[INFO] Total time: 29 seconds
[INFO] Finished at: Sat Feb 03 12:41:58 MST 2007
[INFO] Final Memory: 8M/508M
[INFO]
------------------------------------------------------------------------

Thanks,

Matt


mraible wrote:
> 
> 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 -DarchetypeArtifactId=@{archetype}
> -DremoteRepositories=http://static.appfuse.org/repository
> -DarchetypeVersion=@{version} -DgroupId=com.mycompany
> -DartifactId=@{name}"/>
>         
>         <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#a8788272
Sent from the Maven - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org