aspose file tools*
The moose likes Ant, Maven and Other Build Tools and the fly likes ant beginner - conditionally select paths Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "ant beginner - conditionally select paths" Watch "ant beginner - conditionally select paths" New topic
Author

ant beginner - conditionally select paths

Dianne Pop
Greenhorn

Joined: May 07, 2003
Posts: 8
Hi!

I have a legacy ant file that I need to modify, and I hope you can help.
Currently, the source directories are defined in path elements that are later passed for compile:
(simplified)


I need to granularize this and specify in a properties file which packages should be used for different compile types - for example "compile1" should only compile package1 stuff, "compile2" another set of packages, and "compile" - all of them.
So something like this



Is there a way to put conditions like this?
Or maybe at the <path> level, only include the source directories based on the specified properties?

Thanks!
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5830
    
    7

I have used two mechanism to do things like this. One is to have different properties files that assign different value and then choose which properties file to use for the build. The other is to use the <condition> task to selectively set properties. If that is not enough of a hint, let us know...

JBoss In Action
Dianne Pop
Greenhorn

Joined: May 07, 2003
Posts: 8
What I figured out yesterday, before you answered is something like this:
(I even had a more complicated problem, with sub-packages)



the properties files specifies which "modules" to add


Is this the correct way and what you meant about <condition> ? Is there a easier way to do this, or perhaps a more elegant one? (with less code, so those reading it afterwards can comprehend what happens easier? )

Thanks!!



Later edited to add that this approach gives me unpredictable behaviour, for example I set in my properties file only "build-b" and I still got, for some reason stuff from "a-1". Can't figure out why
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5830
    
    7

I would go with something more like this:



In other words, conditionally set a property to your desired source base directory and pass that property value off to javac.

Dianne Pop
Greenhorn

Joined: May 07, 2003
Posts: 8
Thanks for your reply!

Your code looks much better and is way more readable than mine, so if I can trouble you a little more:
Unfortunately, my "src" is composed of several such packages for each case, so I need a way to coalesce several paths into one "variable", or to conditionally append more directories to the "src".

For example, for the case "one.a.1", I'd need a package "common.a", then "one.a.1","one.a.1.i","one.a.1.ii","some.other.package" - you get the picture.

Thanks again, in advance

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ant beginner - conditionally select paths