Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Tools / January 2007

Tip: Looking for answers? Try searching our database.

Ant - testing for file existence with wildcards?

Thread view: 
Andy Dingley <dingbat@codesmiths.com> - 18 Jan 2007 16:47 GMT
As usual, I'm falling into the gaps of what <available> can't do.

I need to do two things:

- Determine if a directory has any unknown child directories, i.e. any
directories of any name, except a couple of pre-known excludes.

- Determine if a known directory has any contents, i.e. if matching a
wildcard is a non-empty set

What's the best way to do this, so I have a "once and for all" solution
to this recurring Ant problem?

<available> plain and simple doesn't work. It's not intended to, it
just "almost works" and so we've got into the habit of using it for
this task. If you use it strictly as "available", i.e. "Here's a known
thing, does it exist?" then it's OK.

I have used the following hack for the second, which works OK so long
as the directory exists. I have to wrap it in a vast pile of dependent
targets and test for the directory's existence first with <available>!
As I have to do this a dozen times, that's not attractive.

       <pathconvert property="pt2-src-functions" setonempty="false"
pathsep=" " >
           <path><fileset dir="${customer.db.dir}/functions"
includes="*.*" /></path>
       </pathconvert>

I'm having no success at all with the first.  8-(

Ideally I want a solution that's based on "standard Ant" as much as
possible. I could write my own Java task pretty easily, but I have to
deploy and maintain this script worldwide. One of the reasons for using
Ant at all is that it's a pre-deployed common platform. Ha!

And _why_ doesn't <echo> support if and unless ?   8-(

Any assistance very gratefully received (beer, chocolate or noodles if
you're local to Bristol!)
Daniel Dyer - 18 Jan 2007 21:33 GMT
> As usual, I'm falling into the gaps of what <available> can't do.
>
[quoted text clipped - 8 lines]
> What's the best way to do this, so I have a "once and for all" solution
> to this recurring Ant problem?

Write a custom task?

> I have used the following hack for the second, which works OK so long
> as the directory exists. I have to wrap it in a vast pile of dependent
[quoted text clipped - 6 lines]
> includes="*.*" /></path>
>         </pathconvert>

If you need to do the same thing over and over, perhaps you could  
encapsulate the ugliness in a macro?  However, the dependent targets may  
complicate this, unless you use the if task from Ant-Contrib.

> I'm having no success at all with the first.  8-(

If you don't have to support pre-1.7 versions of Ant, you can use the  
ResourceCount task  
(http://ant.apache.org/manual/CoreTasks/resourcecount.html).  Provide a  
nested fileset with the necessary includes/excludes and it will set a  
property based on the number of matching files.  I haven't tried it but I  
think that you could probably solve both of your problems with this.

Dan.

Signature

Daniel Dyer
https://watchmaker.dev.java.net - Evolutionary Algorithm Framework for Java

Andy Dingley <dingbat@codesmiths.com> - 19 Jan 2007 10:56 GMT
> If you don't have to support pre-1.7 versions of Ant, you can use the
> ResourceCount task
> (http://ant.apache.org/manual/CoreTasks/resourcecount.html).

Thanks, that looks excellent!

Now I just need to wait for the Redhat distributions to catch up and
deploy Ant 1.7   (some time around 2012, I expect)

In the meantime though I think I can defer the need for this tweak; if
it's unworkably ugly today and there's a neat fix for it happening
soon(ish).


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.