ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Igor Bukanov <i...@fastmail.fm>
Subject Re: AW: Search for file in parent directories
Date Fri, 11 Jul 2003 18:52:29 GMT
At the end I put a patch to extend <property> to get what I want to 
bugzilla:
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=21494

With that I can write:

<property name="file" location="build" find="on"/>
to locate build in the project's base dir or its parents.

Yes, I can use javascript, but that is messy especially if I want to use 
that code from multiple files. In the mean time I wrap ant invocation 
into a shell script that does the search for all properties that I need.

Regards, Igor


Jan.Materne@rzf.fin-nrw.de wrote:
> He, he
> 
> a very quick hack, but works (but without any exception handling):
> 
> 
> 
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <project name="test" basedir="." default="main">
>     <target name="main">
>         <property name="file" value="boot.ini"/>
>         <property name="startdir" value="C:/tmp/anttests/search"/>
> 
>         <script language="javascript"> <![CDATA[
>             // import statements
>             importClass(java.io.File);
> 
>             file = project.getProperty("file");
>             dir  = project.getProperty("startdir");
>             dirf = new File(dir);
>             f = new File(dir, file);
> 
>             while (!f.exists()) {
>                 dirf = new File(dirf.getParent());
>                 f = new File(dirf, file);
>             }
> 
>             project.setProperty("location", f.getAbsolutePath());
>         ]]></script>
> 
>         <echo>${file} found in ${location}</echo>
>     </target>
> </project>
> 
> 
> 
> Maybe you want to start here...
> 
> 
> Jan
> 
> 
> 
> 
>>-----Urspr√ľngliche Nachricht-----
>>Von: Igor Bukanov [mailto:igor@fastmail.fm]
>>Gesendet am: Dienstag, 8. Juli 2003 19:00
>>An: user@ant.apache.org
>>Betreff: Search for file in parent directories
>>
>>Hi!
>>
>>I would like to search for the given file name in the given 
>>directory or 
>>one of its parents and set a property to found location. 
>>Something like 
>>ant -find <name> does. Are there any better way to do it then 
>>use when 
>>searching for a.txt:
>>
>><avaialble property="found-path"
>>  file="a.txt" value="a.txt"/>
>><avaialble property="found-path"
>>  file="../a.txt" value="../a.txt"/>
>><avaialble property="found-path"
>>  file="../../a.txt" value="../../a.txt"/>
>><avaialble property="found-path"
>>  file="../../../a.txt" value="../../../a.txt"/>
>>etc.
>>
>>
>>Although it works if there is single a.txt in searched parent 
>>directories, but when there several a.txt, then trouble 
>>starts. First a 
>>warning will be produced about changing of property value, 
>>and second, 
>>it will set found-path to the outemost a.txt. I can fix the later by 
>>reversing <available> order, but then I would depend on deprecated 
>>bahaviour.
>>
>>Any better ways to do it?
>>
>>Regards, Igor
>>
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>>For additional commands, e-mail: user-help@ant.apache.org
> 
> 
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message