You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by mb...@apache.org on 2005/03/01 23:59:44 UTC

cvs commit: ant/src/testcases/org/apache/tools/ant/util FileUtilsTest.java

mbenson     2005/03/01 14:59:44

  Modified:    .        WHATSNEW
               src/main/org/apache/tools/ant/util FileUtils.java
               src/testcases/org/apache/tools/ant ProjectTest.java
               src/testcases/org/apache/tools/ant/taskdefs DirnameTest.java
               src/testcases/org/apache/tools/ant/types PathTest.java
               src/testcases/org/apache/tools/ant/util FileUtilsTest.java
  Log:
  On DOS and Netware, filenames beginning with a drive letter
  and followed by a colon but with no directory separator following
  the colon are no longer (incorrectly) accepted as absolute pathnames
  by FileUtils.normalize() and FileUtils.isAbsolutePath().  Netware
  volumes can still be specified without an intervening separator.
  UNC pathnames on Windows must include a server and share name, i.e.
  "\\a\b" to be considered valid absolute paths.
  FileUtils.resolveFile() promised to return absolute files but
  did not always do so.
  
  Revision  Changes    Path
  1.759     +12 -2     ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/ant/WHATSNEW,v
  retrieving revision 1.758
  retrieving revision 1.759
  diff -u -r1.758 -r1.759
  --- WHATSNEW	25 Feb 2005 22:23:06 -0000	1.758
  +++ WHATSNEW	1 Mar 2005 22:59:44 -0000	1.759
  @@ -18,8 +18,15 @@
   
   * The Reference class now has a project field that will get
     used (if set) in preference to the passed in project, when
  -  dereferencing the reference.
  -  Bugzilla Report 25777.
  +  dereferencing the reference. Bugzilla Report 25777.
  +
  +* On DOS and Netware, filenames beginning with a drive letter
  +  and followed by a colon but with no directory separator following
  +  the colon are no longer (incorrectly) accepted as absolute pathnames
  +  by FileUtils.normalize() and FileUtils.isAbsolutePath().  Netware
  +  volumes can still be specified without an intervening separator.
  +  UNC pathnames on Windows must include a server and share name, i.e.
  +  "\\a\b" to be considered valid absolute paths.
   
   Fixed bugs:
   -----------
  @@ -47,6 +54,9 @@
   * Create signjar's helper ExecTask instance directly rather than by
     typedef discovery mechanisms. Bugzilla report 33433.
   
  +* FileUtils.resolveFile() promised to return absolute files but
  +  did not always do so.
  +
   Other changes:
   --------------
   
  
  
  
  1.89      +131 -122  ant/src/main/org/apache/tools/ant/util/FileUtils.java
  
  Index: FileUtils.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/util/FileUtils.java,v
  retrieving revision 1.88
  retrieving revision 1.89
  diff -u -r1.88 -r1.89
  --- FileUtils.java	4 Feb 2005 16:18:10 -0000	1.88
  +++ FileUtils.java	1 Mar 2005 22:59:44 -0000	1.89
  @@ -664,71 +664,99 @@
       /**
        * Interpret the filename as a file relative to the given file
        * unless the filename already represents an absolute filename.
  +     * Differs from <code>new File(file, filename)</code> in that
  +     * the resulting File's path will always be a normalized,
  +     * absolute pathname.  Also, if it is determined that
  +     * <code>filename</code> is context-relative, <code>file</code>
  +     * will be discarded and the reference will be resolved using
  +     * available context/state information about the filesystem.
        *
        * @param file the "reference" file for relative paths. This
        * instance must be an absolute file and must not contain
        * &quot;./&quot; or &quot;../&quot; sequences (same for \ instead
        * of /).  If it is null, this call is equivalent to
  -     * <code>new java.io.File(filename)</code>.
  +     * <code>new java.io.File(filename).getAbsoluteFile()</code>.
        *
        * @param filename a file name.
        *
  -     * @return an absolute file that doesn't contain &quot;./&quot; or
  -     * &quot;../&quot; sequences and uses the correct separator for
  -     * the current platform.
  +     * @return an absolute file.
  +     * @throws java.lang.NullPointerException if filename is null.
        */
       public File resolveFile(File file, String filename) {
  -        filename = filename.replace('/', File.separatorChar)
  -            .replace('\\', File.separatorChar);
  -
  -        // deal with absolute files
  -        if (isAbsolutePath(filename)) {
  -            return normalize(filename);
  -        }
  -        if (file == null) {
  -            return new File(filename);
  -        }
  -        File helpFile = new File(file.getAbsolutePath());
  -        StringTokenizer tok = new StringTokenizer(filename, File.separator);
  -        while (tok.hasMoreTokens()) {
  -            String part = tok.nextToken();
  -            if (part.equals("..")) {
  -                helpFile = helpFile.getParentFile();
  -                if (helpFile == null) {
  -                    String msg = "The file or path you specified ("
  -                        + filename + ") is invalid relative to "
  -                        + file.getPath();
  -                    throw new BuildException(msg);
  +        if (!isAbsolutePath(filename)) {
  +            char sep = File.separatorChar;
  +            filename = filename.replace('/', sep).replace('\\', sep);
  +            if (isContextRelativePath(filename)) {
  +                file = null;
  +                // on cygwin, our current directory can be a UNC;
  +                // assume user.dir is absolute or all hell breaks loose...
  +                String udir = System.getProperty("user.dir");
  +                if (filename.charAt(0) == sep && udir.charAt(0) == sep) {
  +                    filename = dissect(udir)[0] + filename.substring(1);
                   }
  -            } else if (part.equals(".")) {
  -                // Do nothing here
  -            } else {
  -                helpFile = new File(helpFile, part);
               }
  +            filename = new File(file, filename).getAbsolutePath();
           }
  -        return new File(helpFile.getAbsolutePath());
  +        return normalize(filename);
  +    }
  +
  +    /**
  +     * On DOS and NetWare, the evaluation of certain file
  +     * specifications is context-dependent.  These are filenames
  +     * beginning with a single separator (relative to current root directory)
  +     * and filenames with a drive specification and no intervening separator
  +     * (relative to current directory of the specified root).
  +     * @param filename the filename to evaluate.
  +     * @return true if the filename is relative to system context.
  +     * @throws java.lang.NullPointerException if filename is null.
  +     * @since Ant 1.7
  +     */
  +    public static boolean isContextRelativePath(String filename) {
  +        if (!(onDos || onNetWare) || filename.length() == 0) {
  +            return false;
  +        }
  +        char sep = File.separatorChar;
  +        filename = filename.replace('/', sep).replace('\\', sep);
  +        char c = filename.charAt(0);
  +        int len = filename.length();
  +        return (c == sep && (len == 1 || filename.charAt(1) != sep))
  +            || (Character.isLetter(c) && len > 1
  +            && filename.indexOf(':') == 1
  +            && (len == 2 || filename.charAt(2) != sep));
       }
   
       /**
        * Verifies that the specified filename represents an absolute path.
  +     * Differs from new java.io.File("filename").isAbsolute() in that a path
  +     * beginning with a double file separator--signifying a Windows UNC--must
  +     * at minimum match "\\a\b" to be considered an absolute path.
        * @param filename the filename to be checked.
        * @return true if the filename represents an absolute path.
  +     * @throws java.lang.NullPointerException if filename is null.
  +     * @since Ant 1.6.3
        */
       public static boolean isAbsolutePath(String filename) {
  -        if (filename.startsWith(File.separator)) {
  -            // common for all os
  -            return true;
  +        int len = filename.length();
  +        if (len == 0) {
  +            return false;
           }
  -        if (onDos && filename.length() >= 2
  -            && Character.isLetter(filename.charAt(0))
  -            && filename.charAt(1) == ':') {
  -            // Actually on windows the : must be followed by a \ for
  -            // the path to be absolute, else the path is relative
  -            // to the current working directory on that drive.
  -            // (Every drive may have another current working directory)
  -            return true;
  +        char sep = File.separatorChar;
  +        filename = filename.replace('/', sep).replace('\\', sep);
  +        char c = filename.charAt(0);
  +        if (!(onDos || onNetWare)) {
  +            return (c == sep);
           }
  -        return (onNetWare && filename.indexOf(":") > -1);
  +        if (c == sep) {
  +            if (!(onDos && len > 4 && filename.charAt(1) == sep)) {
  +                return false;
  +            }
  +            int nextsep = filename.indexOf(sep, 2);
  +            return nextsep > 2 && nextsep + 1 < len;
  +        }
  +        int colon = filename.indexOf(':');
  +        return (Character.isLetter(c) && colon == 1
  +            && filename.length() > 2 && filename.charAt(2) == sep)
  +            || (onNetWare && colon > 0);
       }
   
       /**
  @@ -748,78 +776,23 @@
        * @param path the path to be normalized.
        * @return the normalized version of the path.
        *
  -     * @throws java.lang.NullPointerException if the file path is
  -     * equal to null.
  +     * @throws java.lang.NullPointerException if path is null.
        */
  -    public File normalize(String path) {
  -        String orig = path;
  -
  -        path = path.replace('/', File.separatorChar)
  -            .replace('\\', File.separatorChar);
  -
  -        // make sure we are dealing with an absolute path
  -        int colon = path.indexOf(":");
  -
  -        if (!isAbsolutePath(path)) {
  -            String msg = path + " is not an absolute path";
  -            throw new BuildException(msg);
  -        }
  -        boolean dosWithDrive = false;
  -        String root = null;
  -        // Eliminate consecutive slashes after the drive spec
  -        if ((onDos && path.length() >= 2
  -                && Character.isLetter(path.charAt(0))
  -                && path.charAt(1) == ':')
  -            || (onNetWare && colon > -1)) {
  -
  -            dosWithDrive = true;
  -
  -            char[] ca = path.replace('/', '\\').toCharArray();
  -            StringBuffer sbRoot = new StringBuffer();
  -            for (int i = 0; i < colon; i++) {
  -                sbRoot.append(Character.toUpperCase(ca[i]));
  -            }
  -            sbRoot.append(':');
  -            if (colon + 1 < path.length()) {
  -                sbRoot.append(File.separatorChar);
  -            }
  -            root = sbRoot.toString();
  -
  -            // Eliminate consecutive slashes after the drive spec
  -            StringBuffer sbPath = new StringBuffer();
  -            for (int i = colon + 1; i < ca.length; i++) {
  -                if ((ca[i] != '\\')
  -                    || (ca[i] == '\\' && ca[i - 1] != '\\')) {
  -                    sbPath.append(ca[i]);
  -                }
  -            }
  -            path = sbPath.toString().replace('\\', File.separatorChar);
  -        } else {
  -            if (path.length() == 1) {
  -                root = File.separator;
  -                path = "";
  -            } else if (path.charAt(1) == File.separatorChar) {
  -                // UNC drive
  -                root = File.separator + File.separator;
  -                path = path.substring(2);
  -            } else {
  -                root = File.separator;
  -                path = path.substring(1);
  -            }
  -        }
  +    public File normalize(final String path) {
           Stack s = new Stack();
  -        s.push(root);
  -        StringTokenizer tok = new StringTokenizer(path, File.separator);
  +        String[] dissect = dissect(path);
  +        s.push(dissect[0]);
  +
  +        StringTokenizer tok = new StringTokenizer(dissect[1], File.separator);
           while (tok.hasMoreTokens()) {
               String thisToken = tok.nextToken();
               if (".".equals(thisToken)) {
                   continue;
               } else if ("..".equals(thisToken)) {
                   if (s.size() < 2) {
  -                    throw new BuildException("Cannot resolve path " + orig);
  -                } else {
  -                    s.pop();
  +                    throw new BuildException("Cannot resolve path " + path);
                   }
  +                s.pop();
               } else { // plain component
                   s.push(thisToken);
               }
  @@ -833,11 +806,53 @@
               }
               sb.append(s.elementAt(i));
           }
  -        path = sb.toString();
  -        if (dosWithDrive) {
  -            path = path.replace('/', '\\');
  +        return new File(sb.toString());
  +    }
  +
  +    /**
  +     * Dissect the specified absolute path.
  +     * @param path the path to dissect.
  +     * @return String[] {root, remaining path}.
  +     * @throws java.lang.NullPointerException if path is null.
  +     */
  +    public String[] dissect(String path) {
  +        char sep = File.separatorChar;
  +        path = path.replace('/', sep).replace('\\', sep);
  +
  +        // make sure we are dealing with an absolute path
  +        if (!isAbsolutePath(path)) {
  +            throw new BuildException(path + " is not an absolute path");
           }
  -        return new File(path);
  +        String root = null;
  +        int colon = path.indexOf(':');
  +        if (colon > 0 && (onDos || onNetWare)) {
  +
  +            int next = colon + 1;
  +            root = path.substring(0, next).toUpperCase();
  +            char[] ca = path.toCharArray();
  +            root += sep;
  +            //remove the initial separator; the root has it.
  +            next = (ca[next] == sep) ? next + 1 : next;
  +
  +            StringBuffer sbPath = new StringBuffer();
  +            // Eliminate consecutive slashes after the drive spec:
  +            for (int i = next; i < ca.length; i++) {
  +                if (ca[i] != sep || ca[i - 1] != sep) {
  +                    sbPath.append(ca[i]);
  +                }
  +            }
  +            path = sbPath.toString();
  +        } else if (path.length() > 1 && path.charAt(1) == sep) {
  +            // UNC drive
  +            int nextsep = path.indexOf(sep, 2);
  +            nextsep = path.indexOf(sep, nextsep + 1);
  +            root = (nextsep > 2) ? path.substring(0, nextsep + 1) : path;
  +            path = path.substring(root.length());
  +        } else {
  +            root = File.separator;
  +            path = path.substring(1);
  +        }
  +        return new String[] {root, path};
       }
   
       /**
  @@ -1213,22 +1228,16 @@
        * @since Ant 1.6
        */
       public String toURI(String path) {
  -        boolean isDir = (new File(path)).isDirectory();
  +        boolean isDir = new File(path).isDirectory();
   
           StringBuffer sb = new StringBuffer("file:");
   
  -        // catch exception if normalize thinks this is not an absolute path
  -        try {
  -            path = normalize(path).getAbsolutePath();
  -            sb.append("//");
  -            // add an extra slash for filesystems with drive-specifiers
  -            if (!path.startsWith(File.separator)) {
  -                sb.append("/");
  -            }
  -        } catch (BuildException e) {
  -            // relative path
  +        path = resolveFile(null, path).getPath();
  +        sb.append("//");
  +        // add an extra slash for filesystems with drive-specifiers
  +        if (!path.startsWith(File.separator)) {
  +            sb.append("/");
           }
  -
           path = path.replace('\\', '/');
   
           CharacterIterator iter = new StringCharacterIterator(path);
  
  
  
  1.29      +35 -13    ant/src/testcases/org/apache/tools/ant/ProjectTest.java
  
  Index: ProjectTest.java
  ===================================================================
  RCS file: /home/cvs/ant/src/testcases/org/apache/tools/ant/ProjectTest.java,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- ProjectTest.java	4 Feb 2005 08:08:59 -0000	1.28
  +++ ProjectTest.java	1 Mar 2005 22:59:44 -0000	1.29
  @@ -48,7 +48,7 @@
       public void setUp() {
           p = new Project();
           p.init();
  -        root = new File(File.separator).getAbsolutePath();
  +        root = new File(File.separator).getAbsolutePath().toUpperCase();
           mbl = new MockBuildListener(p);
       }
   
  @@ -67,15 +67,11 @@
        * This test has been a starting point for moving the code to FileUtils.
        */
       public void testResolveFile() {
  -        /*
  -         * Start with simple absolute file names.
  -         */
  -        assertEquals(File.separator,
  -                     p.resolveFile("/", null).getPath());
  -        assertEquals(File.separator,
  -                     p.resolveFile("\\", null).getPath());
  -
           if (Os.isFamily("netware") || Os.isFamily("dos")) {
  +            assertEqualsIgnoreDriveCase(localize(File.separator),
  +                p.resolveFile("/", null).getPath());
  +            assertEqualsIgnoreDriveCase(localize(File.separator),
  +                p.resolveFile("\\", null).getPath());
               /*
                * throw in drive letters
                */
  @@ -98,18 +94,26 @@
                            p.resolveFile(driveSpec + "\\\\\\\\\\\\", null).getPath());
           } else {
               /*
  +             * Start with simple absolute file names.
  +             */
  +            assertEquals(File.separator,
  +                         p.resolveFile("/", null).getPath());
  +            assertEquals(File.separator,
  +                         p.resolveFile("\\", null).getPath());
  +            /*
                * drive letters are not used, just to be considered as normal
                * part of a name
                */
               String driveSpec = "C:";
  -            assertEquals(driveSpec,
  +            String udir = System.getProperty("user.dir") + File.separatorChar;
  +            assertEquals(udir + driveSpec,
                            p.resolveFile(driveSpec + "/", null).getPath());
  -            assertEquals(driveSpec,
  +            assertEquals(udir + driveSpec,
                            p.resolveFile(driveSpec + "\\", null).getPath());
               String driveSpecLower = "c:";
  -            assertEquals(driveSpecLower,
  +            assertEquals(udir + driveSpecLower,
                            p.resolveFile(driveSpecLower + "/", null).getPath());
  -            assertEquals(driveSpecLower,
  +            assertEquals(udir + driveSpecLower,
                            p.resolveFile(driveSpecLower + "\\", null).getPath());
           }
           /*
  @@ -142,6 +146,24 @@
           return path.replace('\\', File.separatorChar).replace('/', File.separatorChar);
       }
   
  +    /**
  +     * convenience method
  +     * the drive letter is in lower case under cygwin
  +     * calling this method allows tests where FileUtils.normalize
  +     * is called via resolveFile to pass under cygwin
  +     */
  +    private void assertEqualsIgnoreDriveCase(String s1, String s2) {
  +        if ((Os.isFamily("dos") || Os.isFamily("netware"))
  +            && s1.length() >= 1 && s2.length() >= 1) {
  +            StringBuffer sb1 = new StringBuffer(s1);
  +            StringBuffer sb2 = new StringBuffer(s2);
  +            sb1.setCharAt(0, Character.toUpperCase(s1.charAt(0)));
  +            sb2.setCharAt(0, Character.toUpperCase(s2.charAt(0)));
  +            assertEquals(sb1.toString(), sb2.toString());
  +        } else {
  +            assertEquals(s1, s2);
  +        }
  +    }
   
       private void assertTaskDefFails(final Class taskClass,
                                          final String message) {
  
  
  
  1.8       +4 -0      ant/src/testcases/org/apache/tools/ant/taskdefs/DirnameTest.java
  
  Index: DirnameTest.java
  ===================================================================
  RCS file: /home/cvs/ant/src/testcases/org/apache/tools/ant/taskdefs/DirnameTest.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- DirnameTest.java	9 Mar 2004 16:48:57 -0000	1.7
  +++ DirnameTest.java	1 Mar 2005 22:59:44 -0000	1.8
  @@ -19,6 +19,7 @@
   
   import java.io.File;
   import org.apache.tools.ant.BuildFileTest;
  +import org.apache.tools.ant.taskdefs.condition.Os;
   
   /**
    */
  @@ -45,6 +46,9 @@
       }
   
       public void test4() {
  +        if (Os.isFamily("netware") || Os.isFamily("dos")) {
  +            return;
  +        }
           executeTarget("test4");
           String filesep = System.getProperty("file.separator");
           String expected = filesep + "usr" + filesep + "local";
  
  
  
  1.26      +12 -8     ant/src/testcases/org/apache/tools/ant/types/PathTest.java
  
  Index: PathTest.java
  ===================================================================
  RCS file: /home/cvs/ant/src/testcases/org/apache/tools/ant/types/PathTest.java,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- PathTest.java	7 Dec 2004 09:10:38 -0000	1.25
  +++ PathTest.java	1 Mar 2005 22:59:44 -0000	1.26
  @@ -60,8 +60,9 @@
               assertEquals("\\a", l[0]);
               assertEquals("\\b", l[1]);
           } else {
  -            assertEquals(":\\a", l[0].substring(1));
  -            assertEquals(":\\b", l[1].substring(1));
  +            String base = new File(File.separator).getAbsolutePath().toUpperCase();
  +            assertEquals(base + "a", l[0]);
  +            assertEquals(base + "b", l[1]);
           }
       }
   
  @@ -99,8 +100,9 @@
               assertEquals("\\a", l[0]);
               assertEquals("\\b", l[1]);
           } else {
  -            assertEquals(":\\a", l[0].substring(1));
  -            assertEquals(":\\b", l[1].substring(1));
  +            String base = new File(File.separator).getAbsolutePath().toUpperCase();
  +            assertEquals(base + "a", l[0]);
  +            assertEquals(base + "b", l[1]);
           }
   
           p = new Path(project, "c:\\test");
  @@ -307,9 +309,10 @@
               assertEquals("\\b", l[1]);
               assertEquals("\\c", l[2]);
           } else {
  -            assertEquals(":\\a", l[0].substring(1));
  -            assertEquals(":\\b", l[1].substring(1));
  -            assertEquals(":\\c", l[2].substring(1));
  +            String base = new File(File.separator).getAbsolutePath().toUpperCase();
  +            assertEquals(base + "a", l[0]);
  +            assertEquals(base + "b", l[1]);
  +            assertEquals(base + "c", l[2]);
           }
       }
   
  @@ -366,7 +369,8 @@
           Path p = new Path(project, "/a:/a");
           String[] l = p.list();
           assertEquals("1 after construction", 1, l.length);
  -        p.setLocation(new File(File.separatorChar+"a"));
  +        String base = new File(File.separator).getAbsolutePath().toUpperCase();
  +        p.setLocation(new File(base, "a"));
           l = p.list();
           assertEquals("1 after setLocation", 1, l.length);
           p.setPath("\\a;/a");
  
  
  
  1.33      +69 -42    ant/src/testcases/org/apache/tools/ant/util/FileUtilsTest.java
  
  Index: FileUtilsTest.java
  ===================================================================
  RCS file: /home/cvs/ant/src/testcases/org/apache/tools/ant/util/FileUtilsTest.java,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- FileUtilsTest.java	7 Jan 2005 14:04:41 -0000	1.32
  +++ FileUtilsTest.java	1 Mar 2005 22:59:44 -0000	1.33
  @@ -101,15 +101,19 @@
       }
   
       public void testResolveFile() {
  -        /*
  -         * Start with simple absolute file names.
  -         */
  -        assertEquals(File.separator,
  -                     FILE_UTILS.resolveFile(null, "/").getPath());
  -        assertEquals(File.separator,
  -                     FILE_UTILS.resolveFile(null, "\\").getPath());
  -
  -        if (Os.isFamily("dos")) {
  +        if (!(Os.isFamily("dos") || Os.isFamily("netware"))) {
  +            /*
  +             * Start with simple absolute file names.
  +             */
  +            assertEquals(File.separator,
  +                         FILE_UTILS.resolveFile(null, "/").getPath());
  +            assertEquals(File.separator,
  +                         FILE_UTILS.resolveFile(null, "\\").getPath());
  +        } else {
  +            assertEqualsIgnoreDriveCase(localize(File.separator),
  +                FILE_UTILS.resolveFile(null, "/").getPath());
  +            assertEqualsIgnoreDriveCase(localize(File.separator),
  +                FILE_UTILS.resolveFile(null, "\\").getPath());
               /*
                * throw in drive letters
                */
  @@ -130,7 +134,8 @@
                            FILE_UTILS.resolveFile(null, driveSpec + "/////").getPath());
               assertEquals(driveSpec + "\\",
                            FILE_UTILS.resolveFile(null, driveSpec + "\\\\\\\\\\\\").getPath());
  -        } else if (Os.isFamily("netware")) {
  +        }
  +        if (Os.isFamily("netware")) {
               /*
                * throw in NetWare volume names
                */
  @@ -151,19 +156,20 @@
                            FILE_UTILS.resolveFile(null, driveSpec + "/////").getPath());
               assertEquals(driveSpec,
                            FILE_UTILS.resolveFile(null, driveSpec + "\\\\\\\\\\\\").getPath());
  -        } else {
  +        } else if (!(Os.isFamily("dos"))) {
               /*
                * drive letters must be considered just normal filenames.
                */
               String driveSpec = "C:";
  -            assertEquals(driveSpec,
  +            String udir = System.getProperty("user.dir");
  +            assertEquals(udir + File.separator + driveSpec,
                            FILE_UTILS.resolveFile(null, driveSpec + "/").getPath());
  -            assertEquals(driveSpec,
  +            assertEquals(udir + File.separator + driveSpec,
                            FILE_UTILS.resolveFile(null, driveSpec + "\\").getPath());
               String driveSpecLower = "c:";
  -            assertEquals(driveSpecLower,
  +            assertEquals(udir + File.separator + driveSpecLower,
                            FILE_UTILS.resolveFile(null, driveSpecLower + "/").getPath());
  -            assertEquals(driveSpecLower,
  +            assertEquals(udir + File.separator + driveSpecLower,
                            FILE_UTILS.resolveFile(null, driveSpecLower + "\\").getPath());
           }
   
  @@ -197,21 +203,37 @@
       }
   
       public void testNormalize() {
  -        /*
  -         * Start with simple absolute file names.
  -         */
  -        assertEquals(File.separator,
  -                     FILE_UTILS.normalize("/").getPath());
  -        assertEquals(File.separator,
  -                     FILE_UTILS.normalize("\\").getPath());
  +        if (!(Os.isFamily("dos") || Os.isFamily("netware"))) {
  +            /*
  +             * Start with simple absolute file names.
  +             */
  +            assertEquals(File.separator,
  +                         FILE_UTILS.normalize("/").getPath());
  +            assertEquals(File.separator,
  +                         FILE_UTILS.normalize("\\").getPath());
  +        } else {
  +            try {
  +                 FILE_UTILS.normalize("/").getPath();
  +                 fail("normalized \"/\" on dos or netware");
  +            } catch (Exception e) {
  +            }
  +            try {
  +                 FILE_UTILS.normalize("\\").getPath();
  +                 fail("normalized \"\\\" on dos or netware");
  +            } catch (Exception e) {
  +            }
  +        }
   
           if (Os.isFamily("dos")) {
               /*
                * throw in drive letters
                */
               String driveSpec = "C:";
  -            assertEquals(driveSpec,
  -                         FILE_UTILS.normalize(driveSpec).getPath());
  +            try {
  +                 FILE_UTILS.normalize(driveSpec).getPath();
  +                 fail(driveSpec + " is not an absolute path");
  +            } catch (Exception e) {
  +            }
               assertEquals(driveSpec + "\\",
                            FILE_UTILS.normalize(driveSpec + "/").getPath());
               assertEquals(driveSpec + "\\",
  @@ -313,7 +335,7 @@
           }
   
           File f = FILE_UTILS.resolveFile(null, "a");
  -        assertEquals(f, new File("a"));
  +        assertEquals(f, new File("a").getAbsoluteFile());
       }
   
       /**
  @@ -390,10 +412,12 @@
                                                    new File("c:\\foo\\bar")));
           assertEquals("bar", FILE_UTILS.removeLeadingPath(new File("c:\\foo\\"),
                                                    new File("c:\\foo\\bar")));
  -        assertEqualsIgnoreDriveCase(FILE_UTILS.normalize("/bar").getAbsolutePath(),
  -                     FILE_UTILS.removeLeadingPath(new File("/foo"), new File("/bar")));
  -        assertEqualsIgnoreDriveCase(FILE_UTILS.normalize("/foobar").getAbsolutePath(),
  -                     FILE_UTILS.removeLeadingPath(new File("/foo"), new File("/foobar")));
  +        if (!(Os.isFamily("dos") || Os.isFamily("netware"))) {
  +            assertEquals(FILE_UTILS.normalize("/bar").getAbsolutePath(),
  +                         FILE_UTILS.removeLeadingPath(new File("/foo"), new File("/bar")));
  +            assertEquals(FILE_UTILS.normalize("/foobar").getAbsolutePath(),
  +                         FILE_UTILS.removeLeadingPath(new File("/foo"), new File("/foobar")));
  +        }
           // bugzilla report 19979
           assertEquals("", FILE_UTILS.removeLeadingPath(new File("/foo/bar"),
                                                 new File("/foo/bar")));
  @@ -419,8 +443,9 @@
        */
       public void testToURI() {
           String dosRoot = null;
  -        if (Os.isFamily("dos")) {
  -            dosRoot = System.getProperty("user.dir").charAt(0) + ":/";
  +        if (Os.isFamily("dos") || Os.isFamily("netware")) {
  +            dosRoot = Character.toUpperCase(
  +                System.getProperty("user.dir").charAt(0)) + ":/";
           }
           else
           {
  @@ -457,11 +482,11 @@
           if (Os.isFamily("dos")) {
               assertEqualsIgnoreDriveCase("C:\\foo", FILE_UTILS.fromURI("file:///c:/foo"));
           }
  -        assertEqualsIgnoreDriveCase(localize("/foo"), FILE_UTILS.fromURI("file:///foo"));
  +        assertEqualsIgnoreDriveCase(File.separator + "foo", FILE_UTILS.fromURI("file:///foo"));
           assertEquals("." + File.separator + "foo",
                        FILE_UTILS.fromURI("file:./foo"));
  -        assertEqualsIgnoreDriveCase(localize("/foo bar"), FILE_UTILS.fromURI("file:///foo%20bar"));
  -        assertEqualsIgnoreDriveCase(localize("/foo#bar"), FILE_UTILS.fromURI("file:///foo%23bar"));
  +        assertEquals(File.separator + "foo bar", FILE_UTILS.fromURI("file:///foo%20bar"));
  +        assertEquals(File.separator + "foo#bar", FILE_UTILS.fromURI("file:///foo%23bar"));
       }
   
       public void testModificationTests() {
  @@ -493,6 +518,7 @@
           path = root + path.substring(1);
           return path.replace('\\', File.separatorChar).replace('/', File.separatorChar);
       }
  +
       /**
        * convenience method
        * normalize brings the drive in uppercase
  @@ -500,14 +526,15 @@
        * calling this method allows tests where normalize is called to pass under cygwin
        */
       private void assertEqualsIgnoreDriveCase(String s1, String s2) {
  -        if (Os.isFamily("dos") && s1.length()>=1 && s2.length()>=1) {
  -            StringBuffer sb1= new StringBuffer(s1);
  -            StringBuffer sb2= new StringBuffer(s2);
  -            sb1.setCharAt(0,Character.toUpperCase(s1.charAt(0)));
  -            sb2.setCharAt(0,Character.toUpperCase(s2.charAt(0)));
  -            assertEquals(sb1.toString(),sb2.toString());
  -        }   else {
  -            assertEquals(s1,s2);
  +        if ((Os.isFamily("dos") || Os.isFamily("netware"))
  +            && s1.length() > 0 && s2.length() > 0) {
  +            StringBuffer sb1 = new StringBuffer(s1);
  +            StringBuffer sb2 = new StringBuffer(s2);
  +            sb1.setCharAt(0, Character.toUpperCase(s1.charAt(0)));
  +            sb2.setCharAt(0, Character.toUpperCase(s2.charAt(0)));
  +            assertEquals(sb1.toString(), sb2.toString());
  +        } else {
  +            assertEquals(s1, s2);
           }
       }
   }
  
  
  

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