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