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