You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by cm...@yahoo.com on 2001/07/18 06:19:34 UTC

small PATCH: ant -find with build.xml in CWD

If "ant -find build.xml" is used and build.xml is in the current
dir, the returned file will be "/foo/bar/./build.xml", and that
might brake a number of <property location="..." /> and other
relative paths.


Index: src/main/org/apache/tools/ant/Main.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/Main.java,v
retrieving revision 1.37
diff -u -r1.37 Main.java
--- src/main/org/apache/tools/ant/Main.java     2001/07/17 12:12:39
1.37
+++ src/main/org/apache/tools/ant/Main.java     2001/07/17 21:26:48
@@ -360,6 +360,12 @@

         File parent = new File(new File(start).getAbsolutePath());
         File file = new File(parent, suffix);
+
+       if( file.exists() ) {
+           // it would be "/path/./build.xml, many things will brake
+           file=new File(suffix); // in cwd
+           return file;
+       }

         // check if the target file exists in the current directory
         while (!file.exists()) {






Re: small PATCH: ant -find with build.xml in CWD

Posted by Stefan Bodewig <bo...@apache.org>.
On Wed, 18 Jul 2001, Jesse Glick <Je...@netbeans.com> wrote:

> I could be wrong but I think cmanolache (Costin?) is on target that
> the bug is in Main rather than Project.

Yes and no.  resolveProperty assumes that rootDir is a "non-messy"
File, I'm not sure whether this is a save assumption (as it gets
called from several other places, not just Main).

Maybe we should simply fix both places?

Stefan

Re: small PATCH: ant -find with build.xml in CWD

Posted by Jesse Glick <Je...@netbeans.com>.
I could be wrong but I think cmanolache (Costin?) is on target that the bug is
in Main rather than Project. If nobody passes a messy File into Project, it
should not create them (hopefully). In this case Main.findBuildFile is simply
creating a non-normal File object (since it is called with "." as the initial
argument). If you fix the original algorithm that produces the bad file paths,
there should be no need to try to normalize anything later on. E.g. try giving
start as System.getProperty("user.dir") rather than ".", or something like
that.

Stefan Bodewig wrote:
> 
> On Tue, 17 Jul 2001, <cm...@yahoo.com> wrote:
> 
> > If "ant -find build.xml" is used and build.xml is in the current
> > dir, the returned file will be "/foo/bar/./build.xml", and that
> > might brake a number of <property location="..." /> and other
> > relative paths.
> 
> What you see is a symptom of removing the getCanonicalPath invocations
> everywhere - getCanonicalPath would strip out the /. while
> getAbsolutePath doesn't.  I think we need a different fix (in
> Project.resolveFile) to account for that completely.

-- 
Jesse Glick   <ma...@netbeans.com>
NetBeans, Open APIs  <http://www.netbeans.org/>
tel (+4202) 3300-9161 Sun Micro x49161 Praha CR

Re: small PATCH: ant -find with build.xml in CWD

Posted by Peter Donald <do...@apache.org>.
On Wed, 18 Jul 2001 17:21, cmanolache@yahoo.com wrote:
> On 18 Jul 2001, Stefan Bodewig wrote:
> > On Tue, 17 Jul 2001, <cm...@yahoo.com> wrote:
> > > If "ant -find build.xml" is used and build.xml is in the current
> > > dir, the returned file will be "/foo/bar/./build.xml", and that
> > > might brake a number of <property location="..." /> and other
> > > relative paths.
> >
> > What you see is a symptom of removing the getCanonicalPath invocations
> > everywhere - getCanonicalPath would strip out the /. while
> > getAbsolutePath doesn't.  I think we need a different fix (in
> > Project.resolveFile) to account for that completely.
>
> What was the reason for removing getCanonicalPath() ( or a pointer to
> the thread or period when this was discussed ) ? We're using
> getCanonicalPath() in tomcat - is there anything we should know about it ?
> ( besides bad performance in certain cases )

Essentially there was two errors it caused. It was inducing a lot of 
unexpected behaviour regarding unix softlinks. It also was breaking a 
particular OS (IBMs OS490 ?? or something???).


Cheers,

Pete

*-----------------------------------------------------*
| "Faced with the choice between changing one's mind, |
| and proving that there is no need to do so - almost |
| everyone gets busy on the proof."                   |
|              - John Kenneth Galbraith               |
*-----------------------------------------------------*

Re: small PATCH: ant -find with build.xml in CWD

Posted by Stefan Bodewig <bo...@apache.org>.
On Wed, 18 Jul 2001, <cm...@yahoo.com> wrote:

> What was the reason for removing getCanonicalPath()

It leads to some strange anonmalies when dealing with symbolic links.
<http://marc.theaimsgroup.com/?l=ant-dev&m=99358037323340&w=2>

> Or more information about what a good fix will be - I can try to
> adapt some "normalize URL" code from tc.

"normalizing" rootDir.getAbsolutePath() in
Project.resolveFile(String,File) should suffice.  If you want to look
into this, go ahead.

Stefan

Re: small PATCH: ant -find with build.xml in CWD

Posted by cm...@yahoo.com.
On 18 Jul 2001, Stefan Bodewig wrote:

> On Tue, 17 Jul 2001, <cm...@yahoo.com> wrote:
>
> > If "ant -find build.xml" is used and build.xml is in the current
> > dir, the returned file will be "/foo/bar/./build.xml", and that
> > might brake a number of <property location="..." /> and other
> > relative paths.
>
> What you see is a symptom of removing the getCanonicalPath invocations
> everywhere - getCanonicalPath would strip out the /. while
> getAbsolutePath doesn't.  I think we need a different fix (in
> Project.resolveFile) to account for that completely.

What was the reason for removing getCanonicalPath() ( or a pointer to
the thread or period when this was discussed ) ? We're using
getCanonicalPath() in tomcat - is there anything we should know about it ?
( besides bad performance in certain cases )

Also - could I have this fix in ( with a comment about removing it when
the "real" thing is done ) ? Or more information about what a good fix
will be - I can try to adapt some "normalize URL" code from tc.

Costin


Re: small PATCH: ant -find with build.xml in CWD

Posted by Stefan Bodewig <bo...@apache.org>.
On Tue, 17 Jul 2001, <cm...@yahoo.com> wrote:

> If "ant -find build.xml" is used and build.xml is in the current
> dir, the returned file will be "/foo/bar/./build.xml", and that
> might brake a number of <property location="..." /> and other
> relative paths.

What you see is a symptom of removing the getCanonicalPath invocations
everywhere - getCanonicalPath would strip out the /. while
getAbsolutePath doesn't.  I think we need a different fix (in
Project.resolveFile) to account for that completely.

Stefan