Jon Jagger (11) [Avatar] Offline
#1
package name --> path name conversion
Hi,
first thanks for a great book. It's answered all my questions up to now. Here's my question In my build.xml file I use a pattern like this:

<target name="a.b.c" description="..." depends="...">
<antcall target="run-test" ... ><param name="package" value="a/b/c" />
</antcall>
</target>

This works very nicely - a &included xml library has a standard run-test --> build-test --> build dependency etc.

The problem is that I'd like to avoid the obvious duplication. I should be able to get ant to translate a.b.c into a/b/c.

Can I use the package mapper (p61) or the custom mapper (p514)? If so how? I can't see it.

TIA
JJ
ErikHatcher (211) [Avatar] Offline
#2
Re: package name --&gt; path name conversion
There are a number of tricks that can be used.

First - I caution against using <antcall> these days. Ant 1.6 has made it unnecessary. <antcall>'s are slow. Consider updating it to <macrodef> instead, and use <import> instead of the entity reference includes.

It looks like you want to get the target name - which is not possible within Ant. However, to run a single unit test consider using the technique you'll see at http://www.ehatchersolutions.com/JavaDevWithAnt (note the if/unless attributes on <batchtest>smilie.
Jon Jagger (11) [Avatar] Offline
#3
Re: package name --&gt; path name conversion
> There are a number of tricks that can be used.

Wow. That was a quick response.

> First - I caution against using <antcall> these days.
> Ant 1.6 has made it unnecessary. <antcall>'s are
> e slow. Consider updating it to <macrodef> instead,
> and use <import> instead of the entity reference
> includes.

macrodef and import - neither of these are mentioned in the book. New features in 1.6 I'm guessing. ok.

> It looks like you want to get the target name -

Yes.

> which is not possible within Ant.

smilie Is there a reason for that?

> However, to run a single
> unit test consider using the technique you'll see at
> http://www.ehatchersolutions.com/JavaDevWithAnt (note
> the if/unless attributes on <batchtest>smilie.

Sure - run all the tests in a package. But the <batchtest> is inside a <target> so I still need to pass in the package name as the module property.

If I can't get hold of the target name then it seems I will just have to live with the duplication....

Thanks
JJ
ErikHatcher (211) [Avatar] Offline
#4
Re: package name --&gt; path name conversion
> macrodef and import - neither of these are mentioned
> in the book. New features in 1.6 I'm guessing. ok.

Correct - these were added well after our book was published. Such is life - trying to keep up with technology.

> > It looks like you want to get the target name -
>
> Yes.
>
> > which is not possible within Ant.
>
> smilie Is there a reason for that?

This issue has been discussed ad naseum on the Ant e-mail lists. Feel free to check the archives if you want to see all the arguments for and against it.

> > > However, to run a single
> > unit test consider using the technique you'll see
> at
> > http://www.ehatchersolutions.com/JavaDevWithAnt
> (note
> > the if/unless attributes on <batchtest>smilie.
>
> Sure - run all the tests in a package. But the
> <batchtest> is inside a <target> so I still need to
> pass in the package name as the module property.

I'm not sure why you need a target to do this. Make a generic "run-single-package-tests" target, use an Ant property called "package" to represent it. Then run "ant -Dpackage=com" for example. Would that suffice?

> If I can't get hold of the target name then it seems
> I will just have to live with the duplication....

Not necessarily. See above. Lots of tricks can be played with clever use of Ant properties.

Erik
Jon Jagger (11) [Avatar] Offline
#5
Re: package name --&gt; path name conversion
> > macrodef and import - neither of these are
> mentioned
> > in the book. New features in 1.6 I'm guessing. ok.
>
> Correct - these were added well after our book was
> published. Such is life - trying to keep up with
> technology.

Indeed.

> > > It looks like you want to get the target name -
> >
> > Yes.
> >
> > > which is not possible within Ant.
> >
> > smilie Is there a reason for that?
>
> This issue has been discussed ad naseum on the Ant
> e-mail lists. Feel free to check the archives if you
> want to see all the arguments for and against it.

ok. thanks.

> > > > However, to run a single
> > > unit test consider using the technique you'll
> see
> > at
> > > http://www.ehatchersolutions.com/JavaDevWithAnt
> > (note
> > > the if/unless attributes on <batchtest>smilie.
> >
> > Sure - run all the tests in a package. But the
> > <batchtest> is inside a <target> so I still need
> to
> > pass in the package name as the module property.
>
> I'm not sure why you need a target to do this. Make
> a generic "run-single-package-tests" target, use an
> Ant property called "package" to represent it. Then
> run "ant -Dpackage=com" for example. Would that
> suffice?

Ok. If I understand you you're saying rather than my current

>ant com.wibble.fubar

I should consider instead the more explicit

>ant -Dpackage=com.wibble.fubar target-name-here

yes? Ok. I'll play along...smilie If I did that would I then be able to get ant to convert com.wibble.fubar into com/wibble/fubar ?

Cheers
JJ
Jon Jagger (11) [Avatar] Offline
#6
Re: package name --&gt; path name conversion
And to partly answer my own question - I see ant 1.6 now has an unpackage mapper to go with the package mapper from 1.5
Is there a web page at apache.org that lists the new tasks in 1.6?

JJ
ErikHatcher (211) [Avatar] Offline
#7
Re: package name --&gt; path name conversion
Jon - you're really best to hop onto the Ant user e-mail list at this point. We've gone beyond the role of this forum as it relates to the Java Development with Ant book. You'll get a lot more answers with a variety of options on that list - and I'm there too to possibly reply.
Jon Jagger (11) [Avatar] Offline
#8
Re: package name --&gt; path name conversion
Yes you're right. Thanks again.
JJ