You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Edson Alves Pereira <Ca...@netscape.net> on 2001/09/04 17:06:53 UTC

Ant and FileSystem

I´ve just using Ant1.3 to deploy in my root directory under WindowsNT like:
d:\usr\local\htdocs-ssl with this project tag.

<project name="Pannet" default="dist" basedir="/usr/local/htdocs-ssl>
 ...
</project>

  But with run the build.xml Ant create this tree in the directory where i´m it´s a error? If a change the tag to:

<project name="Pannet" default="dist" basedir="d:/usr/local/htdocs-ssl>
 ...
</project>

  Everything looks fine.

  With best wishes,
  Edson Alves Pereira

-- 
////////////////////////////////////////
Well done is better than well said 
////////////////////////////////////////



__________________________________________________________________
Your favorite stores, helpful shopping tools and great gift ideas. Experience the convenience of buying online with Shop@Netscape! http://shopnow.netscape.com/

Get your own FREE, personal Netscape Mail account today at http://webmail.netscape.com/


Re: Ant and FileSystem

Posted by Stefan Bodewig <bo...@apache.org>.
On Tue, 11 Sep 2001, Alejandro Abdelnur <al...@sun.com>
wrote:

> based on your description on how things work, shouldn't the
> Ant.setAntfile(String) method be changed to Ant.setAntfile(File) ?

No, because this would resolve antfile relative to the current
project's basedir instead of relative to the value of the dir
attribute (which it must do for backwards compatibility, if not for a
better reason).

I've applied a patch that should make <ant> treat DOS "absolute" paths
that don't start with a drive letter for the antfile attribute the
same way other paths are handeled in Ant.

Stefan

Re: Ant and FileSystem

Posted by Alejandro Abdelnur <al...@sun.com>.
stefan,

what you say makes sense, now based on your description on how things
work, shouldn't the Ant.setAntfile(String) method be changed to
Ant.setAntfile(File) ?

thxs.

a


Stefan Bodewig wrote:

