ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Antoine Levy-Lambert" <>
Subject Re: FileUtils#normalize(File)
Date Mon, 28 Jul 2003 10:55:54 GMT
----- Original Message -----
From: "Wannheden, Knut" <>
Sent: Monday, July 28, 2003 12:33 PM

> I've noticed that the normalize(File) method in FileUtils requires that
> File to normalize is absolute.  I was wondering what the reason is for
> reason.  Would it be too complex to normalize a relative path on Windows
> systems?
I do not know.
> I think it makes perfectly sense to normalize a path like "./foo" into
> or "foo/bar/.." into "foo".  Even a path like "../foo" could be normalized
> using the system property "user.dir", but it could also cause an Exception
> to be thrown as the absolute path "/../foo" would (a Unix system would
> normalize that as "/foo").
> The reason I'm askin is because I wanted to reuse the code in normalize
> which handles ".." and "." path segments.  But maybe I should copy and
> instead.
The best and most sure option is to factor out the lines of codes that you
are interested in in a separate method, which would be called both by
Normalize and by your specific code for VMS.

I guess these are the lines you are interested in :

these lines could be a method
String resolvePath(String root, String path)

        Stack s = new Stack();
        StringTokenizer tok = new StringTokenizer(path, File.separator);
        while (tok.hasMoreTokens()) {
            String thisToken = tok.nextToken();
            if (".".equals(thisToken)) {
            } else if ("..".equals(thisToken)) {
                if (s.size() < 2) {
                    throw new BuildException("Cannot resolve path " + orig);
                } else {
            } else { // plain component

        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < s.size(); i++) {
            if (i > 1) {
                // not before the filesystem root and not after it, since
                // already contains one

        path = sb.toString();

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message