1 | private String createOutputFileName(File destFile, String optionalOutputFile, | | 1 | /** |
2 | String outputDir) { | | 2 | * Dissect the specified absolute path. |
3 | optionalOutputFile = validateOutputFile(optionalOutputFile, | | 3 | * @param path the path to dissect. |
4 | outputDir); | | 4 | * @return String[] {root, remaining path}. |
5 | String jjtreeFile = destFile.getAbsolutePath().replace('\\', '/'); | | 5 | * @throws java.lang.NullPointerException if path is null. |
6 | | | 6 | * @since Ant 1.7 |
7 | if ((optionalOutputFile == null) || optionalOutputFile.equals("")) { | | 7 | */ |
8 | int filePos = jjtreeFile.lastIndexOf("/"); | | 8 | public String[] dissect(String path) { |
9 | | | 9 | char sep = File.separatorChar; |
10 | if (filePos >= 0) { | | 10 | path = path.replace('/', sep).replace('\\', sep); |
11 | jjtreeFile = jjtreeFile.substring(filePos + 1); | | 11 | |
12 | } | | 12 | // make sure we are dealing with an absolute path |
13 | | | 13 | if (!isAbsolutePath(path)) { |
14 | int suffixPos = jjtreeFile.lastIndexOf('.'); | | 14 | throw new BuildException(path + " is not an absolute path"); |
15 | | | 15 | } |
16 | if (suffixPos == -1) { | | 16 | String root = null; |
17 | optionalOutputFile = jjtreeFile + DEFAULT_SUFFIX; | | 17 | int colon = path.indexOf(':'); |
18 | } else { | | 18 | if (colon > 0 && (onDos || onNetWare)) { |
19 | String currentSuffix = jjtreeFile.substring(suffixPos); | | 19 | |
20 | | | 20 | int next = colon + 1; |
21 | if (currentSuffix.equals(DEFAULT_SUFFIX)) { | | 21 | root = path.substring(0, next); |
22 | optionalOutputFile = jjtreeFile + DEFAULT_SUFFIX; | | 22 | char[] ca = path.toCharArray(); |
23 | } else { | | 23 | root += sep; |
24 | optionalOutputFile = jjtreeFile.substring(0, suffixPos) | | 24 | //remove the initial separator; the root has it. |
25 | + DEFAULT_SUFFIX; | | 25 | next = (ca[next] == sep) ? next + 1 : next; |
26 | } | | 26 | |
27 | } | | 27 | StringBuffer sbPath = new StringBuffer(); |
28 | } | | 28 | // Eliminate consecutive slashes after the drive spec: |
29 | | | 29 | for (int i = next; i < ca.length; i++) { |
30 | if ((outputDir == null) || outputDir.equals("")) { | | 30 | if (ca[i] != sep || ca[i - 1] != sep) { |
31 | outputDir = getDefaultOutputDirectory(); | | 31 | sbPath.append(ca[i]); |
32 | } | | 32 | } |
33 | | | 33 | } |
34 | return (outputDir + "/" + optionalOutputFile).replace('\\', '/'); | | 34 | path = sbPath.toString(); |
35 | } | | 35 | } else if (path.length() > 1 && path.charAt(1) == sep) { |
| | | 36 | // UNC drive |
| | | 37 | int nextsep = path.indexOf(sep, 2); |
| | | 38 | nextsep = path.indexOf(sep, nextsep + 1); |
| | | 39 | root = (nextsep > 2) ? path.substring(0, nextsep + 1) : path; |
| | | 40 | path = path.substring(root.length()); |
| | | 41 | } else { |
| | | 42 | root = File.separator; |
| | | 43 | path = path.substring(1); |
| | | 44 | } |
| | | 45 | return new String[] {root, path}; |
| | | 46 | } |