author | mchung |
Fri, 20 Jun 2014 13:36:10 -0700 | |
changeset 25303 | 5f9e68207588 |
parent 24897 | 655b72d7b96e |
permissions | -rw-r--r-- |
10 | 1 |
/* |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
2 |
* Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved. |
10 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
10 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5520 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
10 | 24 |
*/ |
731
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
171
diff
changeset
|
25 |
package com.sun.tools.javac.file; |
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
171
diff
changeset
|
26 |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
27 |
import java.io.File; |
10818 | 28 |
import java.io.FileNotFoundException; |
10 | 29 |
import java.io.IOException; |
4937
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
30 |
import java.net.MalformedURLException; |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
31 |
import java.net.URL; |
10818 | 32 |
import java.util.Arrays; |
33 |
import java.util.Collection; |
|
34 |
import java.util.Collections; |
|
35 |
import java.util.EnumMap; |
|
36 |
import java.util.EnumSet; |
|
10 | 37 |
import java.util.HashMap; |
38 |
import java.util.HashSet; |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
39 |
import java.util.Iterator; |
10818 | 40 |
import java.util.LinkedHashSet; |
10 | 41 |
import java.util.Map; |
42 |
import java.util.Set; |
|
4937
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
43 |
import java.util.StringTokenizer; |
10 | 44 |
import java.util.zip.ZipFile; |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
45 |
|
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
46 |
import javax.tools.JavaFileManager; |
10 | 47 |
import javax.tools.JavaFileManager.Location; |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
48 |
import javax.tools.StandardJavaFileManager; |
10818 | 49 |
import javax.tools.StandardLocation; |
10 | 50 |
|
731
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
171
diff
changeset
|
51 |
import com.sun.tools.javac.code.Lint; |
11314 | 52 |
import com.sun.tools.javac.main.Option; |
1486 | 53 |
import com.sun.tools.javac.util.ListBuffer; |
731
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
171
diff
changeset
|
54 |
import com.sun.tools.javac.util.Log; |
22153
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
14360
diff
changeset
|
55 |
import com.sun.tools.javac.util.StringUtils; |
731
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
171
diff
changeset
|
56 |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
57 |
import static javax.tools.StandardLocation.CLASS_PATH; |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
58 |
import static javax.tools.StandardLocation.PLATFORM_CLASS_PATH; |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
59 |
import static javax.tools.StandardLocation.SOURCE_PATH; |
10 | 60 |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
61 |
import static com.sun.tools.javac.main.Option.BOOTCLASSPATH; |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
62 |
import static com.sun.tools.javac.main.Option.DJAVA_ENDORSED_DIRS; |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
63 |
import static com.sun.tools.javac.main.Option.DJAVA_EXT_DIRS; |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
64 |
import static com.sun.tools.javac.main.Option.ENDORSEDDIRS; |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
65 |
import static com.sun.tools.javac.main.Option.EXTDIRS; |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
66 |
import static com.sun.tools.javac.main.Option.XBOOTCLASSPATH; |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
67 |
import static com.sun.tools.javac.main.Option.XBOOTCLASSPATH_APPEND; |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
68 |
import static com.sun.tools.javac.main.Option.XBOOTCLASSPATH_PREPEND; |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
69 |
|
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
70 |
/** |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
71 |
* This class converts command line arguments, environment variables and system properties (in |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
72 |
* File.pathSeparator-separated String form) into a boot class path, user class path, and source |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
73 |
* path (in {@code Collection<String>} form). |
10 | 74 |
* |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
75 |
* <p> |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
76 |
* <b>This is NOT part of any supported API. If you write code that depends on this, you do so at |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
77 |
* your own risk. This code and its internal interfaces are subject to change or deletion without |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
78 |
* notice.</b> |
10 | 79 |
*/ |
10818 | 80 |
public class Locations { |
10 | 81 |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
82 |
/** |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
83 |
* The log to use for warning output |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
84 |
*/ |
10 | 85 |
private Log log; |
86 |
||
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
87 |
/** |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
88 |
* Access to (possibly cached) file info |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
89 |
*/ |
1208 | 90 |
private FSInfo fsInfo; |
10 | 91 |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
92 |
/** |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
93 |
* Whether to warn about non-existent path elements |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
94 |
*/ |
10818 | 95 |
private boolean warn; |
96 |
||
97 |
public Locations() { |
|
98 |
initHandlers(); |
|
10 | 99 |
} |
100 |
||
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
101 |
// could replace Lint by "boolean warn" |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
102 |
public void update(Log log, Lint lint, FSInfo fsInfo) { |
10813
95b39a692cd0
7101146: Paths should more directly managed by BaseFileManager
jjg
parents:
8424
diff
changeset
|
103 |
this.log = log; |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
104 |
warn = lint.isEnabled(Lint.LintCategory.PATH); |
10813
95b39a692cd0
7101146: Paths should more directly managed by BaseFileManager
jjg
parents:
8424
diff
changeset
|
105 |
this.fsInfo = fsInfo; |
10 | 106 |
} |
107 |
||
10818 | 108 |
public Collection<File> bootClassPath() { |
109 |
return getLocation(PLATFORM_CLASS_PATH); |
|
10 | 110 |
} |
111 |
||
7336
3fd30668e9b5
7003477: Paths.isDefaultBootClassPath needs to be public
jjg
parents:
7335
diff
changeset
|
112 |
public boolean isDefaultBootClassPath() { |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
113 |
BootClassPathLocationHandler h |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
114 |
= (BootClassPathLocationHandler) getHandler(PLATFORM_CLASS_PATH); |
10818 | 115 |
return h.isDefault(); |
10 | 116 |
} |
117 |
||
8034
d3b29ef9c062
6430241: Hard to disable symbol file feature through API
jjg
parents:
7847
diff
changeset
|
118 |
boolean isDefaultBootClassPathRtJar(File file) { |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
119 |
BootClassPathLocationHandler h |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
120 |
= (BootClassPathLocationHandler) getHandler(PLATFORM_CLASS_PATH); |
10818 | 121 |
return h.isDefaultRtJar(file); |
122 |
} |
|
123 |
||
124 |
public Collection<File> userClassPath() { |
|
125 |
return getLocation(CLASS_PATH); |
|
126 |
} |
|
127 |
||
128 |
public Collection<File> sourcePath() { |
|
129 |
Collection<File> p = getLocation(SOURCE_PATH); |
|
130 |
// TODO: this should be handled by the LocationHandler |
|
131 |
return p == null || p.isEmpty() ? null : p; |
|
10 | 132 |
} |
133 |
||
1486 | 134 |
/** |
135 |
* Split a path into its elements. Empty path elements will be ignored. |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
136 |
* |
1486 | 137 |
* @param path The path to be split |
138 |
* @return The elements of the path |
|
139 |
*/ |
|
140 |
private static Iterable<File> getPathEntries(String path) { |
|
141 |
return getPathEntries(path, null); |
|
142 |
} |
|
10 | 143 |
|
1486 | 144 |
/** |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
145 |
* Split a path into its elements. If emptyPathDefault is not null, all empty elements in the |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
146 |
* path, including empty elements at either end of the path, will be replaced with the value of |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
147 |
* emptyPathDefault. |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
148 |
* |
1486 | 149 |
* @param path The path to be split |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
150 |
* @param emptyPathDefault The value to substitute for empty path elements, or null, to ignore |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
151 |
* empty path elements |
1486 | 152 |
* @return The elements of the path |
153 |
*/ |
|
154 |
private static Iterable<File> getPathEntries(String path, File emptyPathDefault) { |
|
22163 | 155 |
ListBuffer<File> entries = new ListBuffer<>(); |
1486 | 156 |
int start = 0; |
157 |
while (start <= path.length()) { |
|
158 |
int sep = path.indexOf(File.pathSeparatorChar, start); |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
159 |
if (sep == -1) { |
1486 | 160 |
sep = path.length(); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
161 |
} |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
162 |
if (start < sep) { |
1486 | 163 |
entries.add(new File(path.substring(start, sep))); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
164 |
} else if (emptyPathDefault != null) { |
1486 | 165 |
entries.add(emptyPathDefault); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
166 |
} |
1486 | 167 |
start = sep + 1; |
10 | 168 |
} |
1486 | 169 |
return entries; |
10 | 170 |
} |
171 |
||
10818 | 172 |
/** |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
173 |
* Utility class to help evaluate a path option. Duplicate entries are ignored, jar class paths |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
174 |
* can be expanded. |
10818 | 175 |
*/ |
10 | 176 |
private class Path extends LinkedHashSet<File> { |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
177 |
|
10 | 178 |
private static final long serialVersionUID = 0; |
179 |
||
180 |
private boolean expandJarClassPaths = false; |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
181 |
private final Set<File> canonicalValues = new HashSet<>(); |
10 | 182 |
|
183 |
public Path expandJarClassPaths(boolean x) { |
|
184 |
expandJarClassPaths = x; |
|
185 |
return this; |
|
186 |
} |
|
187 |
||
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
188 |
/** |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
189 |
* What to use when path element is the empty string |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
190 |
*/ |
1486 | 191 |
private File emptyPathDefault = null; |
10 | 192 |
|
1486 | 193 |
public Path emptyPathDefault(File x) { |
10 | 194 |
emptyPathDefault = x; |
195 |
return this; |
|
196 |
} |
|
197 |
||
198 |
public Path addDirectories(String dirs, boolean warn) { |
|
8424
5e31b2eb5aa3
6485027: javac incorrectly handles relative paths in manifest classpath
jjg
parents:
8034
diff
changeset
|
199 |
boolean prev = expandJarClassPaths; |
5e31b2eb5aa3
6485027: javac incorrectly handles relative paths in manifest classpath
jjg
parents:
8034
diff
changeset
|
200 |
expandJarClassPaths = true; |
5e31b2eb5aa3
6485027: javac incorrectly handles relative paths in manifest classpath
jjg
parents:
8034
diff
changeset
|
201 |
try { |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
202 |
if (dirs != null) { |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
203 |
for (File dir : getPathEntries(dirs)) { |
8424
5e31b2eb5aa3
6485027: javac incorrectly handles relative paths in manifest classpath
jjg
parents:
8034
diff
changeset
|
204 |
addDirectory(dir, warn); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
205 |
} |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
206 |
} |
8424
5e31b2eb5aa3
6485027: javac incorrectly handles relative paths in manifest classpath
jjg
parents:
8034
diff
changeset
|
207 |
return this; |
5e31b2eb5aa3
6485027: javac incorrectly handles relative paths in manifest classpath
jjg
parents:
8034
diff
changeset
|
208 |
} finally { |
5e31b2eb5aa3
6485027: javac incorrectly handles relative paths in manifest classpath
jjg
parents:
8034
diff
changeset
|
209 |
expandJarClassPaths = prev; |
5e31b2eb5aa3
6485027: javac incorrectly handles relative paths in manifest classpath
jjg
parents:
8034
diff
changeset
|
210 |
} |
10 | 211 |
} |
212 |
||
213 |
public Path addDirectories(String dirs) { |
|
214 |
return addDirectories(dirs, warn); |
|
215 |
} |
|
216 |
||
1486 | 217 |
private void addDirectory(File dir, boolean warn) { |
218 |
if (!dir.isDirectory()) { |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
219 |
if (warn) { |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
220 |
log.warning(Lint.LintCategory.PATH, |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
221 |
"dir.path.element.not.found", dir); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
222 |
} |
10 | 223 |
return; |
224 |
} |
|
225 |
||
1486 | 226 |
File[] files = dir.listFiles(); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
227 |
if (files == null) { |
10 | 228 |
return; |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
229 |
} |
10 | 230 |
|
231 |
for (File direntry : files) { |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
232 |
if (isArchive(direntry)) { |
10 | 233 |
addFile(direntry, warn); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
234 |
} |
10 | 235 |
} |
236 |
} |
|
237 |
||
238 |
public Path addFiles(String files, boolean warn) { |
|
7335
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
6151
diff
changeset
|
239 |
if (files != null) { |
10818 | 240 |
addFiles(getPathEntries(files, emptyPathDefault), warn); |
241 |
} |
|
242 |
return this; |
|
243 |
} |
|
244 |
||
245 |
public Path addFiles(String files) { |
|
246 |
return addFiles(files, warn); |
|
247 |
} |
|
248 |
||
249 |
public Path addFiles(Iterable<? extends File> files, boolean warn) { |
|
250 |
if (files != null) { |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
251 |
for (File file : files) { |
10 | 252 |
addFile(file, warn); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
253 |
} |
7335
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
6151
diff
changeset
|
254 |
} |
10 | 255 |
return this; |
256 |
} |
|
257 |
||
10818 | 258 |
public Path addFiles(Iterable<? extends File> files) { |
10 | 259 |
return addFiles(files, warn); |
260 |
} |
|
261 |
||
262 |
public void addFile(File file, boolean warn) { |
|
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7336
diff
changeset
|
263 |
if (contains(file)) { |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7336
diff
changeset
|
264 |
// discard duplicates |
10 | 265 |
return; |
266 |
} |
|
267 |
||
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
268 |
if (!fsInfo.exists(file)) { |
10 | 269 |
/* No such file or directory exists */ |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
270 |
if (warn) { |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
271 |
log.warning(Lint.LintCategory.PATH, |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
272 |
"path.element.not.found", file); |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
273 |
} |
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7336
diff
changeset
|
274 |
super.add(file); |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7336
diff
changeset
|
275 |
return; |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7336
diff
changeset
|
276 |
} |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7336
diff
changeset
|
277 |
|
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7336
diff
changeset
|
278 |
File canonFile = fsInfo.getCanonicalFile(file); |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7336
diff
changeset
|
279 |
if (canonicalValues.contains(canonFile)) { |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7336
diff
changeset
|
280 |
/* Discard duplicates and avoid infinite recursion */ |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7336
diff
changeset
|
281 |
return; |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7336
diff
changeset
|
282 |
} |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7336
diff
changeset
|
283 |
|
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7336
diff
changeset
|
284 |
if (fsInfo.isFile(file)) { |
10 | 285 |
/* File is an ordinary file. */ |
286 |
if (!isArchive(file)) { |
|
287 |
/* Not a recognized extension; open it to see if |
|
288 |
it looks like a valid zip file. */ |
|
289 |
try { |
|
290 |
ZipFile z = new ZipFile(file); |
|
291 |
z.close(); |
|
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
292 |
if (warn) { |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
293 |
log.warning(Lint.LintCategory.PATH, |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
294 |
"unexpected.archive.file", file); |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
295 |
} |
10 | 296 |
} catch (IOException e) { |
297 |
// FIXME: include e.getLocalizedMessage in warning |
|
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
298 |
if (warn) { |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
299 |
log.warning(Lint.LintCategory.PATH, |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
300 |
"invalid.archive.file", file); |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
301 |
} |
10 | 302 |
return; |
303 |
} |
|
304 |
} |
|
305 |
} |
|
306 |
||
307 |
/* Now what we have left is either a directory or a file name |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
308 |
conforming to archive naming convention */ |
10 | 309 |
super.add(file); |
1208 | 310 |
canonicalValues.add(canonFile); |
10 | 311 |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
312 |
if (expandJarClassPaths && fsInfo.isFile(file)) { |
10 | 313 |
addJarClassPath(file, warn); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
314 |
} |
10 | 315 |
} |
316 |
||
317 |
// Adds referenced classpath elements from a jar's Class-Path |
|
318 |
// Manifest entry. In some future release, we may want to |
|
319 |
// update this code to recognize URLs rather than simple |
|
320 |
// filenames, but if we do, we should redo all path-related code. |
|
321 |
private void addJarClassPath(File jarFile, boolean warn) { |
|
322 |
try { |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
323 |
for (File f : fsInfo.getJarClassPath(jarFile)) { |
1208 | 324 |
addFile(f, warn); |
10 | 325 |
} |
326 |
} catch (IOException e) { |
|
5007
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4937
diff
changeset
|
327 |
log.error("error.reading.file", jarFile, JavacFileManager.getMessage(e)); |
10 | 328 |
} |
329 |
} |
|
330 |
} |
|
331 |
||
10818 | 332 |
/** |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
333 |
* Base class for handling support for the representation of Locations. Implementations are |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
334 |
* responsible for handling the interactions between the command line options for a location, |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
335 |
* and API access via setLocation. |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
336 |
* |
10818 | 337 |
* @see #initHandlers |
338 |
* @see #getHandler |
|
339 |
*/ |
|
340 |
protected abstract class LocationHandler { |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
341 |
|
10818 | 342 |
final Location location; |
11314 | 343 |
final Set<Option> options; |
7335
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
6151
diff
changeset
|
344 |
|
10818 | 345 |
/** |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
346 |
* Create a handler. The location and options provide a way to map from a location or an |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
347 |
* option to the corresponding handler. |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
348 |
* |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
349 |
* @param location the location for which this is the handler |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
350 |
* @param options the options affecting this location |
10818 | 351 |
* @see #initHandlers |
352 |
*/ |
|
11314 | 353 |
protected LocationHandler(Location location, Option... options) { |
10818 | 354 |
this.location = location; |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
355 |
this.options = options.length == 0 |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
356 |
? EnumSet.noneOf(Option.class) |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
357 |
: EnumSet.copyOf(Arrays.asList(options)); |
10818 | 358 |
} |
10 | 359 |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
360 |
/** |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
361 |
* @see JavaFileManager#handleOption |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
362 |
*/ |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
363 |
abstract boolean handleOption(Option option, String value); |
10 | 364 |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
365 |
/** |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
366 |
* @see StandardJavaFileManager#getLocation |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
367 |
*/ |
10818 | 368 |
abstract Collection<File> getLocation(); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
369 |
|
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
370 |
/** |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
371 |
* @see StandardJavaFileManager#setLocation |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
372 |
*/ |
10818 | 373 |
abstract void setLocation(Iterable<? extends File> files) throws IOException; |
374 |
} |
|
375 |
||
376 |
/** |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
377 |
* General purpose implementation for output locations, such as -d/CLASS_OUTPUT and |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
378 |
* -s/SOURCE_OUTPUT. All options are treated as equivalent (i.e. aliases.) The value is a single |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
379 |
* file, possibly null. |
10818 | 380 |
*/ |
381 |
private class OutputLocationHandler extends LocationHandler { |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
382 |
|
10818 | 383 |
private File outputDir; |
384 |
||
11314 | 385 |
OutputLocationHandler(Location location, Option... options) { |
10818 | 386 |
super(location, options); |
387 |
} |
|
388 |
||
389 |
@Override |
|
11314 | 390 |
boolean handleOption(Option option, String value) { |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
391 |
if (!options.contains(option)) { |
10818 | 392 |
return false; |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
393 |
} |
10 | 394 |
|
10818 | 395 |
// TODO: could/should validate outputDir exists and is a directory |
396 |
// need to decide how best to report issue for benefit of |
|
397 |
// direct API call on JavaFileManager.handleOption(specifies IAE) |
|
398 |
// vs. command line decoding. |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
399 |
outputDir = (value == null) ? null : new File(value); |
10818 | 400 |
return true; |
401 |
} |
|
402 |
||
403 |
@Override |
|
404 |
Collection<File> getLocation() { |
|
405 |
return (outputDir == null) ? null : Collections.singleton(outputDir); |
|
406 |
} |
|
10 | 407 |
|
10818 | 408 |
@Override |
409 |
void setLocation(Iterable<? extends File> files) throws IOException { |
|
410 |
if (files == null) { |
|
411 |
outputDir = null; |
|
412 |
} else { |
|
413 |
Iterator<? extends File> pathIter = files.iterator(); |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
414 |
if (!pathIter.hasNext()) { |
10818 | 415 |
throw new IllegalArgumentException("empty path for directory"); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
416 |
} |
10818 | 417 |
File dir = pathIter.next(); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
418 |
if (pathIter.hasNext()) { |
10818 | 419 |
throw new IllegalArgumentException("path too long for directory"); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
420 |
} |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
421 |
if (!dir.exists()) { |
10818 | 422 |
throw new FileNotFoundException(dir + ": does not exist"); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
423 |
} else if (!dir.isDirectory()) { |
10818 | 424 |
throw new IOException(dir + ": not a directory"); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
425 |
} |
10818 | 426 |
outputDir = dir; |
427 |
} |
|
428 |
} |
|
10 | 429 |
} |
430 |
||
10818 | 431 |
/** |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
432 |
* General purpose implementation for search path locations, such as -sourcepath/SOURCE_PATH and |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
433 |
* -processorPath/ANNOTATION_PROCESS_PATH. All options are treated as equivalent (i.e. aliases.) |
10818 | 434 |
* The value is an ordered set of files and/or directories. |
435 |
*/ |
|
436 |
private class SimpleLocationHandler extends LocationHandler { |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
437 |
|
10818 | 438 |
protected Collection<File> searchPath; |
10 | 439 |
|
11314 | 440 |
SimpleLocationHandler(Location location, Option... options) { |
10818 | 441 |
super(location, options); |
442 |
} |
|
10 | 443 |
|
10818 | 444 |
@Override |
11314 | 445 |
boolean handleOption(Option option, String value) { |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
446 |
if (!options.contains(option)) { |
10818 | 447 |
return false; |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
448 |
} |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
449 |
searchPath = value == null ? null |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
450 |
: Collections.unmodifiableCollection(createPath().addFiles(value)); |
10818 | 451 |
return true; |
452 |
} |
|
453 |
||
454 |
@Override |
|
455 |
Collection<File> getLocation() { |
|
456 |
return searchPath; |
|
457 |
} |
|
10 | 458 |
|
10818 | 459 |
@Override |
460 |
void setLocation(Iterable<? extends File> files) { |
|
461 |
Path p; |
|
462 |
if (files == null) { |
|
463 |
p = computePath(null); |
|
464 |
} else { |
|
14360
2a8304e421ed
6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents:
14259
diff
changeset
|
465 |
p = createPath().addFiles(files); |
10818 | 466 |
} |
467 |
searchPath = Collections.unmodifiableCollection(p); |
|
468 |
} |
|
14360
2a8304e421ed
6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents:
14259
diff
changeset
|
469 |
|
2a8304e421ed
6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents:
14259
diff
changeset
|
470 |
protected Path computePath(String value) { |
2a8304e421ed
6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents:
14259
diff
changeset
|
471 |
return createPath().addFiles(value); |
2a8304e421ed
6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents:
14259
diff
changeset
|
472 |
} |
2a8304e421ed
6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents:
14259
diff
changeset
|
473 |
|
2a8304e421ed
6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents:
14259
diff
changeset
|
474 |
protected Path createPath() { |
2a8304e421ed
6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents:
14259
diff
changeset
|
475 |
return new Path(); |
2a8304e421ed
6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents:
14259
diff
changeset
|
476 |
} |
10 | 477 |
} |
478 |
||
10818 | 479 |
/** |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
480 |
* Subtype of SimpleLocationHandler for -classpath/CLASS_PATH. If no value is given, a default |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
481 |
* is provided, based on system properties and other values. |
10818 | 482 |
*/ |
483 |
private class ClassPathLocationHandler extends SimpleLocationHandler { |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
484 |
|
10818 | 485 |
ClassPathLocationHandler() { |
486 |
super(StandardLocation.CLASS_PATH, |
|
11314 | 487 |
Option.CLASSPATH, Option.CP); |
10818 | 488 |
} |
489 |
||
490 |
@Override |
|
491 |
Collection<File> getLocation() { |
|
492 |
lazy(); |
|
493 |
return searchPath; |
|
494 |
} |
|
495 |
||
496 |
@Override |
|
497 |
protected Path computePath(String value) { |
|
498 |
String cp = value; |
|
10 | 499 |
|
10818 | 500 |
// CLASSPATH environment variable when run from `javac'. |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
501 |
if (cp == null) { |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
502 |
cp = System.getProperty("env.class.path"); |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
503 |
} |
10818 | 504 |
|
505 |
// If invoked via a java VM (not the javac launcher), use the |
|
506 |
// platform class path |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
507 |
if (cp == null && System.getProperty("application.home") == null) { |
10818 | 508 |
cp = System.getProperty("java.class.path"); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
509 |
} |
10818 | 510 |
|
511 |
// Default to current working directory. |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
512 |
if (cp == null) { |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
513 |
cp = "."; |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
514 |
} |
10818 | 515 |
|
14360
2a8304e421ed
6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents:
14259
diff
changeset
|
516 |
return createPath().addFiles(cp); |
2a8304e421ed
6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents:
14259
diff
changeset
|
517 |
} |
2a8304e421ed
6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents:
14259
diff
changeset
|
518 |
|
2a8304e421ed
6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents:
14259
diff
changeset
|
519 |
@Override |
2a8304e421ed
6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents:
14259
diff
changeset
|
520 |
protected Path createPath() { |
10818 | 521 |
return new Path() |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
522 |
.expandJarClassPaths(true) // Only search user jars for Class-Paths |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
523 |
.emptyPathDefault(new File(".")); // Empty path elt ==> current directory |
14360
2a8304e421ed
6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents:
14259
diff
changeset
|
524 |
} |
10818 | 525 |
|
526 |
private void lazy() { |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
527 |
if (searchPath == null) { |
10818 | 528 |
setLocation(null); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
529 |
} |
10818 | 530 |
} |
10 | 531 |
} |
532 |
||
10818 | 533 |
/** |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
534 |
* Custom subtype of LocationHandler for PLATFORM_CLASS_PATH. Various options are supported for |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
535 |
* different components of the platform class path. Setting a value with setLocation overrides |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
536 |
* all existing option values. Setting any option overrides any value set with setLocation, and |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
537 |
* reverts to using default values for options that have not been set. Setting -bootclasspath or |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
538 |
* -Xbootclasspath overrides any existing value for -Xbootclasspath/p: and -Xbootclasspath/a:. |
10818 | 539 |
*/ |
540 |
private class BootClassPathLocationHandler extends LocationHandler { |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
541 |
|
10818 | 542 |
private Collection<File> searchPath; |
22163 | 543 |
final Map<Option, String> optionValues = new EnumMap<>(Option.class); |
10818 | 544 |
|
545 |
/** |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
546 |
* rt.jar as found on the default bootclasspath. If the user specified a bootclasspath, null |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
547 |
* is used. |
10818 | 548 |
*/ |
549 |
private File defaultBootClassPathRtJar = null; |
|
10 | 550 |
|
10818 | 551 |
/** |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
552 |
* Is bootclasspath the default? |
10818 | 553 |
*/ |
554 |
private boolean isDefaultBootClassPath; |
|
555 |
||
556 |
BootClassPathLocationHandler() { |
|
557 |
super(StandardLocation.PLATFORM_CLASS_PATH, |
|
11314 | 558 |
Option.BOOTCLASSPATH, Option.XBOOTCLASSPATH, |
559 |
Option.XBOOTCLASSPATH_PREPEND, |
|
560 |
Option.XBOOTCLASSPATH_APPEND, |
|
561 |
Option.ENDORSEDDIRS, Option.DJAVA_ENDORSED_DIRS, |
|
562 |
Option.EXTDIRS, Option.DJAVA_EXT_DIRS); |
|
10818 | 563 |
} |
564 |
||
565 |
boolean isDefault() { |
|
566 |
lazy(); |
|
567 |
return isDefaultBootClassPath; |
|
568 |
} |
|
569 |
||
570 |
boolean isDefaultRtJar(File file) { |
|
571 |
lazy(); |
|
572 |
return file.equals(defaultBootClassPathRtJar); |
|
573 |
} |
|
574 |
||
575 |
@Override |
|
11314 | 576 |
boolean handleOption(Option option, String value) { |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
577 |
if (!options.contains(option)) { |
10818 | 578 |
return false; |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
579 |
} |
10 | 580 |
|
10818 | 581 |
option = canonicalize(option); |
582 |
optionValues.put(option, value); |
|
583 |
if (option == BOOTCLASSPATH) { |
|
584 |
optionValues.remove(XBOOTCLASSPATH_PREPEND); |
|
585 |
optionValues.remove(XBOOTCLASSPATH_APPEND); |
|
586 |
} |
|
587 |
searchPath = null; // reset to "uninitialized" |
|
588 |
return true; |
|
589 |
} |
|
590 |
// where |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
591 |
// TODO: would be better if option aliasing was handled at a higher |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
592 |
// level |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
593 |
private Option canonicalize(Option option) { |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
594 |
switch (option) { |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
595 |
case XBOOTCLASSPATH: |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
596 |
return Option.BOOTCLASSPATH; |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
597 |
case DJAVA_ENDORSED_DIRS: |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
598 |
return Option.ENDORSEDDIRS; |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
599 |
case DJAVA_EXT_DIRS: |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
600 |
return Option.EXTDIRS; |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
601 |
default: |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
602 |
return option; |
10818 | 603 |
} |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
604 |
} |
10 | 605 |
|
10818 | 606 |
@Override |
607 |
Collection<File> getLocation() { |
|
10 | 608 |
lazy(); |
10818 | 609 |
return searchPath; |
610 |
} |
|
611 |
||
612 |
@Override |
|
613 |
void setLocation(Iterable<? extends File> files) { |
|
614 |
if (files == null) { |
|
615 |
searchPath = null; // reset to "uninitialized" |
|
616 |
} else { |
|
617 |
defaultBootClassPathRtJar = null; |
|
618 |
isDefaultBootClassPath = false; |
|
619 |
Path p = new Path().addFiles(files, false); |
|
620 |
searchPath = Collections.unmodifiableCollection(p); |
|
621 |
optionValues.clear(); |
|
622 |
} |
|
10 | 623 |
} |
10818 | 624 |
|
625 |
Path computePath() { |
|
626 |
defaultBootClassPathRtJar = null; |
|
627 |
Path path = new Path(); |
|
628 |
||
629 |
String bootclasspathOpt = optionValues.get(BOOTCLASSPATH); |
|
630 |
String endorseddirsOpt = optionValues.get(ENDORSEDDIRS); |
|
631 |
String extdirsOpt = optionValues.get(EXTDIRS); |
|
632 |
String xbootclasspathPrependOpt = optionValues.get(XBOOTCLASSPATH_PREPEND); |
|
633 |
String xbootclasspathAppendOpt = optionValues.get(XBOOTCLASSPATH_APPEND); |
|
634 |
path.addFiles(xbootclasspathPrependOpt); |
|
635 |
||
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
636 |
if (endorseddirsOpt != null) { |
10818 | 637 |
path.addDirectories(endorseddirsOpt); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
638 |
} else { |
10818 | 639 |
path.addDirectories(System.getProperty("java.endorsed.dirs"), false); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
640 |
} |
10818 | 641 |
|
642 |
if (bootclasspathOpt != null) { |
|
643 |
path.addFiles(bootclasspathOpt); |
|
644 |
} else { |
|
645 |
// Standard system classes for this compiler's release. |
|
646 |
String files = System.getProperty("sun.boot.class.path"); |
|
647 |
path.addFiles(files, false); |
|
648 |
File rt_jar = new File("rt.jar"); |
|
649 |
for (File file : getPathEntries(files)) { |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
650 |
if (new File(file.getName()).equals(rt_jar)) { |
10818 | 651 |
defaultBootClassPathRtJar = file; |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
652 |
} |
10818 | 653 |
} |
654 |
} |
|
655 |
||
656 |
path.addFiles(xbootclasspathAppendOpt); |
|
657 |
||
658 |
// Strictly speaking, standard extensions are not bootstrap |
|
659 |
// classes, but we treat them identically, so we'll pretend |
|
660 |
// that they are. |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
661 |
if (extdirsOpt != null) { |
10818 | 662 |
path.addDirectories(extdirsOpt); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
663 |
} else { |
10818 | 664 |
path.addDirectories(System.getProperty("java.ext.dirs"), false); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
665 |
} |
10818 | 666 |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
667 |
isDefaultBootClassPath |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
668 |
= (xbootclasspathPrependOpt == null) |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
669 |
&& (bootclasspathOpt == null) |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
670 |
&& (xbootclasspathAppendOpt == null); |
10818 | 671 |
|
672 |
return path; |
|
673 |
} |
|
674 |
||
675 |
private void lazy() { |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
676 |
if (searchPath == null) { |
10818 | 677 |
searchPath = Collections.unmodifiableCollection(computePath()); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
678 |
} |
10818 | 679 |
} |
10 | 680 |
} |
681 |
||
10818 | 682 |
Map<Location, LocationHandler> handlersForLocation; |
11314 | 683 |
Map<Option, LocationHandler> handlersForOption; |
10818 | 684 |
|
685 |
void initHandlers() { |
|
22163 | 686 |
handlersForLocation = new HashMap<>(); |
687 |
handlersForOption = new EnumMap<>(Option.class); |
|
10818 | 688 |
|
689 |
LocationHandler[] handlers = { |
|
690 |
new BootClassPathLocationHandler(), |
|
691 |
new ClassPathLocationHandler(), |
|
11314 | 692 |
new SimpleLocationHandler(StandardLocation.SOURCE_PATH, Option.SOURCEPATH), |
693 |
new SimpleLocationHandler(StandardLocation.ANNOTATION_PROCESSOR_PATH, Option.PROCESSORPATH), |
|
694 |
new OutputLocationHandler((StandardLocation.CLASS_OUTPUT), Option.D), |
|
12213
516b112d6c68
7150368: javac should include basic ability to generate native headers
jjg
parents:
11314
diff
changeset
|
695 |
new OutputLocationHandler((StandardLocation.SOURCE_OUTPUT), Option.S), |
516b112d6c68
7150368: javac should include basic ability to generate native headers
jjg
parents:
11314
diff
changeset
|
696 |
new OutputLocationHandler((StandardLocation.NATIVE_HEADER_OUTPUT), Option.H) |
10818 | 697 |
}; |
10 | 698 |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
699 |
for (LocationHandler h : handlers) { |
10818 | 700 |
handlersForLocation.put(h.location, h); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
701 |
for (Option o : h.options) { |
10818 | 702 |
handlersForOption.put(o, h); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
703 |
} |
10 | 704 |
} |
10818 | 705 |
} |
706 |
||
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
707 |
public boolean handleOption(Option option, String value) { |
10818 | 708 |
LocationHandler h = handlersForOption.get(option); |
709 |
return (h == null ? false : h.handleOption(option, value)); |
|
710 |
} |
|
711 |
||
712 |
Collection<File> getLocation(Location location) { |
|
713 |
LocationHandler h = getHandler(location); |
|
714 |
return (h == null ? null : h.getLocation()); |
|
10 | 715 |
} |
716 |
||
10818 | 717 |
File getOutputLocation(Location location) { |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
718 |
if (!location.isOutputLocation()) { |
10818 | 719 |
throw new IllegalArgumentException(); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
720 |
} |
10818 | 721 |
LocationHandler h = getHandler(location); |
722 |
return ((OutputLocationHandler) h).outputDir; |
|
723 |
} |
|
10 | 724 |
|
10818 | 725 |
void setLocation(Location location, Iterable<? extends File> files) throws IOException { |
726 |
LocationHandler h = getHandler(location); |
|
727 |
if (h == null) { |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
728 |
if (location.isOutputLocation()) { |
10818 | 729 |
h = new OutputLocationHandler(location); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
730 |
} else { |
10818 | 731 |
h = new SimpleLocationHandler(location); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
732 |
} |
10818 | 733 |
handlersForLocation.put(location, h); |
734 |
} |
|
735 |
h.setLocation(files); |
|
736 |
} |
|
737 |
||
738 |
protected LocationHandler getHandler(Location location) { |
|
739 |
location.getClass(); // null check |
|
740 |
return handlersForLocation.get(location); |
|
741 |
} |
|
742 |
||
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
743 |
/** |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
744 |
* Is this the name of an archive file? |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
745 |
*/ |
1208 | 746 |
private boolean isArchive(File file) { |
22153
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
14360
diff
changeset
|
747 |
String n = StringUtils.toLowerCase(file.getName()); |
1208 | 748 |
return fsInfo.isFile(file) |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
749 |
&& (n.endsWith(".jar") || n.endsWith(".zip")); |
10 | 750 |
} |
4937
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
751 |
|
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
752 |
/** |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
753 |
* Utility method for converting a search path string to an array of directory and JAR file |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
754 |
* URLs. |
4937
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
755 |
* |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
756 |
* Note that this method is called by apt and the DocletInvoker. |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
757 |
* |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
758 |
* @param path the search path string |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
759 |
* @return the resulting array of directory and JAR file URLs |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
760 |
*/ |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
761 |
public static URL[] pathToURLs(String path) { |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
762 |
StringTokenizer st = new StringTokenizer(path, File.pathSeparator); |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
763 |
URL[] urls = new URL[st.countTokens()]; |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
764 |
int count = 0; |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
765 |
while (st.hasMoreTokens()) { |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
766 |
URL url = fileToURL(new File(st.nextToken())); |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
767 |
if (url != null) { |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
768 |
urls[count++] = url; |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
769 |
} |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
770 |
} |
14049
3207422a0f9b
7193657: provide internal ArrayUtils class to simplify common usage of arrays in javac
jjg
parents:
12213
diff
changeset
|
771 |
urls = Arrays.copyOf(urls, count); |
4937
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
772 |
return urls; |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
773 |
} |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
774 |
|
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
775 |
/** |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
776 |
* Returns the directory or JAR file URL corresponding to the specified local file name. |
4937
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
777 |
* |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
778 |
* @param file the File object |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
779 |
* @return the resulting directory or JAR file URL, or null if unknown |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
780 |
*/ |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
781 |
private static URL fileToURL(File file) { |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
782 |
String name; |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
783 |
try { |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
784 |
name = file.getCanonicalPath(); |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
785 |
} catch (IOException e) { |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
786 |
name = file.getAbsolutePath(); |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
787 |
} |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
788 |
name = name.replace(File.separatorChar, '/'); |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
789 |
if (!name.startsWith("/")) { |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
790 |
name = "/" + name; |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
791 |
} |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
792 |
// If the file does not exist, then assume that it's a directory |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
793 |
if (!file.isFile()) { |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
794 |
name = name + "/"; |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
795 |
} |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
796 |
try { |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
797 |
return new URL("file", "", name); |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
798 |
} catch (MalformedURLException e) { |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
799 |
throw new IllegalArgumentException(file.toString()); |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
800 |
} |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
801 |
} |
10 | 802 |
} |