Bug 21494 - <property>: version of location to search parent dirs
Summary: <property>: version of location to search parent dirs
Status: NEW
Alias: None
Product: Ant
Classification: Unclassified
Component: Core tasks (show other bugs)
Version: unspecified
Hardware: Other All
: P3 enhancement (vote)
Target Milestone: ---
Assignee: Ant Notifications List
URL:
Keywords: PatchAvailable
Depends on:
Blocks:
 
Reported: 2003-07-11 10:40 UTC by Igor Bukanov
Modified: 2009-07-30 08:14 UTC (History)
0 users



Attachments
Patch to extend <property> with searchparents attribute (3.95 KB, patch)
2003-07-11 10:42 UTC, Igor Bukanov
Details | Diff
Another idea: adding searchparents flag to influence either file or location attribute (8.90 KB, patch)
2003-07-11 17:47 UTC, Igor Bukanov
Details | Diff
The version of the previous patch with searchparents renamed to find to match command line option -find (8.76 KB, patch)
2003-07-11 18:07 UTC, Igor Bukanov
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Igor Bukanov 2003-07-11 10:40:26 UTC
I have found it would be very useful to have an version of property.location
that searches for parent directories. For example, I would like to be able to
write in a nested build.xml file:

<property name="build" searchparents="build"/>

<property name="global-properties" searchparents="global.properties"/>

which would set build to the first build dir found in project's base dir or its
parents and similarly for global-properties. If such file or directory does not
exist, searchparents would work exactly as current location attribute.

In this way I can safely invoke ant against build.xml in an arbitrary
subdirectory and it will properly initialize itself without the need to specify
absolute path names in the environment or on command line.

I emulate this functionality by wrapping ant invocation into a shell script that
does that for all properties that I need to search but it would be nice to have
the option in the ant directly.
Comment 1 Igor Bukanov 2003-07-11 10:42:38 UTC
Created attachment 7240 [details]
Patch to extend <property> with searchparents attribute
Comment 2 Igor Bukanov 2003-07-11 17:47:49 UTC
Created attachment 7252 [details]
Another idea: adding searchparents flag to influence either file or location attribute
Comment 3 Igor Bukanov 2003-07-11 18:00:55 UTC
The above patch takes a different approach to extend <property>. It adds
searchparents as a boolean attribute that can be used either with location or
file. When set to true it makes location or file to search for their argument in
parents directories if it is a relative path. With this version one can not only
write:

<property name="build" location="igor"  searchparents="on"/>

but also:

<property file="global.properties" searchparents="on"/>

to make ant to search for global.properties in base dir or its parents.

Such functionality can be implement withthe first version of the patch by the
following 2 liner:

<property name="global-location" searchparents="global.properties"/>
<property file="${global-location}"/>

but it require to introduce unnecessary global-location property.

On the other hand the patch is bigger and more intrusive since it has to change
setLocation/setFile signatures from File to String as File arguments are already
resolved into absolute path and searchparents option requires access to the
original relative path.
Comment 4 Igor Bukanov 2003-07-11 18:07:26 UTC
Created attachment 7253 [details]
The version of the previous patch with searchparents renamed to find to match command line option -find
Comment 5 Igor Bukanov 2003-07-11 18:09:11 UTC
Ok, the third version of the patch: I renamed searchparents to find since it has
exactly the same semantics as -find command line option to ant itself. So the
above example now reads:

<property name="build" location="igor"  find="on"/>

<property file="global.properties" find="on"/>