Hi Vincent,

I'm a little confused after looking at the code and trying to understand 
the role of the helpers.  I'll walk through my setup, to help me talk 
things through:

1) If I don't want to set up an external classpath, then I need to define 
a classpath within the taskdef that defines RunServerTestsTask.

2) When RunServerTestsTask is invoked under ant, it internally executes 
an 'antcall' to the test task that was defined as a parameter.

3) This antcall corresponds to the "run-tests" target (below).  This 
throws a ClassNotDefException for 
Junit.Framework.TestListener.

If I understand you correctly, RunServerTestsTask runs with a specific 
classloader, and the antcall to run-tests executes under another.  Are 
you suggesting that creation of a custom version of RunServerTestsTask 
will fix things, if the new version does not make the antcall itself, but 
instead calls a helper that makes the antcall?  If so, I don't understand 
why this should change things, but it's what the cactus code seems to do 
in your StartServerTask example?

J.

>>>>>>>>>>>>>>>>>> Original Message <<<<<<<<<<<<<<<<<<

On 7/23/01, 1:08:09 AM, "Vincent Massol" <[EMAIL PROTECTED]> wrote regarding 
Re: Defining classpath within ant build file:


> Hi Jason,

> Ant 2.0 will change that but for the time being it is not possible to use 
an
> explicit classpath when defining a task that will call another task. For
> example, in Cactus, what I have done is to write helper classes. For 
example
> the startserver task is simply a wrapper around a helper class that has 
the
> logic. This so that the runservertask will actually not call the 
startserver
> task but rather it's helper. This is because as you mentionned, in Ant 
1.x
> it is not possible to call a task from another task when explicitely
> defining a classpath (when using the taskdef task).

> Note: The exception to this is when the second task to call is an Ant 
task
> (i.e. located in an Ant package, can't remember which but I remember that 
an
> Ant package was automatically added to the classloader class path, 
probably
> org.apache.tools.ant.task).

> I don't know what's wrong with your script.

> Cheers,
> -Vincent

> ----- Original Message -----
> From: "Jason Grant" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Sunday, July 22, 2001 2:29 PM
> Subject: Defining classpath within ant build file


> I have a question that relates to testing via taskdefs & classloaders
> under ant.

> I have not been able to conduct tests after defining a classpath within
> ant's build.xml file.  If I define the classpath externally (i.e. within
> the shell that executes ant), I am able to conduct my tests.  If I
> instead define a classpath in either taskdefs, or in the targets
> themselves, I get ClassNotFound exceptions.

> Back when cactus was j2eeunit, Vincent explained that use of explicit
> classpath entries in either taskdefs or targets causes ant to run each of
> the tasks [having custom classpaths] under different classloaders, and so
> it is not possible for one task to call another (as done by the cactus
> server task) under these circumstances.  This explains why things work
> when the classpath is configured externally by the shell - all of the
> tasks run under the same classloader.

> I would now like to dispense with the use of a wrapper script that sets
> up the classpath for me, and instead define the classpath within my
> build.xml file.  I want to use a combination of path and refid
> statements, as shown below.

> Suggestions appreciated.

> Here's an example of what I'd like to do:

>   <!-- Build classpath -->
>   <path id="classpath">
>     <fileset dir="../lib">
>       <include name="**/*.jar"/>
>     </fileset>
>     <fileset dir="../../../../common/lib">
>       <include name="**/servlet*.jar"/>
>     </fileset>
>   </path>

> ...

> <taskdef name="runservertests"
> classname="org.apache.commons.cactus.ant.RunServerTestsTask">
>       <classpath refid="classpath"/>
> <taskdef/>
> <taskdef name="junit"
> classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask">
>       <classpath refid="classpath"/>
> <taskdef/>
> <taskdef name="batchtest"
> classname="org.apache.tools.ant.taskdefs.optional.junit.BatchTest">
>       <classpath refid="classpath"/>
> <taskdef/>

> ...

> <target name="run-tests">
>         <junit printsummary="yes" haltonfailure="yes" haltonerror="yes"
> fork="yes">
>           <formatter type="plain" usefile="false"/>
>           <batchtest>
>             <fileset dir="${src.dir}">
>               <include name="**/*ServletTest.java"/>
>             </fileset>
>           </batchtest>
>         </junit>
> </target>

> <target name="tests" depends="init-tasks">
>         <runservertests testURL="http://localhost:8080";
>             startTarget="start_tomcat_40"
>             stopTarget="stop_tomcat_40"
>             testTarget="run-tests"/>
> </target>

Reply via email to