> On Tue, 04 Sep 2001, Alejandro Abdelnur <al...@sun.com>
> wrote:
>
> > i've run into a similar problem in the ant's antfile, the problem
> > appears to be a bug in the java.io.File.isAbsolute() method in the
> > windows platform.
>
> Judging from your patch I assume that you think File.isAbsolute()
> should return true for \temp on Windows, right?
>
> From the javadocs of File:
>
> >> An absolute pathname is complete in that no other information is
> >> required in order to locate the file that it denotes.
>
> with this definition, I think you are wrong.
>
> A completely different issue is whether FileUtils.normalize() should
> treat \temp the same way it treats an absolute path (it does) - I'm
> not sure as I cannot really see all consequences here.
>
> In which situation would a Windows user (I'm not part of that
> community, so I don't really know) use \temp instead of C:\temp?
>
> > i think the place to add this workaround is the
> > FileUtils.normalize() method,
>
> I think it already treats paths starting with File.separator as
> absolute paths.  Looks as if <ant> should use
> FileUtils.resolveFile(dir, antfile) in its execute method.
>
> > then the ant.setAntfile() method should be retrofitted to use the
> > normalized (similarly any other attribute that expects a file name).
>
> Most tasks have setters that expect a File argument when they expect
> filenames - these setters will receive File instances that went
> through FileUtils.normalize (via FileUtils.resolveFile) automatically.
>
> Stefan


Re: Ant and FileSystem

Posted by Stefan Bodewig <bo...@apache.org>.
On Tue, 04 Sep 2001, Alejandro Abdelnur <al...@sun.com>
wrote:

> i've run into a similar problem in the ant's antfile, the problem
> appears to be a bug in the java.io.File.isAbsolute() method in the
> windows platform.

Judging from your patch I assume that you think File.isAbsolute()
should return true for \temp on Windows, right?

>From the javadocs of File:

>> An absolute pathname is complete in that no other information is
>> required in order to locate the file that it denotes.

with this definition, I think you are wrong.

A completely different issue is whether FileUtils.normalize() should
treat \temp the same way it treats an absolute path (it does) - I'm
not sure as I cannot really see all consequences here.

In which situation would a Windows user (I'm not part of that
community, so I don't really know) use \temp instead of C:\temp?

> i think the place to add this workaround is the
> FileUtils.normalize() method,

I think it already treats paths starting with File.separator as
absolute paths.  Looks as if <ant> should use
FileUtils.resolveFile(dir, antfile) in its execute method.

> then the ant.setAntfile() method should be retrofitted to use the
> normalized (similarly any other attribute that expects a file name).

Most tasks have setters that expect a File argument when they expect
filenames - these setters will receive File instances that went
through FileUtils.normalize (via FileUtils.resolveFile) automatically.

Stefan

Re: Ant and FileSystem

Posted by Alejandro Abdelnur <al...@sun.com>.
i've run into a similar problem in the ant's antfile, the problem appears to be a bug in the java.io.File.isAbsolute() method in the windows platform.

in my case i've modified the Ant task to use the following piece of code.

i've just looked how Project.setBasedir works and it uses the FileUtils.normalize() method.

i think the place to add this workaround is the FileUtils.normalize() method, then the ant.setAntfile() method should be retrofitted to use the normalized
(similarly any other attribute that expects a file name).

hope this helps.

a

-------------------------------------------------------------
   private File getAntFile(String fileName) {
        File file = new File(fileName);
        if (file.exists() && file.isFile()) {
            if (!file.isAbsolute()) {
                // i have to do this because a bug in the JDK (1.2) java.io.File.isAbsolute() method in Windows platforms.
                boolean doIt = true;
                boolean winOS = (System.getProperty("os.name").indexOf("indows")>0);
                if (winOS) {
                    doIt = !(antFile.startsWith("\\") || antFile.startsWith("/"));
                }
                if (doIt) {
                    antFile = (new File(dir, antFile)).getAbsolutePath();
                    file = (new File(antFile)) ;
                }
            }
        }
        else {
            file = null;
        }
        return file;
    }
-------------------------------------------------------------

Edson Alves Pereira wrote:

> I´ve just using Ant1.3 to deploy in my root directory under WindowsNT like:
> d:\usr\local\htdocs-ssl with this project tag.
>
> <project name="Pannet" default="dist" basedir="/usr/local/htdocs-ssl>
>  ...
> </project>
>
>   But with run the build.xml Ant create this tree in the directory where i´m it´s a error? If a change the tag to:
>
> <project name="Pannet" default="dist" basedir="d:/usr/local/htdocs-ssl>
>  ...
> </project>
>
>   Everything looks fine.
>
>   With best wishes,
>   Edson Alves Pereira
>
> --
> ////////////////////////////////////////
> Well done is better than well said
> ////////////////////////////////////////
>
> __________________________________________________________________
> Your favorite stores, helpful shopping tools and great gift ideas. Experience the convenience of buying online with Shop@Netscape! http://shopnow.netscape.com/
>
> Get your own FREE, personal Netscape Mail account today at http://webmail.netscape.com/


Re: Ant and FileSystem

Posted by Nico Seessle <ni...@apache.org>.
----- Original Message -----
From: "Edson Alves Pereira" <Ca...@netscape.net>
To: <an...@jakarta.apache.org>
Sent: Tuesday, September 04, 2001 5:06 PM
Subject: Ant and FileSystem


> I´ve just using Ant1.3 to deploy in my root directory under WindowsNT
like:
> d:\usr\local\htdocs-ssl with this project tag.
>
> <project name="Pannet" default="dist" basedir="/usr/local/htdocs-ssl>
>  ...
> </project>

As it's *impossible* to deploy anything anywhere with just these tags I
don't think we can really help you.

Can you please provide more details about your environment and the buildfile
itself?

(I just made some experiments with the basedir-attribute and for me it seems
to work better with 1.4 than with 1.3, i.e. using "C:\temp\test1" works with
both versions, "\temp\test1" works only with 1.4 for the following target:

  <target name="exec">
    <exec executable="cmd">
      <arg line="/c dir"/>
    </exec>
  </target>)

Nico