author | jjg |
Wed, 19 Oct 2011 15:29:46 -0700 | |
changeset 10813 | 95b39a692cd0 |
parent 8837 | 141b22c7e7b2 |
child 10818 | e95eb04c68cc |
permissions | -rw-r--r-- |
10 | 1 |
/* |
8034
d3b29ef9c062
6430241: Hard to disable symbol file feature through API
jjg
parents:
7840
diff
changeset
|
2 |
* Copyright (c) 2005, 2011, 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:
657
diff
changeset
|
26 |
package com.sun.tools.javac.file; |
10 | 27 |
|
28 |
import java.io.ByteArrayOutputStream; |
|
29 |
import java.io.File; |
|
30 |
import java.io.FileNotFoundException; |
|
31 |
import java.io.IOException; |
|
32 |
import java.io.OutputStreamWriter; |
|
33 |
import java.net.MalformedURLException; |
|
34 |
import java.net.URI; |
|
3782 | 35 |
import java.net.URISyntaxException; |
10 | 36 |
import java.net.URL; |
37 |
import java.nio.CharBuffer; |
|
38 |
import java.nio.charset.Charset; |
|
39 |
import java.util.ArrayList; |
|
40 |
import java.util.Arrays; |
|
41 |
import java.util.Collection; |
|
42 |
import java.util.Collections; |
|
10813
95b39a692cd0
7101146: Paths should more directly managed by BaseFileManager
jjg
parents:
8837
diff
changeset
|
43 |
import java.util.Comparator; |
10 | 44 |
import java.util.EnumSet; |
45 |
import java.util.HashMap; |
|
46 |
import java.util.Iterator; |
|
47 |
import java.util.Map; |
|
48 |
import java.util.Set; |
|
49 |
import java.util.zip.ZipFile; |
|
50 |
||
51 |
import javax.lang.model.SourceVersion; |
|
52 |
import javax.tools.FileObject; |
|
53 |
import javax.tools.JavaFileManager; |
|
54 |
import javax.tools.JavaFileObject; |
|
731
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
657
diff
changeset
|
55 |
import javax.tools.StandardJavaFileManager; |
10 | 56 |
|
10813
95b39a692cd0
7101146: Paths should more directly managed by BaseFileManager
jjg
parents:
8837
diff
changeset
|
57 |
import com.sun.tools.javac.code.Lint; |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
58 |
import com.sun.tools.javac.file.RelativePath.RelativeFile; |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
59 |
import com.sun.tools.javac.file.RelativePath.RelativeDirectory; |
731
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
657
diff
changeset
|
60 |
import com.sun.tools.javac.main.OptionName; |
4548 | 61 |
import com.sun.tools.javac.util.BaseFileManager; |
731
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
657
diff
changeset
|
62 |
import com.sun.tools.javac.util.Context; |
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
657
diff
changeset
|
63 |
import com.sun.tools.javac.util.List; |
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
657
diff
changeset
|
64 |
import com.sun.tools.javac.util.ListBuffer; |
10 | 65 |
|
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
66 |
import static javax.tools.StandardLocation.*; |
10 | 67 |
import static com.sun.tools.javac.main.OptionName.*; |
68 |
||
69 |
/** |
|
70 |
* This class provides access to the source, class and other files |
|
71 |
* used by the compiler and related tools. |
|
3380
a6c2bcab0fec
6865399: some javac files are missing Sun internal API comment
jjg
parents:
1789
diff
changeset
|
72 |
* |
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
73 |
* <p><b>This is NOT part of any supported API. |
3380
a6c2bcab0fec
6865399: some javac files are missing Sun internal API comment
jjg
parents:
1789
diff
changeset
|
74 |
* If you write code that depends on this, you do so at your own risk. |
a6c2bcab0fec
6865399: some javac files are missing Sun internal API comment
jjg
parents:
1789
diff
changeset
|
75 |
* This code and its internal interfaces are subject to change or |
a6c2bcab0fec
6865399: some javac files are missing Sun internal API comment
jjg
parents:
1789
diff
changeset
|
76 |
* deletion without notice.</b> |
10 | 77 |
*/ |
4548 | 78 |
public class JavacFileManager extends BaseFileManager implements StandardJavaFileManager { |
10 | 79 |
|
80 |
public static char[] toArray(CharBuffer buffer) { |
|
81 |
if (buffer.hasArray()) |
|
82 |
return ((CharBuffer)buffer.compact().flip()).array(); |
|
83 |
else |
|
84 |
return buffer.toString().toCharArray(); |
|
85 |
} |
|
86 |
||
1208
5072b0dd3d52
6743107: clean up use of static caches in file manager
jjg
parents:
1205
diff
changeset
|
87 |
private FSInfo fsInfo; |
5072b0dd3d52
6743107: clean up use of static caches in file manager
jjg
parents:
1205
diff
changeset
|
88 |
|
8837 | 89 |
private boolean contextUseOptimizedZip; |
8223
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
8034
diff
changeset
|
90 |
private ZipFileIndexCache zipFileIndexCache; |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
8034
diff
changeset
|
91 |
|
10 | 92 |
private final File uninited = new File("U N I N I T E D"); |
93 |
||
94 |
private final Set<JavaFileObject.Kind> sourceOrClass = |
|
95 |
EnumSet.of(JavaFileObject.Kind.SOURCE, JavaFileObject.Kind.CLASS); |
|
96 |
||
97 |
/** The standard output directory, primarily used for classes. |
|
98 |
* Initialized by the "-d" option. |
|
99 |
* If classOutDir = null, files are written into same directory as the sources |
|
100 |
* they were generated from. |
|
101 |
*/ |
|
102 |
private File classOutDir = uninited; |
|
103 |
||
104 |
/** The output directory, used when generating sources while processing annotations. |
|
105 |
* Initialized by the "-s" option. |
|
106 |
*/ |
|
107 |
private File sourceOutDir = uninited; |
|
108 |
||
109 |
protected boolean mmappedIO; |
|
110 |
protected boolean ignoreSymbolFile; |
|
111 |
||
7334
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
112 |
protected enum SortFiles implements Comparator<File> { |
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
113 |
FORWARD { |
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
114 |
public int compare(File f1, File f2) { |
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
115 |
return f1.getName().compareTo(f2.getName()); |
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
116 |
} |
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
117 |
}, |
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
118 |
REVERSE { |
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
119 |
public int compare(File f1, File f2) { |
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
120 |
return -f1.getName().compareTo(f2.getName()); |
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
121 |
} |
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
122 |
}; |
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
123 |
}; |
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
124 |
protected SortFiles sortFiles; |
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
125 |
|
10 | 126 |
/** |
127 |
* Register a Context.Factory to create a JavacFileManager. |
|
128 |
*/ |
|
8614 | 129 |
public static void preRegister(Context context) { |
10 | 130 |
context.put(JavaFileManager.class, new Context.Factory<JavaFileManager>() { |
8614 | 131 |
public JavaFileManager make(Context c) { |
132 |
return new JavacFileManager(c, true, null); |
|
10 | 133 |
} |
134 |
}); |
|
135 |
} |
|
136 |
||
137 |
/** |
|
138 |
* Create a JavacFileManager using a given context, optionally registering |
|
139 |
* it as the JavaFileManager for that context. |
|
140 |
*/ |
|
141 |
public JavacFileManager(Context context, boolean register, Charset charset) { |
|
4548 | 142 |
super(charset); |
10 | 143 |
if (register) |
144 |
context.put(JavaFileManager.class, this); |
|
145 |
setContext(context); |
|
146 |
} |
|
147 |
||
148 |
/** |
|
149 |
* Set the context for JavacFileManager. |
|
150 |
*/ |
|
4548 | 151 |
@Override |
10 | 152 |
public void setContext(Context context) { |
4548 | 153 |
super.setContext(context); |
10 | 154 |
|
1208
5072b0dd3d52
6743107: clean up use of static caches in file manager
jjg
parents:
1205
diff
changeset
|
155 |
fsInfo = FSInfo.instance(context); |
10 | 156 |
|
8837 | 157 |
contextUseOptimizedZip = options.getBoolean("useOptimizedZip", true); |
158 |
if (contextUseOptimizedZip) |
|
8223
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
8034
diff
changeset
|
159 |
zipFileIndexCache = ZipFileIndexCache.getSharedInstance(); |
10 | 160 |
|
6721 | 161 |
mmappedIO = options.isSet("mmappedIO"); |
162 |
ignoreSymbolFile = options.isSet("ignore.symbol.file"); |
|
7334
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
163 |
|
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
164 |
String sf = options.get("sortFiles"); |
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
165 |
if (sf != null) { |
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
166 |
sortFiles = (sf.equals("reverse") ? SortFiles.REVERSE : SortFiles.FORWARD); |
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
167 |
} |
10 | 168 |
} |
169 |
||
7335
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
7334
diff
changeset
|
170 |
@Override |
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
7334
diff
changeset
|
171 |
public boolean isDefaultBootClassPath() { |
10813
95b39a692cd0
7101146: Paths should more directly managed by BaseFileManager
jjg
parents:
8837
diff
changeset
|
172 |
return searchPaths.isDefaultBootClassPath(); |
7335
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
7334
diff
changeset
|
173 |
} |
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
7334
diff
changeset
|
174 |
|
10 | 175 |
public JavaFileObject getFileForInput(String name) { |
176 |
return getRegularFile(new File(name)); |
|
177 |
} |
|
178 |
||
179 |
public JavaFileObject getRegularFile(File file) { |
|
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
809
diff
changeset
|
180 |
return new RegularFileObject(this, file); |
10 | 181 |
} |
182 |
||
183 |
public JavaFileObject getFileForOutput(String classname, |
|
184 |
JavaFileObject.Kind kind, |
|
185 |
JavaFileObject sibling) |
|
186 |
throws IOException |
|
187 |
{ |
|
188 |
return getJavaFileForOutput(CLASS_OUTPUT, classname, kind, sibling); |
|
189 |
} |
|
190 |
||
191 |
public Iterable<? extends JavaFileObject> getJavaFileObjectsFromStrings(Iterable<String> names) { |
|
192 |
ListBuffer<File> files = new ListBuffer<File>(); |
|
193 |
for (String name : names) |
|
194 |
files.append(new File(nullCheck(name))); |
|
195 |
return getJavaFileObjectsFromFiles(files.toList()); |
|
196 |
} |
|
197 |
||
198 |
public Iterable<? extends JavaFileObject> getJavaFileObjects(String... names) { |
|
199 |
return getJavaFileObjectsFromStrings(Arrays.asList(nullCheck(names))); |
|
200 |
} |
|
201 |
||
202 |
private static boolean isValidName(String name) { |
|
203 |
// Arguably, isValidName should reject keywords (such as in SourceVersion.isName() ), |
|
204 |
// but the set of keywords depends on the source level, and we don't want |
|
205 |
// impls of JavaFileManager to have to be dependent on the source level. |
|
206 |
// Therefore we simply check that the argument is a sequence of identifiers |
|
207 |
// separated by ".". |
|
208 |
for (String s : name.split("\\.", -1)) { |
|
209 |
if (!SourceVersion.isIdentifier(s)) |
|
210 |
return false; |
|
211 |
} |
|
212 |
return true; |
|
213 |
} |
|
214 |
||
215 |
private static void validateClassName(String className) { |
|
216 |
if (!isValidName(className)) |
|
217 |
throw new IllegalArgumentException("Invalid class name: " + className); |
|
218 |
} |
|
219 |
||
220 |
private static void validatePackageName(String packageName) { |
|
221 |
if (packageName.length() > 0 && !isValidName(packageName)) |
|
222 |
throw new IllegalArgumentException("Invalid packageName name: " + packageName); |
|
223 |
} |
|
224 |
||
225 |
public static void testName(String name, |
|
226 |
boolean isValidPackageName, |
|
227 |
boolean isValidClassName) |
|
228 |
{ |
|
229 |
try { |
|
230 |
validatePackageName(name); |
|
231 |
if (!isValidPackageName) |
|
232 |
throw new AssertionError("Invalid package name accepted: " + name); |
|
233 |
printAscii("Valid package name: \"%s\"", name); |
|
234 |
} catch (IllegalArgumentException e) { |
|
235 |
if (isValidPackageName) |
|
236 |
throw new AssertionError("Valid package name rejected: " + name); |
|
237 |
printAscii("Invalid package name: \"%s\"", name); |
|
238 |
} |
|
239 |
try { |
|
240 |
validateClassName(name); |
|
241 |
if (!isValidClassName) |
|
242 |
throw new AssertionError("Invalid class name accepted: " + name); |
|
243 |
printAscii("Valid class name: \"%s\"", name); |
|
244 |
} catch (IllegalArgumentException e) { |
|
245 |
if (isValidClassName) |
|
246 |
throw new AssertionError("Valid class name rejected: " + name); |
|
247 |
printAscii("Invalid class name: \"%s\"", name); |
|
248 |
} |
|
249 |
} |
|
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
250 |
|
10 | 251 |
private static void printAscii(String format, Object... args) { |
252 |
String message; |
|
253 |
try { |
|
254 |
final String ascii = "US-ASCII"; |
|
255 |
message = new String(String.format(null, format, args).getBytes(ascii), ascii); |
|
256 |
} catch (java.io.UnsupportedEncodingException ex) { |
|
257 |
throw new AssertionError(ex); |
|
258 |
} |
|
259 |
System.out.println(message); |
|
260 |
} |
|
261 |
||
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
262 |
|
10 | 263 |
/** |
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
264 |
* Insert all files in subdirectory subdirectory of directory directory |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
265 |
* which match fileKinds into resultList |
10 | 266 |
*/ |
267 |
private void listDirectory(File directory, |
|
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
268 |
RelativeDirectory subdirectory, |
10 | 269 |
Set<JavaFileObject.Kind> fileKinds, |
270 |
boolean recurse, |
|
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
271 |
ListBuffer<JavaFileObject> resultList) { |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
272 |
File d = subdirectory.getFile(directory); |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
273 |
if (!caseMapCheck(d, subdirectory)) |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
274 |
return; |
10 | 275 |
|
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
276 |
File[] files = d.listFiles(); |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
277 |
if (files == null) |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
278 |
return; |
10 | 279 |
|
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
280 |
if (sortFiles != null) |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
281 |
Arrays.sort(files, sortFiles); |
10 | 282 |
|
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
283 |
for (File f: files) { |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
284 |
String fname = f.getName(); |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
285 |
if (f.isDirectory()) { |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
286 |
if (recurse && SourceVersion.isIdentifier(fname)) { |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
287 |
listDirectory(directory, |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
288 |
new RelativeDirectory(subdirectory, fname), |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
289 |
fileKinds, |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
290 |
recurse, |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
291 |
resultList); |
10 | 292 |
} |
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
293 |
} else { |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
294 |
if (isValidFile(fname, fileKinds)) { |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
295 |
JavaFileObject fe = |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
296 |
new RegularFileObject(this, fname, new File(d, fname)); |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
297 |
resultList.append(fe); |
10 | 298 |
} |
299 |
} |
|
300 |
} |
|
301 |
} |
|
302 |
||
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
303 |
/** |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
304 |
* Insert all files in subdirectory subdirectory of archive archive |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
305 |
* which match fileKinds into resultList |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
306 |
*/ |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
307 |
private void listArchive(Archive archive, |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
308 |
RelativeDirectory subdirectory, |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
309 |
Set<JavaFileObject.Kind> fileKinds, |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
310 |
boolean recurse, |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
311 |
ListBuffer<JavaFileObject> resultList) { |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
312 |
// Get the files directly in the subdir |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
313 |
List<String> files = archive.getFiles(subdirectory); |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
314 |
if (files != null) { |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
315 |
for (; !files.isEmpty(); files = files.tail) { |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
316 |
String file = files.head; |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
317 |
if (isValidFile(file, fileKinds)) { |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
318 |
resultList.append(archive.getFileObject(subdirectory, file)); |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
319 |
} |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
320 |
} |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
321 |
} |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
322 |
if (recurse) { |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
323 |
for (RelativeDirectory s: archive.getSubdirectories()) { |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
324 |
if (subdirectory.contains(s)) { |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
325 |
// Because the archive map is a flat list of directories, |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
326 |
// the enclosing loop will pick up all child subdirectories. |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
327 |
// Therefore, there is no need to recurse deeper. |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
328 |
listArchive(archive, s, fileKinds, false, resultList); |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
329 |
} |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
330 |
} |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
331 |
} |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
332 |
} |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
333 |
|
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
334 |
/** |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
335 |
* container is a directory, a zip file, or a non-existant path. |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
336 |
* Insert all files in subdirectory subdirectory of container which |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
337 |
* match fileKinds into resultList |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
338 |
*/ |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
339 |
private void listContainer(File container, |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
340 |
RelativeDirectory subdirectory, |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
341 |
Set<JavaFileObject.Kind> fileKinds, |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
342 |
boolean recurse, |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
343 |
ListBuffer<JavaFileObject> resultList) { |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
344 |
Archive archive = archives.get(container); |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
345 |
if (archive == null) { |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
346 |
// archives are not created for directories. |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
347 |
if (fsInfo.isDirectory(container)) { |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
348 |
listDirectory(container, |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
349 |
subdirectory, |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
350 |
fileKinds, |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
351 |
recurse, |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
352 |
resultList); |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
353 |
return; |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
354 |
} |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
355 |
|
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
356 |
// Not a directory; either a file or non-existant, create the archive |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
357 |
try { |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
358 |
archive = openArchive(container); |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
359 |
} catch (IOException ex) { |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
360 |
log.error("error.reading.file", |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
361 |
container, getMessage(ex)); |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
362 |
return; |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
363 |
} |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
364 |
} |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
365 |
listArchive(archive, |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
366 |
subdirectory, |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
367 |
fileKinds, |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
368 |
recurse, |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
369 |
resultList); |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
370 |
} |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
371 |
|
10 | 372 |
private boolean isValidFile(String s, Set<JavaFileObject.Kind> fileKinds) { |
4548 | 373 |
JavaFileObject.Kind kind = getKind(s); |
10 | 374 |
return fileKinds.contains(kind); |
375 |
} |
|
376 |
||
377 |
private static final boolean fileSystemIsCaseSensitive = |
|
378 |
File.separatorChar == '/'; |
|
379 |
||
380 |
/** Hack to make Windows case sensitive. Test whether given path |
|
381 |
* ends in a string of characters with the same case as given name. |
|
382 |
* Ignore file separators in both path and name. |
|
383 |
*/ |
|
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
384 |
private boolean caseMapCheck(File f, RelativePath name) { |
10 | 385 |
if (fileSystemIsCaseSensitive) return true; |
386 |
// Note that getCanonicalPath() returns the case-sensitive |
|
387 |
// spelled file name. |
|
388 |
String path; |
|
389 |
try { |
|
390 |
path = f.getCanonicalPath(); |
|
391 |
} catch (IOException ex) { |
|
392 |
return false; |
|
393 |
} |
|
394 |
char[] pcs = path.toCharArray(); |
|
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
395 |
char[] ncs = name.path.toCharArray(); |
10 | 396 |
int i = pcs.length - 1; |
397 |
int j = ncs.length - 1; |
|
398 |
while (i >= 0 && j >= 0) { |
|
399 |
while (i >= 0 && pcs[i] == File.separatorChar) i--; |
|
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
400 |
while (j >= 0 && ncs[j] == '/') j--; |
10 | 401 |
if (i >= 0 && j >= 0) { |
402 |
if (pcs[i] != ncs[j]) return false; |
|
403 |
i--; |
|
404 |
j--; |
|
405 |
} |
|
406 |
} |
|
407 |
return j < 0; |
|
408 |
} |
|
409 |
||
410 |
/** |
|
411 |
* An archive provides a flat directory structure of a ZipFile by |
|
412 |
* mapping directory names to lists of files (basenames). |
|
413 |
*/ |
|
414 |
public interface Archive { |
|
415 |
void close() throws IOException; |
|
416 |
||
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
417 |
boolean contains(RelativePath name); |
10 | 418 |
|
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
419 |
JavaFileObject getFileObject(RelativeDirectory subdirectory, String file); |
10 | 420 |
|
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
421 |
List<String> getFiles(RelativeDirectory subdirectory); |
10 | 422 |
|
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
423 |
Set<RelativeDirectory> getSubdirectories(); |
10 | 424 |
} |
425 |
||
426 |
public class MissingArchive implements Archive { |
|
427 |
final File zipFileName; |
|
428 |
public MissingArchive(File name) { |
|
429 |
zipFileName = name; |
|
430 |
} |
|
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
431 |
public boolean contains(RelativePath name) { |
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
809
diff
changeset
|
432 |
return false; |
10 | 433 |
} |
434 |
||
435 |
public void close() { |
|
436 |
} |
|
437 |
||
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
438 |
public JavaFileObject getFileObject(RelativeDirectory subdirectory, String file) { |
10 | 439 |
return null; |
440 |
} |
|
441 |
||
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
442 |
public List<String> getFiles(RelativeDirectory subdirectory) { |
10 | 443 |
return List.nil(); |
444 |
} |
|
445 |
||
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
446 |
public Set<RelativeDirectory> getSubdirectories() { |
10 | 447 |
return Collections.emptySet(); |
448 |
} |
|
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
449 |
|
3782 | 450 |
@Override |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
451 |
public String toString() { |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
452 |
return "MissingArchive[" + zipFileName + "]"; |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
453 |
} |
10 | 454 |
} |
455 |
||
456 |
/** A directory of zip files already opened. |
|
457 |
*/ |
|
458 |
Map<File, Archive> archives = new HashMap<File,Archive>(); |
|
459 |
||
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
460 |
private static final String[] symbolFileLocation = { "lib", "ct.sym" }; |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
461 |
private static final RelativeDirectory symbolFilePrefix |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
462 |
= new RelativeDirectory("META-INF/sym/rt.jar/"); |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
463 |
|
8837 | 464 |
/* |
465 |
* This method looks for a ZipFormatException and takes appropriate |
|
466 |
* evasive action. If there is a failure in the fast mode then we |
|
467 |
* fail over to the platform zip, and allow it to deal with a potentially |
|
468 |
* non compliant zip file. |
|
469 |
*/ |
|
470 |
protected Archive openArchive(File zipFilename) throws IOException { |
|
471 |
try { |
|
472 |
return openArchive(zipFilename, contextUseOptimizedZip); |
|
473 |
} catch (IOException ioe) { |
|
474 |
if (ioe instanceof ZipFileIndex.ZipFormatException) { |
|
475 |
return openArchive(zipFilename, false); |
|
476 |
} else { |
|
477 |
throw ioe; |
|
478 |
} |
|
479 |
} |
|
480 |
} |
|
481 |
||
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
482 |
/** Open a new zip file directory, and cache it. |
10 | 483 |
*/ |
8837 | 484 |
private Archive openArchive(File zipFileName, boolean useOptimizedZip) throws IOException { |
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
485 |
File origZipFileName = zipFileName; |
10813
95b39a692cd0
7101146: Paths should more directly managed by BaseFileManager
jjg
parents:
8837
diff
changeset
|
486 |
if (!ignoreSymbolFile && searchPaths.isDefaultBootClassPathRtJar(zipFileName)) { |
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
487 |
File file = zipFileName.getParentFile().getParentFile(); // ${java.home} |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
488 |
if (new File(file.getName()).equals(new File("jre"))) |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
489 |
file = file.getParentFile(); |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
490 |
// file == ${jdk.home} |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
491 |
for (String name : symbolFileLocation) |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
492 |
file = new File(file, name); |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
493 |
// file == ${jdk.home}/lib/ct.sym |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
494 |
if (file.exists()) |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
495 |
zipFileName = file; |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
496 |
} |
10 | 497 |
|
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
498 |
Archive archive; |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
499 |
try { |
10 | 500 |
|
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
501 |
ZipFile zdir = null; |
10 | 502 |
|
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
503 |
boolean usePreindexedCache = false; |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
504 |
String preindexCacheLocation = null; |
10 | 505 |
|
8837 | 506 |
if (!useOptimizedZip) { |
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
507 |
zdir = new ZipFile(zipFileName); |
8432
d3380b1e4779
7018859: javac turn off the Zip optimization by default
ksrini
parents:
8223
diff
changeset
|
508 |
} else { |
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
509 |
usePreindexedCache = options.isSet("usezipindex"); |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
510 |
preindexCacheLocation = options.get("java.io.tmpdir"); |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
511 |
String optCacheLoc = options.get("cachezipindexdir"); |
10 | 512 |
|
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
513 |
if (optCacheLoc != null && optCacheLoc.length() != 0) { |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
514 |
if (optCacheLoc.startsWith("\"")) { |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
515 |
if (optCacheLoc.endsWith("\"")) { |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
516 |
optCacheLoc = optCacheLoc.substring(1, optCacheLoc.length() - 1); |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
517 |
} |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
518 |
else { |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
519 |
optCacheLoc = optCacheLoc.substring(1); |
10 | 520 |
} |
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
521 |
} |
10 | 522 |
|
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
523 |
File cacheDir = new File(optCacheLoc); |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
524 |
if (cacheDir.exists() && cacheDir.canWrite()) { |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
525 |
preindexCacheLocation = optCacheLoc; |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
526 |
if (!preindexCacheLocation.endsWith("/") && |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
527 |
!preindexCacheLocation.endsWith(File.separator)) { |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
528 |
preindexCacheLocation += File.separator; |
10 | 529 |
} |
530 |
} |
|
531 |
} |
|
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
532 |
} |
10 | 533 |
|
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
534 |
if (origZipFileName == zipFileName) { |
8837 | 535 |
if (!useOptimizedZip) { |
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
536 |
archive = new ZipArchive(this, zdir); |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
537 |
} else { |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
538 |
archive = new ZipFileIndexArchive(this, |
8837 | 539 |
zipFileIndexCache.getZipFileIndex(zipFileName, |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
540 |
null, |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
541 |
usePreindexedCache, |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
542 |
preindexCacheLocation, |
6721 | 543 |
options.isSet("writezipindexfiles"))); |
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
544 |
} |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
545 |
} else { |
8837 | 546 |
if (!useOptimizedZip) { |
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
547 |
archive = new SymbolArchive(this, origZipFileName, zdir, symbolFilePrefix); |
8837 | 548 |
} else { |
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
549 |
archive = new ZipFileIndexArchive(this, |
8837 | 550 |
zipFileIndexCache.getZipFileIndex(zipFileName, |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
551 |
symbolFilePrefix, |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
552 |
usePreindexedCache, |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
553 |
preindexCacheLocation, |
6721 | 554 |
options.isSet("writezipindexfiles"))); |
10 | 555 |
} |
556 |
} |
|
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
557 |
} catch (FileNotFoundException ex) { |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
558 |
archive = new MissingArchive(zipFileName); |
8837 | 559 |
} catch (ZipFileIndex.ZipFormatException zfe) { |
560 |
throw zfe; |
|
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
561 |
} catch (IOException ex) { |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
562 |
if (zipFileName.exists()) |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
563 |
log.error("error.reading.file", zipFileName, getMessage(ex)); |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
564 |
archive = new MissingArchive(zipFileName); |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
565 |
} |
10 | 566 |
|
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
567 |
archives.put(origZipFileName, archive); |
10 | 568 |
return archive; |
569 |
} |
|
570 |
||
571 |
/** Flush any output resources. |
|
572 |
*/ |
|
573 |
public void flush() { |
|
574 |
contentCache.clear(); |
|
575 |
} |
|
576 |
||
577 |
/** |
|
578 |
* Close the JavaFileManager, releasing resources. |
|
579 |
*/ |
|
580 |
public void close() { |
|
581 |
for (Iterator<Archive> i = archives.values().iterator(); i.hasNext(); ) { |
|
582 |
Archive a = i.next(); |
|
583 |
i.remove(); |
|
584 |
try { |
|
585 |
a.close(); |
|
586 |
} catch (IOException e) { |
|
587 |
} |
|
588 |
} |
|
589 |
} |
|
590 |
||
591 |
private String defaultEncodingName; |
|
592 |
private String getDefaultEncodingName() { |
|
593 |
if (defaultEncodingName == null) { |
|
594 |
defaultEncodingName = |
|
595 |
new OutputStreamWriter(new ByteArrayOutputStream()).getEncoding(); |
|
596 |
} |
|
597 |
return defaultEncodingName; |
|
598 |
} |
|
599 |
||
600 |
public ClassLoader getClassLoader(Location location) { |
|
601 |
nullCheck(location); |
|
602 |
Iterable<? extends File> path = getLocation(location); |
|
603 |
if (path == null) |
|
604 |
return null; |
|
605 |
ListBuffer<URL> lb = new ListBuffer<URL>(); |
|
606 |
for (File f: path) { |
|
607 |
try { |
|
608 |
lb.append(f.toURI().toURL()); |
|
609 |
} catch (MalformedURLException e) { |
|
610 |
throw new AssertionError(e); |
|
611 |
} |
|
612 |
} |
|
3656
d4e34b76b0c3
6558476: com/sun/tools/javac/Main.compile don't release file handles on return
jjg
parents:
3380
diff
changeset
|
613 |
|
4548 | 614 |
return getClassLoader(lb.toArray(new URL[lb.size()])); |
10 | 615 |
} |
616 |
||
617 |
public Iterable<JavaFileObject> list(Location location, |
|
618 |
String packageName, |
|
619 |
Set<JavaFileObject.Kind> kinds, |
|
620 |
boolean recurse) |
|
621 |
throws IOException |
|
622 |
{ |
|
623 |
// validatePackageName(packageName); |
|
624 |
nullCheck(packageName); |
|
625 |
nullCheck(kinds); |
|
626 |
||
627 |
Iterable<? extends File> path = getLocation(location); |
|
628 |
if (path == null) |
|
629 |
return List.nil(); |
|
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
630 |
RelativeDirectory subdirectory = RelativeDirectory.forPackage(packageName); |
10 | 631 |
ListBuffer<JavaFileObject> results = new ListBuffer<JavaFileObject>(); |
632 |
||
633 |
for (File directory : path) |
|
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
634 |
listContainer(directory, subdirectory, kinds, recurse, results); |
10 | 635 |
return results.toList(); |
636 |
} |
|
637 |
||
638 |
public String inferBinaryName(Location location, JavaFileObject file) { |
|
639 |
file.getClass(); // null check |
|
640 |
location.getClass(); // null check |
|
641 |
// Need to match the path semantics of list(location, ...) |
|
642 |
Iterable<? extends File> path = getLocation(location); |
|
643 |
if (path == null) { |
|
644 |
return null; |
|
645 |
} |
|
646 |
||
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
809
diff
changeset
|
647 |
if (file instanceof BaseFileObject) { |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
809
diff
changeset
|
648 |
return ((BaseFileObject) file).inferBinaryName(path); |
10 | 649 |
} else |
650 |
throw new IllegalArgumentException(file.getClass().getName()); |
|
651 |
} |
|
652 |
||
653 |
public boolean isSameFile(FileObject a, FileObject b) { |
|
654 |
nullCheck(a); |
|
655 |
nullCheck(b); |
|
656 |
if (!(a instanceof BaseFileObject)) |
|
657 |
throw new IllegalArgumentException("Not supported: " + a); |
|
658 |
if (!(b instanceof BaseFileObject)) |
|
659 |
throw new IllegalArgumentException("Not supported: " + b); |
|
660 |
return a.equals(b); |
|
661 |
} |
|
662 |
||
663 |
public boolean hasLocation(Location location) { |
|
664 |
return getLocation(location) != null; |
|
665 |
} |
|
666 |
||
667 |
public JavaFileObject getJavaFileForInput(Location location, |
|
668 |
String className, |
|
669 |
JavaFileObject.Kind kind) |
|
670 |
throws IOException |
|
671 |
{ |
|
672 |
nullCheck(location); |
|
673 |
// validateClassName(className); |
|
674 |
nullCheck(className); |
|
675 |
nullCheck(kind); |
|
676 |
if (!sourceOrClass.contains(kind)) |
|
6719
1ce993f87850
6502392: Invalid relative names for Filer.createResource and Filer.getResource
jjg
parents:
5847
diff
changeset
|
677 |
throw new IllegalArgumentException("Invalid kind: " + kind); |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
678 |
return getFileForInput(location, RelativeFile.forClass(className, kind)); |
10 | 679 |
} |
680 |
||
681 |
public FileObject getFileForInput(Location location, |
|
682 |
String packageName, |
|
683 |
String relativeName) |
|
684 |
throws IOException |
|
685 |
{ |
|
686 |
nullCheck(location); |
|
687 |
// validatePackageName(packageName); |
|
688 |
nullCheck(packageName); |
|
3782 | 689 |
if (!isRelativeUri(relativeName)) |
10 | 690 |
throw new IllegalArgumentException("Invalid relative name: " + relativeName); |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
691 |
RelativeFile name = packageName.length() == 0 |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
692 |
? new RelativeFile(relativeName) |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
693 |
: new RelativeFile(RelativeDirectory.forPackage(packageName), relativeName); |
10 | 694 |
return getFileForInput(location, name); |
695 |
} |
|
696 |
||
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
697 |
private JavaFileObject getFileForInput(Location location, RelativeFile name) throws IOException { |
10 | 698 |
Iterable<? extends File> path = getLocation(location); |
699 |
if (path == null) |
|
700 |
return null; |
|
701 |
||
702 |
for (File dir: path) { |
|
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
703 |
Archive a = archives.get(dir); |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
704 |
if (a == null) { |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
705 |
if (fsInfo.isDirectory(dir)) { |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
706 |
File f = name.getFile(dir); |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
707 |
if (f.exists()) |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
708 |
return new RegularFileObject(this, f); |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
709 |
continue; |
10 | 710 |
} |
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
711 |
// Not a directory, create the archive |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
712 |
a = openArchive(dir); |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
713 |
} |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
714 |
// Process the archive |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
715 |
if (a.contains(name)) { |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
716 |
return a.getFileObject(name.dirname(), name.basename()); |
10 | 717 |
} |
718 |
} |
|
719 |
return null; |
|
720 |
} |
|
721 |
||
722 |
public JavaFileObject getJavaFileForOutput(Location location, |
|
723 |
String className, |
|
724 |
JavaFileObject.Kind kind, |
|
725 |
FileObject sibling) |
|
726 |
throws IOException |
|
727 |
{ |
|
728 |
nullCheck(location); |
|
729 |
// validateClassName(className); |
|
730 |
nullCheck(className); |
|
731 |
nullCheck(kind); |
|
732 |
if (!sourceOrClass.contains(kind)) |
|
6719
1ce993f87850
6502392: Invalid relative names for Filer.createResource and Filer.getResource
jjg
parents:
5847
diff
changeset
|
733 |
throw new IllegalArgumentException("Invalid kind: " + kind); |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
734 |
return getFileForOutput(location, RelativeFile.forClass(className, kind), sibling); |
10 | 735 |
} |
736 |
||
737 |
public FileObject getFileForOutput(Location location, |
|
738 |
String packageName, |
|
739 |
String relativeName, |
|
740 |
FileObject sibling) |
|
741 |
throws IOException |
|
742 |
{ |
|
743 |
nullCheck(location); |
|
744 |
// validatePackageName(packageName); |
|
745 |
nullCheck(packageName); |
|
3782 | 746 |
if (!isRelativeUri(relativeName)) |
6719
1ce993f87850
6502392: Invalid relative names for Filer.createResource and Filer.getResource
jjg
parents:
5847
diff
changeset
|
747 |
throw new IllegalArgumentException("Invalid relative name: " + relativeName); |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
748 |
RelativeFile name = packageName.length() == 0 |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
749 |
? new RelativeFile(relativeName) |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
750 |
: new RelativeFile(RelativeDirectory.forPackage(packageName), relativeName); |
10 | 751 |
return getFileForOutput(location, name, sibling); |
752 |
} |
|
753 |
||
754 |
private JavaFileObject getFileForOutput(Location location, |
|
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
755 |
RelativeFile fileName, |
10 | 756 |
FileObject sibling) |
757 |
throws IOException |
|
758 |
{ |
|
759 |
File dir; |
|
760 |
if (location == CLASS_OUTPUT) { |
|
761 |
if (getClassOutDir() != null) { |
|
762 |
dir = getClassOutDir(); |
|
763 |
} else { |
|
764 |
File siblingDir = null; |
|
765 |
if (sibling != null && sibling instanceof RegularFileObject) { |
|
4073
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
766 |
siblingDir = ((RegularFileObject)sibling).file.getParentFile(); |
10 | 767 |
} |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
768 |
return new RegularFileObject(this, new File(siblingDir, fileName.basename())); |
10 | 769 |
} |
770 |
} else if (location == SOURCE_OUTPUT) { |
|
771 |
dir = (getSourceOutDir() != null ? getSourceOutDir() : getClassOutDir()); |
|
772 |
} else { |
|
10813
95b39a692cd0
7101146: Paths should more directly managed by BaseFileManager
jjg
parents:
8837
diff
changeset
|
773 |
Iterable<? extends File> path = searchPaths.getPathForLocation(location); |
10 | 774 |
dir = null; |
775 |
for (File f: path) { |
|
776 |
dir = f; |
|
777 |
break; |
|
778 |
} |
|
779 |
} |
|
780 |
||
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
781 |
File file = fileName.getFile(dir); // null-safe |
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
809
diff
changeset
|
782 |
return new RegularFileObject(this, file); |
10 | 783 |
|
784 |
} |
|
785 |
||
786 |
public Iterable<? extends JavaFileObject> getJavaFileObjectsFromFiles( |
|
787 |
Iterable<? extends File> files) |
|
788 |
{ |
|
789 |
ArrayList<RegularFileObject> result; |
|
1789
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1208
diff
changeset
|
790 |
if (files instanceof Collection<?>) |
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1208
diff
changeset
|
791 |
result = new ArrayList<RegularFileObject>(((Collection<?>)files).size()); |
10 | 792 |
else |
793 |
result = new ArrayList<RegularFileObject>(); |
|
794 |
for (File f: files) |
|
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
809
diff
changeset
|
795 |
result.add(new RegularFileObject(this, nullCheck(f))); |
10 | 796 |
return result; |
797 |
} |
|
798 |
||
799 |
public Iterable<? extends JavaFileObject> getJavaFileObjects(File... files) { |
|
800 |
return getJavaFileObjectsFromFiles(Arrays.asList(nullCheck(files))); |
|
801 |
} |
|
802 |
||
803 |
public void setLocation(Location location, |
|
804 |
Iterable<? extends File> path) |
|
805 |
throws IOException |
|
806 |
{ |
|
807 |
nullCheck(location); |
|
10813
95b39a692cd0
7101146: Paths should more directly managed by BaseFileManager
jjg
parents:
8837
diff
changeset
|
808 |
searchPaths.lazy(); |
10 | 809 |
|
810 |
final File dir = location.isOutputLocation() ? getOutputDirectory(path) : null; |
|
811 |
||
812 |
if (location == CLASS_OUTPUT) |
|
813 |
classOutDir = getOutputLocation(dir, D); |
|
814 |
else if (location == SOURCE_OUTPUT) |
|
815 |
sourceOutDir = getOutputLocation(dir, S); |
|
816 |
else |
|
10813
95b39a692cd0
7101146: Paths should more directly managed by BaseFileManager
jjg
parents:
8837
diff
changeset
|
817 |
searchPaths.setPathForLocation(location, path); |
10 | 818 |
} |
819 |
// where |
|
820 |
private File getOutputDirectory(Iterable<? extends File> path) throws IOException { |
|
821 |
if (path == null) |
|
822 |
return null; |
|
823 |
Iterator<? extends File> pathIter = path.iterator(); |
|
824 |
if (!pathIter.hasNext()) |
|
825 |
throw new IllegalArgumentException("empty path for directory"); |
|
826 |
File dir = pathIter.next(); |
|
827 |
if (pathIter.hasNext()) |
|
828 |
throw new IllegalArgumentException("path too long for directory"); |
|
829 |
if (!dir.exists()) |
|
830 |
throw new FileNotFoundException(dir + ": does not exist"); |
|
831 |
else if (!dir.isDirectory()) |
|
832 |
throw new IOException(dir + ": not a directory"); |
|
833 |
return dir; |
|
834 |
} |
|
835 |
||
836 |
private File getOutputLocation(File dir, OptionName defaultOptionName) { |
|
837 |
if (dir != null) |
|
838 |
return dir; |
|
839 |
String arg = options.get(defaultOptionName); |
|
840 |
if (arg == null) |
|
841 |
return null; |
|
842 |
return new File(arg); |
|
843 |
} |
|
844 |
||
845 |
public Iterable<? extends File> getLocation(Location location) { |
|
846 |
nullCheck(location); |
|
10813
95b39a692cd0
7101146: Paths should more directly managed by BaseFileManager
jjg
parents:
8837
diff
changeset
|
847 |
searchPaths.lazy(); |
10 | 848 |
if (location == CLASS_OUTPUT) { |
849 |
return (getClassOutDir() == null ? null : List.of(getClassOutDir())); |
|
850 |
} else if (location == SOURCE_OUTPUT) { |
|
851 |
return (getSourceOutDir() == null ? null : List.of(getSourceOutDir())); |
|
852 |
} else |
|
10813
95b39a692cd0
7101146: Paths should more directly managed by BaseFileManager
jjg
parents:
8837
diff
changeset
|
853 |
return searchPaths.getPathForLocation(location); |
10 | 854 |
} |
855 |
||
856 |
private File getClassOutDir() { |
|
857 |
if (classOutDir == uninited) |
|
858 |
classOutDir = getOutputLocation(null, D); |
|
859 |
return classOutDir; |
|
860 |
} |
|
861 |
||
862 |
private File getSourceOutDir() { |
|
863 |
if (sourceOutDir == uninited) |
|
864 |
sourceOutDir = getOutputLocation(null, S); |
|
865 |
return sourceOutDir; |
|
866 |
} |
|
867 |
||
868 |
/** |
|
869 |
* Enforces the specification of a "relative" URI as used in |
|
870 |
* {@linkplain #getFileForInput(Location,String,URI) |
|
871 |
* getFileForInput}. This method must follow the rules defined in |
|
872 |
* that method, do not make any changes without consulting the |
|
873 |
* specification. |
|
874 |
*/ |
|
875 |
protected static boolean isRelativeUri(URI uri) { |
|
876 |
if (uri.isAbsolute()) |
|
877 |
return false; |
|
878 |
String path = uri.normalize().getPath(); |
|
879 |
if (path.length() == 0 /* isEmpty() is mustang API */) |
|
880 |
return false; |
|
6719
1ce993f87850
6502392: Invalid relative names for Filer.createResource and Filer.getResource
jjg
parents:
5847
diff
changeset
|
881 |
if (!path.equals(uri.getPath())) // implicitly checks for embedded . and .. |
1ce993f87850
6502392: Invalid relative names for Filer.createResource and Filer.getResource
jjg
parents:
5847
diff
changeset
|
882 |
return false; |
7840 | 883 |
if (path.startsWith("/") || path.startsWith("./") || path.startsWith("../")) |
884 |
return false; |
|
885 |
return true; |
|
10 | 886 |
} |
887 |
||
3782 | 888 |
// Convenience method |
889 |
protected static boolean isRelativeUri(String u) { |
|
890 |
try { |
|
891 |
return isRelativeUri(new URI(u)); |
|
892 |
} catch (URISyntaxException e) { |
|
893 |
return false; |
|
894 |
} |
|
895 |
} |
|
896 |
||
10 | 897 |
/** |
898 |
* Converts a relative file name to a relative URI. This is |
|
899 |
* different from File.toURI as this method does not canonicalize |
|
900 |
* the file before creating the URI. Furthermore, no schema is |
|
901 |
* used. |
|
902 |
* @param file a relative file name |
|
903 |
* @return a relative URI |
|
904 |
* @throws IllegalArgumentException if the file name is not |
|
905 |
* relative according to the definition given in {@link |
|
906 |
* javax.tools.JavaFileManager#getFileForInput} |
|
907 |
*/ |
|
908 |
public static String getRelativeName(File file) { |
|
909 |
if (!file.isAbsolute()) { |
|
910 |
String result = file.getPath().replace(File.separatorChar, '/'); |
|
3782 | 911 |
if (isRelativeUri(result)) |
10 | 912 |
return result; |
913 |
} |
|
914 |
throw new IllegalArgumentException("Invalid relative path: " + file); |
|
915 |
} |
|
5007
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
916 |
|
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
917 |
/** |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
918 |
* Get a detail message from an IOException. |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
919 |
* Most, but not all, instances of IOException provide a non-null result |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
920 |
* for getLocalizedMessage(). But some instances return null: in these |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
921 |
* cases, fallover to getMessage(), and if even that is null, return the |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
922 |
* name of the exception itself. |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
923 |
* @param e an IOException |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
924 |
* @return a string to include in a compiler diagnostic |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
925 |
*/ |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
926 |
public static String getMessage(IOException e) { |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
927 |
String s = e.getLocalizedMessage(); |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
928 |
if (s != null) |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
929 |
return s; |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
930 |
s = e.getMessage(); |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
931 |
if (s != null) |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
932 |
return s; |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
933 |
return e.toString(); |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
934 |
} |
10 | 935 |
} |