• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ant beginner - conditionally select paths

 
Dianne Pop
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Dianne Pop
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic