author | jjh |
Mon, 13 Dec 2010 17:35:57 -0800 | |
changeset 7839 | a1ca72d05b20 |
parent 7336 | 3fd30668e9b5 |
child 7847 | 5d1dad3342a3 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
5520 | 2 |
* Copyright (c) 2003, 2008, 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 |
*/ |
25 |
||
731
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
171
diff
changeset
|
26 |
package com.sun.tools.javac.file; |
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
171
diff
changeset
|
27 |
|
10 | 28 |
import java.io.File; |
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; |
10 | 32 |
import java.util.HashMap; |
33 |
import java.util.HashSet; |
|
34 |
import java.util.Map; |
|
35 |
import java.util.Set; |
|
36 |
import java.util.Collection; |
|
37 |
import java.util.Collections; |
|
38 |
import java.util.LinkedHashSet; |
|
4937
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
39 |
import java.util.StringTokenizer; |
10 | 40 |
import java.util.zip.ZipFile; |
41 |
import javax.tools.JavaFileManager.Location; |
|
42 |
||
731
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
171
diff
changeset
|
43 |
import com.sun.tools.javac.code.Lint; |
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
171
diff
changeset
|
44 |
import com.sun.tools.javac.util.Context; |
1486 | 45 |
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
|
46 |
import com.sun.tools.javac.util.Log; |
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
171
diff
changeset
|
47 |
import com.sun.tools.javac.util.Options; |
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
171
diff
changeset
|
48 |
|
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
171
diff
changeset
|
49 |
import static javax.tools.StandardLocation.*; |
10 | 50 |
import static com.sun.tools.javac.main.OptionName.*; |
51 |
||
52 |
/** This class converts command line arguments, environment variables |
|
53 |
* and system properties (in File.pathSeparator-separated String form) |
|
54 |
* into a boot class path, user class path, and source path (in |
|
55 |
* Collection<String> form). |
|
56 |
* |
|
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
57 |
* <p><b>This is NOT part of any supported API. |
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
58 |
* If you write code that depends on this, you do so at your own risk. |
10 | 59 |
* This code and its internal interfaces are subject to change or |
60 |
* deletion without notice.</b> |
|
61 |
*/ |
|
62 |
public class Paths { |
|
63 |
||
64 |
/** The context key for the todo list */ |
|
65 |
protected static final Context.Key<Paths> pathsKey = |
|
66 |
new Context.Key<Paths>(); |
|
67 |
||
171 | 68 |
/** Get the Paths instance for this context. |
69 |
* @param context the context |
|
70 |
* @return the Paths instance for this context |
|
71 |
*/ |
|
4548 | 72 |
public static Paths instance(Context context) { |
10 | 73 |
Paths instance = context.get(pathsKey); |
74 |
if (instance == null) |
|
75 |
instance = new Paths(context); |
|
76 |
return instance; |
|
77 |
} |
|
78 |
||
79 |
/** The log to use for warning output */ |
|
80 |
private Log log; |
|
81 |
||
82 |
/** Collection of command-line options */ |
|
83 |
private Options options; |
|
84 |
||
85 |
/** Handler for -Xlint options */ |
|
86 |
private Lint lint; |
|
87 |
||
1208 | 88 |
/** Access to (possibly cached) file info */ |
89 |
private FSInfo fsInfo; |
|
10 | 90 |
|
91 |
protected Paths(Context context) { |
|
92 |
context.put(pathsKey, this); |
|
93 |
pathsForLocation = new HashMap<Location,Path>(16); |
|
94 |
setContext(context); |
|
95 |
} |
|
96 |
||
97 |
void setContext(Context context) { |
|
98 |
log = Log.instance(context); |
|
99 |
options = Options.instance(context); |
|
100 |
lint = Lint.instance(context); |
|
1208 | 101 |
fsInfo = FSInfo.instance(context); |
10 | 102 |
} |
103 |
||
104 |
/** Whether to warn about non-existent path elements */ |
|
105 |
private boolean warn; |
|
106 |
||
107 |
private Map<Location, Path> pathsForLocation; |
|
108 |
||
109 |
private boolean inited = false; // TODO? caching bad? |
|
110 |
||
111 |
/** |
|
112 |
* rt.jar as found on the default bootclass path. If the user specified a |
|
113 |
* bootclasspath, null is used. |
|
114 |
*/ |
|
115 |
private File bootClassPathRtJar = null; |
|
116 |
||
7335
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
6151
diff
changeset
|
117 |
/** |
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
6151
diff
changeset
|
118 |
* Is bootclasspath the default? |
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
6151
diff
changeset
|
119 |
*/ |
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
6151
diff
changeset
|
120 |
private boolean isDefaultBootClassPath; |
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
6151
diff
changeset
|
121 |
|
10 | 122 |
Path getPathForLocation(Location location) { |
123 |
Path path = pathsForLocation.get(location); |
|
124 |
if (path == null) |
|
125 |
setPathForLocation(location, null); |
|
126 |
return pathsForLocation.get(location); |
|
127 |
} |
|
128 |
||
129 |
void setPathForLocation(Location location, Iterable<? extends File> path) { |
|
130 |
// TODO? if (inited) throw new IllegalStateException |
|
131 |
// TODO: otherwise reset sourceSearchPath, classSearchPath as needed |
|
132 |
Path p; |
|
133 |
if (path == null) { |
|
134 |
if (location == CLASS_PATH) |
|
135 |
p = computeUserClassPath(); |
|
136 |
else if (location == PLATFORM_CLASS_PATH) |
|
7335
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
6151
diff
changeset
|
137 |
p = computeBootClassPath(); // sets isDefaultBootClassPath |
10 | 138 |
else if (location == ANNOTATION_PROCESSOR_PATH) |
139 |
p = computeAnnotationProcessorPath(); |
|
140 |
else if (location == SOURCE_PATH) |
|
141 |
p = computeSourcePath(); |
|
142 |
else |
|
143 |
// no defaults for other paths |
|
144 |
p = null; |
|
145 |
} else { |
|
7335
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
6151
diff
changeset
|
146 |
if (location == PLATFORM_CLASS_PATH) |
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
6151
diff
changeset
|
147 |
isDefaultBootClassPath = false; |
10 | 148 |
p = new Path(); |
149 |
for (File f: path) |
|
150 |
p.addFile(f, warn); // TODO: is use of warn appropriate? |
|
151 |
} |
|
152 |
pathsForLocation.put(location, p); |
|
153 |
} |
|
154 |
||
7336
3fd30668e9b5
7003477: Paths.isDefaultBootClassPath needs to be public
jjg
parents:
7335
diff
changeset
|
155 |
public boolean isDefaultBootClassPath() { |
7335
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
6151
diff
changeset
|
156 |
lazy(); |
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
6151
diff
changeset
|
157 |
return isDefaultBootClassPath; |
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
6151
diff
changeset
|
158 |
} |
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
6151
diff
changeset
|
159 |
|
10 | 160 |
protected void lazy() { |
161 |
if (!inited) { |
|
162 |
warn = lint.isEnabled(Lint.LintCategory.PATH); |
|
163 |
||
164 |
pathsForLocation.put(PLATFORM_CLASS_PATH, computeBootClassPath()); |
|
165 |
pathsForLocation.put(CLASS_PATH, computeUserClassPath()); |
|
166 |
pathsForLocation.put(SOURCE_PATH, computeSourcePath()); |
|
167 |
||
168 |
inited = true; |
|
169 |
} |
|
170 |
} |
|
171 |
||
172 |
public Collection<File> bootClassPath() { |
|
173 |
lazy(); |
|
174 |
return Collections.unmodifiableCollection(getPathForLocation(PLATFORM_CLASS_PATH)); |
|
175 |
} |
|
176 |
public Collection<File> userClassPath() { |
|
177 |
lazy(); |
|
178 |
return Collections.unmodifiableCollection(getPathForLocation(CLASS_PATH)); |
|
179 |
} |
|
180 |
public Collection<File> sourcePath() { |
|
181 |
lazy(); |
|
182 |
Path p = getPathForLocation(SOURCE_PATH); |
|
183 |
return p == null || p.size() == 0 |
|
184 |
? null |
|
185 |
: Collections.unmodifiableCollection(p); |
|
186 |
} |
|
187 |
||
188 |
boolean isBootClassPathRtJar(File file) { |
|
189 |
return file.equals(bootClassPathRtJar); |
|
190 |
} |
|
191 |
||
1486 | 192 |
/** |
193 |
* Split a path into its elements. Empty path elements will be ignored. |
|
194 |
* @param path The path to be split |
|
195 |
* @return The elements of the path |
|
196 |
*/ |
|
197 |
private static Iterable<File> getPathEntries(String path) { |
|
198 |
return getPathEntries(path, null); |
|
199 |
} |
|
10 | 200 |
|
1486 | 201 |
/** |
202 |
* Split a path into its elements. If emptyPathDefault is not null, all |
|
203 |
* empty elements in the path, including empty elements at either end of |
|
204 |
* the path, will be replaced with the value of emptyPathDefault. |
|
205 |
* @param path The path to be split |
|
206 |
* @param emptyPathDefault The value to substitute for empty path elements, |
|
207 |
* or null, to ignore empty path elements |
|
208 |
* @return The elements of the path |
|
209 |
*/ |
|
210 |
private static Iterable<File> getPathEntries(String path, File emptyPathDefault) { |
|
211 |
ListBuffer<File> entries = new ListBuffer<File>(); |
|
212 |
int start = 0; |
|
213 |
while (start <= path.length()) { |
|
214 |
int sep = path.indexOf(File.pathSeparatorChar, start); |
|
215 |
if (sep == -1) |
|
216 |
sep = path.length(); |
|
217 |
if (start < sep) |
|
218 |
entries.add(new File(path.substring(start, sep))); |
|
219 |
else if (emptyPathDefault != null) |
|
220 |
entries.add(emptyPathDefault); |
|
221 |
start = sep + 1; |
|
10 | 222 |
} |
1486 | 223 |
return entries; |
10 | 224 |
} |
225 |
||
226 |
private class Path extends LinkedHashSet<File> { |
|
227 |
private static final long serialVersionUID = 0; |
|
228 |
||
229 |
private boolean expandJarClassPaths = false; |
|
230 |
private Set<File> canonicalValues = new HashSet<File>(); |
|
231 |
||
232 |
public Path expandJarClassPaths(boolean x) { |
|
233 |
expandJarClassPaths = x; |
|
234 |
return this; |
|
235 |
} |
|
236 |
||
237 |
/** What to use when path element is the empty string */ |
|
1486 | 238 |
private File emptyPathDefault = null; |
10 | 239 |
|
1486 | 240 |
public Path emptyPathDefault(File x) { |
10 | 241 |
emptyPathDefault = x; |
242 |
return this; |
|
243 |
} |
|
244 |
||
245 |
public Path() { super(); } |
|
246 |
||
247 |
public Path addDirectories(String dirs, boolean warn) { |
|
248 |
if (dirs != null) |
|
1486 | 249 |
for (File dir : getPathEntries(dirs)) |
10 | 250 |
addDirectory(dir, warn); |
251 |
return this; |
|
252 |
} |
|
253 |
||
254 |
public Path addDirectories(String dirs) { |
|
255 |
return addDirectories(dirs, warn); |
|
256 |
} |
|
257 |
||
1486 | 258 |
private void addDirectory(File dir, boolean warn) { |
259 |
if (!dir.isDirectory()) { |
|
10 | 260 |
if (warn) |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
261 |
log.warning(Lint.LintCategory.PATH, |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
262 |
"dir.path.element.not.found", dir); |
10 | 263 |
return; |
264 |
} |
|
265 |
||
1486 | 266 |
File[] files = dir.listFiles(); |
10 | 267 |
if (files == null) |
268 |
return; |
|
269 |
||
270 |
for (File direntry : files) { |
|
271 |
if (isArchive(direntry)) |
|
272 |
addFile(direntry, warn); |
|
273 |
} |
|
274 |
} |
|
275 |
||
276 |
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
|
277 |
if (files != null) { |
1486 | 278 |
for (File file : getPathEntries(files, emptyPathDefault)) |
10 | 279 |
addFile(file, warn); |
7335
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
6151
diff
changeset
|
280 |
} |
10 | 281 |
return this; |
282 |
} |
|
283 |
||
284 |
public Path addFiles(String files) { |
|
285 |
return addFiles(files, warn); |
|
286 |
} |
|
287 |
||
288 |
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
|
289 |
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
|
290 |
// discard duplicates |
10 | 291 |
return; |
292 |
} |
|
293 |
||
1208 | 294 |
if (! fsInfo.exists(file)) { |
10 | 295 |
/* No such file or directory exists */ |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
296 |
if (warn) { |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
297 |
log.warning(Lint.LintCategory.PATH, |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
298 |
"path.element.not.found", file); |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
299 |
} |
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7336
diff
changeset
|
300 |
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
|
301 |
return; |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7336
diff
changeset
|
302 |
} |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7336
diff
changeset
|
303 |
|
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7336
diff
changeset
|
304 |
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
|
305 |
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
|
306 |
/* 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
|
307 |
return; |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7336
diff
changeset
|
308 |
} |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7336
diff
changeset
|
309 |
|
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7336
diff
changeset
|
310 |
if (fsInfo.isFile(file)) { |
10 | 311 |
/* File is an ordinary file. */ |
312 |
if (!isArchive(file)) { |
|
313 |
/* Not a recognized extension; open it to see if |
|
314 |
it looks like a valid zip file. */ |
|
315 |
try { |
|
316 |
ZipFile z = new ZipFile(file); |
|
317 |
z.close(); |
|
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
318 |
if (warn) { |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
319 |
log.warning(Lint.LintCategory.PATH, |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
320 |
"unexpected.archive.file", file); |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
321 |
} |
10 | 322 |
} catch (IOException e) { |
323 |
// FIXME: include e.getLocalizedMessage in warning |
|
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
324 |
if (warn) { |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
325 |
log.warning(Lint.LintCategory.PATH, |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
326 |
"invalid.archive.file", file); |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
327 |
} |
10 | 328 |
return; |
329 |
} |
|
330 |
} |
|
331 |
} |
|
332 |
||
333 |
/* Now what we have left is either a directory or a file name |
|
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7336
diff
changeset
|
334 |
conforming to archive naming convention */ |
10 | 335 |
super.add(file); |
1208 | 336 |
canonicalValues.add(canonFile); |
10 | 337 |
|
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7336
diff
changeset
|
338 |
if (expandJarClassPaths && fsInfo.isFile(file)) |
10 | 339 |
addJarClassPath(file, warn); |
340 |
} |
|
341 |
||
342 |
// Adds referenced classpath elements from a jar's Class-Path |
|
343 |
// Manifest entry. In some future release, we may want to |
|
344 |
// update this code to recognize URLs rather than simple |
|
345 |
// filenames, but if we do, we should redo all path-related code. |
|
346 |
private void addJarClassPath(File jarFile, boolean warn) { |
|
347 |
try { |
|
1208 | 348 |
for (File f: fsInfo.getJarClassPath(jarFile)) { |
349 |
addFile(f, warn); |
|
10 | 350 |
} |
351 |
} catch (IOException e) { |
|
5007
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4937
diff
changeset
|
352 |
log.error("error.reading.file", jarFile, JavacFileManager.getMessage(e)); |
10 | 353 |
} |
354 |
} |
|
355 |
} |
|
356 |
||
357 |
private Path computeBootClassPath() { |
|
358 |
bootClassPathRtJar = null; |
|
359 |
Path path = new Path(); |
|
360 |
||
7335
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
6151
diff
changeset
|
361 |
String bootclasspathOpt = options.get(BOOTCLASSPATH); |
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
6151
diff
changeset
|
362 |
String endorseddirsOpt = options.get(ENDORSEDDIRS); |
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
6151
diff
changeset
|
363 |
String extdirsOpt = options.get(EXTDIRS); |
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
6151
diff
changeset
|
364 |
String xbootclasspathPrependOpt = options.get(XBOOTCLASSPATH_PREPEND); |
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
6151
diff
changeset
|
365 |
String xbootclasspathAppendOpt = options.get(XBOOTCLASSPATH_APPEND); |
10 | 366 |
|
7335
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
6151
diff
changeset
|
367 |
path.addFiles(xbootclasspathPrependOpt); |
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
6151
diff
changeset
|
368 |
|
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
6151
diff
changeset
|
369 |
if (endorseddirsOpt != null) |
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
6151
diff
changeset
|
370 |
path.addDirectories(endorseddirsOpt); |
10 | 371 |
else |
372 |
path.addDirectories(System.getProperty("java.endorsed.dirs"), false); |
|
373 |
||
7335
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
6151
diff
changeset
|
374 |
if (bootclasspathOpt != null) { |
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
6151
diff
changeset
|
375 |
path.addFiles(bootclasspathOpt); |
10 | 376 |
} else { |
377 |
// Standard system classes for this compiler's release. |
|
378 |
String files = System.getProperty("sun.boot.class.path"); |
|
379 |
path.addFiles(files, false); |
|
380 |
File rt_jar = new File("rt.jar"); |
|
1486 | 381 |
for (File file : getPathEntries(files)) { |
382 |
if (new File(file.getName()).equals(rt_jar)) |
|
383 |
bootClassPathRtJar = file; |
|
10 | 384 |
} |
385 |
} |
|
386 |
||
7335
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
6151
diff
changeset
|
387 |
path.addFiles(xbootclasspathAppendOpt); |
10 | 388 |
|
389 |
// Strictly speaking, standard extensions are not bootstrap |
|
390 |
// classes, but we treat them identically, so we'll pretend |
|
391 |
// that they are. |
|
7335
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
6151
diff
changeset
|
392 |
if (extdirsOpt != null) |
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
6151
diff
changeset
|
393 |
path.addDirectories(extdirsOpt); |
10 | 394 |
else |
395 |
path.addDirectories(System.getProperty("java.ext.dirs"), false); |
|
396 |
||
7335
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
6151
diff
changeset
|
397 |
isDefaultBootClassPath = |
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
6151
diff
changeset
|
398 |
(xbootclasspathPrependOpt == null) && |
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
6151
diff
changeset
|
399 |
(bootclasspathOpt == null) && |
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
6151
diff
changeset
|
400 |
(xbootclasspathAppendOpt == null); |
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
6151
diff
changeset
|
401 |
|
10 | 402 |
return path; |
403 |
} |
|
404 |
||
405 |
private Path computeUserClassPath() { |
|
406 |
String cp = options.get(CLASSPATH); |
|
407 |
||
408 |
// CLASSPATH environment variable when run from `javac'. |
|
409 |
if (cp == null) cp = System.getProperty("env.class.path"); |
|
410 |
||
411 |
// If invoked via a java VM (not the javac launcher), use the |
|
412 |
// platform class path |
|
413 |
if (cp == null && System.getProperty("application.home") == null) |
|
414 |
cp = System.getProperty("java.class.path"); |
|
415 |
||
416 |
// Default to current working directory. |
|
417 |
if (cp == null) cp = "."; |
|
418 |
||
419 |
return new Path() |
|
1486 | 420 |
.expandJarClassPaths(true) // Only search user jars for Class-Paths |
421 |
.emptyPathDefault(new File(".")) // Empty path elt ==> current directory |
|
10 | 422 |
.addFiles(cp); |
423 |
} |
|
424 |
||
425 |
private Path computeSourcePath() { |
|
426 |
String sourcePathArg = options.get(SOURCEPATH); |
|
427 |
if (sourcePathArg == null) |
|
428 |
return null; |
|
429 |
||
430 |
return new Path().addFiles(sourcePathArg); |
|
431 |
} |
|
432 |
||
433 |
private Path computeAnnotationProcessorPath() { |
|
434 |
String processorPathArg = options.get(PROCESSORPATH); |
|
435 |
if (processorPathArg == null) |
|
436 |
return null; |
|
437 |
||
438 |
return new Path().addFiles(processorPathArg); |
|
439 |
} |
|
440 |
||
441 |
/** The actual effective locations searched for sources */ |
|
442 |
private Path sourceSearchPath; |
|
443 |
||
444 |
public Collection<File> sourceSearchPath() { |
|
445 |
if (sourceSearchPath == null) { |
|
446 |
lazy(); |
|
447 |
Path sourcePath = getPathForLocation(SOURCE_PATH); |
|
448 |
Path userClassPath = getPathForLocation(CLASS_PATH); |
|
449 |
sourceSearchPath = sourcePath != null ? sourcePath : userClassPath; |
|
450 |
} |
|
451 |
return Collections.unmodifiableCollection(sourceSearchPath); |
|
452 |
} |
|
453 |
||
454 |
/** The actual effective locations searched for classes */ |
|
455 |
private Path classSearchPath; |
|
456 |
||
457 |
public Collection<File> classSearchPath() { |
|
458 |
if (classSearchPath == null) { |
|
459 |
lazy(); |
|
460 |
Path bootClassPath = getPathForLocation(PLATFORM_CLASS_PATH); |
|
461 |
Path userClassPath = getPathForLocation(CLASS_PATH); |
|
462 |
classSearchPath = new Path(); |
|
463 |
classSearchPath.addAll(bootClassPath); |
|
464 |
classSearchPath.addAll(userClassPath); |
|
465 |
} |
|
466 |
return Collections.unmodifiableCollection(classSearchPath); |
|
467 |
} |
|
468 |
||
469 |
/** The actual effective locations for non-source, non-class files */ |
|
470 |
private Path otherSearchPath; |
|
471 |
||
472 |
Collection<File> otherSearchPath() { |
|
473 |
if (otherSearchPath == null) { |
|
474 |
lazy(); |
|
475 |
Path userClassPath = getPathForLocation(CLASS_PATH); |
|
476 |
Path sourcePath = getPathForLocation(SOURCE_PATH); |
|
477 |
if (sourcePath == null) |
|
478 |
otherSearchPath = userClassPath; |
|
479 |
else { |
|
480 |
otherSearchPath = new Path(); |
|
481 |
otherSearchPath.addAll(userClassPath); |
|
482 |
otherSearchPath.addAll(sourcePath); |
|
483 |
} |
|
484 |
} |
|
485 |
return Collections.unmodifiableCollection(otherSearchPath); |
|
486 |
} |
|
487 |
||
488 |
/** Is this the name of an archive file? */ |
|
1208 | 489 |
private boolean isArchive(File file) { |
10 | 490 |
String n = file.getName().toLowerCase(); |
1208 | 491 |
return fsInfo.isFile(file) |
10 | 492 |
&& (n.endsWith(".jar") || n.endsWith(".zip")); |
493 |
} |
|
4937
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
494 |
|
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
495 |
/** |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
496 |
* Utility method for converting a search path string to an array |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
497 |
* of directory and JAR file URLs. |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
498 |
* |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
499 |
* 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
|
500 |
* |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
501 |
* @param path the search path string |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
502 |
* @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
|
503 |
*/ |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
504 |
public static URL[] pathToURLs(String path) { |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
505 |
StringTokenizer st = new StringTokenizer(path, File.pathSeparator); |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
506 |
URL[] urls = new URL[st.countTokens()]; |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
507 |
int count = 0; |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
508 |
while (st.hasMoreTokens()) { |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
509 |
URL url = fileToURL(new File(st.nextToken())); |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
510 |
if (url != null) { |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
511 |
urls[count++] = url; |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
512 |
} |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
513 |
} |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
514 |
if (urls.length != count) { |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
515 |
URL[] tmp = new URL[count]; |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
516 |
System.arraycopy(urls, 0, tmp, 0, count); |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
517 |
urls = tmp; |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
518 |
} |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
519 |
return urls; |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
520 |
} |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
521 |
|
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
522 |
/** |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
523 |
* Returns the directory or JAR file URL corresponding to the specified |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
524 |
* local file name. |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
525 |
* |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
526 |
* @param file the File object |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
527 |
* @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
|
528 |
*/ |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
529 |
private static URL fileToURL(File file) { |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
530 |
String name; |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
531 |
try { |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
532 |
name = file.getCanonicalPath(); |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
533 |
} catch (IOException e) { |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
534 |
name = file.getAbsolutePath(); |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
535 |
} |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
536 |
name = name.replace(File.separatorChar, '/'); |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
537 |
if (!name.startsWith("/")) { |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
538 |
name = "/" + name; |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
539 |
} |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
540 |
// 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
|
541 |
if (!file.isFile()) { |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
542 |
name = name + "/"; |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
543 |
} |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
544 |
try { |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
545 |
return new URL("file", "", name); |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
546 |
} catch (MalformedURLException e) { |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
547 |
throw new IllegalArgumentException(file.toString()); |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
548 |
} |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
549 |
} |
10 | 550 |
} |