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