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.
Created attachment 7240 [details] Patch to extend <property> with searchparents attribute
Created attachment 7252 [details] Another idea: adding searchparents flag to influence either file or location attribute
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.
Created attachment 7253 [details] The version of the previous patch with searchparents renamed to find to match command line option -find
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"/>