Merge branch 'master' into master Project: http://git-wip-us.apache.org/repos/asf/ant-ivy/repo Commit: http://git-wip-us.apache.org/repos/asf/ant-ivy/commit/3cfc7bfe Tree: http://git-wip-us.apache.org/repos/asf/ant-ivy/tree/3cfc7bfe Diff: http://git-wip-us.apache.org/repos/asf/ant-ivy/diff/3cfc7bfe
Branch: refs/heads/master Commit: 3cfc7bfe70c038055939533b56c408419b01de81 Parents: baf03a9 90274e1 Author: twogee <[email protected]> Authored: Sun May 28 14:14:25 2017 +0200 Committer: GitHub <[email protected]> Committed: Sun May 28 14:14:25 2017 +0200 ---------------------------------------------------------------------- doc/release-notes.html | 2 + src/java/org/apache/ivy/util/FileUtil.java | 108 ++++++++++++-------- test/java/org/apache/ivy/ant/FileUtilTest.java | 92 +++++++++++++++++ 3 files changed, 157 insertions(+), 45 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/3cfc7bfe/src/java/org/apache/ivy/util/FileUtil.java ---------------------------------------------------------------------- diff --cc src/java/org/apache/ivy/util/FileUtil.java index c938007,52e03db..17fbaf4 --- a/src/java/org/apache/ivy/util/FileUtil.java +++ b/src/java/org/apache/ivy/util/FileUtil.java @@@ -535,16 -535,19 +535,16 @@@ public final class FileUtil * Unlike {@link File#getCanonicalPath()} this method specifically does not resolve symbolic * links. * - * @param path - * the path to be normalized. + * @param path the path to be normalized. * @return the normalized version of the path. - * - * @throws java.lang.NullPointerException - * if path is null. + * @throws NullPointerException if path is null. */ public static File normalize(final String path) { - Stack<String> s = new Stack<String>(); - String[] dissect = dissect(path); - s.push(dissect[0]); + final Stack<String> s = new Stack<String>(); + final DissectedPath dissectedPath = dissect(path); + s.push(dissectedPath.root); - StringTokenizer tok = new StringTokenizer(dissect[1], File.separator); + final StringTokenizer tok = new StringTokenizer(dissectedPath.remainingPath, File.separator); while (tok.hasMoreTokens()) { String thisToken = tok.nextToken(); if (".".equals(thisToken)) { @@@ -574,51 -577,53 +574,53 @@@ /** * Dissect the specified absolute path. -- * - * @param path the path to dissect. - * @return String[] {root, remaining path}. - * @throws NullPointerException if path is null. ++ * + * @param path + * the path to dissect. + * @return {@link DissectedPath} + * @throws java.lang.NullPointerException + * if path is null. * @since Ant 1.7 */ - private static 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"); - * } - */ - String root = null; - int colon = path.indexOf(':'); - if (colon > 0) { // && (ON_DOS || ON_NETWARE)) { - - int next = colon + 1; - root = path.substring(0, next); - 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]); + private static DissectedPath dissect(final String path) { + final char sep = File.separatorChar; + final String pathToDissect = path.replace('/', sep).replace('\\', sep).trim(); + + // check if the path starts with a filesystem root + final File[] filesystemRoots = File.listRoots(); + if (filesystemRoots != null) { + for (final File filesystemRoot : filesystemRoots) { + if (pathToDissect.startsWith(filesystemRoot.getPath())) { + // filesystem root is the root and the rest of the path is the "remaining path" + final String root = filesystemRoot.getPath(); + final String rest = pathToDissect.substring(root.length()); + final StringBuffer sbPath = new StringBuffer(); + // Eliminate consecutive slashes after the drive spec: + for (int i = 0; i < rest.length(); i++) { + final char currentChar = rest.charAt(i); + if (i == 0) { + sbPath.append(currentChar); + continue; + } + final char previousChar = rest.charAt(i -1); + if (currentChar != sep || previousChar != sep) { + sbPath.append(currentChar); + } + } + return new DissectedPath(root, sbPath.toString()); } } - 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}; + // UNC drive + if (pathToDissect.length() > 1 && pathToDissect.charAt(1) == sep) { + int nextsep = pathToDissect.indexOf(sep, 2); + nextsep = pathToDissect.indexOf(sep, nextsep + 1); + final String root = (nextsep > 2) ? pathToDissect.substring(0, nextsep + 1) : pathToDissect; + final String rest = pathToDissect.substring(root.length()); + return new DissectedPath(root, rest); + } + + return new DissectedPath(File.separator, pathToDissect.substring(1)); } /**
