author | mchung |
Fri, 20 Jun 2014 13:36:10 -0700 | |
changeset 25303 | 5f9e68207588 |
parent 24897 | 655b72d7b96e |
permissions | -rw-r--r-- |
10 | 1 |
/* |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
2 |
* Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved. |
10 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
10 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5520 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
10 | 24 |
*/ |
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 |
|
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; |
4548 | 59 |
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
|
60 |
import com.sun.tools.javac.util.Context; |
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
657
diff
changeset
|
61 |
import com.sun.tools.javac.util.List; |
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
657
diff
changeset
|
62 |
import com.sun.tools.javac.util.ListBuffer; |
10 | 63 |
|
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
64 |
import static javax.tools.StandardLocation.*; |
10 | 65 |
|
66 |
/** |
|
67 |
* This class provides access to the source, class and other files |
|
68 |
* used by the compiler and related tools. |
|
3380
a6c2bcab0fec
6865399: some javac files are missing Sun internal API comment
jjg
parents:
1789
diff
changeset
|
69 |
* |
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
70 |
* <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
|
71 |
* 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
|
72 |
* 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
|
73 |
* deletion without notice.</b> |
10 | 74 |
*/ |
4548 | 75 |
public class JavacFileManager extends BaseFileManager implements StandardJavaFileManager { |
10 | 76 |
|
77 |
public static char[] toArray(CharBuffer buffer) { |
|
78 |
if (buffer.hasArray()) |
|
79 |
return ((CharBuffer)buffer.compact().flip()).array(); |
|
80 |
else |
|
81 |
return buffer.toString().toCharArray(); |
|
82 |
} |
|
83 |
||
1208
5072b0dd3d52
6743107: clean up use of static caches in file manager
jjg
parents:
1205
diff
changeset
|
84 |
private FSInfo fsInfo; |
5072b0dd3d52
6743107: clean up use of static caches in file manager
jjg
parents:
1205
diff
changeset
|
85 |
|
8837 | 86 |
private boolean contextUseOptimizedZip; |
8223
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
8034
diff
changeset
|
87 |
private ZipFileIndexCache zipFileIndexCache; |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
8034
diff
changeset
|
88 |
|
10 | 89 |
private final Set<JavaFileObject.Kind> sourceOrClass = |
90 |
EnumSet.of(JavaFileObject.Kind.SOURCE, JavaFileObject.Kind.CLASS); |
|
91 |
||
92 |
protected boolean mmappedIO; |
|
14362
598fd301e4de
8001229: refactor javac so that ct.sym is just used for javac, not all clients of JavacFileManager
jjg
parents:
14259
diff
changeset
|
93 |
protected boolean symbolFileEnabled; |
10 | 94 |
|
7334
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
95 |
protected enum SortFiles implements Comparator<File> { |
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
96 |
FORWARD { |
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
97 |
public int compare(File f1, File f2) { |
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
98 |
return f1.getName().compareTo(f2.getName()); |
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
99 |
} |
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
100 |
}, |
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
101 |
REVERSE { |
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
102 |
public int compare(File f1, File f2) { |
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
103 |
return -f1.getName().compareTo(f2.getName()); |
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
104 |
} |
22163 | 105 |
} |
106 |
} |
|
107 |
||
7334
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
108 |
protected SortFiles sortFiles; |
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
109 |
|
10 | 110 |
/** |
111 |
* Register a Context.Factory to create a JavacFileManager. |
|
112 |
*/ |
|
8614 | 113 |
public static void preRegister(Context context) { |
10 | 114 |
context.put(JavaFileManager.class, new Context.Factory<JavaFileManager>() { |
8614 | 115 |
public JavaFileManager make(Context c) { |
116 |
return new JavacFileManager(c, true, null); |
|
10 | 117 |
} |
118 |
}); |
|
119 |
} |
|
120 |
||
121 |
/** |
|
122 |
* Create a JavacFileManager using a given context, optionally registering |
|
123 |
* it as the JavaFileManager for that context. |
|
124 |
*/ |
|
125 |
public JavacFileManager(Context context, boolean register, Charset charset) { |
|
4548 | 126 |
super(charset); |
10 | 127 |
if (register) |
128 |
context.put(JavaFileManager.class, this); |
|
129 |
setContext(context); |
|
130 |
} |
|
131 |
||
132 |
/** |
|
133 |
* Set the context for JavacFileManager. |
|
134 |
*/ |
|
4548 | 135 |
@Override |
10 | 136 |
public void setContext(Context context) { |
4548 | 137 |
super.setContext(context); |
10 | 138 |
|
1208
5072b0dd3d52
6743107: clean up use of static caches in file manager
jjg
parents:
1205
diff
changeset
|
139 |
fsInfo = FSInfo.instance(context); |
10 | 140 |
|
8837 | 141 |
contextUseOptimizedZip = options.getBoolean("useOptimizedZip", true); |
142 |
if (contextUseOptimizedZip) |
|
8223
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
8034
diff
changeset
|
143 |
zipFileIndexCache = ZipFileIndexCache.getSharedInstance(); |
10 | 144 |
|
6721 | 145 |
mmappedIO = options.isSet("mmappedIO"); |
14362
598fd301e4de
8001229: refactor javac so that ct.sym is just used for javac, not all clients of JavacFileManager
jjg
parents:
14259
diff
changeset
|
146 |
symbolFileEnabled = !options.isSet("ignore.symbol.file"); |
7334
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
147 |
|
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
148 |
String sf = options.get("sortFiles"); |
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
149 |
if (sf != null) { |
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
150 |
sortFiles = (sf.equals("reverse") ? SortFiles.REVERSE : SortFiles.FORWARD); |
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
151 |
} |
10 | 152 |
} |
153 |
||
14362
598fd301e4de
8001229: refactor javac so that ct.sym is just used for javac, not all clients of JavacFileManager
jjg
parents:
14259
diff
changeset
|
154 |
/** |
598fd301e4de
8001229: refactor javac so that ct.sym is just used for javac, not all clients of JavacFileManager
jjg
parents:
14259
diff
changeset
|
155 |
* Set whether or not to use ct.sym as an alternate to rt.jar. |
598fd301e4de
8001229: refactor javac so that ct.sym is just used for javac, not all clients of JavacFileManager
jjg
parents:
14259
diff
changeset
|
156 |
*/ |
598fd301e4de
8001229: refactor javac so that ct.sym is just used for javac, not all clients of JavacFileManager
jjg
parents:
14259
diff
changeset
|
157 |
public void setSymbolFileEnabled(boolean b) { |
598fd301e4de
8001229: refactor javac so that ct.sym is just used for javac, not all clients of JavacFileManager
jjg
parents:
14259
diff
changeset
|
158 |
symbolFileEnabled = b; |
598fd301e4de
8001229: refactor javac so that ct.sym is just used for javac, not all clients of JavacFileManager
jjg
parents:
14259
diff
changeset
|
159 |
} |
598fd301e4de
8001229: refactor javac so that ct.sym is just used for javac, not all clients of JavacFileManager
jjg
parents:
14259
diff
changeset
|
160 |
|
10 | 161 |
public JavaFileObject getFileForInput(String name) { |
162 |
return getRegularFile(new File(name)); |
|
163 |
} |
|
164 |
||
165 |
public JavaFileObject getRegularFile(File file) { |
|
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
809
diff
changeset
|
166 |
return new RegularFileObject(this, file); |
10 | 167 |
} |
168 |
||
169 |
public JavaFileObject getFileForOutput(String classname, |
|
170 |
JavaFileObject.Kind kind, |
|
171 |
JavaFileObject sibling) |
|
172 |
throws IOException |
|
173 |
{ |
|
174 |
return getJavaFileForOutput(CLASS_OUTPUT, classname, kind, sibling); |
|
175 |
} |
|
176 |
||
177 |
public Iterable<? extends JavaFileObject> getJavaFileObjectsFromStrings(Iterable<String> names) { |
|
22163 | 178 |
ListBuffer<File> files = new ListBuffer<>(); |
10 | 179 |
for (String name : names) |
180 |
files.append(new File(nullCheck(name))); |
|
181 |
return getJavaFileObjectsFromFiles(files.toList()); |
|
182 |
} |
|
183 |
||
184 |
public Iterable<? extends JavaFileObject> getJavaFileObjects(String... names) { |
|
185 |
return getJavaFileObjectsFromStrings(Arrays.asList(nullCheck(names))); |
|
186 |
} |
|
187 |
||
188 |
private static boolean isValidName(String name) { |
|
189 |
// Arguably, isValidName should reject keywords (such as in SourceVersion.isName() ), |
|
190 |
// but the set of keywords depends on the source level, and we don't want |
|
191 |
// impls of JavaFileManager to have to be dependent on the source level. |
|
192 |
// Therefore we simply check that the argument is a sequence of identifiers |
|
193 |
// separated by ".". |
|
194 |
for (String s : name.split("\\.", -1)) { |
|
195 |
if (!SourceVersion.isIdentifier(s)) |
|
196 |
return false; |
|
197 |
} |
|
198 |
return true; |
|
199 |
} |
|
200 |
||
201 |
private static void validateClassName(String className) { |
|
202 |
if (!isValidName(className)) |
|
203 |
throw new IllegalArgumentException("Invalid class name: " + className); |
|
204 |
} |
|
205 |
||
206 |
private static void validatePackageName(String packageName) { |
|
207 |
if (packageName.length() > 0 && !isValidName(packageName)) |
|
208 |
throw new IllegalArgumentException("Invalid packageName name: " + packageName); |
|
209 |
} |
|
210 |
||
211 |
public static void testName(String name, |
|
212 |
boolean isValidPackageName, |
|
213 |
boolean isValidClassName) |
|
214 |
{ |
|
215 |
try { |
|
216 |
validatePackageName(name); |
|
217 |
if (!isValidPackageName) |
|
218 |
throw new AssertionError("Invalid package name accepted: " + name); |
|
219 |
printAscii("Valid package name: \"%s\"", name); |
|
220 |
} catch (IllegalArgumentException e) { |
|
221 |
if (isValidPackageName) |
|
222 |
throw new AssertionError("Valid package name rejected: " + name); |
|
223 |
printAscii("Invalid package name: \"%s\"", name); |
|
224 |
} |
|
225 |
try { |
|
226 |
validateClassName(name); |
|
227 |
if (!isValidClassName) |
|
228 |
throw new AssertionError("Invalid class name accepted: " + name); |
|
229 |
printAscii("Valid class name: \"%s\"", name); |
|
230 |
} catch (IllegalArgumentException e) { |
|
231 |
if (isValidClassName) |
|
232 |
throw new AssertionError("Valid class name rejected: " + name); |
|
233 |
printAscii("Invalid class name: \"%s\"", name); |
|
234 |
} |
|
235 |
} |
|
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
236 |
|
10 | 237 |
private static void printAscii(String format, Object... args) { |
238 |
String message; |
|
239 |
try { |
|
240 |
final String ascii = "US-ASCII"; |
|
241 |
message = new String(String.format(null, format, args).getBytes(ascii), ascii); |
|
242 |
} catch (java.io.UnsupportedEncodingException ex) { |
|
243 |
throw new AssertionError(ex); |
|
244 |
} |
|
245 |
System.out.println(message); |
|
246 |
} |
|
247 |
||
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
248 |
|
10 | 249 |
/** |
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
250 |
* 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
|
251 |
* which match fileKinds into resultList |
10 | 252 |
*/ |
253 |
private void listDirectory(File directory, |
|
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
254 |
RelativeDirectory subdirectory, |
10 | 255 |
Set<JavaFileObject.Kind> fileKinds, |
256 |
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
|
257 |
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
|
258 |
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
|
259 |
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
|
260 |
return; |
10 | 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 |
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
|
263 |
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
|
264 |
return; |
10 | 265 |
|
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
266 |
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
|
267 |
Arrays.sort(files, sortFiles); |
10 | 268 |
|
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
269 |
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
|
270 |
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
|
271 |
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
|
272 |
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
|
273 |
listDirectory(directory, |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
274 |
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
|
275 |
fileKinds, |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
276 |
recurse, |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
277 |
resultList); |
10 | 278 |
} |
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
279 |
} else { |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
280 |
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
|
281 |
JavaFileObject fe = |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
282 |
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
|
283 |
resultList.append(fe); |
10 | 284 |
} |
285 |
} |
|
286 |
} |
|
287 |
} |
|
288 |
||
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
289 |
/** |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
290 |
* 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
|
291 |
* 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
|
292 |
*/ |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
293 |
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
|
294 |
RelativeDirectory subdirectory, |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
295 |
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
|
296 |
boolean recurse, |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
297 |
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
|
298 |
// 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
|
299 |
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
|
300 |
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
|
301 |
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
|
302 |
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
|
303 |
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
|
304 |
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
|
305 |
} |
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 |
} |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
308 |
if (recurse) { |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
309 |
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
|
310 |
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
|
311 |
// 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
|
312 |
// 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
|
313 |
// 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
|
314 |
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
|
315 |
} |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
316 |
} |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
317 |
} |
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 |
|
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 |
* 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
|
322 |
* 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
|
323 |
* 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
|
324 |
*/ |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
325 |
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
|
326 |
RelativeDirectory subdirectory, |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
327 |
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
|
328 |
boolean recurse, |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
329 |
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
|
330 |
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
|
331 |
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
|
332 |
// 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
|
333 |
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
|
334 |
listDirectory(container, |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
335 |
subdirectory, |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
336 |
fileKinds, |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
337 |
recurse, |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
338 |
resultList); |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
339 |
return; |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
340 |
} |
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 |
// 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
|
343 |
try { |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
344 |
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
|
345 |
} 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
|
346 |
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
|
347 |
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
|
348 |
return; |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
349 |
} |
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 |
listArchive(archive, |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
352 |
subdirectory, |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
353 |
fileKinds, |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
354 |
recurse, |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
355 |
resultList); |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
356 |
} |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
357 |
|
10 | 358 |
private boolean isValidFile(String s, Set<JavaFileObject.Kind> fileKinds) { |
4548 | 359 |
JavaFileObject.Kind kind = getKind(s); |
10 | 360 |
return fileKinds.contains(kind); |
361 |
} |
|
362 |
||
363 |
private static final boolean fileSystemIsCaseSensitive = |
|
364 |
File.separatorChar == '/'; |
|
365 |
||
366 |
/** Hack to make Windows case sensitive. Test whether given path |
|
367 |
* ends in a string of characters with the same case as given name. |
|
368 |
* Ignore file separators in both path and name. |
|
369 |
*/ |
|
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
370 |
private boolean caseMapCheck(File f, RelativePath name) { |
10 | 371 |
if (fileSystemIsCaseSensitive) return true; |
372 |
// Note that getCanonicalPath() returns the case-sensitive |
|
373 |
// spelled file name. |
|
374 |
String path; |
|
375 |
try { |
|
376 |
path = f.getCanonicalPath(); |
|
377 |
} catch (IOException ex) { |
|
378 |
return false; |
|
379 |
} |
|
380 |
char[] pcs = path.toCharArray(); |
|
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
381 |
char[] ncs = name.path.toCharArray(); |
10 | 382 |
int i = pcs.length - 1; |
383 |
int j = ncs.length - 1; |
|
384 |
while (i >= 0 && j >= 0) { |
|
385 |
while (i >= 0 && pcs[i] == File.separatorChar) i--; |
|
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
386 |
while (j >= 0 && ncs[j] == '/') j--; |
10 | 387 |
if (i >= 0 && j >= 0) { |
388 |
if (pcs[i] != ncs[j]) return false; |
|
389 |
i--; |
|
390 |
j--; |
|
391 |
} |
|
392 |
} |
|
393 |
return j < 0; |
|
394 |
} |
|
395 |
||
396 |
/** |
|
397 |
* An archive provides a flat directory structure of a ZipFile by |
|
398 |
* mapping directory names to lists of files (basenames). |
|
399 |
*/ |
|
400 |
public interface Archive { |
|
401 |
void close() throws IOException; |
|
402 |
||
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
403 |
boolean contains(RelativePath name); |
10 | 404 |
|
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
405 |
JavaFileObject getFileObject(RelativeDirectory subdirectory, String file); |
10 | 406 |
|
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
407 |
List<String> getFiles(RelativeDirectory subdirectory); |
10 | 408 |
|
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
409 |
Set<RelativeDirectory> getSubdirectories(); |
10 | 410 |
} |
411 |
||
412 |
public class MissingArchive implements Archive { |
|
413 |
final File zipFileName; |
|
414 |
public MissingArchive(File name) { |
|
415 |
zipFileName = name; |
|
416 |
} |
|
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
417 |
public boolean contains(RelativePath name) { |
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
809
diff
changeset
|
418 |
return false; |
10 | 419 |
} |
420 |
||
421 |
public void close() { |
|
422 |
} |
|
423 |
||
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
424 |
public JavaFileObject getFileObject(RelativeDirectory subdirectory, String file) { |
10 | 425 |
return null; |
426 |
} |
|
427 |
||
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
428 |
public List<String> getFiles(RelativeDirectory subdirectory) { |
10 | 429 |
return List.nil(); |
430 |
} |
|
431 |
||
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
432 |
public Set<RelativeDirectory> getSubdirectories() { |
10 | 433 |
return Collections.emptySet(); |
434 |
} |
|
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
435 |
|
3782 | 436 |
@Override |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
437 |
public String toString() { |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
438 |
return "MissingArchive[" + zipFileName + "]"; |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
439 |
} |
10 | 440 |
} |
441 |
||
442 |
/** A directory of zip files already opened. |
|
443 |
*/ |
|
22163 | 444 |
Map<File, Archive> archives = new HashMap<>(); |
10 | 445 |
|
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
446 |
private static final String[] symbolFileLocation = { "lib", "ct.sym" }; |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
447 |
private static final RelativeDirectory symbolFilePrefix |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
448 |
= new RelativeDirectory("META-INF/sym/rt.jar/"); |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
449 |
|
8837 | 450 |
/* |
451 |
* This method looks for a ZipFormatException and takes appropriate |
|
452 |
* evasive action. If there is a failure in the fast mode then we |
|
453 |
* fail over to the platform zip, and allow it to deal with a potentially |
|
454 |
* non compliant zip file. |
|
455 |
*/ |
|
456 |
protected Archive openArchive(File zipFilename) throws IOException { |
|
457 |
try { |
|
458 |
return openArchive(zipFilename, contextUseOptimizedZip); |
|
459 |
} catch (IOException ioe) { |
|
460 |
if (ioe instanceof ZipFileIndex.ZipFormatException) { |
|
461 |
return openArchive(zipFilename, false); |
|
462 |
} else { |
|
463 |
throw ioe; |
|
464 |
} |
|
465 |
} |
|
466 |
} |
|
467 |
||
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
468 |
/** Open a new zip file directory, and cache it. |
10 | 469 |
*/ |
8837 | 470 |
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
|
471 |
File origZipFileName = zipFileName; |
14362
598fd301e4de
8001229: refactor javac so that ct.sym is just used for javac, not all clients of JavacFileManager
jjg
parents:
14259
diff
changeset
|
472 |
if (symbolFileEnabled && locations.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
|
473 |
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
|
474 |
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
|
475 |
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
|
476 |
// 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
|
477 |
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
|
478 |
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
|
479 |
// 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
|
480 |
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
|
481 |
zipFileName = file; |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
482 |
} |
10 | 483 |
|
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
484 |
Archive archive; |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
485 |
try { |
10 | 486 |
|
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
487 |
ZipFile zdir = null; |
10 | 488 |
|
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
489 |
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
|
490 |
String preindexCacheLocation = null; |
10 | 491 |
|
8837 | 492 |
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
|
493 |
zdir = new ZipFile(zipFileName); |
8432
d3380b1e4779
7018859: javac turn off the Zip optimization by default
ksrini
parents:
8223
diff
changeset
|
494 |
} else { |
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
495 |
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
|
496 |
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
|
497 |
String optCacheLoc = options.get("cachezipindexdir"); |
10 | 498 |
|
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
499 |
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
|
500 |
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
|
501 |
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
|
502 |
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
|
503 |
} |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
504 |
else { |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
505 |
optCacheLoc = optCacheLoc.substring(1); |
10 | 506 |
} |
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
507 |
} |
10 | 508 |
|
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
509 |
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
|
510 |
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
|
511 |
preindexCacheLocation = optCacheLoc; |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
512 |
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
|
513 |
!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
|
514 |
preindexCacheLocation += File.separator; |
10 | 515 |
} |
516 |
} |
|
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 |
} |
10 | 519 |
|
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
520 |
if (origZipFileName == zipFileName) { |
8837 | 521 |
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
|
522 |
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
|
523 |
} else { |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
524 |
archive = new ZipFileIndexArchive(this, |
8837 | 525 |
zipFileIndexCache.getZipFileIndex(zipFileName, |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
526 |
null, |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
527 |
usePreindexedCache, |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
528 |
preindexCacheLocation, |
6721 | 529 |
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
|
530 |
} |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
531 |
} else { |
8837 | 532 |
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
|
533 |
archive = new SymbolArchive(this, origZipFileName, zdir, symbolFilePrefix); |
8837 | 534 |
} else { |
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
535 |
archive = new ZipFileIndexArchive(this, |
8837 | 536 |
zipFileIndexCache.getZipFileIndex(zipFileName, |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
537 |
symbolFilePrefix, |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
538 |
usePreindexedCache, |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
539 |
preindexCacheLocation, |
6721 | 540 |
options.isSet("writezipindexfiles"))); |
10 | 541 |
} |
542 |
} |
|
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
543 |
} 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
|
544 |
archive = new MissingArchive(zipFileName); |
8837 | 545 |
} catch (ZipFileIndex.ZipFormatException zfe) { |
546 |
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
|
547 |
} 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
|
548 |
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
|
549 |
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
|
550 |
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
|
551 |
} |
10 | 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 |
archives.put(origZipFileName, archive); |
10 | 554 |
return archive; |
555 |
} |
|
556 |
||
557 |
/** Flush any output resources. |
|
558 |
*/ |
|
559 |
public void flush() { |
|
560 |
contentCache.clear(); |
|
561 |
} |
|
562 |
||
563 |
/** |
|
564 |
* Close the JavaFileManager, releasing resources. |
|
565 |
*/ |
|
566 |
public void close() { |
|
567 |
for (Iterator<Archive> i = archives.values().iterator(); i.hasNext(); ) { |
|
568 |
Archive a = i.next(); |
|
569 |
i.remove(); |
|
570 |
try { |
|
571 |
a.close(); |
|
572 |
} catch (IOException e) { |
|
573 |
} |
|
574 |
} |
|
575 |
} |
|
576 |
||
577 |
public ClassLoader getClassLoader(Location location) { |
|
578 |
nullCheck(location); |
|
579 |
Iterable<? extends File> path = getLocation(location); |
|
580 |
if (path == null) |
|
581 |
return null; |
|
22163 | 582 |
ListBuffer<URL> lb = new ListBuffer<>(); |
10 | 583 |
for (File f: path) { |
584 |
try { |
|
585 |
lb.append(f.toURI().toURL()); |
|
586 |
} catch (MalformedURLException e) { |
|
587 |
throw new AssertionError(e); |
|
588 |
} |
|
589 |
} |
|
3656
d4e34b76b0c3
6558476: com/sun/tools/javac/Main.compile don't release file handles on return
jjg
parents:
3380
diff
changeset
|
590 |
|
4548 | 591 |
return getClassLoader(lb.toArray(new URL[lb.size()])); |
10 | 592 |
} |
593 |
||
594 |
public Iterable<JavaFileObject> list(Location location, |
|
595 |
String packageName, |
|
596 |
Set<JavaFileObject.Kind> kinds, |
|
597 |
boolean recurse) |
|
598 |
throws IOException |
|
599 |
{ |
|
600 |
// validatePackageName(packageName); |
|
601 |
nullCheck(packageName); |
|
602 |
nullCheck(kinds); |
|
603 |
||
604 |
Iterable<? extends File> path = getLocation(location); |
|
605 |
if (path == null) |
|
606 |
return List.nil(); |
|
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
607 |
RelativeDirectory subdirectory = RelativeDirectory.forPackage(packageName); |
22163 | 608 |
ListBuffer<JavaFileObject> results = new ListBuffer<>(); |
10 | 609 |
|
610 |
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
|
611 |
listContainer(directory, subdirectory, kinds, recurse, results); |
10 | 612 |
return results.toList(); |
613 |
} |
|
614 |
||
615 |
public String inferBinaryName(Location location, JavaFileObject file) { |
|
616 |
file.getClass(); // null check |
|
617 |
location.getClass(); // null check |
|
618 |
// Need to match the path semantics of list(location, ...) |
|
619 |
Iterable<? extends File> path = getLocation(location); |
|
620 |
if (path == null) { |
|
621 |
return null; |
|
622 |
} |
|
623 |
||
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
809
diff
changeset
|
624 |
if (file instanceof BaseFileObject) { |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
809
diff
changeset
|
625 |
return ((BaseFileObject) file).inferBinaryName(path); |
10 | 626 |
} else |
627 |
throw new IllegalArgumentException(file.getClass().getName()); |
|
628 |
} |
|
629 |
||
630 |
public boolean isSameFile(FileObject a, FileObject b) { |
|
631 |
nullCheck(a); |
|
632 |
nullCheck(b); |
|
633 |
if (!(a instanceof BaseFileObject)) |
|
634 |
throw new IllegalArgumentException("Not supported: " + a); |
|
635 |
if (!(b instanceof BaseFileObject)) |
|
636 |
throw new IllegalArgumentException("Not supported: " + b); |
|
637 |
return a.equals(b); |
|
638 |
} |
|
639 |
||
640 |
public boolean hasLocation(Location location) { |
|
641 |
return getLocation(location) != null; |
|
642 |
} |
|
643 |
||
644 |
public JavaFileObject getJavaFileForInput(Location location, |
|
645 |
String className, |
|
646 |
JavaFileObject.Kind kind) |
|
647 |
throws IOException |
|
648 |
{ |
|
649 |
nullCheck(location); |
|
650 |
// validateClassName(className); |
|
651 |
nullCheck(className); |
|
652 |
nullCheck(kind); |
|
653 |
if (!sourceOrClass.contains(kind)) |
|
6719
1ce993f87850
6502392: Invalid relative names for Filer.createResource and Filer.getResource
jjg
parents:
5847
diff
changeset
|
654 |
throw new IllegalArgumentException("Invalid kind: " + kind); |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
655 |
return getFileForInput(location, RelativeFile.forClass(className, kind)); |
10 | 656 |
} |
657 |
||
658 |
public FileObject getFileForInput(Location location, |
|
659 |
String packageName, |
|
660 |
String relativeName) |
|
661 |
throws IOException |
|
662 |
{ |
|
663 |
nullCheck(location); |
|
664 |
// validatePackageName(packageName); |
|
665 |
nullCheck(packageName); |
|
3782 | 666 |
if (!isRelativeUri(relativeName)) |
10 | 667 |
throw new IllegalArgumentException("Invalid relative name: " + relativeName); |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
668 |
RelativeFile name = packageName.length() == 0 |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
669 |
? new RelativeFile(relativeName) |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
670 |
: new RelativeFile(RelativeDirectory.forPackage(packageName), relativeName); |
10 | 671 |
return getFileForInput(location, name); |
672 |
} |
|
673 |
||
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
674 |
private JavaFileObject getFileForInput(Location location, RelativeFile name) throws IOException { |
10 | 675 |
Iterable<? extends File> path = getLocation(location); |
676 |
if (path == null) |
|
677 |
return null; |
|
678 |
||
679 |
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
|
680 |
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
|
681 |
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
|
682 |
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
|
683 |
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
|
684 |
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
|
685 |
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
|
686 |
continue; |
10 | 687 |
} |
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
688 |
// 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
|
689 |
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
|
690 |
} |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
691 |
// 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
|
692 |
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
|
693 |
return a.getFileObject(name.dirname(), name.basename()); |
10 | 694 |
} |
695 |
} |
|
696 |
return null; |
|
697 |
} |
|
698 |
||
699 |
public JavaFileObject getJavaFileForOutput(Location location, |
|
700 |
String className, |
|
701 |
JavaFileObject.Kind kind, |
|
702 |
FileObject sibling) |
|
703 |
throws IOException |
|
704 |
{ |
|
705 |
nullCheck(location); |
|
706 |
// validateClassName(className); |
|
707 |
nullCheck(className); |
|
708 |
nullCheck(kind); |
|
709 |
if (!sourceOrClass.contains(kind)) |
|
6719
1ce993f87850
6502392: Invalid relative names for Filer.createResource and Filer.getResource
jjg
parents:
5847
diff
changeset
|
710 |
throw new IllegalArgumentException("Invalid kind: " + kind); |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
711 |
return getFileForOutput(location, RelativeFile.forClass(className, kind), sibling); |
10 | 712 |
} |
713 |
||
714 |
public FileObject getFileForOutput(Location location, |
|
715 |
String packageName, |
|
716 |
String relativeName, |
|
717 |
FileObject sibling) |
|
718 |
throws IOException |
|
719 |
{ |
|
720 |
nullCheck(location); |
|
721 |
// validatePackageName(packageName); |
|
722 |
nullCheck(packageName); |
|
3782 | 723 |
if (!isRelativeUri(relativeName)) |
6719
1ce993f87850
6502392: Invalid relative names for Filer.createResource and Filer.getResource
jjg
parents:
5847
diff
changeset
|
724 |
throw new IllegalArgumentException("Invalid relative name: " + relativeName); |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
725 |
RelativeFile name = packageName.length() == 0 |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
726 |
? new RelativeFile(relativeName) |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
727 |
: new RelativeFile(RelativeDirectory.forPackage(packageName), relativeName); |
10 | 728 |
return getFileForOutput(location, name, sibling); |
729 |
} |
|
730 |
||
731 |
private JavaFileObject getFileForOutput(Location location, |
|
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
732 |
RelativeFile fileName, |
10 | 733 |
FileObject sibling) |
734 |
throws IOException |
|
735 |
{ |
|
736 |
File dir; |
|
737 |
if (location == CLASS_OUTPUT) { |
|
738 |
if (getClassOutDir() != null) { |
|
739 |
dir = getClassOutDir(); |
|
740 |
} else { |
|
741 |
File siblingDir = null; |
|
742 |
if (sibling != null && sibling instanceof RegularFileObject) { |
|
4073
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
743 |
siblingDir = ((RegularFileObject)sibling).file.getParentFile(); |
10 | 744 |
} |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
745 |
return new RegularFileObject(this, new File(siblingDir, fileName.basename())); |
10 | 746 |
} |
747 |
} else if (location == SOURCE_OUTPUT) { |
|
748 |
dir = (getSourceOutDir() != null ? getSourceOutDir() : getClassOutDir()); |
|
749 |
} else { |
|
10818 | 750 |
Iterable<? extends File> path = locations.getLocation(location); |
10 | 751 |
dir = null; |
752 |
for (File f: path) { |
|
753 |
dir = f; |
|
754 |
break; |
|
755 |
} |
|
756 |
} |
|
757 |
||
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
758 |
File file = fileName.getFile(dir); // null-safe |
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
809
diff
changeset
|
759 |
return new RegularFileObject(this, file); |
10 | 760 |
|
761 |
} |
|
762 |
||
763 |
public Iterable<? extends JavaFileObject> getJavaFileObjectsFromFiles( |
|
764 |
Iterable<? extends File> files) |
|
765 |
{ |
|
766 |
ArrayList<RegularFileObject> result; |
|
1789
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1208
diff
changeset
|
767 |
if (files instanceof Collection<?>) |
22163 | 768 |
result = new ArrayList<>(((Collection<?>)files).size()); |
10 | 769 |
else |
22163 | 770 |
result = new ArrayList<>(); |
10 | 771 |
for (File f: files) |
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
809
diff
changeset
|
772 |
result.add(new RegularFileObject(this, nullCheck(f))); |
10 | 773 |
return result; |
774 |
} |
|
775 |
||
776 |
public Iterable<? extends JavaFileObject> getJavaFileObjects(File... files) { |
|
777 |
return getJavaFileObjectsFromFiles(Arrays.asList(nullCheck(files))); |
|
778 |
} |
|
779 |
||
780 |
public void setLocation(Location location, |
|
781 |
Iterable<? extends File> path) |
|
782 |
throws IOException |
|
783 |
{ |
|
784 |
nullCheck(location); |
|
10818 | 785 |
locations.setLocation(location, path); |
10 | 786 |
} |
787 |
||
788 |
public Iterable<? extends File> getLocation(Location location) { |
|
789 |
nullCheck(location); |
|
10818 | 790 |
return locations.getLocation(location); |
10 | 791 |
} |
792 |
||
793 |
private File getClassOutDir() { |
|
10818 | 794 |
return locations.getOutputLocation(CLASS_OUTPUT); |
10 | 795 |
} |
796 |
||
797 |
private File getSourceOutDir() { |
|
10818 | 798 |
return locations.getOutputLocation(SOURCE_OUTPUT); |
10 | 799 |
} |
800 |
||
801 |
/** |
|
14259 | 802 |
* Enforces the specification of a "relative" name as used in |
803 |
* {@linkplain #getFileForInput(Location,String,String) |
|
10 | 804 |
* getFileForInput}. This method must follow the rules defined in |
805 |
* that method, do not make any changes without consulting the |
|
806 |
* specification. |
|
807 |
*/ |
|
808 |
protected static boolean isRelativeUri(URI uri) { |
|
809 |
if (uri.isAbsolute()) |
|
810 |
return false; |
|
811 |
String path = uri.normalize().getPath(); |
|
812 |
if (path.length() == 0 /* isEmpty() is mustang API */) |
|
813 |
return false; |
|
6719
1ce993f87850
6502392: Invalid relative names for Filer.createResource and Filer.getResource
jjg
parents:
5847
diff
changeset
|
814 |
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
|
815 |
return false; |
7840 | 816 |
if (path.startsWith("/") || path.startsWith("./") || path.startsWith("../")) |
817 |
return false; |
|
818 |
return true; |
|
10 | 819 |
} |
820 |
||
3782 | 821 |
// Convenience method |
822 |
protected static boolean isRelativeUri(String u) { |
|
823 |
try { |
|
824 |
return isRelativeUri(new URI(u)); |
|
825 |
} catch (URISyntaxException e) { |
|
826 |
return false; |
|
827 |
} |
|
828 |
} |
|
829 |
||
10 | 830 |
/** |
831 |
* Converts a relative file name to a relative URI. This is |
|
832 |
* different from File.toURI as this method does not canonicalize |
|
833 |
* the file before creating the URI. Furthermore, no schema is |
|
834 |
* used. |
|
835 |
* @param file a relative file name |
|
836 |
* @return a relative URI |
|
837 |
* @throws IllegalArgumentException if the file name is not |
|
838 |
* relative according to the definition given in {@link |
|
839 |
* javax.tools.JavaFileManager#getFileForInput} |
|
840 |
*/ |
|
841 |
public static String getRelativeName(File file) { |
|
842 |
if (!file.isAbsolute()) { |
|
843 |
String result = file.getPath().replace(File.separatorChar, '/'); |
|
3782 | 844 |
if (isRelativeUri(result)) |
10 | 845 |
return result; |
846 |
} |
|
847 |
throw new IllegalArgumentException("Invalid relative path: " + file); |
|
848 |
} |
|
5007
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
849 |
|
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
850 |
/** |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
851 |
* 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
|
852 |
* 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
|
853 |
* 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
|
854 |
* 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
|
855 |
* name of the exception itself. |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
856 |
* @param e an IOException |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
857 |
* @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
|
858 |
*/ |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
859 |
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
|
860 |
String s = e.getLocalizedMessage(); |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
861 |
if (s != null) |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
862 |
return s; |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
863 |
s = e.getMessage(); |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
864 |
if (s != null) |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
865 |
return s; |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
866 |
return e.toString(); |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
867 |
} |
10 | 868 |
} |