author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 45504 | langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/JavacFileManager.java@ea7475564d07 |
child 47446 | fd458b0b7749 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
2 |
* Copyright (c) 2005, 2017, 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; |
37390
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
45 |
import java.nio.file.ProviderNotFoundException; |
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
46 |
import java.nio.file.SimpleFileVisitor; |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
47 |
import java.nio.file.attribute.BasicFileAttributes; |
37394
c36230ee15d9
8149757: Implement Multi-Release JAR aware JavacFileManager for javac
jjg
parents:
37390
diff
changeset
|
48 |
import java.nio.file.spi.FileSystemProvider; |
10 | 49 |
import java.util.ArrayList; |
50 |
import java.util.Arrays; |
|
51 |
import java.util.Collection; |
|
36526 | 52 |
import java.util.Collections; |
10813
95b39a692cd0
7101146: Paths should more directly managed by BaseFileManager
jjg
parents:
8837
diff
changeset
|
53 |
import java.util.Comparator; |
10 | 54 |
import java.util.EnumSet; |
55 |
import java.util.HashMap; |
|
56 |
import java.util.Iterator; |
|
57 |
import java.util.Map; |
|
29291
076c277565f7
8073550: java* tools: replace obj.getClass hacks with Assert.checkNonNull or Objects.requireNonNull
mcimadamore
parents:
28332
diff
changeset
|
58 |
import java.util.Objects; |
36526 | 59 |
import java.util.ServiceLoader; |
10 | 60 |
import java.util.Set; |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
61 |
import java.util.stream.Collectors; |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
62 |
import java.util.stream.Stream; |
10 | 63 |
|
64 |
import javax.lang.model.SourceVersion; |
|
65 |
import javax.tools.FileObject; |
|
66 |
import javax.tools.JavaFileManager; |
|
67 |
import javax.tools.JavaFileObject; |
|
731
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
657
diff
changeset
|
68 |
import javax.tools.StandardJavaFileManager; |
10 | 69 |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
70 |
import com.sun.tools.javac.file.RelativePath.RelativeDirectory; |
27226 | 71 |
import com.sun.tools.javac.file.RelativePath.RelativeFile; |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44822
diff
changeset
|
72 |
import com.sun.tools.javac.resources.CompilerProperties.Errors; |
40513
39b67170b045
8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
38533
diff
changeset
|
73 |
import com.sun.tools.javac.util.Assert; |
731
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
657
diff
changeset
|
74 |
import com.sun.tools.javac.util.Context; |
42827
36468b5fa7f4
8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents:
42815
diff
changeset
|
75 |
import com.sun.tools.javac.util.Context.Factory; |
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
76 |
import com.sun.tools.javac.util.DefinedBy; |
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
77 |
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
|
78 |
import com.sun.tools.javac.util.List; |
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
657
diff
changeset
|
79 |
import com.sun.tools.javac.util.ListBuffer; |
38533
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37944
diff
changeset
|
80 |
import com.sun.tools.javac.util.JDK9Wrappers.Configuration; |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37944
diff
changeset
|
81 |
import com.sun.tools.javac.util.JDK9Wrappers.Layer; |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37944
diff
changeset
|
82 |
import com.sun.tools.javac.util.JDK9Wrappers.ModuleFinder; |
41033
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40513
diff
changeset
|
83 |
import com.sun.tools.javac.util.JDK9Wrappers.Module; |
38533
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37944
diff
changeset
|
84 |
import com.sun.tools.javac.util.JDK9Wrappers.ServiceLoaderHelper; |
10 | 85 |
|
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
86 |
import static java.nio.file.FileVisitOption.FOLLOW_LINKS; |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
87 |
|
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
88 |
import static javax.tools.StandardLocation.*; |
10 | 89 |
|
90 |
/** |
|
91 |
* This class provides access to the source, class and other files |
|
92 |
* used by the compiler and related tools. |
|
3380
a6c2bcab0fec
6865399: some javac files are missing Sun internal API comment
jjg
parents:
1789
diff
changeset
|
93 |
* |
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
94 |
* <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
|
95 |
* 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
|
96 |
* 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
|
97 |
* deletion without notice.</b> |
10 | 98 |
*/ |
4548 | 99 |
public class JavacFileManager extends BaseFileManager implements StandardJavaFileManager { |
10 | 100 |
|
27318
4660a5da7d90
8062376: Suppress cast warnings when using NIO buffers
rwarburton
parents:
27226
diff
changeset
|
101 |
@SuppressWarnings("cast") |
10 | 102 |
public static char[] toArray(CharBuffer buffer) { |
103 |
if (buffer.hasArray()) |
|
104 |
return ((CharBuffer)buffer.compact().flip()).array(); |
|
105 |
else |
|
106 |
return buffer.toString().toCharArray(); |
|
107 |
} |
|
108 |
||
1208
5072b0dd3d52
6743107: clean up use of static caches in file manager
jjg
parents:
1205
diff
changeset
|
109 |
private FSInfo fsInfo; |
5072b0dd3d52
6743107: clean up use of static caches in file manager
jjg
parents:
1205
diff
changeset
|
110 |
|
10 | 111 |
private final Set<JavaFileObject.Kind> sourceOrClass = |
112 |
EnumSet.of(JavaFileObject.Kind.SOURCE, JavaFileObject.Kind.CLASS); |
|
113 |
||
14362
598fd301e4de
8001229: refactor javac so that ct.sym is just used for javac, not all clients of JavacFileManager
jjg
parents:
14259
diff
changeset
|
114 |
protected boolean symbolFileEnabled; |
10 | 115 |
|
37944
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37394
diff
changeset
|
116 |
private PathFactory pathFactory = Paths::get; |
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37394
diff
changeset
|
117 |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
118 |
protected enum SortFiles implements Comparator<Path> { |
7334
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
119 |
FORWARD { |
27579 | 120 |
@Override |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
121 |
public int compare(Path f1, Path f2) { |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
122 |
return f1.getFileName().compareTo(f2.getFileName()); |
7334
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
123 |
} |
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
124 |
}, |
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
125 |
REVERSE { |
27579 | 126 |
@Override |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
127 |
public int compare(Path f1, Path f2) { |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
128 |
return -f1.getFileName().compareTo(f2.getFileName()); |
7334
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
129 |
} |
22163 | 130 |
} |
131 |
} |
|
132 |
||
7334
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
133 |
protected SortFiles sortFiles; |
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
134 |
|
10 | 135 |
/** |
136 |
* Register a Context.Factory to create a JavacFileManager. |
|
137 |
*/ |
|
8614 | 138 |
public static void preRegister(Context context) { |
42827
36468b5fa7f4
8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents:
42815
diff
changeset
|
139 |
context.put(JavaFileManager.class, |
36468b5fa7f4
8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents:
42815
diff
changeset
|
140 |
(Factory<JavaFileManager>)c -> new JavacFileManager(c, true, null)); |
10 | 141 |
} |
142 |
||
143 |
/** |
|
144 |
* Create a JavacFileManager using a given context, optionally registering |
|
145 |
* it as the JavaFileManager for that context. |
|
146 |
*/ |
|
147 |
public JavacFileManager(Context context, boolean register, Charset charset) { |
|
4548 | 148 |
super(charset); |
10 | 149 |
if (register) |
150 |
context.put(JavaFileManager.class, this); |
|
151 |
setContext(context); |
|
152 |
} |
|
153 |
||
154 |
/** |
|
155 |
* Set the context for JavacFileManager. |
|
156 |
*/ |
|
4548 | 157 |
@Override |
10 | 158 |
public void setContext(Context context) { |
4548 | 159 |
super.setContext(context); |
10 | 160 |
|
1208
5072b0dd3d52
6743107: clean up use of static caches in file manager
jjg
parents:
1205
diff
changeset
|
161 |
fsInfo = FSInfo.instance(context); |
10 | 162 |
|
14362
598fd301e4de
8001229: refactor javac so that ct.sym is just used for javac, not all clients of JavacFileManager
jjg
parents:
14259
diff
changeset
|
163 |
symbolFileEnabled = !options.isSet("ignore.symbol.file"); |
7334
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
164 |
|
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
165 |
String sf = options.get("sortFiles"); |
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
166 |
if (sf != null) { |
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
167 |
sortFiles = (sf.equals("reverse") ? SortFiles.REVERSE : SortFiles.FORWARD); |
f432af22de29
7003006: add option to list directory in deterministic order
jjg
parents:
6721
diff
changeset
|
168 |
} |
10 | 169 |
} |
170 |
||
37944
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37394
diff
changeset
|
171 |
@Override @DefinedBy(DefinedBy.Api.COMPILER) |
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37394
diff
changeset
|
172 |
public void setPathFactory(PathFactory f) { |
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37394
diff
changeset
|
173 |
pathFactory = Objects.requireNonNull(f); |
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37394
diff
changeset
|
174 |
locations.setPathFactory(f); |
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37394
diff
changeset
|
175 |
} |
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37394
diff
changeset
|
176 |
|
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37394
diff
changeset
|
177 |
private Path getPath(String first, String... more) { |
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37394
diff
changeset
|
178 |
return pathFactory.getPath(first, more); |
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37394
diff
changeset
|
179 |
} |
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37394
diff
changeset
|
180 |
|
14362
598fd301e4de
8001229: refactor javac so that ct.sym is just used for javac, not all clients of JavacFileManager
jjg
parents:
14259
diff
changeset
|
181 |
/** |
598fd301e4de
8001229: refactor javac so that ct.sym is just used for javac, not all clients of JavacFileManager
jjg
parents:
14259
diff
changeset
|
182 |
* 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
|
183 |
*/ |
598fd301e4de
8001229: refactor javac so that ct.sym is just used for javac, not all clients of JavacFileManager
jjg
parents:
14259
diff
changeset
|
184 |
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
|
185 |
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
|
186 |
} |
598fd301e4de
8001229: refactor javac so that ct.sym is just used for javac, not all clients of JavacFileManager
jjg
parents:
14259
diff
changeset
|
187 |
|
27579 | 188 |
public boolean isSymbolFileEnabled() { |
189 |
return symbolFileEnabled; |
|
190 |
} |
|
191 |
||
28332
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
192 |
// used by tests |
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
193 |
public JavaFileObject getJavaFileObject(String name) { |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
194 |
return getJavaFileObjects(name).iterator().next(); |
10 | 195 |
} |
196 |
||
28332
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
197 |
// used by tests |
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
198 |
public JavaFileObject getJavaFileObject(Path file) { |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
199 |
return getJavaFileObjects(file).iterator().next(); |
10 | 200 |
} |
201 |
||
202 |
public JavaFileObject getFileForOutput(String classname, |
|
203 |
JavaFileObject.Kind kind, |
|
204 |
JavaFileObject sibling) |
|
205 |
throws IOException |
|
206 |
{ |
|
207 |
return getJavaFileForOutput(CLASS_OUTPUT, classname, kind, sibling); |
|
208 |
} |
|
209 |
||
27579 | 210 |
@Override @DefinedBy(Api.COMPILER) |
10 | 211 |
public Iterable<? extends JavaFileObject> getJavaFileObjectsFromStrings(Iterable<String> names) { |
28332
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
212 |
ListBuffer<Path> paths = new ListBuffer<>(); |
10 | 213 |
for (String name : names) |
37944
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37394
diff
changeset
|
214 |
paths.append(getPath(nullCheck(name))); |
28332
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
215 |
return getJavaFileObjectsFromPaths(paths.toList()); |
10 | 216 |
} |
217 |
||
27579 | 218 |
@Override @DefinedBy(Api.COMPILER) |
10 | 219 |
public Iterable<? extends JavaFileObject> getJavaFileObjects(String... names) { |
220 |
return getJavaFileObjectsFromStrings(Arrays.asList(nullCheck(names))); |
|
221 |
} |
|
222 |
||
223 |
private static boolean isValidName(String name) { |
|
224 |
// Arguably, isValidName should reject keywords (such as in SourceVersion.isName() ), |
|
225 |
// but the set of keywords depends on the source level, and we don't want |
|
226 |
// impls of JavaFileManager to have to be dependent on the source level. |
|
227 |
// Therefore we simply check that the argument is a sequence of identifiers |
|
228 |
// separated by ".". |
|
229 |
for (String s : name.split("\\.", -1)) { |
|
230 |
if (!SourceVersion.isIdentifier(s)) |
|
231 |
return false; |
|
232 |
} |
|
233 |
return true; |
|
234 |
} |
|
235 |
||
236 |
private static void validateClassName(String className) { |
|
237 |
if (!isValidName(className)) |
|
238 |
throw new IllegalArgumentException("Invalid class name: " + className); |
|
239 |
} |
|
240 |
||
241 |
private static void validatePackageName(String packageName) { |
|
242 |
if (packageName.length() > 0 && !isValidName(packageName)) |
|
243 |
throw new IllegalArgumentException("Invalid packageName name: " + packageName); |
|
244 |
} |
|
245 |
||
246 |
public static void testName(String name, |
|
247 |
boolean isValidPackageName, |
|
248 |
boolean isValidClassName) |
|
249 |
{ |
|
250 |
try { |
|
251 |
validatePackageName(name); |
|
252 |
if (!isValidPackageName) |
|
253 |
throw new AssertionError("Invalid package name accepted: " + name); |
|
254 |
printAscii("Valid package name: \"%s\"", name); |
|
255 |
} catch (IllegalArgumentException e) { |
|
256 |
if (isValidPackageName) |
|
257 |
throw new AssertionError("Valid package name rejected: " + name); |
|
258 |
printAscii("Invalid package name: \"%s\"", name); |
|
259 |
} |
|
260 |
try { |
|
261 |
validateClassName(name); |
|
262 |
if (!isValidClassName) |
|
263 |
throw new AssertionError("Invalid class name accepted: " + name); |
|
264 |
printAscii("Valid class name: \"%s\"", name); |
|
265 |
} catch (IllegalArgumentException e) { |
|
266 |
if (isValidClassName) |
|
267 |
throw new AssertionError("Valid class name rejected: " + name); |
|
268 |
printAscii("Invalid class name: \"%s\"", name); |
|
269 |
} |
|
270 |
} |
|
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
271 |
|
10 | 272 |
private static void printAscii(String format, Object... args) { |
273 |
String message; |
|
274 |
try { |
|
275 |
final String ascii = "US-ASCII"; |
|
276 |
message = new String(String.format(null, format, args).getBytes(ascii), ascii); |
|
277 |
} catch (java.io.UnsupportedEncodingException ex) { |
|
278 |
throw new AssertionError(ex); |
|
279 |
} |
|
280 |
System.out.println(message); |
|
281 |
} |
|
282 |
||
37390
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
283 |
private final Map<Path, Container> containers = new HashMap<>(); |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
284 |
|
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
285 |
synchronized Container getContainer(Path path) throws IOException { |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
286 |
Container fs = containers.get(path); |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
287 |
|
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
288 |
if (fs != null) { |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
289 |
return fs; |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
290 |
} |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
291 |
|
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
292 |
if (fsInfo.isFile(path) && path.equals(Locations.thisSystemModules)) { |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
293 |
containers.put(path, fs = new JRTImageContainer()); |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
294 |
return fs; |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
295 |
} |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
296 |
|
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
297 |
Path realPath = fsInfo.getCanonicalFile(path); |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
298 |
|
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
299 |
fs = containers.get(realPath); |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
300 |
|
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
301 |
if (fs != null) { |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
302 |
containers.put(path, fs); |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
303 |
return fs; |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
304 |
} |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
305 |
|
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
306 |
BasicFileAttributes attr = null; |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
307 |
|
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
308 |
try { |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
309 |
attr = Files.readAttributes(realPath, BasicFileAttributes.class); |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
310 |
} catch (IOException ex) { |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
311 |
//non-existing |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
312 |
fs = MISSING_CONTAINER; |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
313 |
} |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
314 |
|
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
315 |
if (attr != null) { |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
316 |
if (attr.isDirectory()) { |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
317 |
fs = new DirectoryContainer(realPath); |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
318 |
} else { |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
319 |
try { |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
320 |
fs = new ArchiveContainer(realPath); |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
321 |
} catch (ProviderNotFoundException | SecurityException ex) { |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
322 |
throw new IOException(ex); |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
323 |
} |
27579 | 324 |
} |
325 |
} |
|
326 |
||
37390
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
327 |
containers.put(realPath, fs); |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
328 |
containers.put(path, fs); |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
329 |
|
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
330 |
return fs; |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
331 |
} |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
332 |
|
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
333 |
private interface Container { |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
334 |
/** |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
335 |
* Insert all files in subdirectory subdirectory of container which |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
336 |
* match fileKinds into resultList |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
337 |
*/ |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
338 |
public abstract void list(Path userPath, |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
339 |
RelativeDirectory subdirectory, |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
340 |
Set<JavaFileObject.Kind> fileKinds, |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
341 |
boolean recurse, |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
342 |
ListBuffer<JavaFileObject> resultList) throws IOException; |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
343 |
public abstract JavaFileObject getFileObject(Path userPath, RelativeFile name) throws IOException; |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
344 |
public abstract void close() throws IOException; |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
345 |
} |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
346 |
|
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
347 |
private static final Container MISSING_CONTAINER = new Container() { |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
348 |
@Override |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
349 |
public void list(Path userPath, |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
350 |
RelativeDirectory subdirectory, |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
351 |
Set<JavaFileObject.Kind> fileKinds, |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
352 |
boolean recurse, |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
353 |
ListBuffer<JavaFileObject> resultList) throws IOException { |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
354 |
} |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
355 |
@Override |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
356 |
public JavaFileObject getFileObject(Path userPath, RelativeFile name) throws IOException { |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
357 |
return null; |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
358 |
} |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
359 |
@Override |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
360 |
public void close() throws IOException {} |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
361 |
}; |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
362 |
|
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
363 |
private final class JRTImageContainer implements Container { |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
364 |
|
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
365 |
/** |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
366 |
* Insert all files in a subdirectory of the platform image |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
367 |
* which match fileKinds into resultList. |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
368 |
*/ |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
369 |
@Override |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
370 |
public void list(Path userPath, |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
371 |
RelativeDirectory subdirectory, |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
372 |
Set<JavaFileObject.Kind> fileKinds, |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
373 |
boolean recurse, |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
374 |
ListBuffer<JavaFileObject> resultList) throws IOException { |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
375 |
try { |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
376 |
JRTIndex.Entry e = getJRTIndex().getEntry(subdirectory); |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
377 |
if (symbolFileEnabled && e.ctSym.hidden) |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
378 |
return; |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
379 |
for (Path file: e.files.values()) { |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
380 |
if (fileKinds.contains(getKind(file))) { |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
381 |
JavaFileObject fe |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
382 |
= PathFileObject.forJRTPath(JavacFileManager.this, file); |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
383 |
resultList.append(fe); |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
384 |
} |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
385 |
} |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
386 |
|
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
387 |
if (recurse) { |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
388 |
for (RelativeDirectory rd: e.subdirs) { |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
389 |
list(userPath, rd, fileKinds, recurse, resultList); |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
390 |
} |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
391 |
} |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
392 |
} catch (IOException ex) { |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
393 |
ex.printStackTrace(System.err); |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44822
diff
changeset
|
394 |
log.error(Errors.ErrorReadingFile(userPath, getMessage(ex))); |
27579 | 395 |
} |
396 |
} |
|
37390
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
397 |
|
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
398 |
@Override |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
399 |
public JavaFileObject getFileObject(Path userPath, RelativeFile name) throws IOException { |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
400 |
JRTIndex.Entry e = getJRTIndex().getEntry(name.dirname()); |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
401 |
if (symbolFileEnabled && e.ctSym.hidden) |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
402 |
return null; |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
403 |
Path p = e.files.get(name.basename()); |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
404 |
if (p != null) { |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
405 |
return PathFileObject.forJRTPath(JavacFileManager.this, p); |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
406 |
} else { |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
407 |
return null; |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
408 |
} |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
409 |
} |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
410 |
|
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
411 |
@Override |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
412 |
public void close() throws IOException { |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
413 |
} |
27579 | 414 |
} |
415 |
||
416 |
private synchronized JRTIndex getJRTIndex() { |
|
417 |
if (jrtIndex == null) |
|
418 |
jrtIndex = JRTIndex.getSharedInstance(); |
|
419 |
return jrtIndex; |
|
420 |
} |
|
421 |
||
422 |
private JRTIndex jrtIndex; |
|
423 |
||
37390
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
424 |
private final class DirectoryContainer implements Container { |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
425 |
private final Path directory; |
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
426 |
|
37390
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
427 |
public DirectoryContainer(Path directory) { |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
428 |
this.directory = directory; |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
429 |
} |
10 | 430 |
|
37390
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
431 |
/** |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
432 |
* Insert all files in subdirectory subdirectory of directory userPath |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
433 |
* which match fileKinds into resultList |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
434 |
*/ |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
435 |
@Override |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
436 |
public void list(Path userPath, |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
437 |
RelativeDirectory subdirectory, |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
438 |
Set<JavaFileObject.Kind> fileKinds, |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
439 |
boolean recurse, |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
440 |
ListBuffer<JavaFileObject> resultList) throws IOException { |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
441 |
Path d; |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
442 |
try { |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
443 |
d = subdirectory.resolveAgainst(userPath); |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
444 |
} catch (InvalidPathException ignore) { |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
445 |
return ; |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
446 |
} |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
447 |
|
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
448 |
if (!Files.exists(d)) { |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
449 |
return; |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
450 |
} |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
451 |
|
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
452 |
if (!caseMapCheck(d, subdirectory)) { |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
453 |
return; |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
454 |
} |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
455 |
|
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
456 |
java.util.List<Path> files; |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
457 |
try (Stream<Path> s = Files.list(d)) { |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
458 |
files = (sortFiles == null ? s : s.sorted(sortFiles)).collect(Collectors.toList()); |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
459 |
} catch (IOException ignore) { |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
460 |
return; |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
461 |
} |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
462 |
|
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
463 |
for (Path f: files) { |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
464 |
String fname = f.getFileName().toString(); |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
465 |
if (fname.endsWith("/")) |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
466 |
fname = fname.substring(0, fname.length() - 1); |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
467 |
if (Files.isDirectory(f)) { |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
468 |
if (recurse && SourceVersion.isIdentifier(fname)) { |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
469 |
list(userPath, |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
470 |
new RelativeDirectory(subdirectory, fname), |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
471 |
fileKinds, |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
472 |
recurse, |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
473 |
resultList); |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
474 |
} |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
475 |
} else { |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
476 |
if (isValidFile(fname, fileKinds)) { |
44566
db270eef83ae
8177332: The presence of a file with a Japanese ShiftJIS name can cause javac to fail
vromero
parents:
44063
diff
changeset
|
477 |
try { |
db270eef83ae
8177332: The presence of a file with a Japanese ShiftJIS name can cause javac to fail
vromero
parents:
44063
diff
changeset
|
478 |
RelativeFile file = new RelativeFile(subdirectory, fname); |
db270eef83ae
8177332: The presence of a file with a Japanese ShiftJIS name can cause javac to fail
vromero
parents:
44063
diff
changeset
|
479 |
JavaFileObject fe = PathFileObject.forDirectoryPath(JavacFileManager.this, |
db270eef83ae
8177332: The presence of a file with a Japanese ShiftJIS name can cause javac to fail
vromero
parents:
44063
diff
changeset
|
480 |
file.resolveAgainst(directory), userPath, file); |
db270eef83ae
8177332: The presence of a file with a Japanese ShiftJIS name can cause javac to fail
vromero
parents:
44063
diff
changeset
|
481 |
resultList.append(fe); |
db270eef83ae
8177332: The presence of a file with a Japanese ShiftJIS name can cause javac to fail
vromero
parents:
44063
diff
changeset
|
482 |
} catch (InvalidPathException e) { |
db270eef83ae
8177332: The presence of a file with a Japanese ShiftJIS name can cause javac to fail
vromero
parents:
44063
diff
changeset
|
483 |
throw new IOException("error accessing directory " + directory + e); |
db270eef83ae
8177332: The presence of a file with a Japanese ShiftJIS name can cause javac to fail
vromero
parents:
44063
diff
changeset
|
484 |
} |
37390
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
485 |
} |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
486 |
} |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
487 |
} |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
488 |
} |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
489 |
|
37390
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
490 |
@Override |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
491 |
public JavaFileObject getFileObject(Path userPath, RelativeFile name) throws IOException { |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
492 |
try { |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
493 |
Path f = name.resolveAgainst(userPath); |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
494 |
if (Files.exists(f)) |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
495 |
return PathFileObject.forSimplePath(JavacFileManager.this, |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
496 |
fsInfo.getCanonicalFile(f), f); |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
497 |
} catch (InvalidPathException ignore) { |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
498 |
} |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
499 |
return null; |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
500 |
} |
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
501 |
|
37390
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
502 |
@Override |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
503 |
public void close() throws IOException { |
10 | 504 |
} |
505 |
} |
|
506 |
||
37390
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
507 |
private final class ArchiveContainer implements Container { |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
508 |
private final Path archivePath; |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
509 |
private final FileSystem fileSystem; |
43565
266c9503e22f
8171294: Slow compilation with long classpaths under JDK 9
jlahoda
parents:
42827
diff
changeset
|
510 |
private final Map<RelativePath, Path> packages; |
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
511 |
|
37390
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
512 |
public ArchiveContainer(Path archivePath) throws IOException, ProviderNotFoundException, SecurityException { |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
513 |
this.archivePath = archivePath; |
37394
c36230ee15d9
8149757: Implement Multi-Release JAR aware JavacFileManager for javac
jjg
parents:
37390
diff
changeset
|
514 |
if (multiReleaseValue != null && archivePath.toString().endsWith(".jar")) { |
c36230ee15d9
8149757: Implement Multi-Release JAR aware JavacFileManager for javac
jjg
parents:
37390
diff
changeset
|
515 |
Map<String,String> env = Collections.singletonMap("multi-release", multiReleaseValue); |
40513
39b67170b045
8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
38533
diff
changeset
|
516 |
FileSystemProvider jarFSProvider = fsInfo.getJarFSProvider(); |
39b67170b045
8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
38533
diff
changeset
|
517 |
Assert.checkNonNull(jarFSProvider, "should have been caught before!"); |
39b67170b045
8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
38533
diff
changeset
|
518 |
this.fileSystem = jarFSProvider.newFileSystem(archivePath, env); |
37394
c36230ee15d9
8149757: Implement Multi-Release JAR aware JavacFileManager for javac
jjg
parents:
37390
diff
changeset
|
519 |
} else { |
c36230ee15d9
8149757: Implement Multi-Release JAR aware JavacFileManager for javac
jjg
parents:
37390
diff
changeset
|
520 |
this.fileSystem = FileSystems.newFileSystem(archivePath, null); |
c36230ee15d9
8149757: Implement Multi-Release JAR aware JavacFileManager for javac
jjg
parents:
37390
diff
changeset
|
521 |
} |
43565
266c9503e22f
8171294: Slow compilation with long classpaths under JDK 9
jlahoda
parents:
42827
diff
changeset
|
522 |
packages = new HashMap<>(); |
266c9503e22f
8171294: Slow compilation with long classpaths under JDK 9
jlahoda
parents:
42827
diff
changeset
|
523 |
for (Path root : fileSystem.getRootDirectories()) { |
266c9503e22f
8171294: Slow compilation with long classpaths under JDK 9
jlahoda
parents:
42827
diff
changeset
|
524 |
Files.walkFileTree(root, EnumSet.noneOf(FileVisitOption.class), Integer.MAX_VALUE, |
266c9503e22f
8171294: Slow compilation with long classpaths under JDK 9
jlahoda
parents:
42827
diff
changeset
|
525 |
new SimpleFileVisitor<Path>() { |
266c9503e22f
8171294: Slow compilation with long classpaths under JDK 9
jlahoda
parents:
42827
diff
changeset
|
526 |
@Override |
266c9503e22f
8171294: Slow compilation with long classpaths under JDK 9
jlahoda
parents:
42827
diff
changeset
|
527 |
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) { |
266c9503e22f
8171294: Slow compilation with long classpaths under JDK 9
jlahoda
parents:
42827
diff
changeset
|
528 |
if (isValid(dir.getFileName())) { |
266c9503e22f
8171294: Slow compilation with long classpaths under JDK 9
jlahoda
parents:
42827
diff
changeset
|
529 |
packages.put(new RelativeDirectory(root.relativize(dir).toString()), dir); |
266c9503e22f
8171294: Slow compilation with long classpaths under JDK 9
jlahoda
parents:
42827
diff
changeset
|
530 |
return FileVisitResult.CONTINUE; |
266c9503e22f
8171294: Slow compilation with long classpaths under JDK 9
jlahoda
parents:
42827
diff
changeset
|
531 |
} else { |
266c9503e22f
8171294: Slow compilation with long classpaths under JDK 9
jlahoda
parents:
42827
diff
changeset
|
532 |
return FileVisitResult.SKIP_SUBTREE; |
266c9503e22f
8171294: Slow compilation with long classpaths under JDK 9
jlahoda
parents:
42827
diff
changeset
|
533 |
} |
266c9503e22f
8171294: Slow compilation with long classpaths under JDK 9
jlahoda
parents:
42827
diff
changeset
|
534 |
} |
266c9503e22f
8171294: Slow compilation with long classpaths under JDK 9
jlahoda
parents:
42827
diff
changeset
|
535 |
}); |
266c9503e22f
8171294: Slow compilation with long classpaths under JDK 9
jlahoda
parents:
42827
diff
changeset
|
536 |
} |
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
537 |
} |
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
538 |
|
37390
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
539 |
/** |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
540 |
* Insert all files in subdirectory subdirectory of this archive |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
541 |
* which match fileKinds into resultList |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
542 |
*/ |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
543 |
@Override |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
544 |
public void list(Path userPath, |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
545 |
RelativeDirectory subdirectory, |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
546 |
Set<JavaFileObject.Kind> fileKinds, |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
547 |
boolean recurse, |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
548 |
ListBuffer<JavaFileObject> resultList) throws IOException { |
43565
266c9503e22f
8171294: Slow compilation with long classpaths under JDK 9
jlahoda
parents:
42827
diff
changeset
|
549 |
Path resolvedSubdirectory = packages.get(subdirectory); |
37390
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
550 |
|
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
551 |
if (resolvedSubdirectory == null) |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
552 |
return ; |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
553 |
|
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
554 |
int maxDepth = (recurse ? Integer.MAX_VALUE : 1); |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
555 |
Set<FileVisitOption> opts = EnumSet.of(FOLLOW_LINKS); |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
556 |
Files.walkFileTree(resolvedSubdirectory, opts, maxDepth, |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
557 |
new SimpleFileVisitor<Path>() { |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
558 |
@Override |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
559 |
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) { |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
560 |
if (isValid(dir.getFileName())) { |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
561 |
return FileVisitResult.CONTINUE; |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
562 |
} else { |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
563 |
return FileVisitResult.SKIP_SUBTREE; |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
564 |
} |
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
565 |
} |
37390
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
566 |
|
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
567 |
@Override |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
568 |
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
569 |
if (attrs.isRegularFile() && fileKinds.contains(getKind(file.getFileName().toString()))) { |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
570 |
JavaFileObject fe = PathFileObject.forJarPath( |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
571 |
JavacFileManager.this, file, archivePath); |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
572 |
resultList.append(fe); |
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
573 |
} |
37390
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
574 |
return FileVisitResult.CONTINUE; |
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
575 |
} |
37390
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
576 |
}); |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
577 |
|
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
578 |
} |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
579 |
|
43565
266c9503e22f
8171294: Slow compilation with long classpaths under JDK 9
jlahoda
parents:
42827
diff
changeset
|
580 |
private boolean isValid(Path fileName) { |
266c9503e22f
8171294: Slow compilation with long classpaths under JDK 9
jlahoda
parents:
42827
diff
changeset
|
581 |
if (fileName == null) { |
266c9503e22f
8171294: Slow compilation with long classpaths under JDK 9
jlahoda
parents:
42827
diff
changeset
|
582 |
return true; |
266c9503e22f
8171294: Slow compilation with long classpaths under JDK 9
jlahoda
parents:
42827
diff
changeset
|
583 |
} else { |
266c9503e22f
8171294: Slow compilation with long classpaths under JDK 9
jlahoda
parents:
42827
diff
changeset
|
584 |
String name = fileName.toString(); |
266c9503e22f
8171294: Slow compilation with long classpaths under JDK 9
jlahoda
parents:
42827
diff
changeset
|
585 |
if (name.endsWith("/")) { |
266c9503e22f
8171294: Slow compilation with long classpaths under JDK 9
jlahoda
parents:
42827
diff
changeset
|
586 |
name = name.substring(0, name.length() - 1); |
266c9503e22f
8171294: Slow compilation with long classpaths under JDK 9
jlahoda
parents:
42827
diff
changeset
|
587 |
} |
266c9503e22f
8171294: Slow compilation with long classpaths under JDK 9
jlahoda
parents:
42827
diff
changeset
|
588 |
return SourceVersion.isIdentifier(name); |
266c9503e22f
8171294: Slow compilation with long classpaths under JDK 9
jlahoda
parents:
42827
diff
changeset
|
589 |
} |
37390
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
590 |
} |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
591 |
|
43565
266c9503e22f
8171294: Slow compilation with long classpaths under JDK 9
jlahoda
parents:
42827
diff
changeset
|
592 |
@Override |
266c9503e22f
8171294: Slow compilation with long classpaths under JDK 9
jlahoda
parents:
42827
diff
changeset
|
593 |
public JavaFileObject getFileObject(Path userPath, RelativeFile name) throws IOException { |
266c9503e22f
8171294: Slow compilation with long classpaths under JDK 9
jlahoda
parents:
42827
diff
changeset
|
594 |
RelativeDirectory root = name.dirname(); |
266c9503e22f
8171294: Slow compilation with long classpaths under JDK 9
jlahoda
parents:
42827
diff
changeset
|
595 |
Path packagepath = packages.get(root); |
266c9503e22f
8171294: Slow compilation with long classpaths under JDK 9
jlahoda
parents:
42827
diff
changeset
|
596 |
if (packagepath != null) { |
266c9503e22f
8171294: Slow compilation with long classpaths under JDK 9
jlahoda
parents:
42827
diff
changeset
|
597 |
Path relpath = packagepath.resolve(name.basename()); |
266c9503e22f
8171294: Slow compilation with long classpaths under JDK 9
jlahoda
parents:
42827
diff
changeset
|
598 |
if (Files.exists(relpath)) { |
266c9503e22f
8171294: Slow compilation with long classpaths under JDK 9
jlahoda
parents:
42827
diff
changeset
|
599 |
return PathFileObject.forJarPath(JavacFileManager.this, relpath, userPath); |
37390
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
600 |
} |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
601 |
} |
43565
266c9503e22f
8171294: Slow compilation with long classpaths under JDK 9
jlahoda
parents:
42827
diff
changeset
|
602 |
return null; |
37390
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
603 |
} |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
604 |
|
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
605 |
@Override |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
606 |
public void close() throws IOException { |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
607 |
fileSystem.close(); |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
608 |
} |
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
609 |
} |
37394
c36230ee15d9
8149757: Implement Multi-Release JAR aware JavacFileManager for javac
jjg
parents:
37390
diff
changeset
|
610 |
|
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
611 |
/** |
37394
c36230ee15d9
8149757: Implement Multi-Release JAR aware JavacFileManager for javac
jjg
parents:
37390
diff
changeset
|
612 |
* container is a directory, a zip file, or a non-existent path. |
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7335
diff
changeset
|
613 |
*/ |
10 | 614 |
private boolean isValidFile(String s, Set<JavaFileObject.Kind> fileKinds) { |
4548 | 615 |
JavaFileObject.Kind kind = getKind(s); |
10 | 616 |
return fileKinds.contains(kind); |
617 |
} |
|
618 |
||
619 |
private static final boolean fileSystemIsCaseSensitive = |
|
620 |
File.separatorChar == '/'; |
|
621 |
||
622 |
/** Hack to make Windows case sensitive. Test whether given path |
|
623 |
* ends in a string of characters with the same case as given name. |
|
624 |
* Ignore file separators in both path and name. |
|
625 |
*/ |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
626 |
private boolean caseMapCheck(Path f, RelativePath name) { |
10 | 627 |
if (fileSystemIsCaseSensitive) return true; |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
628 |
// Note that toRealPath() returns the case-sensitive |
10 | 629 |
// spelled file name. |
630 |
String path; |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
631 |
char sep; |
10 | 632 |
try { |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
633 |
path = f.toRealPath(LinkOption.NOFOLLOW_LINKS).toString(); |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
634 |
sep = f.getFileSystem().getSeparator().charAt(0); |
10 | 635 |
} catch (IOException ex) { |
636 |
return false; |
|
637 |
} |
|
638 |
char[] pcs = path.toCharArray(); |
|
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
639 |
char[] ncs = name.path.toCharArray(); |
10 | 640 |
int i = pcs.length - 1; |
641 |
int j = ncs.length - 1; |
|
642 |
while (i >= 0 && j >= 0) { |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
643 |
while (i >= 0 && pcs[i] == sep) i--; |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
644 |
while (j >= 0 && ncs[j] == '/') j--; |
10 | 645 |
if (i >= 0 && j >= 0) { |
646 |
if (pcs[i] != ncs[j]) return false; |
|
647 |
i--; |
|
648 |
j--; |
|
649 |
} |
|
650 |
} |
|
651 |
return j < 0; |
|
652 |
} |
|
653 |
||
654 |
/** Flush any output resources. |
|
655 |
*/ |
|
27579 | 656 |
@Override @DefinedBy(Api.COMPILER) |
10 | 657 |
public void flush() { |
658 |
contentCache.clear(); |
|
659 |
} |
|
660 |
||
661 |
/** |
|
662 |
* Close the JavaFileManager, releasing resources. |
|
663 |
*/ |
|
27579 | 664 |
@Override @DefinedBy(Api.COMPILER) |
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
665 |
public void close() throws IOException { |
35807
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
34560
diff
changeset
|
666 |
if (deferredCloseTimeout > 0) { |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
34560
diff
changeset
|
667 |
deferredClose(); |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
34560
diff
changeset
|
668 |
return; |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
34560
diff
changeset
|
669 |
} |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
34560
diff
changeset
|
670 |
|
36526 | 671 |
locations.close(); |
37390
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
672 |
for (Container container: containers.values()) { |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
673 |
container.close(); |
35807
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
34560
diff
changeset
|
674 |
} |
37390
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
675 |
containers.clear(); |
35807
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
34560
diff
changeset
|
676 |
contentCache.clear(); |
10 | 677 |
} |
678 |
||
27579 | 679 |
@Override @DefinedBy(Api.COMPILER) |
10 | 680 |
public ClassLoader getClassLoader(Location location) { |
42261
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41033
diff
changeset
|
681 |
checkNotModuleOrientedLocation(location); |
10 | 682 |
Iterable<? extends File> path = getLocation(location); |
683 |
if (path == null) |
|
684 |
return null; |
|
22163 | 685 |
ListBuffer<URL> lb = new ListBuffer<>(); |
10 | 686 |
for (File f: path) { |
687 |
try { |
|
688 |
lb.append(f.toURI().toURL()); |
|
689 |
} catch (MalformedURLException e) { |
|
690 |
throw new AssertionError(e); |
|
691 |
} |
|
692 |
} |
|
3656
d4e34b76b0c3
6558476: com/sun/tools/javac/Main.compile don't release file handles on return
jjg
parents:
3380
diff
changeset
|
693 |
|
4548 | 694 |
return getClassLoader(lb.toArray(new URL[lb.size()])); |
10 | 695 |
} |
696 |
||
27579 | 697 |
@Override @DefinedBy(Api.COMPILER) |
10 | 698 |
public Iterable<JavaFileObject> list(Location location, |
699 |
String packageName, |
|
700 |
Set<JavaFileObject.Kind> kinds, |
|
701 |
boolean recurse) |
|
702 |
throws IOException |
|
703 |
{ |
|
42261
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41033
diff
changeset
|
704 |
checkNotModuleOrientedLocation(location); |
10 | 705 |
// validatePackageName(packageName); |
706 |
nullCheck(packageName); |
|
707 |
nullCheck(kinds); |
|
708 |
||
27858 | 709 |
Iterable<? extends Path> path = getLocationAsPaths(location); |
10 | 710 |
if (path == null) |
711 |
return List.nil(); |
|
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
712 |
RelativeDirectory subdirectory = RelativeDirectory.forPackage(packageName); |
22163 | 713 |
ListBuffer<JavaFileObject> results = new ListBuffer<>(); |
10 | 714 |
|
37390
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
715 |
for (Path directory : path) { |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
716 |
Container container = getContainer(directory); |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
717 |
|
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
718 |
container.list(directory, subdirectory, kinds, recurse, results); |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
719 |
} |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
720 |
|
10 | 721 |
return results.toList(); |
722 |
} |
|
723 |
||
27579 | 724 |
@Override @DefinedBy(Api.COMPILER) |
10 | 725 |
public String inferBinaryName(Location location, JavaFileObject file) { |
42261
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41033
diff
changeset
|
726 |
checkNotModuleOrientedLocation(location); |
29291
076c277565f7
8073550: java* tools: replace obj.getClass hacks with Assert.checkNonNull or Objects.requireNonNull
mcimadamore
parents:
28332
diff
changeset
|
727 |
Objects.requireNonNull(file); |
10 | 728 |
// 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
|
729 |
Iterable<? extends Path> path = getLocationAsPaths(location); |
10 | 730 |
if (path == null) { |
731 |
return null; |
|
732 |
} |
|
733 |
||
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
734 |
if (file instanceof PathFileObject) { |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
735 |
return ((PathFileObject) file).inferBinaryName(path); |
10 | 736 |
} else |
737 |
throw new IllegalArgumentException(file.getClass().getName()); |
|
738 |
} |
|
739 |
||
27579 | 740 |
@Override @DefinedBy(Api.COMPILER) |
10 | 741 |
public boolean isSameFile(FileObject a, FileObject b) { |
742 |
nullCheck(a); |
|
743 |
nullCheck(b); |
|
27579 | 744 |
if (a instanceof PathFileObject && b instanceof PathFileObject) |
745 |
return ((PathFileObject) a).isSameFile((PathFileObject) b); |
|
10 | 746 |
return a.equals(b); |
747 |
} |
|
748 |
||
27579 | 749 |
@Override @DefinedBy(Api.COMPILER) |
10 | 750 |
public boolean hasLocation(Location location) { |
36526 | 751 |
nullCheck(location); |
752 |
return locations.hasLocation(location); |
|
10 | 753 |
} |
754 |
||
27579 | 755 |
@Override @DefinedBy(Api.COMPILER) |
10 | 756 |
public JavaFileObject getJavaFileForInput(Location location, |
757 |
String className, |
|
758 |
JavaFileObject.Kind kind) |
|
759 |
throws IOException |
|
760 |
{ |
|
42261
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41033
diff
changeset
|
761 |
checkNotModuleOrientedLocation(location); |
10 | 762 |
// validateClassName(className); |
763 |
nullCheck(className); |
|
764 |
nullCheck(kind); |
|
765 |
if (!sourceOrClass.contains(kind)) |
|
6719
1ce993f87850
6502392: Invalid relative names for Filer.createResource and Filer.getResource
jjg
parents:
5847
diff
changeset
|
766 |
throw new IllegalArgumentException("Invalid kind: " + kind); |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
767 |
return getFileForInput(location, RelativeFile.forClass(className, kind)); |
10 | 768 |
} |
769 |
||
27579 | 770 |
@Override @DefinedBy(Api.COMPILER) |
10 | 771 |
public FileObject getFileForInput(Location location, |
772 |
String packageName, |
|
773 |
String relativeName) |
|
774 |
throws IOException |
|
775 |
{ |
|
42261
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41033
diff
changeset
|
776 |
checkNotModuleOrientedLocation(location); |
10 | 777 |
// validatePackageName(packageName); |
778 |
nullCheck(packageName); |
|
3782 | 779 |
if (!isRelativeUri(relativeName)) |
10 | 780 |
throw new IllegalArgumentException("Invalid relative name: " + relativeName); |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
781 |
RelativeFile name = packageName.length() == 0 |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
782 |
? new RelativeFile(relativeName) |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
783 |
: new RelativeFile(RelativeDirectory.forPackage(packageName), relativeName); |
10 | 784 |
return getFileForInput(location, name); |
785 |
} |
|
786 |
||
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
787 |
private JavaFileObject getFileForInput(Location location, RelativeFile name) throws IOException { |
27858 | 788 |
Iterable<? extends Path> path = getLocationAsPaths(location); |
10 | 789 |
if (path == null) |
790 |
return null; |
|
791 |
||
27858 | 792 |
for (Path file: path) { |
37390
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
793 |
JavaFileObject fo = getContainer(file).getFileObject(file, name); |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
794 |
|
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
795 |
if (fo != null) { |
bf1552d6bc16
8150641: Repeated compilation with a long classpath significantly slower on JDK 9
jlahoda
parents:
36526
diff
changeset
|
796 |
return fo; |
10 | 797 |
} |
798 |
} |
|
799 |
return null; |
|
800 |
} |
|
801 |
||
27579 | 802 |
@Override @DefinedBy(Api.COMPILER) |
10 | 803 |
public JavaFileObject getJavaFileForOutput(Location location, |
804 |
String className, |
|
805 |
JavaFileObject.Kind kind, |
|
806 |
FileObject sibling) |
|
807 |
throws IOException |
|
808 |
{ |
|
42261
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41033
diff
changeset
|
809 |
checkOutputLocation(location); |
10 | 810 |
// validateClassName(className); |
811 |
nullCheck(className); |
|
812 |
nullCheck(kind); |
|
813 |
if (!sourceOrClass.contains(kind)) |
|
6719
1ce993f87850
6502392: Invalid relative names for Filer.createResource and Filer.getResource
jjg
parents:
5847
diff
changeset
|
814 |
throw new IllegalArgumentException("Invalid kind: " + kind); |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
815 |
return getFileForOutput(location, RelativeFile.forClass(className, kind), sibling); |
10 | 816 |
} |
817 |
||
27579 | 818 |
@Override @DefinedBy(Api.COMPILER) |
10 | 819 |
public FileObject getFileForOutput(Location location, |
820 |
String packageName, |
|
821 |
String relativeName, |
|
822 |
FileObject sibling) |
|
823 |
throws IOException |
|
824 |
{ |
|
42261
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41033
diff
changeset
|
825 |
checkOutputLocation(location); |
10 | 826 |
// validatePackageName(packageName); |
827 |
nullCheck(packageName); |
|
3782 | 828 |
if (!isRelativeUri(relativeName)) |
6719
1ce993f87850
6502392: Invalid relative names for Filer.createResource and Filer.getResource
jjg
parents:
5847
diff
changeset
|
829 |
throw new IllegalArgumentException("Invalid relative name: " + relativeName); |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
830 |
RelativeFile name = packageName.length() == 0 |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
831 |
? new RelativeFile(relativeName) |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
832 |
: new RelativeFile(RelativeDirectory.forPackage(packageName), relativeName); |
10 | 833 |
return getFileForOutput(location, name, sibling); |
834 |
} |
|
835 |
||
836 |
private JavaFileObject getFileForOutput(Location location, |
|
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
815
diff
changeset
|
837 |
RelativeFile fileName, |
10 | 838 |
FileObject sibling) |
839 |
throws IOException |
|
840 |
{ |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
841 |
Path dir; |
10 | 842 |
if (location == CLASS_OUTPUT) { |
843 |
if (getClassOutDir() != null) { |
|
844 |
dir = getClassOutDir(); |
|
845 |
} else { |
|
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
846 |
String baseName = fileName.basename(); |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
847 |
if (sibling != null && sibling instanceof PathFileObject) { |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
848 |
return ((PathFileObject) sibling).getSibling(baseName); |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
849 |
} else { |
37944
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37394
diff
changeset
|
850 |
Path p = getPath(baseName); |
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
851 |
Path real = fsInfo.getCanonicalFile(p); |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
852 |
return PathFileObject.forSimplePath(this, real, p); |
10 | 853 |
} |
854 |
} |
|
855 |
} else if (location == SOURCE_OUTPUT) { |
|
856 |
dir = (getSourceOutDir() != null ? getSourceOutDir() : getClassOutDir()); |
|
857 |
} else { |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
858 |
Iterable<? extends Path> path = locations.getLocation(location); |
10 | 859 |
dir = null; |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
860 |
for (Path f: path) { |
10 | 861 |
dir = f; |
862 |
break; |
|
863 |
} |
|
864 |
} |
|
865 |
||
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
866 |
try { |
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
867 |
if (dir == null) { |
37944
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37394
diff
changeset
|
868 |
dir = getPath(System.getProperty("user.dir")); |
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
869 |
} |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
870 |
Path path = fileName.resolveAgainst(fsInfo.getCanonicalFile(dir)); |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
871 |
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
|
872 |
} catch (InvalidPathException e) { |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
873 |
throw new IOException("bad filename " + fileName, e); |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
874 |
} |
10 | 875 |
} |
876 |
||
27579 | 877 |
@Override @DefinedBy(Api.COMPILER) |
10 | 878 |
public Iterable<? extends JavaFileObject> getJavaFileObjectsFromFiles( |
879 |
Iterable<? extends File> files) |
|
880 |
{ |
|
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
881 |
ArrayList<PathFileObject> result; |
1789
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1208
diff
changeset
|
882 |
if (files instanceof Collection<?>) |
22163 | 883 |
result = new ArrayList<>(((Collection<?>)files).size()); |
10 | 884 |
else |
22163 | 885 |
result = new ArrayList<>(); |
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
886 |
for (File f: files) { |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
887 |
Objects.requireNonNull(f); |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
888 |
Path p = f.toPath(); |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
889 |
result.add(PathFileObject.forSimplePath(this, |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
890 |
fsInfo.getCanonicalFile(p), p)); |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
891 |
} |
10 | 892 |
return result; |
893 |
} |
|
894 |
||
27579 | 895 |
@Override @DefinedBy(Api.COMPILER) |
28332
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
896 |
public Iterable<? extends JavaFileObject> getJavaFileObjectsFromPaths( |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
897 |
Iterable<? extends Path> paths) |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
898 |
{ |
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
899 |
ArrayList<PathFileObject> result; |
28332
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
900 |
if (paths instanceof Collection<?>) |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
901 |
result = new ArrayList<>(((Collection<?>)paths).size()); |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
902 |
else |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
903 |
result = new ArrayList<>(); |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
904 |
for (Path p: paths) |
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
905 |
result.add(PathFileObject.forSimplePath(this, |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
906 |
fsInfo.getCanonicalFile(p), p)); |
28332
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
907 |
return result; |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
908 |
} |
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 |
@Override @DefinedBy(Api.COMPILER) |
10 | 911 |
public Iterable<? extends JavaFileObject> getJavaFileObjects(File... files) { |
912 |
return getJavaFileObjectsFromFiles(Arrays.asList(nullCheck(files))); |
|
913 |
} |
|
914 |
||
27579 | 915 |
@Override @DefinedBy(Api.COMPILER) |
28332
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
916 |
public Iterable<? extends JavaFileObject> getJavaFileObjects(Path... paths) { |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
917 |
return getJavaFileObjectsFromPaths(Arrays.asList(nullCheck(paths))); |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
918 |
} |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
919 |
|
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
920 |
@Override @DefinedBy(Api.COMPILER) |
10 | 921 |
public void setLocation(Location location, |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
922 |
Iterable<? extends File> searchpath) |
10 | 923 |
throws IOException |
924 |
{ |
|
925 |
nullCheck(location); |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
926 |
locations.setLocation(location, asPaths(searchpath)); |
10 | 927 |
} |
928 |
||
27579 | 929 |
@Override @DefinedBy(Api.COMPILER) |
28332
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
930 |
public void setLocationFromPaths(Location location, |
37944
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37394
diff
changeset
|
931 |
Collection<? extends Path> searchpath) |
28332
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
932 |
throws IOException |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
933 |
{ |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
934 |
nullCheck(location); |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
935 |
locations.setLocation(location, nullCheck(searchpath)); |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
936 |
} |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
937 |
|
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
938 |
@Override @DefinedBy(Api.COMPILER) |
10 | 939 |
public Iterable<? extends File> getLocation(Location location) { |
940 |
nullCheck(location); |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
941 |
return asFiles(locations.getLocation(location)); |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
942 |
} |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
943 |
|
28332
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
944 |
@Override @DefinedBy(Api.COMPILER) |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
945 |
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
|
946 |
nullCheck(location); |
10818 | 947 |
return locations.getLocation(location); |
10 | 948 |
} |
949 |
||
44822 | 950 |
@Override @DefinedBy(Api.COMPILER) |
951 |
public boolean contains(Location location, FileObject fo) throws IOException { |
|
952 |
nullCheck(location); |
|
953 |
nullCheck(fo); |
|
954 |
Path p = asPath(fo); |
|
955 |
return locations.contains(location, p); |
|
956 |
} |
|
957 |
||
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
958 |
private Path getClassOutDir() { |
10818 | 959 |
return locations.getOutputLocation(CLASS_OUTPUT); |
10 | 960 |
} |
961 |
||
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
962 |
private Path getSourceOutDir() { |
10818 | 963 |
return locations.getOutputLocation(SOURCE_OUTPUT); |
10 | 964 |
} |
965 |
||
28332
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
966 |
@Override @DefinedBy(Api.COMPILER) |
42261
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41033
diff
changeset
|
967 |
public Location getLocationForModule(Location location, String moduleName) throws IOException { |
42814
058fc03646d9
8171005: Fix JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName) to work with location == CLASS_OUTPUT
jlahoda
parents:
42261
diff
changeset
|
968 |
checkModuleOrientedOrOutputLocation(location); |
36526 | 969 |
nullCheck(moduleName); |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42814
diff
changeset
|
970 |
if (location == SOURCE_OUTPUT && getSourceOutDir() == null) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42814
diff
changeset
|
971 |
location = CLASS_OUTPUT; |
42261
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41033
diff
changeset
|
972 |
return locations.getLocationForModule(location, moduleName); |
36526 | 973 |
} |
974 |
||
975 |
@Override @DefinedBy(Api.COMPILER) |
|
976 |
public <S> ServiceLoader<S> getServiceLoader(Location location, Class<S> service) throws IOException { |
|
977 |
nullCheck(location); |
|
978 |
nullCheck(service); |
|
41033
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40513
diff
changeset
|
979 |
Module.getModule(getClass()).addUses(service); |
42261
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41033
diff
changeset
|
980 |
if (location.isModuleOrientedLocation()) { |
36526 | 981 |
Collection<Path> paths = locations.getLocation(location); |
982 |
ModuleFinder finder = ModuleFinder.of(paths.toArray(new Path[paths.size()])); |
|
983 |
Layer bootLayer = Layer.boot(); |
|
43767
9cff98a149cb
8173393: Module system implementation refresh (2/2017)
alanb
parents:
43565
diff
changeset
|
984 |
Configuration cf = bootLayer.configuration().resolveAndBind(ModuleFinder.of(), finder, Collections.emptySet()); |
36526 | 985 |
Layer layer = bootLayer.defineModulesWithOneLoader(cf, ClassLoader.getSystemClassLoader()); |
986 |
return ServiceLoaderHelper.load(layer, service); |
|
987 |
} else { |
|
988 |
return ServiceLoader.load(service, getClassLoader(location)); |
|
989 |
} |
|
990 |
} |
|
991 |
||
992 |
@Override @DefinedBy(Api.COMPILER) |
|
44063
5f0cf4126949
8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents:
44019
diff
changeset
|
993 |
public Location getLocationForModule(Location location, JavaFileObject fo) throws IOException { |
42814
058fc03646d9
8171005: Fix JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName) to work with location == CLASS_OUTPUT
jlahoda
parents:
42261
diff
changeset
|
994 |
checkModuleOrientedOrOutputLocation(location); |
36526 | 995 |
if (!(fo instanceof PathFileObject)) |
43772
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43767
diff
changeset
|
996 |
return null; |
36526 | 997 |
Path p = Locations.normalize(((PathFileObject) fo).path); |
44063
5f0cf4126949
8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents:
44019
diff
changeset
|
998 |
// need to find p in location |
5f0cf4126949
8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents:
44019
diff
changeset
|
999 |
return locations.getLocationForModule(location, p); |
36526 | 1000 |
} |
1001 |
||
1002 |
@Override @DefinedBy(Api.COMPILER) |
|
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1003 |
public void setLocationForModule(Location location, String moduleName, Collection<? extends Path> paths) |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1004 |
throws IOException { |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1005 |
nullCheck(location); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1006 |
checkModuleOrientedOrOutputLocation(location); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1007 |
locations.setLocationForModule(location, nullCheck(moduleName), nullCheck(paths)); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1008 |
} |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1009 |
|
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1010 |
@Override @DefinedBy(Api.COMPILER) |
36526 | 1011 |
public String inferModuleName(Location location) { |
42261
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41033
diff
changeset
|
1012 |
checkNotModuleOrientedLocation(location); |
36526 | 1013 |
return locations.inferModuleName(location); |
1014 |
} |
|
1015 |
||
1016 |
@Override @DefinedBy(Api.COMPILER) |
|
42261
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41033
diff
changeset
|
1017 |
public Iterable<Set<Location>> listLocationsForModules(Location location) throws IOException { |
42814
058fc03646d9
8171005: Fix JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName) to work with location == CLASS_OUTPUT
jlahoda
parents:
42261
diff
changeset
|
1018 |
checkModuleOrientedOrOutputLocation(location); |
42261
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41033
diff
changeset
|
1019 |
return locations.listLocationsForModules(location); |
36526 | 1020 |
} |
1021 |
||
1022 |
@Override @DefinedBy(Api.COMPILER) |
|
28332
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
1023 |
public Path asPath(FileObject file) { |
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
1024 |
if (file instanceof PathFileObject) { |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
1025 |
return ((PathFileObject) file).path; |
28332
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
1026 |
} else |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
1027 |
throw new IllegalArgumentException(file.getName()); |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
1028 |
} |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
1029 |
|
10 | 1030 |
/** |
14259 | 1031 |
* Enforces the specification of a "relative" name as used in |
1032 |
* {@linkplain #getFileForInput(Location,String,String) |
|
10 | 1033 |
* getFileForInput}. This method must follow the rules defined in |
1034 |
* that method, do not make any changes without consulting the |
|
1035 |
* specification. |
|
1036 |
*/ |
|
1037 |
protected static boolean isRelativeUri(URI uri) { |
|
1038 |
if (uri.isAbsolute()) |
|
1039 |
return false; |
|
1040 |
String path = uri.normalize().getPath(); |
|
1041 |
if (path.length() == 0 /* isEmpty() is mustang API */) |
|
1042 |
return false; |
|
6719
1ce993f87850
6502392: Invalid relative names for Filer.createResource and Filer.getResource
jjg
parents:
5847
diff
changeset
|
1043 |
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
|
1044 |
return false; |
7840 | 1045 |
if (path.startsWith("/") || path.startsWith("./") || path.startsWith("../")) |
1046 |
return false; |
|
1047 |
return true; |
|
10 | 1048 |
} |
1049 |
||
3782 | 1050 |
// Convenience method |
1051 |
protected static boolean isRelativeUri(String u) { |
|
1052 |
try { |
|
1053 |
return isRelativeUri(new URI(u)); |
|
1054 |
} catch (URISyntaxException e) { |
|
1055 |
return false; |
|
1056 |
} |
|
1057 |
} |
|
1058 |
||
10 | 1059 |
/** |
1060 |
* Converts a relative file name to a relative URI. This is |
|
1061 |
* different from File.toURI as this method does not canonicalize |
|
1062 |
* the file before creating the URI. Furthermore, no schema is |
|
1063 |
* used. |
|
1064 |
* @param file a relative file name |
|
1065 |
* @return a relative URI |
|
1066 |
* @throws IllegalArgumentException if the file name is not |
|
1067 |
* relative according to the definition given in {@link |
|
1068 |
* javax.tools.JavaFileManager#getFileForInput} |
|
1069 |
*/ |
|
1070 |
public static String getRelativeName(File file) { |
|
1071 |
if (!file.isAbsolute()) { |
|
1072 |
String result = file.getPath().replace(File.separatorChar, '/'); |
|
3782 | 1073 |
if (isRelativeUri(result)) |
10 | 1074 |
return result; |
1075 |
} |
|
1076 |
throw new IllegalArgumentException("Invalid relative path: " + file); |
|
1077 |
} |
|
5007
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
1078 |
|
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
1079 |
/** |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
1080 |
* 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
|
1081 |
* 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
|
1082 |
* 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
|
1083 |
* 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
|
1084 |
* name of the exception itself. |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
1085 |
* @param e an IOException |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
1086 |
* @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
|
1087 |
*/ |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
1088 |
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
|
1089 |
String s = e.getLocalizedMessage(); |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
1090 |
if (s != null) |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
1091 |
return s; |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
1092 |
s = e.getMessage(); |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
1093 |
if (s != null) |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
1094 |
return s; |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
1095 |
return e.toString(); |
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4548
diff
changeset
|
1096 |
} |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
1097 |
|
42261
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41033
diff
changeset
|
1098 |
private void checkOutputLocation(Location location) { |
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41033
diff
changeset
|
1099 |
Objects.requireNonNull(location); |
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41033
diff
changeset
|
1100 |
if (!location.isOutputLocation()) |
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41033
diff
changeset
|
1101 |
throw new IllegalArgumentException("location is not an output location: " + location.getName()); |
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41033
diff
changeset
|
1102 |
} |
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41033
diff
changeset
|
1103 |
|
42814
058fc03646d9
8171005: Fix JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName) to work with location == CLASS_OUTPUT
jlahoda
parents:
42261
diff
changeset
|
1104 |
private void checkModuleOrientedOrOutputLocation(Location location) { |
42261
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41033
diff
changeset
|
1105 |
Objects.requireNonNull(location); |
42814
058fc03646d9
8171005: Fix JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName) to work with location == CLASS_OUTPUT
jlahoda
parents:
42261
diff
changeset
|
1106 |
if (!location.isModuleOrientedLocation() && !location.isOutputLocation()) |
058fc03646d9
8171005: Fix JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName) to work with location == CLASS_OUTPUT
jlahoda
parents:
42261
diff
changeset
|
1107 |
throw new IllegalArgumentException( |
058fc03646d9
8171005: Fix JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName) to work with location == CLASS_OUTPUT
jlahoda
parents:
42261
diff
changeset
|
1108 |
"location is not an output location or a module-oriented location: " |
058fc03646d9
8171005: Fix JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName) to work with location == CLASS_OUTPUT
jlahoda
parents:
42261
diff
changeset
|
1109 |
+ location.getName()); |
42261
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41033
diff
changeset
|
1110 |
} |
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41033
diff
changeset
|
1111 |
|
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41033
diff
changeset
|
1112 |
private void checkNotModuleOrientedLocation(Location location) { |
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41033
diff
changeset
|
1113 |
Objects.requireNonNull(location); |
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41033
diff
changeset
|
1114 |
if (location.isModuleOrientedLocation()) |
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41033
diff
changeset
|
1115 |
throw new IllegalArgumentException("location is module-oriented: " + location.getName()); |
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41033
diff
changeset
|
1116 |
} |
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41033
diff
changeset
|
1117 |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
1118 |
/* Converters between files and paths. |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
1119 |
* 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
|
1120 |
*/ |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
1121 |
|
27858 | 1122 |
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
|
1123 |
if (files == null) |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
1124 |
return null; |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
1125 |
|
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
1126 |
return () -> new Iterator<Path>() { |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
1127 |
Iterator<? extends File> iter = files.iterator(); |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
1128 |
|
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
1129 |
@Override |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
1130 |
public boolean hasNext() { |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
1131 |
return iter.hasNext(); |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
1132 |
} |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
1133 |
|
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
1134 |
@Override |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
1135 |
public Path next() { |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
1136 |
return iter.next().toPath(); |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
1137 |
} |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
1138 |
}; |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
1139 |
} |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
1140 |
|
27858 | 1141 |
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
|
1142 |
if (paths == null) |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
1143 |
return null; |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
1144 |
|
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
1145 |
return () -> new Iterator<File>() { |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
1146 |
Iterator<? extends Path> iter = paths.iterator(); |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
1147 |
|
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
1148 |
@Override |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
1149 |
public boolean hasNext() { |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
1150 |
return iter.hasNext(); |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
1151 |
} |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
1152 |
|
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
1153 |
@Override |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
1154 |
public File next() { |
28332
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
1155 |
try { |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
1156 |
return iter.next().toFile(); |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
1157 |
} catch (UnsupportedOperationException e) { |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
1158 |
throw new IllegalStateException(e); |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
1159 |
} |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
1160 |
} |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
1161 |
}; |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27380
diff
changeset
|
1162 |
} |
10 | 1163 |
} |