author | alanb |
Thu, 17 Mar 2016 19:04:28 +0000 | |
changeset 36526 | 3b41f1c69604 |
parent 36158 | 85e36c1962ff |
child 37390 | bf1552d6bc16 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
35807
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
34560
diff
changeset
|
2 |
* Copyright (c) 2005, 2016, 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.IOException; |
|
30 |
import java.net.MalformedURLException; |
|
31 |
import java.net.URI; |
|
3782 | 32 |
import java.net.URISyntaxException; |
10 | 33 |
import java.net.URL; |
34 |
import java.nio.CharBuffer; |
|
35 |
import java.nio.charset.Charset; |
|
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
36 |
import java.nio.file.FileSystem; |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
37 |
import java.nio.file.FileSystems; |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
38 |
import java.nio.file.FileVisitOption; |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
39 |
import java.nio.file.FileVisitResult; |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
40 |
import java.nio.file.Files; |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
41 |
import java.nio.file.InvalidPathException; |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
42 |
import java.nio.file.LinkOption; |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
43 |
import java.nio.file.Path; |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
44 |
import java.nio.file.Paths; |
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
45 |
import java.nio.file.SimpleFileVisitor; |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
46 |
import java.nio.file.attribute.BasicFileAttributes; |
10 | 47 |
import java.util.ArrayList; |
48 |
import java.util.Arrays; |
|
49 |
import java.util.Collection; |
|
36526 | 50 |
import java.util.Collections; |
10813
95b39a692cd0
7101146: Paths should more directly managed by BaseFileManager
jjg
parents:
8837
diff
changeset
|
51 |
import java.util.Comparator; |
10 | 52 |
import java.util.EnumSet; |
53 |
import java.util.HashMap; |
|
54 |
import java.util.Iterator; |
|
55 |
import java.util.Map; |
|
29291
076c277565f7
8073550: java* tools: replace obj.getClass hacks with Assert.checkNonNull or Objects.requireNonNull
mcimadamore
parents:
28332
diff
changeset
|
56 |
import java.util.Objects; |
36526 | 57 |
import java.util.ServiceLoader; |
10 | 58 |
import java.util.Set; |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
59 |
import java.util.stream.Collectors; |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
60 |
import java.util.stream.Stream; |
10 | 61 |
|
62 |
import javax.lang.model.SourceVersion; |
|
63 |
import javax.tools.FileObject; |
|
64 |
import javax.tools.JavaFileManager; |
|
65 |
import javax.tools.JavaFileObject; |
|
731
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
657
diff
changeset
|
66 |
import javax.tools.StandardJavaFileManager; |
10 | 67 |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
68 |
import com.sun.tools.javac.file.RelativePath.RelativeDirectory; |
27226 | 69 |
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
|
70 |
import com.sun.tools.javac.util.Context; |
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
71 |
import com.sun.tools.javac.util.DefinedBy; |
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
72 |
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
|
73 |
import com.sun.tools.javac.util.List; |
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
657
diff
changeset
|
74 |
import com.sun.tools.javac.util.ListBuffer; |
36526 | 75 |
import com.sun.tools.javac.util.ModuleWrappers.Configuration; |
76 |
import com.sun.tools.javac.util.ModuleWrappers.Layer; |
|
77 |
import com.sun.tools.javac.util.ModuleWrappers.ModuleFinder; |
|
78 |
import com.sun.tools.javac.util.ModuleWrappers.ServiceLoaderHelper; |
|
10 | 79 |
|
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
80 |
import static java.nio.file.FileVisitOption.FOLLOW_LINKS; |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
81 |
|
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
82 |
import static javax.tools.StandardLocation.*; |
10 | 83 |
|
84 |
/** |
|
85 |
* This class provides access to the source, class and other files |
|
86 |
* used by the compiler and related tools. |
|
3380
a6c2bcab0fec
6865399: some javac files are missing Sun internal API comment
jjg
parents:
1789
diff
changeset
|
87 |
* |
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
88 |
* <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
|
89 |
* 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
|
90 |
* 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
|
91 |
* deletion without notice.</b> |
10 | 92 |
*/ |
4548 | 93 |
public class JavacFileManager extends BaseFileManager implements StandardJavaFileManager { |
10 | 94 |
|
27318
4660a5da7d90
8062376: Suppress cast warnings when using NIO buffers
rwarburton
parents:
27226
diff
changeset
|
95 |
@SuppressWarnings("cast") |
10 | 96 |
public static char[] toArray(CharBuffer buffer) { |
97 |
if (buffer.hasArray()) |
|
98 |
return ((CharBuffer)buffer.compact().flip()).array(); |
|
99 |
else |
|
100 |
return buffer.toString().toCharArray(); |
|
101 |
} |
|
102 |
||
1208
5072b0dd3d52
6743107: clean up use of static caches in file manager
jjg
parents:
1205
diff
changeset
|
103 |
private FSInfo fsInfo; |
5072b0dd3d52
6743107: clean up use of static caches in file manager
jjg
parents:
1205
diff
changeset
|
104 |
|
10 | 105 |
private final Set<JavaFileObject.Kind> sourceOrClass = |
106 |
EnumSet.of(JavaFileObject.Kind.SOURCE, JavaFileObject.Kind.CLASS); |
|
107 |
||
14362
598fd301e4de
8001229: refactor javac so that ct.sym is just used for javac, not all clients of JavacFileManager
jjg
parents:
14259
diff
changeset
|
108 |
protected boolean symbolFileEnabled; |
10 | 109 |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
110 |
protected enum SortFiles implements Comparator<Path> { |
7334
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
111 |
FORWARD { |
27579 | 112 |
@Override |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
113 |
public int compare(Path f1, Path f2) { |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
114 |
return f1.getFileName().compareTo(f2.getFileName()); |
7334
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
115 |
} |
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
116 |
}, |
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
117 |
REVERSE { |
27579 | 118 |
@Override |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
119 |
public int compare(Path f1, Path f2) { |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
120 |
return -f1.getFileName().compareTo(f2.getFileName()); |
7334
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
121 |
} |
22163 | 122 |
} |
123 |
} |
|
124 |
||
7334
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
125 |
protected SortFiles sortFiles; |
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
126 |
|
10 | 127 |
/** |
128 |
* Register a Context.Factory to create a JavacFileManager. |
|
129 |
*/ |
|
8614 | 130 |
public static void preRegister(Context context) { |
10 | 131 |
context.put(JavaFileManager.class, new Context.Factory<JavaFileManager>() { |
27579 | 132 |
@Override |
8614 | 133 |
public JavaFileManager make(Context c) { |
134 |
return new JavacFileManager(c, true, null); |
|
10 | 135 |
} |
136 |
}); |
|
137 |
} |
|
138 |
||
139 |
/** |
|
140 |
* Create a JavacFileManager using a given context, optionally registering |
|
141 |
* it as the JavaFileManager for that context. |
|
142 |
*/ |
|
143 |
public JavacFileManager(Context context, boolean register, Charset charset) { |
|
4548 | 144 |
super(charset); |
10 | 145 |
if (register) |
146 |
context.put(JavaFileManager.class, this); |
|
147 |
setContext(context); |
|
148 |
} |
|
149 |
||
150 |
/** |
|
151 |
* Set the context for JavacFileManager. |
|
152 |
*/ |
|
4548 | 153 |
@Override |
10 | 154 |
public void setContext(Context context) { |
4548 | 155 |
super.setContext(context); |
10 | 156 |
|
1208
5072b0dd3d52
6743107: clean up use of static caches in file manager
jjg
parents:
1205
diff
changeset
|
157 |
fsInfo = FSInfo.instance(context); |
10 | 158 |
|
14362
598fd301e4de
8001229: refactor javac so that ct.sym is just used for javac, not all clients of JavacFileManager
jjg
parents:
14259
diff
changeset
|
159 |
symbolFileEnabled = !options.isSet("ignore.symbol.file"); |
7334
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
160 |
|
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
161 |
String sf = options.get("sortFiles"); |
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
162 |
if (sf != null) { |
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
163 |
sortFiles = (sf.equals("reverse") ? SortFiles.REVERSE : SortFiles.FORWARD); |
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
164 |
} |
10 | 165 |
} |
166 |
||
14362
598fd301e4de
8001229: refactor javac so that ct.sym is just used for javac, not all clients of JavacFileManager
jjg
parents:
14259
diff
changeset
|
167 |
/** |
598fd301e4de
8001229: refactor javac so that ct.sym is just used for javac, not all clients of JavacFileManager
jjg
parents:
14259
diff
changeset
|
168 |
* 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
|
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 |
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
|
171 |
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
|
172 |
} |
598fd301e4de
8001229: refactor javac so that ct.sym is just used for javac, not all clients of JavacFileManager
jjg
parents:
14259
diff
changeset
|
173 |
|
27579 | 174 |
public boolean isSymbolFileEnabled() { |
175 |
return symbolFileEnabled; |
|
176 |
} |
|
177 |
||
28332
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
178 |
// used by tests |
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
179 |
public JavaFileObject getJavaFileObject(String name) { |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
180 |
return getJavaFileObjects(name).iterator().next(); |
10 | 181 |
} |
182 |
||
28332
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
183 |
// used by tests |
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
184 |
public JavaFileObject getJavaFileObject(Path file) { |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
185 |
return getJavaFileObjects(file).iterator().next(); |
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) { |
28332
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
198 |
ListBuffer<Path> paths = new ListBuffer<>(); |
10 | 199 |
for (String name : names) |
28332
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
200 |
paths.append(Paths.get(nullCheck(name))); |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
201 |
return getJavaFileObjectsFromPaths(paths.toList()); |
10 | 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 |
|
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
283 |
= PathFileObject.forJRTPath(JavacFileManager.this, file); |
27579 | 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 |
*/ |
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
308 |
private void listDirectory(Path directory, Path realDirectory, |
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 { |
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
315 |
d = subdirectory.resolveAgainst(directory); |
27852
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 |
|
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
335 |
if (realDirectory == null) |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
336 |
realDirectory = fsInfo.getCanonicalFile(directory); |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
337 |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
338 |
for (Path f: files) { |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
339 |
String fname = f.getFileName().toString(); |
31506
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29780
diff
changeset
|
340 |
if (fname.endsWith("/")) |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29780
diff
changeset
|
341 |
fname = fname.substring(0, fname.length() - 1); |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
342 |
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
|
343 |
if (recurse && SourceVersion.isIdentifier(fname)) { |
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
344 |
listDirectory(directory, realDirectory, |
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
345 |
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
|
346 |
fileKinds, |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
347 |
recurse, |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
348 |
resultList); |
10 | 349 |
} |
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
350 |
} else { |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
351 |
if (isValidFile(fname, fileKinds)) { |
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
352 |
RelativeFile file = new RelativeFile(subdirectory, fname); |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
353 |
JavaFileObject fe = PathFileObject.forDirectoryPath(this, |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
354 |
file.resolveAgainst(realDirectory), directory, file); |
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
355 |
resultList.append(fe); |
10 | 356 |
} |
357 |
} |
|
358 |
} |
|
359 |
} |
|
360 |
||
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
361 |
/** |
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
362 |
* Insert all files in subdirectory subdirectory of archive archivePath |
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
363 |
* 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
|
364 |
*/ |
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
365 |
private void listArchive(Path archivePath, |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
366 |
RelativeDirectory subdirectory, |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
367 |
Set<JavaFileObject.Kind> fileKinds, |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
368 |
boolean recurse, |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
369 |
ListBuffer<JavaFileObject> resultList) |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
370 |
throws IOException { |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
371 |
FileSystem fs = getFileSystem(archivePath); |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
372 |
if (fs == null) { |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
373 |
return; |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
374 |
} |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
375 |
|
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
376 |
Path containerSubdir = subdirectory.resolveAgainst(fs); |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
377 |
if (!Files.exists(containerSubdir)) { |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
378 |
return; |
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
379 |
} |
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
380 |
|
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
381 |
int maxDepth = (recurse ? Integer.MAX_VALUE : 1); |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
382 |
Set<FileVisitOption> opts = EnumSet.of(FOLLOW_LINKS); |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
383 |
Files.walkFileTree(containerSubdir, opts, maxDepth, |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
384 |
new SimpleFileVisitor<Path>() { |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
385 |
@Override |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
386 |
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) { |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
387 |
if (isValid(dir.getFileName())) { |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
388 |
return FileVisitResult.CONTINUE; |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
389 |
} else { |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
390 |
return FileVisitResult.SKIP_SUBTREE; |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
391 |
} |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
392 |
} |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
393 |
|
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
394 |
boolean isValid(Path fileName) { |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
395 |
if (fileName == null) { |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
396 |
return true; |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
397 |
} else { |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
398 |
String name = fileName.toString(); |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
399 |
if (name.endsWith("/")) { |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
400 |
name = name.substring(0, name.length() - 1); |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
401 |
} |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
402 |
return SourceVersion.isIdentifier(name); |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
403 |
} |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
404 |
} |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
405 |
|
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
406 |
@Override |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
407 |
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
408 |
if (attrs.isRegularFile() && fileKinds.contains(getKind(file.getFileName().toString()))) { |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
409 |
JavaFileObject fe = PathFileObject.forJarPath( |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
410 |
JavacFileManager.this, file, archivePath); |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
411 |
resultList.append(fe); |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
412 |
} |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
413 |
return FileVisitResult.CONTINUE; |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
414 |
} |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
415 |
}); |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
416 |
|
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
417 |
} |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
418 |
|
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
419 |
/** |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
420 |
* 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
|
421 |
* 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
|
422 |
* 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
|
423 |
*/ |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
424 |
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
|
425 |
RelativeDirectory subdirectory, |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
426 |
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
|
427 |
boolean recurse, |
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
428 |
ListBuffer<JavaFileObject> resultList) |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
429 |
throws IOException { |
36526 | 430 |
if (Files.isRegularFile(container) && container.equals(Locations.thisSystemModules)) { |
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
431 |
try { |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
432 |
listJRTImage(subdirectory, |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
433 |
fileKinds, |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
434 |
recurse, |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
435 |
resultList); |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
436 |
} catch (IOException ex) { |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
437 |
ex.printStackTrace(System.err); |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
438 |
log.error("error.reading.file", container, getMessage(ex)); |
27579 | 439 |
} |
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
440 |
return; |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
441 |
} |
27579 | 442 |
|
36526 | 443 |
if (Files.isDirectory(container)) { |
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
444 |
listDirectory(container, null, |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
445 |
subdirectory, |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
446 |
fileKinds, |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
447 |
recurse, |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
448 |
resultList); |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
449 |
return; |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
450 |
} |
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
451 |
|
36526 | 452 |
if (Files.isRegularFile(container)) { |
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
453 |
listArchive(container, |
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
454 |
subdirectory, |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
455 |
fileKinds, |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
456 |
recurse, |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
457 |
resultList); |
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
458 |
} |
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
459 |
} |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
460 |
|
10 | 461 |
private boolean isValidFile(String s, Set<JavaFileObject.Kind> fileKinds) { |
4548 | 462 |
JavaFileObject.Kind kind = getKind(s); |
10 | 463 |
return fileKinds.contains(kind); |
464 |
} |
|
465 |
||
466 |
private static final boolean fileSystemIsCaseSensitive = |
|
467 |
File.separatorChar == '/'; |
|
468 |
||
469 |
/** Hack to make Windows case sensitive. Test whether given path |
|
470 |
* ends in a string of characters with the same case as given name. |
|
471 |
* Ignore file separators in both path and name. |
|
472 |
*/ |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
473 |
private boolean caseMapCheck(Path f, RelativePath name) { |
10 | 474 |
if (fileSystemIsCaseSensitive) return true; |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
475 |
// Note that toRealPath() returns the case-sensitive |
10 | 476 |
// spelled file name. |
477 |
String path; |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
478 |
char sep; |
10 | 479 |
try { |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
480 |
path = f.toRealPath(LinkOption.NOFOLLOW_LINKS).toString(); |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
481 |
sep = f.getFileSystem().getSeparator().charAt(0); |
10 | 482 |
} catch (IOException ex) { |
483 |
return false; |
|
484 |
} |
|
485 |
char[] pcs = path.toCharArray(); |
|
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
486 |
char[] ncs = name.path.toCharArray(); |
10 | 487 |
int i = pcs.length - 1; |
488 |
int j = ncs.length - 1; |
|
489 |
while (i >= 0 && j >= 0) { |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
490 |
while (i >= 0 && pcs[i] == sep) i--; |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
491 |
while (j >= 0 && ncs[j] == '/') j--; |
10 | 492 |
if (i >= 0 && j >= 0) { |
493 |
if (pcs[i] != ncs[j]) return false; |
|
494 |
i--; |
|
495 |
j--; |
|
496 |
} |
|
497 |
} |
|
498 |
return j < 0; |
|
499 |
} |
|
500 |
||
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
501 |
private FileSystem getFileSystem(Path path) throws IOException { |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
502 |
Path realPath = fsInfo.getCanonicalFile(path); |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
503 |
FileSystem fs = fileSystems.get(realPath); |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
504 |
if (fs == null) { |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
505 |
fileSystems.put(realPath, fs = FileSystems.newFileSystem(realPath, null)); |
10 | 506 |
} |
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
507 |
return fs; |
10 | 508 |
} |
509 |
||
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
510 |
private final Map<Path,FileSystem> fileSystems = new HashMap<>(); |
10 | 511 |
|
512 |
||
513 |
/** Flush any output resources. |
|
514 |
*/ |
|
27579 | 515 |
@Override @DefinedBy(Api.COMPILER) |
10 | 516 |
public void flush() { |
517 |
contentCache.clear(); |
|
518 |
} |
|
519 |
||
520 |
/** |
|
521 |
* Close the JavaFileManager, releasing resources. |
|
522 |
*/ |
|
27579 | 523 |
@Override @DefinedBy(Api.COMPILER) |
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
524 |
public void close() throws IOException { |
35807
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
34560
diff
changeset
|
525 |
if (deferredCloseTimeout > 0) { |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
34560
diff
changeset
|
526 |
deferredClose(); |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
34560
diff
changeset
|
527 |
return; |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
34560
diff
changeset
|
528 |
} |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
34560
diff
changeset
|
529 |
|
36526 | 530 |
locations.close(); |
35807
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
34560
diff
changeset
|
531 |
for (FileSystem fs: fileSystems.values()) { |
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
532 |
fs.close(); |
35807
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
34560
diff
changeset
|
533 |
} |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
34560
diff
changeset
|
534 |
fileSystems.clear(); |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
34560
diff
changeset
|
535 |
contentCache.clear(); |
10 | 536 |
} |
537 |
||
27579 | 538 |
@Override @DefinedBy(Api.COMPILER) |
10 | 539 |
public ClassLoader getClassLoader(Location location) { |
540 |
nullCheck(location); |
|
541 |
Iterable<? extends File> path = getLocation(location); |
|
542 |
if (path == null) |
|
543 |
return null; |
|
22163 | 544 |
ListBuffer<URL> lb = new ListBuffer<>(); |
10 | 545 |
for (File f: path) { |
546 |
try { |
|
547 |
lb.append(f.toURI().toURL()); |
|
548 |
} catch (MalformedURLException e) { |
|
549 |
throw new AssertionError(e); |
|
550 |
} |
|
551 |
} |
|
3656
d4e34b76b0c3
6558476: com/sun/tools/javac/Main.compile don't release file handles on return
jjg
parents:
3380
diff
changeset
|
552 |
|
4548 | 553 |
return getClassLoader(lb.toArray(new URL[lb.size()])); |
10 | 554 |
} |
555 |
||
27579 | 556 |
@Override @DefinedBy(Api.COMPILER) |
10 | 557 |
public Iterable<JavaFileObject> list(Location location, |
558 |
String packageName, |
|
559 |
Set<JavaFileObject.Kind> kinds, |
|
560 |
boolean recurse) |
|
561 |
throws IOException |
|
562 |
{ |
|
563 |
// validatePackageName(packageName); |
|
564 |
nullCheck(packageName); |
|
565 |
nullCheck(kinds); |
|
566 |
||
27858 | 567 |
Iterable<? extends Path> path = getLocationAsPaths(location); |
10 | 568 |
if (path == null) |
569 |
return List.nil(); |
|
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
570 |
RelativeDirectory subdirectory = RelativeDirectory.forPackage(packageName); |
22163 | 571 |
ListBuffer<JavaFileObject> results = new ListBuffer<>(); |
10 | 572 |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
573 |
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
|
574 |
listContainer(directory, subdirectory, kinds, recurse, results); |
10 | 575 |
return results.toList(); |
576 |
} |
|
577 |
||
27579 | 578 |
@Override @DefinedBy(Api.COMPILER) |
10 | 579 |
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
|
580 |
Objects.requireNonNull(file); |
076c277565f7
8073550: java* tools: replace obj.getClass hacks with Assert.checkNonNull or Objects.requireNonNull
mcimadamore
parents:
28332
diff
changeset
|
581 |
Objects.requireNonNull(location); |
10 | 582 |
// 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
|
583 |
Iterable<? extends Path> path = getLocationAsPaths(location); |
10 | 584 |
if (path == null) { |
585 |
return null; |
|
586 |
} |
|
587 |
||
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
588 |
if (file instanceof PathFileObject) { |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
589 |
return ((PathFileObject) file).inferBinaryName(path); |
10 | 590 |
} else |
591 |
throw new IllegalArgumentException(file.getClass().getName()); |
|
592 |
} |
|
593 |
||
27579 | 594 |
@Override @DefinedBy(Api.COMPILER) |
10 | 595 |
public boolean isSameFile(FileObject a, FileObject b) { |
596 |
nullCheck(a); |
|
597 |
nullCheck(b); |
|
27579 | 598 |
if (a instanceof PathFileObject && b instanceof PathFileObject) |
599 |
return ((PathFileObject) a).isSameFile((PathFileObject) b); |
|
10 | 600 |
return a.equals(b); |
601 |
} |
|
602 |
||
27579 | 603 |
@Override @DefinedBy(Api.COMPILER) |
10 | 604 |
public boolean hasLocation(Location location) { |
36526 | 605 |
nullCheck(location); |
606 |
return locations.hasLocation(location); |
|
10 | 607 |
} |
608 |
||
27579 | 609 |
@Override @DefinedBy(Api.COMPILER) |
10 | 610 |
public JavaFileObject getJavaFileForInput(Location location, |
611 |
String className, |
|
612 |
JavaFileObject.Kind kind) |
|
613 |
throws IOException |
|
614 |
{ |
|
615 |
nullCheck(location); |
|
616 |
// validateClassName(className); |
|
617 |
nullCheck(className); |
|
618 |
nullCheck(kind); |
|
619 |
if (!sourceOrClass.contains(kind)) |
|
6719
1ce993f87850
6502392: Invalid relative names for Filer.createResource and Filer.getResource
jjg
parents:
5847
diff
changeset
|
620 |
throw new IllegalArgumentException("Invalid kind: " + kind); |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
621 |
return getFileForInput(location, RelativeFile.forClass(className, kind)); |
10 | 622 |
} |
623 |
||
27579 | 624 |
@Override @DefinedBy(Api.COMPILER) |
10 | 625 |
public FileObject getFileForInput(Location location, |
626 |
String packageName, |
|
627 |
String relativeName) |
|
628 |
throws IOException |
|
629 |
{ |
|
630 |
nullCheck(location); |
|
631 |
// validatePackageName(packageName); |
|
632 |
nullCheck(packageName); |
|
3782 | 633 |
if (!isRelativeUri(relativeName)) |
10 | 634 |
throw new IllegalArgumentException("Invalid relative name: " + relativeName); |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
635 |
RelativeFile name = packageName.length() == 0 |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
636 |
? new RelativeFile(relativeName) |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
637 |
: new RelativeFile(RelativeDirectory.forPackage(packageName), relativeName); |
10 | 638 |
return getFileForInput(location, name); |
639 |
} |
|
640 |
||
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
641 |
private JavaFileObject getFileForInput(Location location, RelativeFile name) throws IOException { |
27858 | 642 |
Iterable<? extends Path> path = getLocationAsPaths(location); |
10 | 643 |
if (path == null) |
644 |
return null; |
|
645 |
||
27858 | 646 |
for (Path file: path) { |
36526 | 647 |
if (file.equals(Locations.thisSystemModules)) { |
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
648 |
JRTIndex.Entry e = getJRTIndex().getEntry(name.dirname()); |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
649 |
if (symbolFileEnabled && e.ctSym.hidden) |
27579 | 650 |
continue; |
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
651 |
Path p = e.files.get(name.basename()); |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
652 |
if (p != null) |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
653 |
return PathFileObject.forJRTPath(this, p); |
36526 | 654 |
} else if (Files.isDirectory(file)) { |
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
655 |
try { |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
656 |
Path f = name.resolveAgainst(file); |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
657 |
if (Files.exists(f)) |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
658 |
return PathFileObject.forSimplePath(this, |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
659 |
fsInfo.getCanonicalFile(f), f); |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
660 |
} catch (InvalidPathException ignore) { |
10 | 661 |
} |
36526 | 662 |
} else if (Files.isRegularFile(file)) { |
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
663 |
FileSystem fs = getFileSystem(file); |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
664 |
if (fs != null) { |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
665 |
Path fsRoot = fs.getRootDirectories().iterator().next(); |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
666 |
Path f = name.resolveAgainst(fsRoot); |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
667 |
if (Files.exists(f)) |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
668 |
return PathFileObject.forJarPath(this, f, file); |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
669 |
} |
10 | 670 |
} |
671 |
} |
|
672 |
return null; |
|
673 |
} |
|
674 |
||
27579 | 675 |
@Override @DefinedBy(Api.COMPILER) |
10 | 676 |
public JavaFileObject getJavaFileForOutput(Location location, |
677 |
String className, |
|
678 |
JavaFileObject.Kind kind, |
|
679 |
FileObject sibling) |
|
680 |
throws IOException |
|
681 |
{ |
|
682 |
nullCheck(location); |
|
683 |
// validateClassName(className); |
|
684 |
nullCheck(className); |
|
685 |
nullCheck(kind); |
|
686 |
if (!sourceOrClass.contains(kind)) |
|
6719
1ce993f87850
6502392: Invalid relative names for Filer.createResource and Filer.getResource
jjg
parents:
5847
diff
changeset
|
687 |
throw new IllegalArgumentException("Invalid kind: " + kind); |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
688 |
return getFileForOutput(location, RelativeFile.forClass(className, kind), sibling); |
10 | 689 |
} |
690 |
||
27579 | 691 |
@Override @DefinedBy(Api.COMPILER) |
10 | 692 |
public FileObject getFileForOutput(Location location, |
693 |
String packageName, |
|
694 |
String relativeName, |
|
695 |
FileObject sibling) |
|
696 |
throws IOException |
|
697 |
{ |
|
698 |
nullCheck(location); |
|
699 |
// validatePackageName(packageName); |
|
700 |
nullCheck(packageName); |
|
3782 | 701 |
if (!isRelativeUri(relativeName)) |
6719
1ce993f87850
6502392: Invalid relative names for Filer.createResource and Filer.getResource
jjg
parents:
5847
diff
changeset
|
702 |
throw new IllegalArgumentException("Invalid relative name: " + relativeName); |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
703 |
RelativeFile name = packageName.length() == 0 |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
704 |
? new RelativeFile(relativeName) |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
705 |
: new RelativeFile(RelativeDirectory.forPackage(packageName), relativeName); |
10 | 706 |
return getFileForOutput(location, name, sibling); |
707 |
} |
|
708 |
||
709 |
private JavaFileObject getFileForOutput(Location location, |
|
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
710 |
RelativeFile fileName, |
10 | 711 |
FileObject sibling) |
712 |
throws IOException |
|
713 |
{ |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
714 |
Path dir; |
10 | 715 |
if (location == CLASS_OUTPUT) { |
716 |
if (getClassOutDir() != null) { |
|
717 |
dir = getClassOutDir(); |
|
718 |
} else { |
|
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
719 |
String baseName = fileName.basename(); |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
720 |
if (sibling != null && sibling instanceof PathFileObject) { |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
721 |
return ((PathFileObject) sibling).getSibling(baseName); |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
722 |
} else { |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
723 |
Path p = Paths.get(baseName); |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
724 |
Path real = fsInfo.getCanonicalFile(p); |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
725 |
return PathFileObject.forSimplePath(this, real, p); |
10 | 726 |
} |
727 |
} |
|
728 |
} else if (location == SOURCE_OUTPUT) { |
|
729 |
dir = (getSourceOutDir() != null ? getSourceOutDir() : getClassOutDir()); |
|
730 |
} else { |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
731 |
Iterable<? extends Path> path = locations.getLocation(location); |
10 | 732 |
dir = null; |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
733 |
for (Path f: path) { |
10 | 734 |
dir = f; |
735 |
break; |
|
736 |
} |
|
737 |
} |
|
738 |
||
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
739 |
try { |
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
740 |
if (dir == null) { |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
741 |
dir = Paths.get(System.getProperty("user.dir")); |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
742 |
} |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
743 |
Path path = fileName.resolveAgainst(fsInfo.getCanonicalFile(dir)); |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
744 |
return PathFileObject.forDirectoryPath(this, path, dir, fileName); |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
745 |
} catch (InvalidPathException e) { |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
746 |
throw new IOException("bad filename " + fileName, e); |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
747 |
} |
10 | 748 |
} |
749 |
||
27579 | 750 |
@Override @DefinedBy(Api.COMPILER) |
10 | 751 |
public Iterable<? extends JavaFileObject> getJavaFileObjectsFromFiles( |
752 |
Iterable<? extends File> files) |
|
753 |
{ |
|
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
754 |
ArrayList<PathFileObject> result; |
1789
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1208
diff
changeset
|
755 |
if (files instanceof Collection<?>) |
22163 | 756 |
result = new ArrayList<>(((Collection<?>)files).size()); |
10 | 757 |
else |
22163 | 758 |
result = new ArrayList<>(); |
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
759 |
for (File f: files) { |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
760 |
Objects.requireNonNull(f); |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
761 |
Path p = f.toPath(); |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
762 |
result.add(PathFileObject.forSimplePath(this, |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
763 |
fsInfo.getCanonicalFile(p), p)); |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
764 |
} |
10 | 765 |
return result; |
766 |
} |
|
767 |
||
27579 | 768 |
@Override @DefinedBy(Api.COMPILER) |
28332
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
769 |
public Iterable<? extends JavaFileObject> getJavaFileObjectsFromPaths( |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
770 |
Iterable<? extends Path> paths) |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
771 |
{ |
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
772 |
ArrayList<PathFileObject> result; |
28332
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
773 |
if (paths instanceof Collection<?>) |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
774 |
result = new ArrayList<>(((Collection<?>)paths).size()); |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
775 |
else |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
776 |
result = new ArrayList<>(); |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
777 |
for (Path p: paths) |
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
778 |
result.add(PathFileObject.forSimplePath(this, |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
779 |
fsInfo.getCanonicalFile(p), p)); |
28332
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
780 |
return result; |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
781 |
} |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
782 |
|
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
783 |
@Override @DefinedBy(Api.COMPILER) |
10 | 784 |
public Iterable<? extends JavaFileObject> getJavaFileObjects(File... files) { |
785 |
return getJavaFileObjectsFromFiles(Arrays.asList(nullCheck(files))); |
|
786 |
} |
|
787 |
||
27579 | 788 |
@Override @DefinedBy(Api.COMPILER) |
28332
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
789 |
public Iterable<? extends JavaFileObject> getJavaFileObjects(Path... paths) { |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
790 |
return getJavaFileObjectsFromPaths(Arrays.asList(nullCheck(paths))); |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
791 |
} |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
792 |
|
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
793 |
@Override @DefinedBy(Api.COMPILER) |
10 | 794 |
public void setLocation(Location location, |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
795 |
Iterable<? extends File> searchpath) |
10 | 796 |
throws IOException |
797 |
{ |
|
798 |
nullCheck(location); |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
799 |
locations.setLocation(location, asPaths(searchpath)); |
10 | 800 |
} |
801 |
||
27579 | 802 |
@Override @DefinedBy(Api.COMPILER) |
28332
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
803 |
public void setLocationFromPaths(Location location, |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
804 |
Iterable<? extends Path> searchpath) |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
805 |
throws IOException |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
806 |
{ |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
807 |
nullCheck(location); |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
808 |
locations.setLocation(location, nullCheck(searchpath)); |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
809 |
} |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
810 |
|
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
811 |
@Override @DefinedBy(Api.COMPILER) |
10 | 812 |
public Iterable<? extends File> getLocation(Location location) { |
813 |
nullCheck(location); |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
814 |
return asFiles(locations.getLocation(location)); |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
815 |
} |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
816 |
|
28332
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
817 |
@Override @DefinedBy(Api.COMPILER) |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
818 |
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
|
819 |
nullCheck(location); |
10818 | 820 |
return locations.getLocation(location); |
10 | 821 |
} |
822 |
||
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
823 |
private Path getClassOutDir() { |
10818 | 824 |
return locations.getOutputLocation(CLASS_OUTPUT); |
10 | 825 |
} |
826 |
||
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
827 |
private Path getSourceOutDir() { |
10818 | 828 |
return locations.getOutputLocation(SOURCE_OUTPUT); |
10 | 829 |
} |
830 |
||
28332
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
831 |
@Override @DefinedBy(Api.COMPILER) |
36526 | 832 |
public Location getModuleLocation(Location location, String moduleName) throws IOException { |
833 |
nullCheck(location); |
|
834 |
nullCheck(moduleName); |
|
835 |
return locations.getModuleLocation(location, moduleName); |
|
836 |
} |
|
837 |
||
838 |
@Override @DefinedBy(Api.COMPILER) |
|
839 |
public <S> ServiceLoader<S> getServiceLoader(Location location, Class<S> service) throws IOException { |
|
840 |
nullCheck(location); |
|
841 |
nullCheck(service); |
|
842 |
if (location.isModuleLocation()) { |
|
843 |
Collection<Path> paths = locations.getLocation(location); |
|
844 |
ModuleFinder finder = ModuleFinder.of(paths.toArray(new Path[paths.size()])); |
|
845 |
Layer bootLayer = Layer.boot(); |
|
846 |
Configuration cf = bootLayer.configuration().resolveRequiresAndUses(ModuleFinder.empty(), finder, Collections.emptySet()); |
|
847 |
Layer layer = bootLayer.defineModulesWithOneLoader(cf, ClassLoader.getSystemClassLoader()); |
|
848 |
return ServiceLoaderHelper.load(layer, service); |
|
849 |
} else { |
|
850 |
return ServiceLoader.load(service, getClassLoader(location)); |
|
851 |
} |
|
852 |
} |
|
853 |
||
854 |
@Override @DefinedBy(Api.COMPILER) |
|
855 |
public Location getModuleLocation(Location location, JavaFileObject fo, String pkgName) throws IOException { |
|
856 |
nullCheck(location); |
|
857 |
if (!(fo instanceof PathFileObject)) |
|
858 |
throw new IllegalArgumentException(fo.getName()); |
|
859 |
int depth = 1; // allow 1 for filename |
|
860 |
if (pkgName != null && !pkgName.isEmpty()) { |
|
861 |
depth += 1; |
|
862 |
for (int i = 0; i < pkgName.length(); i++) { |
|
863 |
switch (pkgName.charAt(i)) { |
|
864 |
case '/': case '.': |
|
865 |
depth++; |
|
866 |
} |
|
867 |
} |
|
868 |
} |
|
869 |
Path p = Locations.normalize(((PathFileObject) fo).path); |
|
870 |
int fc = p.getNameCount(); |
|
871 |
if (depth < fc) { |
|
872 |
Path root = p.getRoot(); |
|
873 |
Path subpath = p.subpath(0, fc - depth); |
|
874 |
Path dir = (root == null) ? subpath : root.resolve(subpath); |
|
875 |
// need to find dir in location |
|
876 |
return locations.getModuleLocation(location, dir); |
|
877 |
} else { |
|
878 |
return null; |
|
879 |
} |
|
880 |
} |
|
881 |
||
882 |
@Override @DefinedBy(Api.COMPILER) |
|
883 |
public String inferModuleName(Location location) { |
|
884 |
nullCheck(location); |
|
885 |
return locations.inferModuleName(location); |
|
886 |
} |
|
887 |
||
888 |
@Override @DefinedBy(Api.COMPILER) |
|
889 |
public Iterable<Set<Location>> listModuleLocations(Location location) throws IOException { |
|
890 |
nullCheck(location); |
|
891 |
return locations.listModuleLocations(location); |
|
892 |
} |
|
893 |
||
894 |
@Override @DefinedBy(Api.COMPILER) |
|
28332
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
895 |
public Path asPath(FileObject file) { |
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
896 |
if (file instanceof PathFileObject) { |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
897 |
return ((PathFileObject) file).path; |
28332
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
898 |
} else |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
899 |
throw new IllegalArgumentException(file.getName()); |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
900 |
} |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
901 |
|
10 | 902 |
/** |
14259 | 903 |
* Enforces the specification of a "relative" name as used in |
904 |
* {@linkplain #getFileForInput(Location,String,String) |
|
10 | 905 |
* getFileForInput}. This method must follow the rules defined in |
906 |
* that method, do not make any changes without consulting the |
|
907 |
* specification. |
|
908 |
*/ |
|
909 |
protected static boolean isRelativeUri(URI uri) { |
|
910 |
if (uri.isAbsolute()) |
|
911 |
return false; |
|
912 |
String path = uri.normalize().getPath(); |
|
913 |
if (path.length() == 0 /* isEmpty() is mustang API */) |
|
914 |
return false; |
|
6719
1ce993f87850
6502392: Invalid relative names for Filer.createResource and Filer.getResource
jjg
parents:
5847
diff
changeset
|
915 |
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
|
916 |
return false; |
7840 | 917 |
if (path.startsWith("/") || path.startsWith("./") || path.startsWith("../")) |
918 |
return false; |
|
919 |
return true; |
|
10 | 920 |
} |
921 |
||
3782 | 922 |
// Convenience method |
923 |
protected static boolean isRelativeUri(String u) { |
|
924 |
try { |
|
925 |
return isRelativeUri(new URI(u)); |
|
926 |
} catch (URISyntaxException e) { |
|
927 |
return false; |
|
928 |
} |
|
929 |
} |
|
930 |
||
10 | 931 |
/** |
932 |
* Converts a relative file name to a relative URI. This is |
|
933 |
* different from File.toURI as this method does not canonicalize |
|
934 |
* the file before creating the URI. Furthermore, no schema is |
|
935 |
* used. |
|
936 |
* @param file a relative file name |
|
937 |
* @return a relative URI |
|
938 |
* @throws IllegalArgumentException if the file name is not |
|
939 |
* relative according to the definition given in {@link |
|
940 |
* javax.tools.JavaFileManager#getFileForInput} |
|
941 |
*/ |
|
942 |
public static String getRelativeName(File file) { |
|
943 |
if (!file.isAbsolute()) { |
|
944 |
String result = file.getPath().replace(File.separatorChar, '/'); |
|
3782 | 945 |
if (isRelativeUri(result)) |
10 | 946 |
return result; |
947 |
} |
|
948 |
throw new IllegalArgumentException("Invalid relative path: " + file); |
|
949 |
} |
|
5007
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
950 |
|
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
951 |
/** |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
952 |
* 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
|
953 |
* 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
|
954 |
* 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
|
955 |
* 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
|
956 |
* name of the exception itself. |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
957 |
* @param e an IOException |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
958 |
* @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
|
959 |
*/ |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
960 |
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
|
961 |
String s = e.getLocalizedMessage(); |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
962 |
if (s != null) |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
963 |
return s; |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
964 |
s = e.getMessage(); |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
965 |
if (s != null) |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
966 |
return s; |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
967 |
return e.toString(); |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
968 |
} |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
969 |
|
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
970 |
/* Converters between files and paths. |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
971 |
* 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
|
972 |
*/ |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
973 |
|
27858 | 974 |
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
|
975 |
if (files == null) |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
976 |
return null; |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
977 |
|
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
978 |
return () -> new Iterator<Path>() { |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
979 |
Iterator<? extends File> iter = files.iterator(); |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
980 |
|
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
981 |
@Override |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
982 |
public boolean hasNext() { |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
983 |
return iter.hasNext(); |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
984 |
} |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
985 |
|
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
986 |
@Override |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
987 |
public Path next() { |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
988 |
return iter.next().toPath(); |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
989 |
} |
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 |
|
27858 | 993 |
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
|
994 |
if (paths == null) |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
995 |
return null; |
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 |
return () -> new Iterator<File>() { |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
998 |
Iterator<? extends Path> iter = paths.iterator(); |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
999 |
|
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
1000 |
@Override |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
1001 |
public boolean hasNext() { |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
1002 |
return iter.hasNext(); |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
1003 |
} |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
1004 |
|
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
1005 |
@Override |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
1006 |
public File next() { |
28332
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
1007 |
try { |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
1008 |
return iter.next().toFile(); |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
1009 |
} catch (UnsupportedOperationException e) { |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
1010 |
throw new IllegalStateException(e); |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
1011 |
} |
27852
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 |
}; |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
1014 |
} |
10 | 1015 |
} |