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