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