author | jjg |
Tue, 21 Oct 2014 13:08:20 -0700 | |
changeset 27225 | 8369cde9152a |
parent 26266 | 2d24bda701dc |
child 27226 | 53535e4e1b08 |
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.File; |
|
29 |
import java.io.FileNotFoundException; |
|
30 |
import java.io.IOException; |
|
31 |
import java.net.MalformedURLException; |
|
32 |
import java.net.URI; |
|
3782 | 33 |
import java.net.URISyntaxException; |
10 | 34 |
import java.net.URL; |
35 |
import java.nio.CharBuffer; |
|
36 |
import java.nio.charset.Charset; |
|
27225
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
37 |
import java.nio.file.Files; |
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
38 |
import java.nio.file.NoSuchFileException; |
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
39 |
import java.nio.file.Path; |
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
40 |
import java.nio.file.Paths; |
10 | 41 |
import java.util.ArrayList; |
42 |
import java.util.Arrays; |
|
43 |
import java.util.Collection; |
|
44 |
import java.util.Collections; |
|
10813
95b39a692cd0
7101146: Paths should more directly managed by BaseFileManager
jjg
parents:
8837
diff
changeset
|
45 |
import java.util.Comparator; |
10 | 46 |
import java.util.EnumSet; |
47 |
import java.util.HashMap; |
|
48 |
import java.util.Iterator; |
|
49 |
import java.util.Map; |
|
50 |
import java.util.Set; |
|
27225
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
51 |
import java.util.stream.Collectors; |
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
52 |
import java.util.stream.Stream; |
10 | 53 |
import java.util.zip.ZipFile; |
54 |
||
55 |
import javax.lang.model.SourceVersion; |
|
56 |
import javax.tools.FileObject; |
|
57 |
import javax.tools.JavaFileManager; |
|
58 |
import javax.tools.JavaFileObject; |
|
731
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
657
diff
changeset
|
59 |
import javax.tools.StandardJavaFileManager; |
10 | 60 |
|
27225
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
61 |
import com.sun.tools.javac.file.RelativePath.RelativeDirectory; |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
62 |
import com.sun.tools.javac.file.RelativePath.RelativeFile; |
4548 | 63 |
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
|
64 |
import com.sun.tools.javac.util.Context; |
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
65 |
import com.sun.tools.javac.util.DefinedBy; |
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
66 |
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
|
67 |
import com.sun.tools.javac.util.List; |
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
657
diff
changeset
|
68 |
import com.sun.tools.javac.util.ListBuffer; |
10 | 69 |
|
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
70 |
import static javax.tools.StandardLocation.*; |
10 | 71 |
|
72 |
/** |
|
73 |
* This class provides access to the source, class and other files |
|
74 |
* used by the compiler and related tools. |
|
3380
a6c2bcab0fec
6865399: some javac files are missing Sun internal API comment
jjg
parents:
1789
diff
changeset
|
75 |
* |
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
76 |
* <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
|
77 |
* 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
|
78 |
* 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
|
79 |
* deletion without notice.</b> |
10 | 80 |
*/ |
4548 | 81 |
public class JavacFileManager extends BaseFileManager implements StandardJavaFileManager { |
10 | 82 |
|
83 |
public static char[] toArray(CharBuffer buffer) { |
|
84 |
if (buffer.hasArray()) |
|
85 |
return ((CharBuffer)buffer.compact().flip()).array(); |
|
86 |
else |
|
87 |
return buffer.toString().toCharArray(); |
|
88 |
} |
|
89 |
||
1208
5072b0dd3d52
6743107: clean up use of static caches in file manager
jjg
parents:
1205
diff
changeset
|
90 |
private FSInfo fsInfo; |
5072b0dd3d52
6743107: clean up use of static caches in file manager
jjg
parents:
1205
diff
changeset
|
91 |
|
8837 | 92 |
private boolean contextUseOptimizedZip; |
8223
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
8034
diff
changeset
|
93 |
private ZipFileIndexCache zipFileIndexCache; |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
8034
diff
changeset
|
94 |
|
10 | 95 |
private final Set<JavaFileObject.Kind> sourceOrClass = |
96 |
EnumSet.of(JavaFileObject.Kind.SOURCE, JavaFileObject.Kind.CLASS); |
|
97 |
||
98 |
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
|
99 |
protected boolean symbolFileEnabled; |
10 | 100 |
|
27225
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
101 |
protected enum SortFiles implements Comparator<Path> { |
7334
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
102 |
FORWARD { |
27225
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
103 |
public int compare(Path f1, Path f2) { |
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
104 |
return f1.getFileName().compareTo(f2.getFileName()); |
7334
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
105 |
} |
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
106 |
}, |
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
107 |
REVERSE { |
27225
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
108 |
public int compare(Path f1, Path f2) { |
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
109 |
return -f1.getFileName().compareTo(f2.getFileName()); |
7334
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
110 |
} |
22163 | 111 |
} |
112 |
} |
|
113 |
||
7334
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
114 |
protected SortFiles sortFiles; |
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
115 |
|
10 | 116 |
/** |
117 |
* Register a Context.Factory to create a JavacFileManager. |
|
118 |
*/ |
|
8614 | 119 |
public static void preRegister(Context context) { |
10 | 120 |
context.put(JavaFileManager.class, new Context.Factory<JavaFileManager>() { |
8614 | 121 |
public JavaFileManager make(Context c) { |
122 |
return new JavacFileManager(c, true, null); |
|
10 | 123 |
} |
124 |
}); |
|
125 |
} |
|
126 |
||
127 |
/** |
|
128 |
* Create a JavacFileManager using a given context, optionally registering |
|
129 |
* it as the JavaFileManager for that context. |
|
130 |
*/ |
|
131 |
public JavacFileManager(Context context, boolean register, Charset charset) { |
|
4548 | 132 |
super(charset); |
10 | 133 |
if (register) |
134 |
context.put(JavaFileManager.class, this); |
|
135 |
setContext(context); |
|
136 |
} |
|
137 |
||
138 |
/** |
|
139 |
* Set the context for JavacFileManager. |
|
140 |
*/ |
|
4548 | 141 |
@Override |
10 | 142 |
public void setContext(Context context) { |
4548 | 143 |
super.setContext(context); |
10 | 144 |
|
1208
5072b0dd3d52
6743107: clean up use of static caches in file manager
jjg
parents:
1205
diff
changeset
|
145 |
fsInfo = FSInfo.instance(context); |
10 | 146 |
|
8837 | 147 |
contextUseOptimizedZip = options.getBoolean("useOptimizedZip", true); |
148 |
if (contextUseOptimizedZip) |
|
8223
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
8034
diff
changeset
|
149 |
zipFileIndexCache = ZipFileIndexCache.getSharedInstance(); |
10 | 150 |
|
6721 | 151 |
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
|
152 |
symbolFileEnabled = !options.isSet("ignore.symbol.file"); |
7334
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
153 |
|
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
154 |
String sf = options.get("sortFiles"); |
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
155 |
if (sf != null) { |
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
156 |
sortFiles = (sf.equals("reverse") ? SortFiles.REVERSE : SortFiles.FORWARD); |
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
157 |
} |
10 | 158 |
} |
159 |
||
14362
598fd301e4de
8001229: refactor javac so that ct.sym is just used for javac, not all clients of JavacFileManager
jjg
parents:
14259
diff
changeset
|
160 |
/** |
598fd301e4de
8001229: refactor javac so that ct.sym is just used for javac, not all clients of JavacFileManager
jjg
parents:
14259
diff
changeset
|
161 |
* 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
|
162 |
*/ |
598fd301e4de
8001229: refactor javac so that ct.sym is just used for javac, not all clients of JavacFileManager
jjg
parents:
14259
diff
changeset
|
163 |
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
|
164 |
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
|
165 |
} |
598fd301e4de
8001229: refactor javac so that ct.sym is just used for javac, not all clients of JavacFileManager
jjg
parents:
14259
diff
changeset
|
166 |
|
10 | 167 |
public JavaFileObject getFileForInput(String name) { |
27225
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
168 |
return getRegularFile(Paths.get(name)); |
10 | 169 |
} |
170 |
||
27225
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
171 |
public JavaFileObject getRegularFile(Path file) { |
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
809
diff
changeset
|
172 |
return new RegularFileObject(this, file); |
10 | 173 |
} |
174 |
||
175 |
public JavaFileObject getFileForOutput(String classname, |
|
176 |
JavaFileObject.Kind kind, |
|
177 |
JavaFileObject sibling) |
|
178 |
throws IOException |
|
179 |
{ |
|
180 |
return getJavaFileForOutput(CLASS_OUTPUT, classname, kind, sibling); |
|
181 |
} |
|
182 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
183 |
@DefinedBy(Api.COMPILER) |
10 | 184 |
public Iterable<? extends JavaFileObject> getJavaFileObjectsFromStrings(Iterable<String> names) { |
22163 | 185 |
ListBuffer<File> files = new ListBuffer<>(); |
10 | 186 |
for (String name : names) |
187 |
files.append(new File(nullCheck(name))); |
|
188 |
return getJavaFileObjectsFromFiles(files.toList()); |
|
189 |
} |
|
190 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
191 |
@DefinedBy(Api.COMPILER) |
10 | 192 |
public Iterable<? extends JavaFileObject> getJavaFileObjects(String... names) { |
193 |
return getJavaFileObjectsFromStrings(Arrays.asList(nullCheck(names))); |
|
194 |
} |
|
195 |
||
196 |
private static boolean isValidName(String name) { |
|
197 |
// Arguably, isValidName should reject keywords (such as in SourceVersion.isName() ), |
|
198 |
// but the set of keywords depends on the source level, and we don't want |
|
199 |
// impls of JavaFileManager to have to be dependent on the source level. |
|
200 |
// Therefore we simply check that the argument is a sequence of identifiers |
|
201 |
// separated by ".". |
|
202 |
for (String s : name.split("\\.", -1)) { |
|
203 |
if (!SourceVersion.isIdentifier(s)) |
|
204 |
return false; |
|
205 |
} |
|
206 |
return true; |
|
207 |
} |
|
208 |
||
209 |
private static void validateClassName(String className) { |
|
210 |
if (!isValidName(className)) |
|
211 |
throw new IllegalArgumentException("Invalid class name: " + className); |
|
212 |
} |
|
213 |
||
214 |
private static void validatePackageName(String packageName) { |
|
215 |
if (packageName.length() > 0 && !isValidName(packageName)) |
|
216 |
throw new IllegalArgumentException("Invalid packageName name: " + packageName); |
|
217 |
} |
|
218 |
||
219 |
public static void testName(String name, |
|
220 |
boolean isValidPackageName, |
|
221 |
boolean isValidClassName) |
|
222 |
{ |
|
223 |
try { |
|
224 |
validatePackageName(name); |
|
225 |
if (!isValidPackageName) |
|
226 |
throw new AssertionError("Invalid package name accepted: " + name); |
|
227 |
printAscii("Valid package name: \"%s\"", name); |
|
228 |
} catch (IllegalArgumentException e) { |
|
229 |
if (isValidPackageName) |
|
230 |
throw new AssertionError("Valid package name rejected: " + name); |
|
231 |
printAscii("Invalid package name: \"%s\"", name); |
|
232 |
} |
|
233 |
try { |
|
234 |
validateClassName(name); |
|
235 |
if (!isValidClassName) |
|
236 |
throw new AssertionError("Invalid class name accepted: " + name); |
|
237 |
printAscii("Valid class name: \"%s\"", name); |
|
238 |
} catch (IllegalArgumentException e) { |
|
239 |
if (isValidClassName) |
|
240 |
throw new AssertionError("Valid class name rejected: " + name); |
|
241 |
printAscii("Invalid class name: \"%s\"", name); |
|
242 |
} |
|
243 |
} |
|
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
244 |
|
10 | 245 |
private static void printAscii(String format, Object... args) { |
246 |
String message; |
|
247 |
try { |
|
248 |
final String ascii = "US-ASCII"; |
|
249 |
message = new String(String.format(null, format, args).getBytes(ascii), ascii); |
|
250 |
} catch (java.io.UnsupportedEncodingException ex) { |
|
251 |
throw new AssertionError(ex); |
|
252 |
} |
|
253 |
System.out.println(message); |
|
254 |
} |
|
255 |
||
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
256 |
|
10 | 257 |
/** |
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
258 |
* 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
|
259 |
* which match fileKinds into resultList |
10 | 260 |
*/ |
27225
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
261 |
private void listDirectory(Path directory, |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
262 |
RelativeDirectory subdirectory, |
10 | 263 |
Set<JavaFileObject.Kind> fileKinds, |
264 |
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
|
265 |
ListBuffer<JavaFileObject> resultList) { |
27225
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
266 |
Path 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
|
267 |
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
|
268 |
return; |
10 | 269 |
|
270 |
||
27225
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
271 |
java.util.List<Path> files; |
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
272 |
try (Stream<Path> s = Files.list(d)) { |
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
273 |
files = (sortFiles == null ? s : s.sorted(sortFiles)).collect(Collectors.toList()); |
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
274 |
} catch (IOException ignore) { |
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
275 |
return; |
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
276 |
} |
10 | 277 |
|
27225
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
278 |
for (Path f: files) { |
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
279 |
String fname = f.getFileName().toString(); |
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
280 |
if (Files.isDirectory(f)) { |
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
281 |
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
|
282 |
listDirectory(directory, |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
283 |
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
|
284 |
fileKinds, |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
285 |
recurse, |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
286 |
resultList); |
10 | 287 |
} |
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
288 |
} else { |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
289 |
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
|
290 |
JavaFileObject fe = |
27225
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
291 |
new RegularFileObject(this, fname, d.resolve(fname)); |
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
292 |
resultList.append(fe); |
10 | 293 |
} |
294 |
} |
|
295 |
} |
|
296 |
} |
|
297 |
||
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
298 |
/** |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
299 |
* 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
|
300 |
* 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
|
301 |
*/ |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
302 |
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
|
303 |
RelativeDirectory subdirectory, |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
304 |
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
|
305 |
boolean recurse, |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
306 |
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
|
307 |
// 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
|
308 |
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
|
309 |
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
|
310 |
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
|
311 |
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
|
312 |
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
|
313 |
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
|
314 |
} |
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 |
if (recurse) { |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
318 |
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
|
319 |
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
|
320 |
// 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
|
321 |
// 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
|
322 |
// 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
|
323 |
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
|
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 |
|
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
329 |
/** |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
330 |
* 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
|
331 |
* 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
|
332 |
* 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
|
333 |
*/ |
27225
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
334 |
private void listContainer(Path container, |
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
335 |
RelativeDirectory subdirectory, |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
336 |
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
|
337 |
boolean recurse, |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
338 |
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
|
339 |
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
|
340 |
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
|
341 |
// 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
|
342 |
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
|
343 |
listDirectory(container, |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
344 |
subdirectory, |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
345 |
fileKinds, |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
346 |
recurse, |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
347 |
resultList); |
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 |
// 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
|
352 |
try { |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
353 |
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
|
354 |
} 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
|
355 |
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
|
356 |
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
|
357 |
return; |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
358 |
} |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
359 |
} |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
360 |
listArchive(archive, |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
361 |
subdirectory, |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
362 |
fileKinds, |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
363 |
recurse, |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
364 |
resultList); |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
365 |
} |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
366 |
|
10 | 367 |
private boolean isValidFile(String s, Set<JavaFileObject.Kind> fileKinds) { |
4548 | 368 |
JavaFileObject.Kind kind = getKind(s); |
10 | 369 |
return fileKinds.contains(kind); |
370 |
} |
|
371 |
||
372 |
private static final boolean fileSystemIsCaseSensitive = |
|
373 |
File.separatorChar == '/'; |
|
374 |
||
375 |
/** Hack to make Windows case sensitive. Test whether given path |
|
376 |
* ends in a string of characters with the same case as given name. |
|
377 |
* Ignore file separators in both path and name. |
|
378 |
*/ |
|
27225
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
379 |
private boolean caseMapCheck(Path f, RelativePath name) { |
10 | 380 |
if (fileSystemIsCaseSensitive) return true; |
381 |
// Note that getCanonicalPath() returns the case-sensitive |
|
382 |
// spelled file name. |
|
383 |
String path; |
|
384 |
try { |
|
27225
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
385 |
path = f.toRealPath().toString(); |
10 | 386 |
} catch (IOException ex) { |
387 |
return false; |
|
388 |
} |
|
389 |
char[] pcs = path.toCharArray(); |
|
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
390 |
char[] ncs = name.path.toCharArray(); |
10 | 391 |
int i = pcs.length - 1; |
392 |
int j = ncs.length - 1; |
|
393 |
while (i >= 0 && j >= 0) { |
|
394 |
while (i >= 0 && pcs[i] == File.separatorChar) i--; |
|
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
395 |
while (j >= 0 && ncs[j] == '/') j--; |
10 | 396 |
if (i >= 0 && j >= 0) { |
397 |
if (pcs[i] != ncs[j]) return false; |
|
398 |
i--; |
|
399 |
j--; |
|
400 |
} |
|
401 |
} |
|
402 |
return j < 0; |
|
403 |
} |
|
404 |
||
405 |
/** |
|
406 |
* An archive provides a flat directory structure of a ZipFile by |
|
407 |
* mapping directory names to lists of files (basenames). |
|
408 |
*/ |
|
409 |
public interface Archive { |
|
410 |
void close() throws IOException; |
|
411 |
||
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
412 |
boolean contains(RelativePath name); |
10 | 413 |
|
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
414 |
JavaFileObject getFileObject(RelativeDirectory subdirectory, String file); |
10 | 415 |
|
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
416 |
List<String> getFiles(RelativeDirectory subdirectory); |
10 | 417 |
|
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
418 |
Set<RelativeDirectory> getSubdirectories(); |
10 | 419 |
} |
420 |
||
421 |
public class MissingArchive implements Archive { |
|
27225
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
422 |
final Path zipFileName; |
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
423 |
public MissingArchive(Path name) { |
10 | 424 |
zipFileName = name; |
425 |
} |
|
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
426 |
public boolean contains(RelativePath name) { |
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
809
diff
changeset
|
427 |
return false; |
10 | 428 |
} |
429 |
||
430 |
public void close() { |
|
431 |
} |
|
432 |
||
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
433 |
public JavaFileObject getFileObject(RelativeDirectory subdirectory, String file) { |
10 | 434 |
return null; |
435 |
} |
|
436 |
||
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
437 |
public List<String> getFiles(RelativeDirectory subdirectory) { |
10 | 438 |
return List.nil(); |
439 |
} |
|
440 |
||
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
441 |
public Set<RelativeDirectory> getSubdirectories() { |
10 | 442 |
return Collections.emptySet(); |
443 |
} |
|
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
444 |
|
3782 | 445 |
@Override |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
446 |
public String toString() { |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
447 |
return "MissingArchive[" + zipFileName + "]"; |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
448 |
} |
10 | 449 |
} |
450 |
||
451 |
/** A directory of zip files already opened. |
|
452 |
*/ |
|
27225
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
453 |
Map<Path, Archive> archives = new HashMap<>(); |
10 | 454 |
|
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
455 |
private static final String[] symbolFileLocation = { "lib", "ct.sym" }; |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
456 |
private static final RelativeDirectory symbolFilePrefix |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
457 |
= new RelativeDirectory("META-INF/sym/rt.jar/"); |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
458 |
|
8837 | 459 |
/* |
460 |
* This method looks for a ZipFormatException and takes appropriate |
|
461 |
* evasive action. If there is a failure in the fast mode then we |
|
462 |
* fail over to the platform zip, and allow it to deal with a potentially |
|
463 |
* non compliant zip file. |
|
464 |
*/ |
|
27225
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
465 |
protected Archive openArchive(Path zipFilename) throws IOException { |
8837 | 466 |
try { |
467 |
return openArchive(zipFilename, contextUseOptimizedZip); |
|
468 |
} catch (IOException ioe) { |
|
469 |
if (ioe instanceof ZipFileIndex.ZipFormatException) { |
|
470 |
return openArchive(zipFilename, false); |
|
471 |
} else { |
|
472 |
throw ioe; |
|
473 |
} |
|
474 |
} |
|
475 |
} |
|
476 |
||
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
477 |
/** Open a new zip file directory, and cache it. |
10 | 478 |
*/ |
27225
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
479 |
private Archive openArchive(Path zipFileName, boolean useOptimizedZip) throws IOException { |
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
480 |
Path 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
|
481 |
if (symbolFileEnabled && locations.isDefaultBootClassPathRtJar(zipFileName)) { |
27225
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
482 |
Path file = zipFileName.getParent().getParent(); // ${java.home} |
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
483 |
if (file.getFileName().equals(Paths.get("jre"))) |
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
484 |
file = file.getParent(); |
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
485 |
// file == ${jdk.home} |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
486 |
for (String name : symbolFileLocation) |
27225
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
487 |
file = file.resolve(name); |
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
488 |
// file == ${jdk.home}/lib/ct.sym |
27225
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
489 |
if (Files.exists(file)) |
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
490 |
zipFileName = file; |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
491 |
} |
10 | 492 |
|
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
493 |
Archive archive; |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
494 |
try { |
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 |
ZipFile zdir = null; |
10 | 497 |
|
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
498 |
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
|
499 |
String preindexCacheLocation = null; |
10 | 500 |
|
8837 | 501 |
if (!useOptimizedZip) { |
27225
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
502 |
zdir = new ZipFile(zipFileName.toFile()); |
8432
d3380b1e4779
7018859: javac turn off the Zip optimization by default
ksrini
parents:
8223
diff
changeset
|
503 |
} else { |
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
504 |
usePreindexedCache = options.isSet("usezipindex"); |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
505 |
preindexCacheLocation = options.get("java.io.tmpdir"); |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
506 |
String optCacheLoc = options.get("cachezipindexdir"); |
10 | 507 |
|
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
508 |
if (optCacheLoc != null && optCacheLoc.length() != 0) { |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
509 |
if (optCacheLoc.startsWith("\"")) { |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
510 |
if (optCacheLoc.endsWith("\"")) { |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
511 |
optCacheLoc = optCacheLoc.substring(1, optCacheLoc.length() - 1); |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
512 |
} |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
513 |
else { |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
514 |
optCacheLoc = optCacheLoc.substring(1); |
10 | 515 |
} |
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
516 |
} |
10 | 517 |
|
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
518 |
File cacheDir = new File(optCacheLoc); |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
519 |
if (cacheDir.exists() && cacheDir.canWrite()) { |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
520 |
preindexCacheLocation = optCacheLoc; |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
521 |
if (!preindexCacheLocation.endsWith("/") && |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
522 |
!preindexCacheLocation.endsWith(File.separator)) { |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
523 |
preindexCacheLocation += File.separator; |
10 | 524 |
} |
525 |
} |
|
526 |
} |
|
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
527 |
} |
10 | 528 |
|
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
529 |
if (origZipFileName == zipFileName) { |
8837 | 530 |
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
|
531 |
archive = new ZipArchive(this, zdir); |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
532 |
} else { |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
533 |
archive = new ZipFileIndexArchive(this, |
8837 | 534 |
zipFileIndexCache.getZipFileIndex(zipFileName, |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
535 |
null, |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
536 |
usePreindexedCache, |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
537 |
preindexCacheLocation, |
6721 | 538 |
options.isSet("writezipindexfiles"))); |
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
539 |
} |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
540 |
} else { |
8837 | 541 |
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
|
542 |
archive = new SymbolArchive(this, origZipFileName, zdir, symbolFilePrefix); |
8837 | 543 |
} else { |
7839
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 ZipFileIndexArchive(this, |
8837 | 545 |
zipFileIndexCache.getZipFileIndex(zipFileName, |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
546 |
symbolFilePrefix, |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
547 |
usePreindexedCache, |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
548 |
preindexCacheLocation, |
6721 | 549 |
options.isSet("writezipindexfiles"))); |
10 | 550 |
} |
551 |
} |
|
27225
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
552 |
} catch (FileNotFoundException | NoSuchFileException ex) { |
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
553 |
archive = new MissingArchive(zipFileName); |
8837 | 554 |
} catch (ZipFileIndex.ZipFormatException zfe) { |
555 |
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
|
556 |
} catch (IOException ex) { |
27225
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
557 |
if (Files.exists(zipFileName)) |
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
558 |
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
|
559 |
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
|
560 |
} |
10 | 561 |
|
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
562 |
archives.put(origZipFileName, archive); |
10 | 563 |
return archive; |
564 |
} |
|
565 |
||
566 |
/** Flush any output resources. |
|
567 |
*/ |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
568 |
@DefinedBy(Api.COMPILER) |
10 | 569 |
public void flush() { |
570 |
contentCache.clear(); |
|
571 |
} |
|
572 |
||
573 |
/** |
|
574 |
* Close the JavaFileManager, releasing resources. |
|
575 |
*/ |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
576 |
@DefinedBy(Api.COMPILER) |
10 | 577 |
public void close() { |
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 |
||
27225
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
617 |
Iterable<? extends Path> path = asPaths(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 |
|
27225
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
623 |
for (Path 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, ...) |
|
27225
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
633 |
Iterable<? extends Path> path = getLocationAsPaths(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 { |
27225
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
693 |
Iterable<? extends Path> path = asPaths(getLocation(location)); |
10 | 694 |
if (path == null) |
695 |
return null; |
|
696 |
||
27225
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
697 |
for (Path 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)) { |
27225
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
701 |
Path f = name.getFile(dir); |
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
702 |
if (Files.exists(f)) |
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 |
{ |
|
27225
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
756 |
Path dir; |
10 | 757 |
if (location == CLASS_OUTPUT) { |
758 |
if (getClassOutDir() != null) { |
|
759 |
dir = getClassOutDir(); |
|
760 |
} else { |
|
27225
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
761 |
Path siblingDir = null; |
10 | 762 |
if (sibling != null && sibling instanceof RegularFileObject) { |
27225
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
763 |
siblingDir = ((RegularFileObject)sibling).file.getParent(); |
10 | 764 |
} |
27225
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
765 |
if (siblingDir == null) |
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
766 |
return new RegularFileObject(this, Paths.get(fileName.basename())); |
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
767 |
else |
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
768 |
return new RegularFileObject(this, siblingDir.resolve(fileName.basename())); |
10 | 769 |
} |
770 |
} else if (location == SOURCE_OUTPUT) { |
|
771 |
dir = (getSourceOutDir() != null ? getSourceOutDir() : getClassOutDir()); |
|
772 |
} else { |
|
27225
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
773 |
Iterable<? extends Path> path = locations.getLocation(location); |
10 | 774 |
dir = null; |
27225
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
775 |
for (Path f: path) { |
10 | 776 |
dir = f; |
777 |
break; |
|
778 |
} |
|
779 |
} |
|
780 |
||
27225
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
781 |
Path file = fileName.getFile(dir); // null-safe |
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
809
diff
changeset
|
782 |
return new RegularFileObject(this, file); |
10 | 783 |
|
784 |
} |
|
785 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
786 |
@DefinedBy(Api.COMPILER) |
10 | 787 |
public Iterable<? extends JavaFileObject> getJavaFileObjectsFromFiles( |
788 |
Iterable<? extends File> files) |
|
789 |
{ |
|
790 |
ArrayList<RegularFileObject> result; |
|
1789
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1208
diff
changeset
|
791 |
if (files instanceof Collection<?>) |
22163 | 792 |
result = new ArrayList<>(((Collection<?>)files).size()); |
10 | 793 |
else |
22163 | 794 |
result = new ArrayList<>(); |
10 | 795 |
for (File f: files) |
27225
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
796 |
result.add(new RegularFileObject(this, nullCheck(f).toPath())); |
10 | 797 |
return result; |
798 |
} |
|
799 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
800 |
@DefinedBy(Api.COMPILER) |
10 | 801 |
public Iterable<? extends JavaFileObject> getJavaFileObjects(File... files) { |
802 |
return getJavaFileObjectsFromFiles(Arrays.asList(nullCheck(files))); |
|
803 |
} |
|
804 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
805 |
@DefinedBy(Api.COMPILER) |
10 | 806 |
public void setLocation(Location location, |
27225
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
807 |
Iterable<? extends File> searchpath) |
10 | 808 |
throws IOException |
809 |
{ |
|
810 |
nullCheck(location); |
|
27225
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
811 |
locations.setLocation(location, asPaths(searchpath)); |
10 | 812 |
} |
813 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
814 |
@DefinedBy(Api.COMPILER) |
10 | 815 |
public Iterable<? extends File> getLocation(Location location) { |
816 |
nullCheck(location); |
|
27225
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
817 |
return asFiles(locations.getLocation(location)); |
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
818 |
} |
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
819 |
|
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
820 |
private Iterable<? extends Path> getLocationAsPaths(Location location) { |
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
821 |
nullCheck(location); |
10818 | 822 |
return locations.getLocation(location); |
10 | 823 |
} |
824 |
||
27225
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
825 |
private Path getClassOutDir() { |
10818 | 826 |
return locations.getOutputLocation(CLASS_OUTPUT); |
10 | 827 |
} |
828 |
||
27225
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
829 |
private Path getSourceOutDir() { |
10818 | 830 |
return locations.getOutputLocation(SOURCE_OUTPUT); |
10 | 831 |
} |
832 |
||
833 |
/** |
|
14259 | 834 |
* Enforces the specification of a "relative" name as used in |
835 |
* {@linkplain #getFileForInput(Location,String,String) |
|
10 | 836 |
* getFileForInput}. This method must follow the rules defined in |
837 |
* that method, do not make any changes without consulting the |
|
838 |
* specification. |
|
839 |
*/ |
|
840 |
protected static boolean isRelativeUri(URI uri) { |
|
841 |
if (uri.isAbsolute()) |
|
842 |
return false; |
|
843 |
String path = uri.normalize().getPath(); |
|
844 |
if (path.length() == 0 /* isEmpty() is mustang API */) |
|
845 |
return false; |
|
6719
1ce993f87850
6502392: Invalid relative names for Filer.createResource and Filer.getResource
jjg
parents:
5847
diff
changeset
|
846 |
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
|
847 |
return false; |
7840 | 848 |
if (path.startsWith("/") || path.startsWith("./") || path.startsWith("../")) |
849 |
return false; |
|
850 |
return true; |
|
10 | 851 |
} |
852 |
||
3782 | 853 |
// Convenience method |
854 |
protected static boolean isRelativeUri(String u) { |
|
855 |
try { |
|
856 |
return isRelativeUri(new URI(u)); |
|
857 |
} catch (URISyntaxException e) { |
|
858 |
return false; |
|
859 |
} |
|
860 |
} |
|
861 |
||
10 | 862 |
/** |
863 |
* Converts a relative file name to a relative URI. This is |
|
864 |
* different from File.toURI as this method does not canonicalize |
|
865 |
* the file before creating the URI. Furthermore, no schema is |
|
866 |
* used. |
|
867 |
* @param file a relative file name |
|
868 |
* @return a relative URI |
|
869 |
* @throws IllegalArgumentException if the file name is not |
|
870 |
* relative according to the definition given in {@link |
|
871 |
* javax.tools.JavaFileManager#getFileForInput} |
|
872 |
*/ |
|
873 |
public static String getRelativeName(File file) { |
|
874 |
if (!file.isAbsolute()) { |
|
875 |
String result = file.getPath().replace(File.separatorChar, '/'); |
|
3782 | 876 |
if (isRelativeUri(result)) |
10 | 877 |
return result; |
878 |
} |
|
879 |
throw new IllegalArgumentException("Invalid relative path: " + file); |
|
880 |
} |
|
5007
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
881 |
|
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 |
* 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
|
884 |
* 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
|
885 |
* 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
|
886 |
* 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
|
887 |
* name of the exception itself. |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
888 |
* @param e an IOException |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
889 |
* @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
|
890 |
*/ |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
891 |
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
|
892 |
String s = e.getLocalizedMessage(); |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
893 |
if (s != null) |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
894 |
return s; |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
895 |
s = e.getMessage(); |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
896 |
if (s != null) |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
897 |
return s; |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
898 |
return e.toString(); |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
899 |
} |
27225
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
900 |
|
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
901 |
/* Converters between files and paths. |
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
902 |
* These are temporary until we can update the StandardJavaFileManager API. |
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
903 |
*/ |
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
904 |
|
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
905 |
static Iterable<Path> asPaths(final Iterable<? extends File> files) { |
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
906 |
if (files == null) |
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
907 |
return null; |
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
908 |
|
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
909 |
return () -> new Iterator<Path>() { |
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
910 |
Iterator<? extends File> iter = files.iterator(); |
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
911 |
|
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
912 |
@Override |
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
913 |
public boolean hasNext() { |
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
914 |
return iter.hasNext(); |
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
915 |
} |
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
916 |
|
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
917 |
@Override |
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
918 |
public Path next() { |
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
919 |
return iter.next().toPath(); |
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
920 |
} |
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
921 |
}; |
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
922 |
} |
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
923 |
|
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
924 |
static Iterable<File> asFiles(final Iterable<? extends Path> paths) { |
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
925 |
if (paths == null) |
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
926 |
return null; |
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
927 |
|
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
928 |
return () -> new Iterator<File>() { |
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
929 |
Iterator<? extends Path> iter = paths.iterator(); |
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
930 |
|
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
931 |
@Override |
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
932 |
public boolean hasNext() { |
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
933 |
return iter.hasNext(); |
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
934 |
} |
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
935 |
|
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
936 |
@Override |
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
937 |
public File next() { |
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
938 |
return iter.next().toFile(); |
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
939 |
} |
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
940 |
}; |
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
941 |
} |
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
942 |
|
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
943 |
static File asFile(Path path) { |
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
944 |
return path == null ? null : path.toFile(); |
8369cde9152a
8060056: replace java.io.File with java.nio.file.Path
jjg
parents:
26266
diff
changeset
|
945 |
} |
10 | 946 |
} |