author | jlahoda |
Mon, 06 Nov 2017 13:10:43 +0100 | |
changeset 47702 | cf8310446245 |
parent 47363 | 77c792d06646 |
child 47703 | dbfac941197a |
permissions | -rw-r--r-- |
10 | 1 |
/* |
43267 | 2 |
* Copyright (c) 2003, 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 |
*/ |
34752
9c262a013456
8145342: Some copyright notices are inconsistently and ill formatted
vasya
parents:
29780
diff
changeset
|
25 |
|
731
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
171
diff
changeset
|
26 |
package com.sun.tools.javac.file; |
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
171
diff
changeset
|
27 |
|
36526 | 28 |
import java.io.Closeable; |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
29 |
import java.io.File; |
10818 | 30 |
import java.io.FileNotFoundException; |
10 | 31 |
import java.io.IOException; |
45682
fc3b228b9e2a
8181087: Module system implementation refresh (6/2017)
alanb
parents:
44822
diff
changeset
|
32 |
import java.io.InputStream; |
27579 | 33 |
import java.io.UncheckedIOException; |
36526 | 34 |
import java.net.URI; |
4937
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
35 |
import java.net.URL; |
36526 | 36 |
import java.net.URLClassLoader; |
37 |
import java.nio.file.DirectoryIteratorException; |
|
38 |
import java.nio.file.DirectoryStream; |
|
39 |
import java.nio.file.FileSystem; |
|
40 |
import java.nio.file.FileSystemNotFoundException; |
|
41 |
import java.nio.file.FileSystems; |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
42 |
import java.nio.file.Files; |
41861
8c58faf4f03b
8132562: javac fails with CLASSPATH with double-quotes as an environment variable
vromero
parents:
41637
diff
changeset
|
43 |
import java.nio.file.InvalidPathException; |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
44 |
import java.nio.file.Path; |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
45 |
import java.nio.file.Paths; |
36526 | 46 |
import java.nio.file.ProviderNotFoundException; |
43574
042e694725f7
8166675: Latent bug in jar file handling during module path processing.
jjg
parents:
43267
diff
changeset
|
47 |
import java.nio.file.spi.FileSystemProvider; |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
48 |
import java.util.ArrayList; |
10818 | 49 |
import java.util.Arrays; |
50 |
import java.util.Collection; |
|
51 |
import java.util.Collections; |
|
52 |
import java.util.EnumMap; |
|
53 |
import java.util.EnumSet; |
|
10 | 54 |
import java.util.HashMap; |
55 |
import java.util.HashSet; |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
56 |
import java.util.Iterator; |
36526 | 57 |
import java.util.LinkedHashMap; |
10818 | 58 |
import java.util.LinkedHashSet; |
36526 | 59 |
import java.util.List; |
10 | 60 |
import java.util.Map; |
29291
076c277565f7
8073550: java* tools: replace obj.getClass hacks with Assert.checkNonNull or Objects.requireNonNull
mcimadamore
parents:
29053
diff
changeset
|
61 |
import java.util.Objects; |
36526 | 62 |
import java.util.NoSuchElementException; |
10 | 63 |
import java.util.Set; |
44063
5f0cf4126949
8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents:
44021
diff
changeset
|
64 |
import java.util.function.Predicate; |
36526 | 65 |
import java.util.regex.Matcher; |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
66 |
import java.util.regex.Pattern; |
27579 | 67 |
import java.util.stream.Collectors; |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
68 |
import java.util.stream.Stream; |
45682
fc3b228b9e2a
8181087: Module system implementation refresh (6/2017)
alanb
parents:
44822
diff
changeset
|
69 |
import java.util.jar.Attributes; |
fc3b228b9e2a
8181087: Module system implementation refresh (6/2017)
alanb
parents:
44822
diff
changeset
|
70 |
import java.util.jar.Manifest; |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
71 |
|
36526 | 72 |
import javax.lang.model.SourceVersion; |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
73 |
import javax.tools.JavaFileManager; |
10 | 74 |
import javax.tools.JavaFileManager.Location; |
41861
8c58faf4f03b
8132562: javac fails with CLASSPATH with double-quotes as an environment variable
vromero
parents:
41637
diff
changeset
|
75 |
import javax.tools.JavaFileObject; |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
76 |
import javax.tools.StandardJavaFileManager; |
37944
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
77 |
import javax.tools.StandardJavaFileManager.PathFactory; |
10818 | 78 |
import javax.tools.StandardLocation; |
10 | 79 |
|
731
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
171
diff
changeset
|
80 |
import com.sun.tools.javac.code.Lint; |
42837
03ee805ba348
8169005: tools/javac/T8132562/ClassPathWithDoubleQuotesTest.java fails after fix to JDK-8132562
vromero
parents:
42827
diff
changeset
|
81 |
import com.sun.tools.javac.code.Lint.LintCategory; |
11314 | 82 |
import com.sun.tools.javac.main.Option; |
36526 | 83 |
import com.sun.tools.javac.resources.CompilerProperties.Errors; |
84 |
import com.sun.tools.javac.resources.CompilerProperties.Warnings; |
|
37848
3c8ff4204d2d
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36526
diff
changeset
|
85 |
import com.sun.tools.javac.util.DefinedBy; |
3c8ff4204d2d
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36526
diff
changeset
|
86 |
import com.sun.tools.javac.util.DefinedBy.Api; |
41440 | 87 |
import com.sun.tools.javac.util.JDK9Wrappers; |
1486 | 88 |
import com.sun.tools.javac.util.ListBuffer; |
731
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
171
diff
changeset
|
89 |
import com.sun.tools.javac.util.Log; |
41254
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
41155
diff
changeset
|
90 |
import com.sun.tools.javac.jvm.ModuleNameReader; |
47363
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
91 |
import com.sun.tools.javac.util.Iterators; |
36526 | 92 |
import com.sun.tools.javac.util.Pair; |
22153
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
14360
diff
changeset
|
93 |
import com.sun.tools.javac.util.StringUtils; |
731
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
171
diff
changeset
|
94 |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
95 |
import static javax.tools.StandardLocation.PLATFORM_CLASS_PATH; |
10 | 96 |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40302
diff
changeset
|
97 |
import static com.sun.tools.javac.main.Option.BOOT_CLASS_PATH; |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
98 |
import static com.sun.tools.javac.main.Option.DJAVA_ENDORSED_DIRS; |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
99 |
import static com.sun.tools.javac.main.Option.DJAVA_EXT_DIRS; |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
100 |
import static com.sun.tools.javac.main.Option.ENDORSEDDIRS; |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
101 |
import static com.sun.tools.javac.main.Option.EXTDIRS; |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
102 |
import static com.sun.tools.javac.main.Option.XBOOTCLASSPATH; |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
103 |
import static com.sun.tools.javac.main.Option.XBOOTCLASSPATH_APPEND; |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
104 |
import static com.sun.tools.javac.main.Option.XBOOTCLASSPATH_PREPEND; |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
105 |
|
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
106 |
/** |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
107 |
* This class converts command line arguments, environment variables and system properties (in |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
108 |
* File.pathSeparator-separated String form) into a boot class path, user class path, and source |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
109 |
* path (in {@code Collection<String>} form). |
10 | 110 |
* |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
111 |
* <p> |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
112 |
* <b>This is NOT part of any supported API. If you write code that depends on this, you do so at |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
113 |
* your own risk. This code and its internal interfaces are subject to change or deletion without |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
114 |
* notice.</b> |
10 | 115 |
*/ |
10818 | 116 |
public class Locations { |
10 | 117 |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
118 |
/** |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
119 |
* The log to use for warning output |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
120 |
*/ |
10 | 121 |
private Log log; |
122 |
||
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
123 |
/** |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
124 |
* Access to (possibly cached) file info |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
125 |
*/ |
1208 | 126 |
private FSInfo fsInfo; |
10 | 127 |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
128 |
/** |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
129 |
* Whether to warn about non-existent path elements |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
130 |
*/ |
10818 | 131 |
private boolean warn; |
132 |
||
36526 | 133 |
private ModuleNameReader moduleNameReader; |
134 |
||
37944
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
135 |
private PathFactory pathFactory = Paths::get; |
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
136 |
|
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
137 |
static final Path javaHome = FileSystems.getDefault().getPath(System.getProperty("java.home")); |
36526 | 138 |
static final Path thisSystemModules = javaHome.resolve("lib").resolve("modules"); |
139 |
||
140 |
Map<Path, FileSystem> fileSystems = new LinkedHashMap<>(); |
|
141 |
List<Closeable> closeables = new ArrayList<>(); |
|
41155
93dad90c22c1
8156568: Update javac to support compiling against a modular JAR that is a multi-release JAR
sadayapalam
parents:
40762
diff
changeset
|
142 |
private Map<String,String> fsEnv = Collections.emptyMap(); |
27579 | 143 |
|
29780
8f8e54a1fa20
8076420: Consolidate javac file handling in javac.file package
jjg
parents:
29291
diff
changeset
|
144 |
Locations() { |
10818 | 145 |
initHandlers(); |
10 | 146 |
} |
147 |
||
37944
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
148 |
Path getPath(String first, String... more) { |
41861
8c58faf4f03b
8132562: javac fails with CLASSPATH with double-quotes as an environment variable
vromero
parents:
41637
diff
changeset
|
149 |
try { |
8c58faf4f03b
8132562: javac fails with CLASSPATH with double-quotes as an environment variable
vromero
parents:
41637
diff
changeset
|
150 |
return pathFactory.getPath(first, more); |
8c58faf4f03b
8132562: javac fails with CLASSPATH with double-quotes as an environment variable
vromero
parents:
41637
diff
changeset
|
151 |
} catch (InvalidPathException ipe) { |
8c58faf4f03b
8132562: javac fails with CLASSPATH with double-quotes as an environment variable
vromero
parents:
41637
diff
changeset
|
152 |
throw new IllegalArgumentException(ipe); |
8c58faf4f03b
8132562: javac fails with CLASSPATH with double-quotes as an environment variable
vromero
parents:
41637
diff
changeset
|
153 |
} |
37944
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
154 |
} |
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
155 |
|
36526 | 156 |
public void close() throws IOException { |
157 |
ListBuffer<IOException> list = new ListBuffer<>(); |
|
158 |
closeables.forEach(closeable -> { |
|
159 |
try { |
|
160 |
closeable.close(); |
|
161 |
} catch (IOException ex) { |
|
162 |
list.add(ex); |
|
163 |
} |
|
164 |
}); |
|
165 |
if (list.nonEmpty()) { |
|
166 |
IOException ex = new IOException(); |
|
167 |
for (IOException e: list) |
|
168 |
ex.addSuppressed(e); |
|
169 |
throw ex; |
|
170 |
} |
|
171 |
} |
|
172 |
||
41637 | 173 |
void update(Log log, boolean warn, FSInfo fsInfo) { |
10813
95b39a692cd0
7101146: Paths should more directly managed by BaseFileManager
jjg
parents:
8424
diff
changeset
|
174 |
this.log = log; |
41637 | 175 |
this.warn = warn; |
10813
95b39a692cd0
7101146: Paths should more directly managed by BaseFileManager
jjg
parents:
8424
diff
changeset
|
176 |
this.fsInfo = fsInfo; |
10 | 177 |
} |
178 |
||
37944
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
179 |
void setPathFactory(PathFactory f) { |
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
180 |
pathFactory = f; |
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
181 |
} |
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
182 |
|
29780
8f8e54a1fa20
8076420: Consolidate javac file handling in javac.file package
jjg
parents:
29291
diff
changeset
|
183 |
boolean isDefaultBootClassPath() { |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
184 |
BootClassPathLocationHandler h |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
185 |
= (BootClassPathLocationHandler) getHandler(PLATFORM_CLASS_PATH); |
10818 | 186 |
return h.isDefault(); |
10 | 187 |
} |
188 |
||
1486 | 189 |
/** |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
190 |
* Split a search path into its elements. Empty path elements will be ignored. |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
191 |
* |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
192 |
* @param searchPath The search path to be split |
1486 | 193 |
* @return The elements of the path |
194 |
*/ |
|
37944
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
195 |
private Iterable<Path> getPathEntries(String searchPath) { |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
196 |
return getPathEntries(searchPath, null); |
1486 | 197 |
} |
10 | 198 |
|
1486 | 199 |
/** |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
200 |
* Split a search path into its elements. If emptyPathDefault is not null, all empty elements in the |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
201 |
* path, including empty elements at either end of the path, will be replaced with the value of |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
202 |
* emptyPathDefault. |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
203 |
* |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
204 |
* @param searchPath The search path to be split |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
205 |
* @param emptyPathDefault The value to substitute for empty path elements, or null, to ignore |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
206 |
* empty path elements |
1486 | 207 |
* @return The elements of the path |
208 |
*/ |
|
37944
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
209 |
private Iterable<Path> getPathEntries(String searchPath, Path emptyPathDefault) { |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
210 |
ListBuffer<Path> entries = new ListBuffer<>(); |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
211 |
for (String s: searchPath.split(Pattern.quote(File.pathSeparator), -1)) { |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
212 |
if (s.isEmpty()) { |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
213 |
if (emptyPathDefault != null) { |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
214 |
entries.add(emptyPathDefault); |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
215 |
} |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
216 |
} else { |
42837
03ee805ba348
8169005: tools/javac/T8132562/ClassPathWithDoubleQuotesTest.java fails after fix to JDK-8132562
vromero
parents:
42827
diff
changeset
|
217 |
try { |
03ee805ba348
8169005: tools/javac/T8132562/ClassPathWithDoubleQuotesTest.java fails after fix to JDK-8132562
vromero
parents:
42827
diff
changeset
|
218 |
entries.add(getPath(s)); |
03ee805ba348
8169005: tools/javac/T8132562/ClassPathWithDoubleQuotesTest.java fails after fix to JDK-8132562
vromero
parents:
42827
diff
changeset
|
219 |
} catch (IllegalArgumentException e) { |
03ee805ba348
8169005: tools/javac/T8132562/ClassPathWithDoubleQuotesTest.java fails after fix to JDK-8132562
vromero
parents:
42827
diff
changeset
|
220 |
if (warn) { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44822
diff
changeset
|
221 |
log.warning(LintCategory.PATH, Warnings.InvalidPath(s)); |
42837
03ee805ba348
8169005: tools/javac/T8132562/ClassPathWithDoubleQuotesTest.java fails after fix to JDK-8132562
vromero
parents:
42827
diff
changeset
|
222 |
} |
03ee805ba348
8169005: tools/javac/T8132562/ClassPathWithDoubleQuotesTest.java fails after fix to JDK-8132562
vromero
parents:
42827
diff
changeset
|
223 |
} |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
224 |
} |
10 | 225 |
} |
1486 | 226 |
return entries; |
10 | 227 |
} |
228 |
||
41155
93dad90c22c1
8156568: Update javac to support compiling against a modular JAR that is a multi-release JAR
sadayapalam
parents:
40762
diff
changeset
|
229 |
public void setMultiReleaseValue(String multiReleaseValue) { |
93dad90c22c1
8156568: Update javac to support compiling against a modular JAR that is a multi-release JAR
sadayapalam
parents:
40762
diff
changeset
|
230 |
fsEnv = Collections.singletonMap("multi-release", multiReleaseValue); |
93dad90c22c1
8156568: Update javac to support compiling against a modular JAR that is a multi-release JAR
sadayapalam
parents:
40762
diff
changeset
|
231 |
} |
93dad90c22c1
8156568: Update javac to support compiling against a modular JAR that is a multi-release JAR
sadayapalam
parents:
40762
diff
changeset
|
232 |
|
44822 | 233 |
private boolean contains(Collection<Path> searchPath, Path file) throws IOException { |
234 |
||
235 |
if (searchPath == null) { |
|
236 |
return false; |
|
237 |
} |
|
238 |
||
239 |
Path enclosingJar = null; |
|
240 |
if (file.getFileSystem().provider() == fsInfo.getJarFSProvider()) { |
|
241 |
URI uri = file.toUri(); |
|
242 |
if (uri.getScheme().equals("jar")) { |
|
243 |
String ssp = uri.getSchemeSpecificPart(); |
|
244 |
int sep = ssp.lastIndexOf("!"); |
|
245 |
if (ssp.startsWith("file:") && sep > 0) { |
|
246 |
enclosingJar = Paths.get(URI.create(ssp.substring(0, sep))); |
|
247 |
} |
|
248 |
} |
|
249 |
} |
|
250 |
||
251 |
Path nf = normalize(file); |
|
252 |
for (Path p : searchPath) { |
|
253 |
Path np = normalize(p); |
|
254 |
if (np.getFileSystem() == nf.getFileSystem() |
|
255 |
&& Files.isDirectory(np) |
|
256 |
&& nf.startsWith(np)) { |
|
257 |
return true; |
|
258 |
} |
|
259 |
if (enclosingJar != null |
|
260 |
&& Files.isSameFile(enclosingJar, np)) { |
|
261 |
return true; |
|
262 |
} |
|
263 |
} |
|
264 |
||
265 |
return false; |
|
266 |
} |
|
267 |
||
10818 | 268 |
/** |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
269 |
* Utility class to help evaluate a path option. Duplicate entries are ignored, jar class paths |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
270 |
* can be expanded. |
10818 | 271 |
*/ |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
272 |
private class SearchPath extends LinkedHashSet<Path> { |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
273 |
|
10 | 274 |
private static final long serialVersionUID = 0; |
275 |
||
276 |
private boolean expandJarClassPaths = false; |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
277 |
private final Set<Path> canonicalValues = new HashSet<>(); |
10 | 278 |
|
27118
3c8314271af7
8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents:
25874
diff
changeset
|
279 |
public SearchPath expandJarClassPaths(boolean x) { |
10 | 280 |
expandJarClassPaths = x; |
281 |
return this; |
|
282 |
} |
|
283 |
||
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
284 |
/** |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
285 |
* What to use when path element is the empty string |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
286 |
*/ |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
287 |
private Path emptyPathDefault = null; |
10 | 288 |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
289 |
public SearchPath emptyPathDefault(Path x) { |
10 | 290 |
emptyPathDefault = x; |
291 |
return this; |
|
292 |
} |
|
293 |
||
27118
3c8314271af7
8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents:
25874
diff
changeset
|
294 |
public SearchPath addDirectories(String dirs, boolean warn) { |
8424
5e31b2eb5aa3
6485027: javac incorrectly handles relative paths in manifest classpath
jjg
parents:
8034
diff
changeset
|
295 |
boolean prev = expandJarClassPaths; |
5e31b2eb5aa3
6485027: javac incorrectly handles relative paths in manifest classpath
jjg
parents:
8034
diff
changeset
|
296 |
expandJarClassPaths = true; |
5e31b2eb5aa3
6485027: javac incorrectly handles relative paths in manifest classpath
jjg
parents:
8034
diff
changeset
|
297 |
try { |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
298 |
if (dirs != null) { |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
299 |
for (Path dir : getPathEntries(dirs)) { |
8424
5e31b2eb5aa3
6485027: javac incorrectly handles relative paths in manifest classpath
jjg
parents:
8034
diff
changeset
|
300 |
addDirectory(dir, warn); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
301 |
} |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
302 |
} |
8424
5e31b2eb5aa3
6485027: javac incorrectly handles relative paths in manifest classpath
jjg
parents:
8034
diff
changeset
|
303 |
return this; |
5e31b2eb5aa3
6485027: javac incorrectly handles relative paths in manifest classpath
jjg
parents:
8034
diff
changeset
|
304 |
} finally { |
5e31b2eb5aa3
6485027: javac incorrectly handles relative paths in manifest classpath
jjg
parents:
8034
diff
changeset
|
305 |
expandJarClassPaths = prev; |
5e31b2eb5aa3
6485027: javac incorrectly handles relative paths in manifest classpath
jjg
parents:
8034
diff
changeset
|
306 |
} |
10 | 307 |
} |
308 |
||
27118
3c8314271af7
8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents:
25874
diff
changeset
|
309 |
public SearchPath addDirectories(String dirs) { |
10 | 310 |
return addDirectories(dirs, warn); |
311 |
} |
|
312 |
||
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
313 |
private void addDirectory(Path dir, boolean warn) { |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
314 |
if (!Files.isDirectory(dir)) { |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
315 |
if (warn) { |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
316 |
log.warning(Lint.LintCategory.PATH, |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44822
diff
changeset
|
317 |
Warnings.DirPathElementNotFound(dir)); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
318 |
} |
10 | 319 |
return; |
320 |
} |
|
321 |
||
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
322 |
try (Stream<Path> s = Files.list(dir)) { |
42827
36468b5fa7f4
8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents:
42814
diff
changeset
|
323 |
s.filter(Locations.this::isArchive) |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
324 |
.forEach(dirEntry -> addFile(dirEntry, warn)); |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
325 |
} catch (IOException ignore) { |
10 | 326 |
} |
327 |
} |
|
328 |
||
27118
3c8314271af7
8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents:
25874
diff
changeset
|
329 |
public SearchPath addFiles(String files, boolean warn) { |
7335
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
6151
diff
changeset
|
330 |
if (files != null) { |
10818 | 331 |
addFiles(getPathEntries(files, emptyPathDefault), warn); |
332 |
} |
|
333 |
return this; |
|
334 |
} |
|
335 |
||
27118
3c8314271af7
8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents:
25874
diff
changeset
|
336 |
public SearchPath addFiles(String files) { |
10818 | 337 |
return addFiles(files, warn); |
338 |
} |
|
339 |
||
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
340 |
public SearchPath addFiles(Iterable<? extends Path> files, boolean warn) { |
10818 | 341 |
if (files != null) { |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
342 |
for (Path file : files) { |
10 | 343 |
addFile(file, warn); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
344 |
} |
7335
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
6151
diff
changeset
|
345 |
} |
10 | 346 |
return this; |
347 |
} |
|
348 |
||
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
349 |
public SearchPath addFiles(Iterable<? extends Path> files) { |
10 | 350 |
return addFiles(files, warn); |
351 |
} |
|
352 |
||
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
353 |
public void addFile(Path file, boolean warn) { |
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7336
diff
changeset
|
354 |
if (contains(file)) { |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7336
diff
changeset
|
355 |
// discard duplicates |
10 | 356 |
return; |
357 |
} |
|
358 |
||
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
359 |
if (!fsInfo.exists(file)) { |
10 | 360 |
/* No such file or directory exists */ |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
361 |
if (warn) { |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
362 |
log.warning(Lint.LintCategory.PATH, |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44822
diff
changeset
|
363 |
Warnings.PathElementNotFound(file)); |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
364 |
} |
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7336
diff
changeset
|
365 |
super.add(file); |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7336
diff
changeset
|
366 |
return; |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7336
diff
changeset
|
367 |
} |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7336
diff
changeset
|
368 |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
369 |
Path canonFile = fsInfo.getCanonicalFile(file); |
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7336
diff
changeset
|
370 |
if (canonicalValues.contains(canonFile)) { |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7336
diff
changeset
|
371 |
/* Discard duplicates and avoid infinite recursion */ |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7336
diff
changeset
|
372 |
return; |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7336
diff
changeset
|
373 |
} |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7336
diff
changeset
|
374 |
|
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7336
diff
changeset
|
375 |
if (fsInfo.isFile(file)) { |
10 | 376 |
/* File is an ordinary file. */ |
40513
39b67170b045
8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
40308
diff
changeset
|
377 |
if ( !file.getFileName().toString().endsWith(".jmod") |
39b67170b045
8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
40308
diff
changeset
|
378 |
&& !file.endsWith("modules")) { |
39b67170b045
8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
40308
diff
changeset
|
379 |
if (!isArchive(file)) { |
39b67170b045
8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
40308
diff
changeset
|
380 |
/* Not a recognized extension; open it to see if |
39b67170b045
8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
40308
diff
changeset
|
381 |
it looks like a valid zip file. */ |
39b67170b045
8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
40308
diff
changeset
|
382 |
try { |
39b67170b045
8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
40308
diff
changeset
|
383 |
FileSystems.newFileSystem(file, null).close(); |
39b67170b045
8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
40308
diff
changeset
|
384 |
if (warn) { |
39b67170b045
8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
40308
diff
changeset
|
385 |
log.warning(Lint.LintCategory.PATH, |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44822
diff
changeset
|
386 |
Warnings.UnexpectedArchiveFile(file)); |
40513
39b67170b045
8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
40308
diff
changeset
|
387 |
} |
39b67170b045
8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
40308
diff
changeset
|
388 |
} catch (IOException | ProviderNotFoundException e) { |
39b67170b045
8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
40308
diff
changeset
|
389 |
// FIXME: include e.getLocalizedMessage in warning |
39b67170b045
8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
40308
diff
changeset
|
390 |
if (warn) { |
39b67170b045
8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
40308
diff
changeset
|
391 |
log.warning(Lint.LintCategory.PATH, |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44822
diff
changeset
|
392 |
Warnings.InvalidArchiveFile(file)); |
40513
39b67170b045
8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
40308
diff
changeset
|
393 |
} |
39b67170b045
8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
40308
diff
changeset
|
394 |
return; |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
395 |
} |
40513
39b67170b045
8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
40308
diff
changeset
|
396 |
} else { |
39b67170b045
8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
40308
diff
changeset
|
397 |
if (fsInfo.getJarFSProvider() == null) { |
39b67170b045
8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
40308
diff
changeset
|
398 |
log.error(Errors.NoZipfsForArchive(file)); |
39b67170b045
8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
40308
diff
changeset
|
399 |
return ; |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
400 |
} |
10 | 401 |
} |
402 |
} |
|
403 |
} |
|
404 |
||
405 |
/* Now what we have left is either a directory or a file name |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
406 |
conforming to archive naming convention */ |
10 | 407 |
super.add(file); |
1208 | 408 |
canonicalValues.add(canonFile); |
10 | 409 |
|
36526 | 410 |
if (expandJarClassPaths && fsInfo.isFile(file) && !file.endsWith("modules")) { |
10 | 411 |
addJarClassPath(file, warn); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
412 |
} |
10 | 413 |
} |
414 |
||
415 |
// Adds referenced classpath elements from a jar's Class-Path |
|
416 |
// Manifest entry. In some future release, we may want to |
|
417 |
// update this code to recognize URLs rather than simple |
|
418 |
// filenames, but if we do, we should redo all path-related code. |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
419 |
private void addJarClassPath(Path jarFile, boolean warn) { |
10 | 420 |
try { |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
421 |
for (Path f : fsInfo.getJarClassPath(jarFile)) { |
1208 | 422 |
addFile(f, warn); |
10 | 423 |
} |
424 |
} catch (IOException e) { |
|
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44822
diff
changeset
|
425 |
log.error(Errors.ErrorReadingFile(jarFile, JavacFileManager.getMessage(e))); |
10 | 426 |
} |
427 |
} |
|
428 |
} |
|
429 |
||
10818 | 430 |
/** |
36526 | 431 |
* Base class for handling support for the representation of Locations. |
432 |
* |
|
433 |
* Locations are (by design) opaque handles that can easily be implemented |
|
434 |
* by enums like StandardLocation. Within JavacFileManager, each Location |
|
435 |
* has an associated LocationHandler, which provides much of the appropriate |
|
436 |
* functionality for the corresponding Location. |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
437 |
* |
10818 | 438 |
* @see #initHandlers |
439 |
* @see #getHandler |
|
440 |
*/ |
|
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
441 |
protected static abstract class LocationHandler { |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
442 |
|
36526 | 443 |
/** |
444 |
* @see JavaFileManager#handleOption |
|
445 |
*/ |
|
446 |
abstract boolean handleOption(Option option, String value); |
|
447 |
||
448 |
/** |
|
449 |
* @see StandardJavaFileManager#hasLocation |
|
450 |
*/ |
|
451 |
boolean isSet() { |
|
452 |
return (getPaths() != null); |
|
453 |
} |
|
454 |
||
47702
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
455 |
abstract boolean isExplicit(); |
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
456 |
|
36526 | 457 |
/** |
458 |
* @see StandardJavaFileManager#getLocation |
|
459 |
*/ |
|
460 |
abstract Collection<Path> getPaths(); |
|
461 |
||
462 |
/** |
|
463 |
* @see StandardJavaFileManager#setLocation |
|
464 |
*/ |
|
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
465 |
abstract void setPaths(Iterable<? extends Path> paths) throws IOException; |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
466 |
|
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
467 |
/** |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
468 |
* @see StandardJavaFileManager#setLocationForModule |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
469 |
*/ |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
470 |
abstract void setPathsForModule(String moduleName, Iterable<? extends Path> paths) |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
471 |
throws IOException; |
36526 | 472 |
|
473 |
/** |
|
42261
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41861
diff
changeset
|
474 |
* @see JavaFileManager#getLocationForModule(Location, String) |
36526 | 475 |
*/ |
42261
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41861
diff
changeset
|
476 |
Location getLocationForModule(String moduleName) throws IOException { |
36526 | 477 |
return null; |
478 |
} |
|
479 |
||
480 |
/** |
|
42261
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41861
diff
changeset
|
481 |
* @see JavaFileManager#getLocationForModule(Location, JavaFileObject, String) |
36526 | 482 |
*/ |
44063
5f0cf4126949
8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents:
44021
diff
changeset
|
483 |
Location getLocationForModule(Path file) throws IOException { |
36526 | 484 |
return null; |
485 |
} |
|
486 |
||
487 |
/** |
|
488 |
* @see JavaFileManager#inferModuleName |
|
489 |
*/ |
|
490 |
String inferModuleName() { |
|
491 |
return null; |
|
492 |
} |
|
493 |
||
494 |
/** |
|
42261
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41861
diff
changeset
|
495 |
* @see JavaFileManager#listLocationsForModules |
36526 | 496 |
*/ |
42261
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41861
diff
changeset
|
497 |
Iterable<Set<Location>> listLocationsForModules() throws IOException { |
36526 | 498 |
return null; |
499 |
} |
|
44822 | 500 |
|
501 |
/** |
|
502 |
* @see JavaFileManager#contains |
|
503 |
*/ |
|
504 |
abstract boolean contains(Path file) throws IOException; |
|
36526 | 505 |
} |
506 |
||
507 |
/** |
|
508 |
* A LocationHandler for a given Location, and associated set of options. |
|
509 |
*/ |
|
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
510 |
private static abstract class BasicLocationHandler extends LocationHandler { |
36526 | 511 |
|
10818 | 512 |
final Location location; |
11314 | 513 |
final Set<Option> options; |
7335
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
6151
diff
changeset
|
514 |
|
47702
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
515 |
boolean explicit; |
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
516 |
|
10818 | 517 |
/** |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
518 |
* Create a handler. The location and options provide a way to map from a location or an |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
519 |
* option to the corresponding handler. |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
520 |
* |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
521 |
* @param location the location for which this is the handler |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
522 |
* @param options the options affecting this location |
10818 | 523 |
* @see #initHandlers |
524 |
*/ |
|
36526 | 525 |
protected BasicLocationHandler(Location location, Option... options) { |
10818 | 526 |
this.location = location; |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
527 |
this.options = options.length == 0 |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
528 |
? EnumSet.noneOf(Option.class) |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
529 |
: EnumSet.copyOf(Arrays.asList(options)); |
10818 | 530 |
} |
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
531 |
|
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
532 |
@Override |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
533 |
void setPathsForModule(String moduleName, Iterable<? extends Path> files) throws IOException { |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
534 |
// should not happen: protected by check in JavacFileManager |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
535 |
throw new UnsupportedOperationException("not supported for " + location); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
536 |
} |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
537 |
|
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
538 |
protected Path checkSingletonDirectory(Iterable<? extends Path> paths) throws IOException { |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
539 |
Iterator<? extends Path> pathIter = paths.iterator(); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
540 |
if (!pathIter.hasNext()) { |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
541 |
throw new IllegalArgumentException("empty path for directory"); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
542 |
} |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
543 |
Path path = pathIter.next(); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
544 |
if (pathIter.hasNext()) { |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
545 |
throw new IllegalArgumentException("path too long for directory"); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
546 |
} |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
547 |
checkDirectory(path); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
548 |
return path; |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
549 |
} |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
550 |
|
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
551 |
protected Path checkDirectory(Path path) throws IOException { |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
552 |
Objects.requireNonNull(path); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
553 |
if (!Files.exists(path)) { |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
554 |
throw new FileNotFoundException(path + ": does not exist"); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
555 |
} |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
556 |
if (!Files.isDirectory(path)) { |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
557 |
throw new IOException(path + ": not a directory"); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
558 |
} |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
559 |
return path; |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
560 |
} |
47702
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
561 |
|
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
562 |
@Override |
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
563 |
boolean isExplicit() { |
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
564 |
return explicit; |
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
565 |
} |
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
566 |
|
10818 | 567 |
} |
568 |
||
569 |
/** |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
570 |
* General purpose implementation for output locations, such as -d/CLASS_OUTPUT and |
36526 | 571 |
* -s/SOURCE_OUTPUT. All options are treated as equivalent (i.e. aliases.) |
572 |
* The value is a single file, possibly null. |
|
10818 | 573 |
*/ |
36526 | 574 |
private class OutputLocationHandler extends BasicLocationHandler { |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
575 |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
576 |
private Path outputDir; |
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
577 |
private ModuleTable moduleTable; |
10818 | 578 |
|
11314 | 579 |
OutputLocationHandler(Location location, Option... options) { |
10818 | 580 |
super(location, options); |
581 |
} |
|
582 |
||
583 |
@Override |
|
11314 | 584 |
boolean handleOption(Option option, String value) { |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
585 |
if (!options.contains(option)) { |
10818 | 586 |
return false; |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
587 |
} |
10 | 588 |
|
47702
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
589 |
explicit = true; |
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
590 |
|
10818 | 591 |
// TODO: could/should validate outputDir exists and is a directory |
592 |
// need to decide how best to report issue for benefit of |
|
593 |
// direct API call on JavaFileManager.handleOption(specifies IAE) |
|
594 |
// vs. command line decoding. |
|
37944
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
595 |
outputDir = (value == null) ? null : getPath(value); |
10818 | 596 |
return true; |
597 |
} |
|
598 |
||
599 |
@Override |
|
36526 | 600 |
Collection<Path> getPaths() { |
10818 | 601 |
return (outputDir == null) ? null : Collections.singleton(outputDir); |
602 |
} |
|
10 | 603 |
|
10818 | 604 |
@Override |
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
605 |
void setPaths(Iterable<? extends Path> paths) throws IOException { |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
606 |
if (paths == null) { |
10818 | 607 |
outputDir = null; |
608 |
} else { |
|
47702
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
609 |
explicit = true; |
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
610 |
outputDir = checkSingletonDirectory(paths); |
10818 | 611 |
} |
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
612 |
moduleTable = null; |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
613 |
listed = false; |
36526 | 614 |
} |
615 |
||
616 |
@Override |
|
42261
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41861
diff
changeset
|
617 |
Location getLocationForModule(String name) { |
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
618 |
if (moduleTable == null) { |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
619 |
moduleTable = new ModuleTable(); |
42814
058fc03646d9
8171005: Fix JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName) to work with location == CLASS_OUTPUT
jlahoda
parents:
42414
diff
changeset
|
620 |
} |
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
621 |
ModuleLocationHandler l = moduleTable.get(name); |
36526 | 622 |
if (l == null) { |
42814
058fc03646d9
8171005: Fix JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName) to work with location == CLASS_OUTPUT
jlahoda
parents:
42414
diff
changeset
|
623 |
Path out = outputDir.resolve(name); |
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
624 |
l = new ModuleLocationHandler(this, location.getName() + "[" + name + "]", |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
625 |
name, Collections.singletonList(out), true); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
626 |
moduleTable.add(l); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
627 |
} |
42814
058fc03646d9
8171005: Fix JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName) to work with location == CLASS_OUTPUT
jlahoda
parents:
42414
diff
changeset
|
628 |
return l; |
058fc03646d9
8171005: Fix JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName) to work with location == CLASS_OUTPUT
jlahoda
parents:
42414
diff
changeset
|
629 |
} |
058fc03646d9
8171005: Fix JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName) to work with location == CLASS_OUTPUT
jlahoda
parents:
42414
diff
changeset
|
630 |
|
058fc03646d9
8171005: Fix JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName) to work with location == CLASS_OUTPUT
jlahoda
parents:
42414
diff
changeset
|
631 |
@Override |
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
632 |
void setPathsForModule(String name, Iterable<? extends Path> paths) throws IOException { |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
633 |
Path out = checkSingletonDirectory(paths); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
634 |
if (moduleTable == null) { |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
635 |
moduleTable = new ModuleTable(); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
636 |
} |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
637 |
ModuleLocationHandler l = moduleTable.get(name); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
638 |
if (l == null) { |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
639 |
l = new ModuleLocationHandler(this, location.getName() + "[" + name + "]", |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
640 |
name, Collections.singletonList(out), true); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
641 |
moduleTable.add(l); |
47702
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
642 |
} else { |
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
643 |
l.searchPath = Collections.singletonList(out); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
644 |
moduleTable.updatePaths(l); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
645 |
} |
47702
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
646 |
explicit = true; |
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
647 |
} |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
648 |
|
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
649 |
@Override |
44063
5f0cf4126949
8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents:
44021
diff
changeset
|
650 |
Location getLocationForModule(Path file) { |
5f0cf4126949
8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents:
44021
diff
changeset
|
651 |
return (moduleTable == null) ? null : moduleTable.get(file); |
42814
058fc03646d9
8171005: Fix JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName) to work with location == CLASS_OUTPUT
jlahoda
parents:
42414
diff
changeset
|
652 |
} |
058fc03646d9
8171005: Fix JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName) to work with location == CLASS_OUTPUT
jlahoda
parents:
42414
diff
changeset
|
653 |
|
058fc03646d9
8171005: Fix JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName) to work with location == CLASS_OUTPUT
jlahoda
parents:
42414
diff
changeset
|
654 |
private boolean listed; |
058fc03646d9
8171005: Fix JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName) to work with location == CLASS_OUTPUT
jlahoda
parents:
42414
diff
changeset
|
655 |
|
058fc03646d9
8171005: Fix JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName) to work with location == CLASS_OUTPUT
jlahoda
parents:
42414
diff
changeset
|
656 |
@Override |
058fc03646d9
8171005: Fix JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName) to work with location == CLASS_OUTPUT
jlahoda
parents:
42414
diff
changeset
|
657 |
Iterable<Set<Location>> listLocationsForModules() throws IOException { |
058fc03646d9
8171005: Fix JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName) to work with location == CLASS_OUTPUT
jlahoda
parents:
42414
diff
changeset
|
658 |
if (!listed && outputDir != null) { |
058fc03646d9
8171005: Fix JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName) to work with location == CLASS_OUTPUT
jlahoda
parents:
42414
diff
changeset
|
659 |
try (DirectoryStream<Path> stream = Files.newDirectoryStream(outputDir)) { |
058fc03646d9
8171005: Fix JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName) to work with location == CLASS_OUTPUT
jlahoda
parents:
42414
diff
changeset
|
660 |
for (Path p : stream) { |
058fc03646d9
8171005: Fix JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName) to work with location == CLASS_OUTPUT
jlahoda
parents:
42414
diff
changeset
|
661 |
getLocationForModule(p.getFileName().toString()); |
058fc03646d9
8171005: Fix JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName) to work with location == CLASS_OUTPUT
jlahoda
parents:
42414
diff
changeset
|
662 |
} |
058fc03646d9
8171005: Fix JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName) to work with location == CLASS_OUTPUT
jlahoda
parents:
42414
diff
changeset
|
663 |
} |
058fc03646d9
8171005: Fix JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName) to work with location == CLASS_OUTPUT
jlahoda
parents:
42414
diff
changeset
|
664 |
listed = true; |
36526 | 665 |
} |
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
666 |
|
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
667 |
if (moduleTable == null || moduleTable.isEmpty()) |
42814
058fc03646d9
8171005: Fix JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName) to work with location == CLASS_OUTPUT
jlahoda
parents:
42414
diff
changeset
|
668 |
return Collections.emptySet(); |
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
669 |
|
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
670 |
return Collections.singleton(moduleTable.locations()); |
10818 | 671 |
} |
44822 | 672 |
|
673 |
@Override |
|
674 |
boolean contains(Path file) throws IOException { |
|
675 |
if (moduleTable != null) { |
|
676 |
return moduleTable.contains(file); |
|
677 |
} else { |
|
678 |
return (outputDir) != null && normalize(file).startsWith(normalize(outputDir)); |
|
679 |
} |
|
680 |
} |
|
10 | 681 |
} |
682 |
||
10818 | 683 |
/** |
36526 | 684 |
* General purpose implementation for search path locations, |
685 |
* such as -sourcepath/SOURCE_PATH and -processorPath/ANNOTATION_PROCESSOR_PATH. |
|
686 |
* All options are treated as equivalent (i.e. aliases.) |
|
10818 | 687 |
* The value is an ordered set of files and/or directories. |
688 |
*/ |
|
36526 | 689 |
private class SimpleLocationHandler extends BasicLocationHandler { |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
690 |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
691 |
protected Collection<Path> searchPath; |
10 | 692 |
|
11314 | 693 |
SimpleLocationHandler(Location location, Option... options) { |
10818 | 694 |
super(location, options); |
695 |
} |
|
10 | 696 |
|
10818 | 697 |
@Override |
11314 | 698 |
boolean handleOption(Option option, String value) { |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
699 |
if (!options.contains(option)) { |
10818 | 700 |
return false; |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
701 |
} |
47702
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
702 |
|
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
703 |
explicit = true; |
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
704 |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
705 |
searchPath = value == null ? null |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
706 |
: Collections.unmodifiableCollection(createPath().addFiles(value)); |
10818 | 707 |
return true; |
708 |
} |
|
709 |
||
710 |
@Override |
|
36526 | 711 |
Collection<Path> getPaths() { |
10818 | 712 |
return searchPath; |
713 |
} |
|
10 | 714 |
|
10818 | 715 |
@Override |
36526 | 716 |
void setPaths(Iterable<? extends Path> files) { |
27118
3c8314271af7
8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents:
25874
diff
changeset
|
717 |
SearchPath p; |
10818 | 718 |
if (files == null) { |
719 |
p = computePath(null); |
|
720 |
} else { |
|
47702
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
721 |
explicit = true; |
14360
2a8304e421ed
6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents:
14259
diff
changeset
|
722 |
p = createPath().addFiles(files); |
10818 | 723 |
} |
724 |
searchPath = Collections.unmodifiableCollection(p); |
|
725 |
} |
|
14360
2a8304e421ed
6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents:
14259
diff
changeset
|
726 |
|
27118
3c8314271af7
8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents:
25874
diff
changeset
|
727 |
protected SearchPath computePath(String value) { |
14360
2a8304e421ed
6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents:
14259
diff
changeset
|
728 |
return createPath().addFiles(value); |
2a8304e421ed
6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents:
14259
diff
changeset
|
729 |
} |
2a8304e421ed
6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents:
14259
diff
changeset
|
730 |
|
27118
3c8314271af7
8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents:
25874
diff
changeset
|
731 |
protected SearchPath createPath() { |
3c8314271af7
8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents:
25874
diff
changeset
|
732 |
return new SearchPath(); |
14360
2a8304e421ed
6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents:
14259
diff
changeset
|
733 |
} |
44822 | 734 |
|
735 |
@Override |
|
736 |
boolean contains(Path file) throws IOException { |
|
737 |
return Locations.this.contains(searchPath, file); |
|
738 |
} |
|
10 | 739 |
} |
740 |
||
10818 | 741 |
/** |
36526 | 742 |
* Subtype of SimpleLocationHandler for -classpath/CLASS_PATH. |
743 |
* If no value is given, a default is provided, based on system properties and other values. |
|
10818 | 744 |
*/ |
745 |
private class ClassPathLocationHandler extends SimpleLocationHandler { |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
746 |
|
10818 | 747 |
ClassPathLocationHandler() { |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40302
diff
changeset
|
748 |
super(StandardLocation.CLASS_PATH, Option.CLASS_PATH); |
10818 | 749 |
} |
750 |
||
751 |
@Override |
|
36526 | 752 |
Collection<Path> getPaths() { |
10818 | 753 |
lazy(); |
754 |
return searchPath; |
|
755 |
} |
|
756 |
||
757 |
@Override |
|
27118
3c8314271af7
8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents:
25874
diff
changeset
|
758 |
protected SearchPath computePath(String value) { |
10818 | 759 |
String cp = value; |
10 | 760 |
|
10818 | 761 |
// CLASSPATH environment variable when run from `javac'. |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
762 |
if (cp == null) { |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
763 |
cp = System.getProperty("env.class.path"); |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
764 |
} |
10818 | 765 |
|
766 |
// If invoked via a java VM (not the javac launcher), use the |
|
767 |
// platform class path |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
768 |
if (cp == null && System.getProperty("application.home") == null) { |
10818 | 769 |
cp = System.getProperty("java.class.path"); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
770 |
} |
10818 | 771 |
|
772 |
// Default to current working directory. |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
773 |
if (cp == null) { |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
774 |
cp = "."; |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
775 |
} |
10818 | 776 |
|
14360
2a8304e421ed
6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents:
14259
diff
changeset
|
777 |
return createPath().addFiles(cp); |
2a8304e421ed
6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents:
14259
diff
changeset
|
778 |
} |
2a8304e421ed
6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents:
14259
diff
changeset
|
779 |
|
2a8304e421ed
6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents:
14259
diff
changeset
|
780 |
@Override |
27118
3c8314271af7
8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents:
25874
diff
changeset
|
781 |
protected SearchPath createPath() { |
3c8314271af7
8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents:
25874
diff
changeset
|
782 |
return new SearchPath() |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
783 |
.expandJarClassPaths(true) // Only search user jars for Class-Paths |
37944
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
784 |
.emptyPathDefault(getPath(".")); // Empty path elt ==> current directory |
14360
2a8304e421ed
6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents:
14259
diff
changeset
|
785 |
} |
10818 | 786 |
|
787 |
private void lazy() { |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
788 |
if (searchPath == null) { |
36526 | 789 |
setPaths(null); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
790 |
} |
10818 | 791 |
} |
10 | 792 |
} |
793 |
||
10818 | 794 |
/** |
36526 | 795 |
* Custom subtype of LocationHandler for PLATFORM_CLASS_PATH. |
796 |
* Various options are supported for different components of the |
|
797 |
* platform class path. |
|
798 |
* Setting a value with setLocation overrides all existing option values. |
|
799 |
* Setting any option overrides any value set with setLocation, and |
|
800 |
* reverts to using default values for options that have not been set. |
|
801 |
* Setting -bootclasspath or -Xbootclasspath overrides any existing |
|
802 |
* value for -Xbootclasspath/p: and -Xbootclasspath/a:. |
|
10818 | 803 |
*/ |
36526 | 804 |
private class BootClassPathLocationHandler extends BasicLocationHandler { |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
805 |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
806 |
private Collection<Path> searchPath; |
22163 | 807 |
final Map<Option, String> optionValues = new EnumMap<>(Option.class); |
10818 | 808 |
|
809 |
/** |
|
27579 | 810 |
* Is the bootclasspath the default? |
10818 | 811 |
*/ |
27579 | 812 |
private boolean isDefault; |
10818 | 813 |
|
814 |
BootClassPathLocationHandler() { |
|
815 |
super(StandardLocation.PLATFORM_CLASS_PATH, |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40302
diff
changeset
|
816 |
Option.BOOT_CLASS_PATH, Option.XBOOTCLASSPATH, |
11314 | 817 |
Option.XBOOTCLASSPATH_PREPEND, |
818 |
Option.XBOOTCLASSPATH_APPEND, |
|
819 |
Option.ENDORSEDDIRS, Option.DJAVA_ENDORSED_DIRS, |
|
820 |
Option.EXTDIRS, Option.DJAVA_EXT_DIRS); |
|
10818 | 821 |
} |
822 |
||
823 |
boolean isDefault() { |
|
824 |
lazy(); |
|
27579 | 825 |
return isDefault; |
10818 | 826 |
} |
827 |
||
828 |
@Override |
|
11314 | 829 |
boolean handleOption(Option option, String value) { |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
830 |
if (!options.contains(option)) { |
10818 | 831 |
return false; |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
832 |
} |
10 | 833 |
|
47702
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
834 |
explicit = true; |
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
835 |
|
10818 | 836 |
option = canonicalize(option); |
837 |
optionValues.put(option, value); |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40302
diff
changeset
|
838 |
if (option == BOOT_CLASS_PATH) { |
10818 | 839 |
optionValues.remove(XBOOTCLASSPATH_PREPEND); |
840 |
optionValues.remove(XBOOTCLASSPATH_APPEND); |
|
841 |
} |
|
842 |
searchPath = null; // reset to "uninitialized" |
|
843 |
return true; |
|
844 |
} |
|
845 |
// where |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
846 |
// TODO: would be better if option aliasing was handled at a higher |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
847 |
// level |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
848 |
private Option canonicalize(Option option) { |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
849 |
switch (option) { |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
850 |
case XBOOTCLASSPATH: |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40302
diff
changeset
|
851 |
return Option.BOOT_CLASS_PATH; |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
852 |
case DJAVA_ENDORSED_DIRS: |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
853 |
return Option.ENDORSEDDIRS; |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
854 |
case DJAVA_EXT_DIRS: |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
855 |
return Option.EXTDIRS; |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
856 |
default: |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
857 |
return option; |
10818 | 858 |
} |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
859 |
} |
10 | 860 |
|
10818 | 861 |
@Override |
36526 | 862 |
Collection<Path> getPaths() { |
10 | 863 |
lazy(); |
10818 | 864 |
return searchPath; |
865 |
} |
|
866 |
||
867 |
@Override |
|
36526 | 868 |
void setPaths(Iterable<? extends Path> files) { |
10818 | 869 |
if (files == null) { |
870 |
searchPath = null; // reset to "uninitialized" |
|
871 |
} else { |
|
27579 | 872 |
isDefault = false; |
47702
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
873 |
explicit = true; |
27118
3c8314271af7
8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents:
25874
diff
changeset
|
874 |
SearchPath p = new SearchPath().addFiles(files, false); |
10818 | 875 |
searchPath = Collections.unmodifiableCollection(p); |
876 |
optionValues.clear(); |
|
877 |
} |
|
10 | 878 |
} |
10818 | 879 |
|
27579 | 880 |
SearchPath computePath() throws IOException { |
27118
3c8314271af7
8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents:
25874
diff
changeset
|
881 |
SearchPath path = new SearchPath(); |
10818 | 882 |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40302
diff
changeset
|
883 |
String bootclasspathOpt = optionValues.get(BOOT_CLASS_PATH); |
10818 | 884 |
String endorseddirsOpt = optionValues.get(ENDORSEDDIRS); |
885 |
String extdirsOpt = optionValues.get(EXTDIRS); |
|
886 |
String xbootclasspathPrependOpt = optionValues.get(XBOOTCLASSPATH_PREPEND); |
|
887 |
String xbootclasspathAppendOpt = optionValues.get(XBOOTCLASSPATH_APPEND); |
|
888 |
path.addFiles(xbootclasspathPrependOpt); |
|
889 |
||
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
890 |
if (endorseddirsOpt != null) { |
10818 | 891 |
path.addDirectories(endorseddirsOpt); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
892 |
} else { |
10818 | 893 |
path.addDirectories(System.getProperty("java.endorsed.dirs"), false); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
894 |
} |
10818 | 895 |
|
896 |
if (bootclasspathOpt != null) { |
|
897 |
path.addFiles(bootclasspathOpt); |
|
898 |
} else { |
|
899 |
// Standard system classes for this compiler's release. |
|
36526 | 900 |
Collection<Path> systemClasses = systemClasses(); |
27579 | 901 |
if (systemClasses != null) { |
902 |
path.addFiles(systemClasses, false); |
|
903 |
} else { |
|
904 |
// fallback to the value of sun.boot.class.path |
|
905 |
String files = System.getProperty("sun.boot.class.path"); |
|
906 |
path.addFiles(files, false); |
|
10818 | 907 |
} |
908 |
} |
|
909 |
||
910 |
path.addFiles(xbootclasspathAppendOpt); |
|
911 |
||
912 |
// Strictly speaking, standard extensions are not bootstrap |
|
913 |
// classes, but we treat them identically, so we'll pretend |
|
914 |
// that they are. |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
915 |
if (extdirsOpt != null) { |
10818 | 916 |
path.addDirectories(extdirsOpt); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
917 |
} else { |
27579 | 918 |
// Add lib/jfxrt.jar to the search path |
36526 | 919 |
Path jfxrt = javaHome.resolve("lib/jfxrt.jar"); |
27858 | 920 |
if (Files.exists(jfxrt)) { |
27579 | 921 |
path.addFile(jfxrt, false); |
922 |
} |
|
10818 | 923 |
path.addDirectories(System.getProperty("java.ext.dirs"), false); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
924 |
} |
10818 | 925 |
|
27579 | 926 |
isDefault = |
927 |
(xbootclasspathPrependOpt == null) |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
928 |
&& (bootclasspathOpt == null) |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
929 |
&& (xbootclasspathAppendOpt == null); |
10818 | 930 |
|
931 |
return path; |
|
932 |
} |
|
933 |
||
27579 | 934 |
/** |
935 |
* Return a collection of files containing system classes. |
|
936 |
* Returns {@code null} if not running on a modular image. |
|
937 |
* |
|
938 |
* @throws UncheckedIOException if an I/O errors occurs |
|
939 |
*/ |
|
36526 | 940 |
private Collection<Path> systemClasses() throws IOException { |
941 |
// Return "modules" jimage file if available |
|
942 |
if (Files.isRegularFile(thisSystemModules)) { |
|
40302
8c0d8d2c3519
8143048: Re-examine dependency on property sun.boot.class.path
jlahoda
parents:
38536
diff
changeset
|
943 |
return Collections.singleton(thisSystemModules); |
27579 | 944 |
} |
945 |
||
946 |
// Exploded module image |
|
36526 | 947 |
Path modules = javaHome.resolve("modules"); |
27579 | 948 |
if (Files.isDirectory(modules.resolve("java.base"))) { |
29053
5c1f1d6b40f6
8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
28707
diff
changeset
|
949 |
try (Stream<Path> listedModules = Files.list(modules)) { |
40302
8c0d8d2c3519
8143048: Re-examine dependency on property sun.boot.class.path
jlahoda
parents:
38536
diff
changeset
|
950 |
return listedModules.collect(Collectors.toList()); |
29053
5c1f1d6b40f6
8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
28707
diff
changeset
|
951 |
} |
27579 | 952 |
} |
953 |
||
954 |
// not a modular image that we know about |
|
955 |
return null; |
|
956 |
} |
|
957 |
||
10818 | 958 |
private void lazy() { |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
959 |
if (searchPath == null) { |
27579 | 960 |
try { |
44822 | 961 |
searchPath = Collections.unmodifiableCollection(computePath()); |
27579 | 962 |
} catch (IOException e) { |
963 |
// TODO: need better handling here, e.g. javac Abort? |
|
964 |
throw new UncheckedIOException(e); |
|
965 |
} |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
966 |
} |
10818 | 967 |
} |
44822 | 968 |
|
969 |
@Override |
|
970 |
boolean contains(Path file) throws IOException { |
|
971 |
return Locations.this.contains(searchPath, file); |
|
972 |
} |
|
10 | 973 |
} |
974 |
||
36526 | 975 |
/** |
976 |
* A LocationHander to represent modules found from a module-oriented |
|
977 |
* location such as MODULE_SOURCE_PATH, UPGRADE_MODULE_PATH, |
|
978 |
* SYSTEM_MODULES and MODULE_PATH. |
|
979 |
* |
|
980 |
* The Location can be specified to accept overriding classes from the |
|
40762
f8883aa0053c
8160851: Remove old launcher module-related options
mchung
parents:
40513
diff
changeset
|
981 |
* {@code --patch-module <module>=<path> } parameter. |
36526 | 982 |
*/ |
44822 | 983 |
private class ModuleLocationHandler extends LocationHandler implements Location { |
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
984 |
private final LocationHandler parent; |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
985 |
private final String name; |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
986 |
private final String moduleName; |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
987 |
private final boolean output; |
47363
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
988 |
boolean explicit; |
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
989 |
Collection<Path> searchPath; |
36526 | 990 |
|
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
991 |
ModuleLocationHandler(LocationHandler parent, String name, String moduleName, |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
992 |
Collection<Path> searchPath, boolean output) { |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
993 |
this.parent = parent; |
36526 | 994 |
this.name = name; |
995 |
this.moduleName = moduleName; |
|
996 |
this.searchPath = searchPath; |
|
997 |
this.output = output; |
|
998 |
} |
|
999 |
||
37848
3c8ff4204d2d
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36526
diff
changeset
|
1000 |
@Override @DefinedBy(Api.COMPILER) |
36526 | 1001 |
public String getName() { |
1002 |
return name; |
|
1003 |
} |
|
1004 |
||
37848
3c8ff4204d2d
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36526
diff
changeset
|
1005 |
@Override @DefinedBy(Api.COMPILER) |
36526 | 1006 |
public boolean isOutputLocation() { |
1007 |
return output; |
|
1008 |
} |
|
1009 |
||
1010 |
@Override // defined by LocationHandler |
|
1011 |
boolean handleOption(Option option, String value) { |
|
1012 |
throw new UnsupportedOperationException(); |
|
1013 |
} |
|
1014 |
||
1015 |
@Override // defined by LocationHandler |
|
1016 |
Collection<Path> getPaths() { |
|
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1017 |
return Collections.unmodifiableCollection(searchPath); |
36526 | 1018 |
} |
1019 |
||
47702
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
1020 |
@Override |
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
1021 |
boolean isExplicit() { |
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
1022 |
return true; |
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
1023 |
} |
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
1024 |
|
36526 | 1025 |
@Override // defined by LocationHandler |
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1026 |
void setPaths(Iterable<? extends Path> paths) throws IOException { |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1027 |
// defer to the parent to determine if this is acceptable |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1028 |
parent.setPathsForModule(moduleName, paths); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1029 |
} |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1030 |
|
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1031 |
@Override // defined by LocationHandler |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1032 |
void setPathsForModule(String moduleName, Iterable<? extends Path> paths) { |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1033 |
throw new UnsupportedOperationException("not supported for " + name); |
36526 | 1034 |
} |
1035 |
||
1036 |
@Override // defined by LocationHandler |
|
1037 |
String inferModuleName() { |
|
1038 |
return moduleName; |
|
1039 |
} |
|
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1040 |
|
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1041 |
@Override |
44822 | 1042 |
boolean contains(Path file) throws IOException { |
1043 |
return Locations.this.contains(searchPath, file); |
|
1044 |
} |
|
1045 |
||
1046 |
@Override |
|
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1047 |
public String toString() { |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1048 |
return name; |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1049 |
} |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1050 |
} |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1051 |
|
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1052 |
/** |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1053 |
* A table of module location handlers, indexed by name and path. |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1054 |
*/ |
44822 | 1055 |
private class ModuleTable { |
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1056 |
private final Map<String, ModuleLocationHandler> nameMap = new LinkedHashMap<>(); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1057 |
private final Map<Path, ModuleLocationHandler> pathMap = new LinkedHashMap<>(); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1058 |
|
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1059 |
void add(ModuleLocationHandler h) { |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1060 |
nameMap.put(h.moduleName, h); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1061 |
for (Path p : h.searchPath) { |
44021
3ea5514d9fbe
8175990: Javac fails to find module-info.java if module source path contains symlinks
ksrini
parents:
44019
diff
changeset
|
1062 |
pathMap.put(normalize(p), h); |
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1063 |
} |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1064 |
} |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1065 |
|
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1066 |
void updatePaths(ModuleLocationHandler h) { |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1067 |
// use iterator, to be able to remove old entries |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1068 |
for (Iterator<Map.Entry<Path, ModuleLocationHandler>> iter = pathMap.entrySet().iterator(); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1069 |
iter.hasNext(); ) { |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1070 |
Map.Entry<Path, ModuleLocationHandler> e = iter.next(); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1071 |
if (e.getValue() == h) { |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1072 |
iter.remove(); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1073 |
} |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1074 |
} |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1075 |
for (Path p : h.searchPath) { |
44021
3ea5514d9fbe
8175990: Javac fails to find module-info.java if module source path contains symlinks
ksrini
parents:
44019
diff
changeset
|
1076 |
pathMap.put(normalize(p), h); |
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1077 |
} |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1078 |
} |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1079 |
|
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1080 |
ModuleLocationHandler get(String name) { |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1081 |
return nameMap.get(name); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1082 |
} |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1083 |
|
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1084 |
ModuleLocationHandler get(Path path) { |
44063
5f0cf4126949
8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents:
44021
diff
changeset
|
1085 |
while (path != null) { |
5f0cf4126949
8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents:
44021
diff
changeset
|
1086 |
ModuleLocationHandler l = pathMap.get(path); |
5f0cf4126949
8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents:
44021
diff
changeset
|
1087 |
|
5f0cf4126949
8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents:
44021
diff
changeset
|
1088 |
if (l != null) |
5f0cf4126949
8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents:
44021
diff
changeset
|
1089 |
return l; |
5f0cf4126949
8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents:
44021
diff
changeset
|
1090 |
|
5f0cf4126949
8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents:
44021
diff
changeset
|
1091 |
path = path.getParent(); |
5f0cf4126949
8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents:
44021
diff
changeset
|
1092 |
} |
5f0cf4126949
8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents:
44021
diff
changeset
|
1093 |
|
5f0cf4126949
8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents:
44021
diff
changeset
|
1094 |
return null; |
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1095 |
} |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1096 |
|
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1097 |
void clear() { |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1098 |
nameMap.clear(); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1099 |
pathMap.clear(); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1100 |
} |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1101 |
|
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1102 |
boolean isEmpty() { |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1103 |
return nameMap.isEmpty(); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1104 |
} |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1105 |
|
44822 | 1106 |
boolean contains(Path file) throws IOException { |
1107 |
return Locations.this.contains(pathMap.keySet(), file); |
|
1108 |
} |
|
1109 |
||
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1110 |
Set<Location> locations() { |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1111 |
return Collections.unmodifiableSet(nameMap.values().stream().collect(Collectors.toSet())); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1112 |
} |
47363
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
1113 |
|
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
1114 |
Set<Location> explicitLocations() { |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
1115 |
return Collections.unmodifiableSet(nameMap.entrySet() |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
1116 |
.stream() |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
1117 |
.filter(e -> e.getValue().explicit) |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
1118 |
.map(e -> e.getValue()) |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
1119 |
.collect(Collectors.toSet())); |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
1120 |
} |
36526 | 1121 |
} |
1122 |
||
1123 |
/** |
|
1124 |
* A LocationHandler for simple module-oriented search paths, |
|
1125 |
* like UPGRADE_MODULE_PATH and MODULE_PATH. |
|
1126 |
*/ |
|
1127 |
private class ModulePathLocationHandler extends SimpleLocationHandler { |
|
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1128 |
private ModuleTable moduleTable; |
42414
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
42408
diff
changeset
|
1129 |
|
36526 | 1130 |
ModulePathLocationHandler(Location location, Option... options) { |
1131 |
super(location, options); |
|
1132 |
} |
|
1133 |
||
1134 |
@Override |
|
1135 |
public boolean handleOption(Option option, String value) { |
|
1136 |
if (!options.contains(option)) { |
|
1137 |
return false; |
|
1138 |
} |
|
1139 |
setPaths(value == null ? null : getPathEntries(value)); |
|
1140 |
return true; |
|
1141 |
} |
|
1142 |
||
1143 |
@Override |
|
42414
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
42408
diff
changeset
|
1144 |
public Location getLocationForModule(String moduleName) { |
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1145 |
initModuleLocations(); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1146 |
return moduleTable.get(moduleName); |
42414
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
42408
diff
changeset
|
1147 |
} |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
42408
diff
changeset
|
1148 |
|
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
42408
diff
changeset
|
1149 |
@Override |
44822 | 1150 |
public Location getLocationForModule(Path file) { |
1151 |
initModuleLocations(); |
|
1152 |
return moduleTable.get(file); |
|
1153 |
} |
|
1154 |
||
1155 |
@Override |
|
42261
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41861
diff
changeset
|
1156 |
Iterable<Set<Location>> listLocationsForModules() { |
47363
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
1157 |
Set<Location> explicitLocations = moduleTable != null ? |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
1158 |
moduleTable.explicitLocations() : Collections.emptySet(); |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
1159 |
Iterable<Set<Location>> explicitLocationsList = !explicitLocations.isEmpty() |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
1160 |
? Collections.singletonList(explicitLocations) |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
1161 |
: Collections.emptyList(); |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
1162 |
|
36526 | 1163 |
if (searchPath == null) |
47363
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
1164 |
return explicitLocationsList; |
36526 | 1165 |
|
47363
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
1166 |
Iterable<Set<Location>> searchPathLocations = |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
1167 |
() -> new ModulePathIterator(); |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
1168 |
return () -> Iterators.createCompoundIterator(Arrays.asList(explicitLocationsList, |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
1169 |
searchPathLocations), |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
1170 |
Iterable::iterator); |
36526 | 1171 |
} |
1172 |
||
1173 |
@Override |
|
44822 | 1174 |
boolean contains(Path file) throws IOException { |
1175 |
if (moduleTable == null) { |
|
1176 |
initModuleLocations(); |
|
1177 |
} |
|
1178 |
return moduleTable.contains(file); |
|
1179 |
} |
|
1180 |
||
1181 |
@Override |
|
36526 | 1182 |
void setPaths(Iterable<? extends Path> paths) { |
1183 |
if (paths != null) { |
|
1184 |
for (Path p: paths) { |
|
1185 |
checkValidModulePathEntry(p); |
|
1186 |
} |
|
1187 |
} |
|
1188 |
super.setPaths(paths); |
|
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1189 |
moduleTable = null; |
36526 | 1190 |
} |
1191 |
||
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1192 |
@Override |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1193 |
void setPathsForModule(String name, Iterable<? extends Path> paths) throws IOException { |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1194 |
List<Path> checkedPaths = checkPaths(paths); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1195 |
// how far should we go to validate the paths provide a module? |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1196 |
// e.g. contain module-info with the correct name? |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1197 |
initModuleLocations(); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1198 |
ModuleLocationHandler l = moduleTable.get(name); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1199 |
if (l == null) { |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1200 |
l = new ModuleLocationHandler(this, location.getName() + "[" + name + "]", |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1201 |
name, checkedPaths, true); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1202 |
moduleTable.add(l); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1203 |
} else { |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1204 |
l.searchPath = checkedPaths; |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1205 |
moduleTable.updatePaths(l); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1206 |
} |
47363
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
1207 |
l.explicit = true; |
47702
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
1208 |
explicit = true; |
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1209 |
} |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1210 |
|
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1211 |
private List<Path> checkPaths(Iterable<? extends Path> paths) throws IOException { |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1212 |
Objects.requireNonNull(paths); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1213 |
List<Path> validPaths = new ArrayList<>(); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1214 |
for (Path p : paths) { |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1215 |
validPaths.add(checkDirectory(p)); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1216 |
} |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1217 |
return validPaths; |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1218 |
} |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1219 |
|
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1220 |
private void initModuleLocations() { |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1221 |
if (moduleTable != null) { |
42414
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
42408
diff
changeset
|
1222 |
return; |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
42408
diff
changeset
|
1223 |
} |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
42408
diff
changeset
|
1224 |
|
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1225 |
moduleTable = new ModuleTable(); |
42414
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
42408
diff
changeset
|
1226 |
|
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
42408
diff
changeset
|
1227 |
for (Set<Location> set : listLocationsForModules()) { |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
42408
diff
changeset
|
1228 |
for (Location locn : set) { |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
42408
diff
changeset
|
1229 |
if (locn instanceof ModuleLocationHandler) { |
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1230 |
ModuleLocationHandler l = (ModuleLocationHandler) locn; |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1231 |
if (!moduleTable.nameMap.containsKey(l.moduleName)) { |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1232 |
moduleTable.add(l); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1233 |
} |
42414
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
42408
diff
changeset
|
1234 |
} |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
42408
diff
changeset
|
1235 |
} |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
42408
diff
changeset
|
1236 |
} |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
42408
diff
changeset
|
1237 |
} |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
42408
diff
changeset
|
1238 |
|
36526 | 1239 |
private void checkValidModulePathEntry(Path p) { |
43771
25ddac537bb5
8174104: Compiler does not allow non-existent module path entry
jjg
parents:
43574
diff
changeset
|
1240 |
if (!Files.exists(p)) { |
25ddac537bb5
8174104: Compiler does not allow non-existent module path entry
jjg
parents:
43574
diff
changeset
|
1241 |
// warning may be generated later |
25ddac537bb5
8174104: Compiler does not allow non-existent module path entry
jjg
parents:
43574
diff
changeset
|
1242 |
return; |
25ddac537bb5
8174104: Compiler does not allow non-existent module path entry
jjg
parents:
43574
diff
changeset
|
1243 |
} |
25ddac537bb5
8174104: Compiler does not allow non-existent module path entry
jjg
parents:
43574
diff
changeset
|
1244 |
|
36526 | 1245 |
if (Files.isDirectory(p)) { |
1246 |
// either an exploded module or a directory of modules |
|
1247 |
return; |
|
1248 |
} |
|
1249 |
||
1250 |
String name = p.getFileName().toString(); |
|
1251 |
int lastDot = name.lastIndexOf("."); |
|
1252 |
if (lastDot > 0) { |
|
1253 |
switch (name.substring(lastDot)) { |
|
1254 |
case ".jar": |
|
1255 |
case ".jmod": |
|
1256 |
return; |
|
1257 |
} |
|
1258 |
} |
|
1259 |
throw new IllegalArgumentException(p.toString()); |
|
1260 |
} |
|
1261 |
||
1262 |
class ModulePathIterator implements Iterator<Set<Location>> { |
|
1263 |
Iterator<Path> pathIter = searchPath.iterator(); |
|
1264 |
int pathIndex = 0; |
|
1265 |
Set<Location> next = null; |
|
1266 |
||
1267 |
@Override |
|
1268 |
public boolean hasNext() { |
|
1269 |
if (next != null) |
|
1270 |
return true; |
|
1271 |
||
1272 |
while (next == null) { |
|
1273 |
if (pathIter.hasNext()) { |
|
1274 |
Path path = pathIter.next(); |
|
1275 |
if (Files.isDirectory(path)) { |
|
1276 |
next = scanDirectory(path); |
|
1277 |
} else { |
|
1278 |
next = scanFile(path); |
|
1279 |
} |
|
1280 |
pathIndex++; |
|
1281 |
} else |
|
1282 |
return false; |
|
1283 |
} |
|
1284 |
return true; |
|
1285 |
} |
|
1286 |
||
1287 |
@Override |
|
1288 |
public Set<Location> next() { |
|
1289 |
hasNext(); |
|
1290 |
if (next != null) { |
|
1291 |
Set<Location> result = next; |
|
1292 |
next = null; |
|
1293 |
return result; |
|
1294 |
} |
|
1295 |
throw new NoSuchElementException(); |
|
1296 |
} |
|
1297 |
||
1298 |
private Set<Location> scanDirectory(Path path) { |
|
1299 |
Set<Path> paths = new LinkedHashSet<>(); |
|
1300 |
Path moduleInfoClass = null; |
|
1301 |
try (DirectoryStream<Path> stream = Files.newDirectoryStream(path)) { |
|
1302 |
for (Path entry: stream) { |
|
1303 |
if (entry.endsWith("module-info.class")) { |
|
1304 |
moduleInfoClass = entry; |
|
1305 |
break; // no need to continue scanning |
|
1306 |
} |
|
1307 |
paths.add(entry); |
|
1308 |
} |
|
1309 |
} catch (DirectoryIteratorException | IOException ignore) { |
|
1310 |
log.error(Errors.LocnCantReadDirectory(path)); |
|
1311 |
return Collections.emptySet(); |
|
1312 |
} |
|
1313 |
||
1314 |
if (moduleInfoClass != null) { |
|
1315 |
// It's an exploded module directly on the module path. |
|
1316 |
// We can't infer module name from the directory name, so have to |
|
1317 |
// read module-info.class. |
|
1318 |
try { |
|
1319 |
String moduleName = readModuleName(moduleInfoClass); |
|
1320 |
String name = location.getName() |
|
1321 |
+ "[" + pathIndex + ":" + moduleName + "]"; |
|
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1322 |
ModuleLocationHandler l = new ModuleLocationHandler( |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1323 |
ModulePathLocationHandler.this, name, moduleName, |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1324 |
Collections.singletonList(path), false); |
36526 | 1325 |
return Collections.singleton(l); |
1326 |
} catch (ModuleNameReader.BadClassFile e) { |
|
1327 |
log.error(Errors.LocnBadModuleInfo(path)); |
|
1328 |
return Collections.emptySet(); |
|
1329 |
} catch (IOException e) { |
|
1330 |
log.error(Errors.LocnCantReadFile(path)); |
|
1331 |
return Collections.emptySet(); |
|
1332 |
} |
|
1333 |
} |
|
1334 |
||
1335 |
// A directory of modules |
|
1336 |
Set<Location> result = new LinkedHashSet<>(); |
|
1337 |
int index = 0; |
|
1338 |
for (Path entry : paths) { |
|
1339 |
Pair<String,Path> module = inferModuleName(entry); |
|
1340 |
if (module == null) { |
|
1341 |
// diagnostic reported if necessary; skip to next |
|
1342 |
continue; |
|
1343 |
} |
|
1344 |
String moduleName = module.fst; |
|
1345 |
Path modulePath = module.snd; |
|
1346 |
String name = location.getName() |
|
1347 |
+ "[" + pathIndex + "." + (index++) + ":" + moduleName + "]"; |
|
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1348 |
ModuleLocationHandler l = new ModuleLocationHandler( |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1349 |
ModulePathLocationHandler.this, name, moduleName, |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1350 |
Collections.singletonList(modulePath), false); |
36526 | 1351 |
result.add(l); |
1352 |
} |
|
1353 |
return result; |
|
1354 |
} |
|
1355 |
||
1356 |
private Set<Location> scanFile(Path path) { |
|
1357 |
Pair<String,Path> module = inferModuleName(path); |
|
1358 |
if (module == null) { |
|
1359 |
// diagnostic reported if necessary |
|
1360 |
return Collections.emptySet(); |
|
1361 |
} |
|
1362 |
String moduleName = module.fst; |
|
1363 |
Path modulePath = module.snd; |
|
1364 |
String name = location.getName() |
|
1365 |
+ "[" + pathIndex + ":" + moduleName + "]"; |
|
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1366 |
ModuleLocationHandler l = new ModuleLocationHandler( |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1367 |
ModulePathLocationHandler.this, name, moduleName, |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1368 |
Collections.singletonList(modulePath), false); |
36526 | 1369 |
return Collections.singleton(l); |
1370 |
} |
|
1371 |
||
1372 |
private Pair<String,Path> inferModuleName(Path p) { |
|
1373 |
if (Files.isDirectory(p)) { |
|
1374 |
if (Files.exists(p.resolve("module-info.class"))) { |
|
1375 |
String name = p.getFileName().toString(); |
|
1376 |
if (SourceVersion.isName(name)) |
|
1377 |
return new Pair<>(name, p); |
|
1378 |
} |
|
1379 |
return null; |
|
1380 |
} |
|
1381 |
||
38536
42569f7fe4e6
8154824: Compiler should handle java.nio.file.FileSystemNotFoundException gracefully and not abort
sadayapalam
parents:
38519
diff
changeset
|
1382 |
if (p.getFileName().toString().endsWith(".jar") && fsInfo.exists(p)) { |
43574
042e694725f7
8166675: Latent bug in jar file handling during module path processing.
jjg
parents:
43267
diff
changeset
|
1383 |
FileSystemProvider jarFSProvider = fsInfo.getJarFSProvider(); |
042e694725f7
8166675: Latent bug in jar file handling during module path processing.
jjg
parents:
43267
diff
changeset
|
1384 |
if (jarFSProvider == null) { |
042e694725f7
8166675: Latent bug in jar file handling during module path processing.
jjg
parents:
43267
diff
changeset
|
1385 |
log.error(Errors.NoZipfsForArchive(p)); |
042e694725f7
8166675: Latent bug in jar file handling during module path processing.
jjg
parents:
43267
diff
changeset
|
1386 |
return null; |
042e694725f7
8166675: Latent bug in jar file handling during module path processing.
jjg
parents:
43267
diff
changeset
|
1387 |
} |
042e694725f7
8166675: Latent bug in jar file handling during module path processing.
jjg
parents:
43267
diff
changeset
|
1388 |
try (FileSystem fs = jarFSProvider.newFileSystem(p, fsEnv)) { |
36526 | 1389 |
Path moduleInfoClass = fs.getPath("module-info.class"); |
1390 |
if (Files.exists(moduleInfoClass)) { |
|
1391 |
String moduleName = readModuleName(moduleInfoClass); |
|
1392 |
return new Pair<>(moduleName, p); |
|
1393 |
} |
|
45682
fc3b228b9e2a
8181087: Module system implementation refresh (6/2017)
alanb
parents:
44822
diff
changeset
|
1394 |
Path mf = fs.getPath("META-INF/MANIFEST.MF"); |
fc3b228b9e2a
8181087: Module system implementation refresh (6/2017)
alanb
parents:
44822
diff
changeset
|
1395 |
if (Files.exists(mf)) { |
fc3b228b9e2a
8181087: Module system implementation refresh (6/2017)
alanb
parents:
44822
diff
changeset
|
1396 |
try (InputStream in = Files.newInputStream(mf)) { |
fc3b228b9e2a
8181087: Module system implementation refresh (6/2017)
alanb
parents:
44822
diff
changeset
|
1397 |
Manifest man = new Manifest(in); |
fc3b228b9e2a
8181087: Module system implementation refresh (6/2017)
alanb
parents:
44822
diff
changeset
|
1398 |
Attributes attrs = man.getMainAttributes(); |
fc3b228b9e2a
8181087: Module system implementation refresh (6/2017)
alanb
parents:
44822
diff
changeset
|
1399 |
if (attrs != null) { |
fc3b228b9e2a
8181087: Module system implementation refresh (6/2017)
alanb
parents:
44822
diff
changeset
|
1400 |
String moduleName = attrs.getValue(new Attributes.Name("Automatic-Module-Name")); |
fc3b228b9e2a
8181087: Module system implementation refresh (6/2017)
alanb
parents:
44822
diff
changeset
|
1401 |
if (moduleName != null) { |
fc3b228b9e2a
8181087: Module system implementation refresh (6/2017)
alanb
parents:
44822
diff
changeset
|
1402 |
if (isModuleName(moduleName)) { |
fc3b228b9e2a
8181087: Module system implementation refresh (6/2017)
alanb
parents:
44822
diff
changeset
|
1403 |
return new Pair<>(moduleName, p); |
fc3b228b9e2a
8181087: Module system implementation refresh (6/2017)
alanb
parents:
44822
diff
changeset
|
1404 |
} else { |
fc3b228b9e2a
8181087: Module system implementation refresh (6/2017)
alanb
parents:
44822
diff
changeset
|
1405 |
log.error(Errors.LocnCantGetModuleNameForJar(p)); |
fc3b228b9e2a
8181087: Module system implementation refresh (6/2017)
alanb
parents:
44822
diff
changeset
|
1406 |
return null; |
fc3b228b9e2a
8181087: Module system implementation refresh (6/2017)
alanb
parents:
44822
diff
changeset
|
1407 |
} |
fc3b228b9e2a
8181087: Module system implementation refresh (6/2017)
alanb
parents:
44822
diff
changeset
|
1408 |
} |
fc3b228b9e2a
8181087: Module system implementation refresh (6/2017)
alanb
parents:
44822
diff
changeset
|
1409 |
} |
fc3b228b9e2a
8181087: Module system implementation refresh (6/2017)
alanb
parents:
44822
diff
changeset
|
1410 |
} |
fc3b228b9e2a
8181087: Module system implementation refresh (6/2017)
alanb
parents:
44822
diff
changeset
|
1411 |
} |
36526 | 1412 |
} catch (ModuleNameReader.BadClassFile e) { |
1413 |
log.error(Errors.LocnBadModuleInfo(p)); |
|
1414 |
return null; |
|
1415 |
} catch (IOException e) { |
|
1416 |
log.error(Errors.LocnCantReadFile(p)); |
|
1417 |
return null; |
|
1418 |
} |
|
1419 |
||
1420 |
//automatic module: |
|
1421 |
String fn = p.getFileName().toString(); |
|
1422 |
//from ModulePath.deriveModuleDescriptor: |
|
1423 |
||
1424 |
// drop .jar |
|
1425 |
String mn = fn.substring(0, fn.length()-4); |
|
1426 |
||
1427 |
// find first occurrence of -${NUMBER}. or -${NUMBER}$ |
|
1428 |
Matcher matcher = Pattern.compile("-(\\d+(\\.|$))").matcher(mn); |
|
1429 |
if (matcher.find()) { |
|
1430 |
int start = matcher.start(); |
|
1431 |
||
1432 |
mn = mn.substring(0, start); |
|
1433 |
} |
|
1434 |
||
1435 |
// finally clean up the module name |
|
44573
245bb4e6f983
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44063
diff
changeset
|
1436 |
mn = mn.replaceAll("[^A-Za-z0-9]", ".") // replace non-alphanumeric |
36526 | 1437 |
.replaceAll("(\\.)(\\1)+", ".") // collapse repeating dots |
1438 |
.replaceAll("^\\.", "") // drop leading dots |
|
1439 |
.replaceAll("\\.$", ""); // drop trailing dots |
|
1440 |
||
1441 |
||
1442 |
if (!mn.isEmpty()) { |
|
1443 |
return new Pair<>(mn, p); |
|
1444 |
} |
|
1445 |
||
1446 |
log.error(Errors.LocnCantGetModuleNameForJar(p)); |
|
1447 |
return null; |
|
1448 |
} |
|
1449 |
||
1450 |
if (p.getFileName().toString().endsWith(".jmod")) { |
|
1451 |
try { |
|
41440 | 1452 |
// check if the JMOD file is valid |
1453 |
JDK9Wrappers.JmodFile.checkMagic(p); |
|
1454 |
||
1455 |
// No JMOD file system. Use JarFileSystem to |
|
1456 |
// workaround for now |
|
36526 | 1457 |
FileSystem fs = fileSystems.get(p); |
1458 |
if (fs == null) { |
|
43574
042e694725f7
8166675: Latent bug in jar file handling during module path processing.
jjg
parents:
43267
diff
changeset
|
1459 |
FileSystemProvider jarFSProvider = fsInfo.getJarFSProvider(); |
042e694725f7
8166675: Latent bug in jar file handling during module path processing.
jjg
parents:
43267
diff
changeset
|
1460 |
if (jarFSProvider == null) { |
042e694725f7
8166675: Latent bug in jar file handling during module path processing.
jjg
parents:
43267
diff
changeset
|
1461 |
log.error(Errors.LocnCantReadFile(p)); |
042e694725f7
8166675: Latent bug in jar file handling during module path processing.
jjg
parents:
43267
diff
changeset
|
1462 |
return null; |
042e694725f7
8166675: Latent bug in jar file handling during module path processing.
jjg
parents:
43267
diff
changeset
|
1463 |
} |
042e694725f7
8166675: Latent bug in jar file handling during module path processing.
jjg
parents:
43267
diff
changeset
|
1464 |
fs = jarFSProvider.newFileSystem(p, Collections.emptyMap()); |
36526 | 1465 |
try { |
1466 |
Path moduleInfoClass = fs.getPath("classes/module-info.class"); |
|
1467 |
String moduleName = readModuleName(moduleInfoClass); |
|
1468 |
Path modulePath = fs.getPath("classes"); |
|
1469 |
fileSystems.put(p, fs); |
|
1470 |
closeables.add(fs); |
|
1471 |
fs = null; // prevent fs being closed in the finally clause |
|
1472 |
return new Pair<>(moduleName, modulePath); |
|
1473 |
} finally { |
|
1474 |
if (fs != null) |
|
1475 |
fs.close(); |
|
1476 |
} |
|
1477 |
} |
|
1478 |
} catch (ModuleNameReader.BadClassFile e) { |
|
1479 |
log.error(Errors.LocnBadModuleInfo(p)); |
|
43574
042e694725f7
8166675: Latent bug in jar file handling during module path processing.
jjg
parents:
43267
diff
changeset
|
1480 |
} catch (IOException e) { |
36526 | 1481 |
log.error(Errors.LocnCantReadFile(p)); |
1482 |
return null; |
|
1483 |
} |
|
1484 |
} |
|
1485 |
||
38519 | 1486 |
if (warn && false) { // temp disable, when enabled, massage examples.not-yet.txt suitably. |
36526 | 1487 |
log.warning(Warnings.LocnUnknownFileOnModulePath(p)); |
1488 |
} |
|
1489 |
return null; |
|
1490 |
} |
|
1491 |
||
1492 |
private String readModuleName(Path path) throws IOException, ModuleNameReader.BadClassFile { |
|
1493 |
if (moduleNameReader == null) |
|
1494 |
moduleNameReader = new ModuleNameReader(); |
|
1495 |
return moduleNameReader.readModuleName(path); |
|
1496 |
} |
|
1497 |
} |
|
1498 |
||
45682
fc3b228b9e2a
8181087: Module system implementation refresh (6/2017)
alanb
parents:
44822
diff
changeset
|
1499 |
//from jdk.internal.module.Checks: |
fc3b228b9e2a
8181087: Module system implementation refresh (6/2017)
alanb
parents:
44822
diff
changeset
|
1500 |
/** |
fc3b228b9e2a
8181087: Module system implementation refresh (6/2017)
alanb
parents:
44822
diff
changeset
|
1501 |
* Returns {@code true} if the given name is a legal module name. |
fc3b228b9e2a
8181087: Module system implementation refresh (6/2017)
alanb
parents:
44822
diff
changeset
|
1502 |
*/ |
fc3b228b9e2a
8181087: Module system implementation refresh (6/2017)
alanb
parents:
44822
diff
changeset
|
1503 |
private boolean isModuleName(String name) { |
fc3b228b9e2a
8181087: Module system implementation refresh (6/2017)
alanb
parents:
44822
diff
changeset
|
1504 |
int next; |
fc3b228b9e2a
8181087: Module system implementation refresh (6/2017)
alanb
parents:
44822
diff
changeset
|
1505 |
int off = 0; |
fc3b228b9e2a
8181087: Module system implementation refresh (6/2017)
alanb
parents:
44822
diff
changeset
|
1506 |
while ((next = name.indexOf('.', off)) != -1) { |
fc3b228b9e2a
8181087: Module system implementation refresh (6/2017)
alanb
parents:
44822
diff
changeset
|
1507 |
String id = name.substring(off, next); |
fc3b228b9e2a
8181087: Module system implementation refresh (6/2017)
alanb
parents:
44822
diff
changeset
|
1508 |
if (!SourceVersion.isName(id)) |
fc3b228b9e2a
8181087: Module system implementation refresh (6/2017)
alanb
parents:
44822
diff
changeset
|
1509 |
return false; |
fc3b228b9e2a
8181087: Module system implementation refresh (6/2017)
alanb
parents:
44822
diff
changeset
|
1510 |
off = next+1; |
fc3b228b9e2a
8181087: Module system implementation refresh (6/2017)
alanb
parents:
44822
diff
changeset
|
1511 |
} |
fc3b228b9e2a
8181087: Module system implementation refresh (6/2017)
alanb
parents:
44822
diff
changeset
|
1512 |
String last = name.substring(off); |
fc3b228b9e2a
8181087: Module system implementation refresh (6/2017)
alanb
parents:
44822
diff
changeset
|
1513 |
return SourceVersion.isName(last); |
fc3b228b9e2a
8181087: Module system implementation refresh (6/2017)
alanb
parents:
44822
diff
changeset
|
1514 |
} |
36526 | 1515 |
} |
1516 |
||
1517 |
private class ModuleSourcePathLocationHandler extends BasicLocationHandler { |
|
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1518 |
private ModuleTable moduleTable; |
44690
aec722d1b538
8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents:
44573
diff
changeset
|
1519 |
private List<Path> paths; |
36526 | 1520 |
|
1521 |
ModuleSourcePathLocationHandler() { |
|
1522 |
super(StandardLocation.MODULE_SOURCE_PATH, |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40302
diff
changeset
|
1523 |
Option.MODULE_SOURCE_PATH); |
36526 | 1524 |
} |
1525 |
||
1526 |
@Override |
|
1527 |
boolean handleOption(Option option, String value) { |
|
47702
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
1528 |
explicit = true; |
36526 | 1529 |
init(value); |
1530 |
return true; |
|
1531 |
} |
|
1532 |
||
1533 |
void init(String value) { |
|
1534 |
Collection<String> segments = new ArrayList<>(); |
|
1535 |
for (String s: value.split(File.pathSeparator)) { |
|
1536 |
expandBraces(s, segments); |
|
1537 |
} |
|
1538 |
||
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1539 |
Map<String, List<Path>> map = new LinkedHashMap<>(); |
44690
aec722d1b538
8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents:
44573
diff
changeset
|
1540 |
List<Path> noSuffixPaths = new ArrayList<>(); |
aec722d1b538
8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents:
44573
diff
changeset
|
1541 |
boolean anySuffix = false; |
36526 | 1542 |
final String MARKER = "*"; |
1543 |
for (String seg: segments) { |
|
1544 |
int markStart = seg.indexOf(MARKER); |
|
1545 |
if (markStart == -1) { |
|
44690
aec722d1b538
8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents:
44573
diff
changeset
|
1546 |
Path p = getPath(seg); |
aec722d1b538
8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents:
44573
diff
changeset
|
1547 |
add(map, p, null); |
aec722d1b538
8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents:
44573
diff
changeset
|
1548 |
noSuffixPaths.add(p); |
36526 | 1549 |
} else { |
1550 |
if (markStart == 0 || !isSeparator(seg.charAt(markStart - 1))) { |
|
1551 |
throw new IllegalArgumentException("illegal use of " + MARKER + " in " + seg); |
|
1552 |
} |
|
37944
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
1553 |
Path prefix = getPath(seg.substring(0, markStart - 1)); |
36526 | 1554 |
Path suffix; |
1555 |
int markEnd = markStart + MARKER.length(); |
|
1556 |
if (markEnd == seg.length()) { |
|
1557 |
suffix = null; |
|
1558 |
} else if (!isSeparator(seg.charAt(markEnd)) |
|
1559 |
|| seg.indexOf(MARKER, markEnd) != -1) { |
|
1560 |
throw new IllegalArgumentException("illegal use of " + MARKER + " in " + seg); |
|
1561 |
} else { |
|
37944
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
1562 |
suffix = getPath(seg.substring(markEnd + 1)); |
44690
aec722d1b538
8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents:
44573
diff
changeset
|
1563 |
anySuffix = true; |
36526 | 1564 |
} |
1565 |
add(map, prefix, suffix); |
|
44690
aec722d1b538
8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents:
44573
diff
changeset
|
1566 |
if (suffix == null) { |
aec722d1b538
8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents:
44573
diff
changeset
|
1567 |
noSuffixPaths.add(prefix); |
aec722d1b538
8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents:
44573
diff
changeset
|
1568 |
} |
36526 | 1569 |
} |
1570 |
} |
|
1571 |
||
44690
aec722d1b538
8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents:
44573
diff
changeset
|
1572 |
initModuleTable(map); |
aec722d1b538
8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents:
44573
diff
changeset
|
1573 |
paths = anySuffix ? null : noSuffixPaths; |
aec722d1b538
8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents:
44573
diff
changeset
|
1574 |
} |
aec722d1b538
8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents:
44573
diff
changeset
|
1575 |
|
aec722d1b538
8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents:
44573
diff
changeset
|
1576 |
private void initModuleTable(Map<String, List<Path>> map) { |
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1577 |
moduleTable = new ModuleTable(); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1578 |
map.forEach((modName, modPath) -> { |
44063
5f0cf4126949
8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents:
44021
diff
changeset
|
1579 |
boolean hasModuleInfo = modPath.stream().anyMatch(checkModuleInfo); |
5f0cf4126949
8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents:
44021
diff
changeset
|
1580 |
if (hasModuleInfo) { |
5f0cf4126949
8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents:
44021
diff
changeset
|
1581 |
String locnName = location.getName() + "[" + modName + "]"; |
5f0cf4126949
8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents:
44021
diff
changeset
|
1582 |
ModuleLocationHandler l = new ModuleLocationHandler(this, locnName, modName, |
5f0cf4126949
8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents:
44021
diff
changeset
|
1583 |
modPath, false); |
5f0cf4126949
8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents:
44021
diff
changeset
|
1584 |
moduleTable.add(l); |
5f0cf4126949
8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents:
44021
diff
changeset
|
1585 |
} |
36526 | 1586 |
}); |
1587 |
} |
|
44063
5f0cf4126949
8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents:
44021
diff
changeset
|
1588 |
//where: |
5f0cf4126949
8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents:
44021
diff
changeset
|
1589 |
private final Predicate<Path> checkModuleInfo = |
5f0cf4126949
8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents:
44021
diff
changeset
|
1590 |
p -> Files.exists(p.resolve("module-info.java")); |
5f0cf4126949
8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents:
44021
diff
changeset
|
1591 |
|
36526 | 1592 |
|
1593 |
private boolean isSeparator(char ch) { |
|
1594 |
// allow both separators on Windows |
|
1595 |
return (ch == File.separatorChar) || (ch == '/'); |
|
1596 |
} |
|
1597 |
||
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1598 |
void add(Map<String, List<Path>> map, Path prefix, Path suffix) { |
36526 | 1599 |
if (!Files.isDirectory(prefix)) { |
1600 |
if (warn) { |
|
1601 |
String key = Files.exists(prefix) |
|
1602 |
? "dir.path.element.not.directory" |
|
1603 |
: "dir.path.element.not.found"; |
|
1604 |
log.warning(Lint.LintCategory.PATH, key, prefix); |
|
1605 |
} |
|
1606 |
return; |
|
1607 |
} |
|
1608 |
try (DirectoryStream<Path> stream = Files.newDirectoryStream(prefix, path -> Files.isDirectory(path))) { |
|
1609 |
for (Path entry: stream) { |
|
1610 |
Path path = (suffix == null) ? entry : entry.resolve(suffix); |
|
1611 |
if (Files.isDirectory(path)) { |
|
1612 |
String name = entry.getFileName().toString(); |
|
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1613 |
List<Path> paths = map.get(name); |
36526 | 1614 |
if (paths == null) |
1615 |
map.put(name, paths = new ArrayList<>()); |
|
1616 |
paths.add(path); |
|
1617 |
} |
|
1618 |
} |
|
1619 |
} catch (IOException e) { |
|
1620 |
// TODO? What to do? |
|
1621 |
System.err.println(e); |
|
1622 |
} |
|
1623 |
} |
|
1624 |
||
1625 |
private void expandBraces(String value, Collection<String> results) { |
|
1626 |
int depth = 0; |
|
1627 |
int start = -1; |
|
1628 |
String prefix = null; |
|
1629 |
String suffix = null; |
|
1630 |
for (int i = 0; i < value.length(); i++) { |
|
1631 |
switch (value.charAt(i)) { |
|
1632 |
case '{': |
|
1633 |
depth++; |
|
1634 |
if (depth == 1) { |
|
1635 |
prefix = value.substring(0, i); |
|
1636 |
suffix = value.substring(getMatchingBrace(value, i) + 1); |
|
1637 |
start = i + 1; |
|
1638 |
} |
|
1639 |
break; |
|
1640 |
||
1641 |
case ',': |
|
1642 |
if (depth == 1) { |
|
1643 |
String elem = value.substring(start, i); |
|
1644 |
expandBraces(prefix + elem + suffix, results); |
|
1645 |
start = i + 1; |
|
1646 |
} |
|
1647 |
break; |
|
1648 |
||
1649 |
case '}': |
|
1650 |
switch (depth) { |
|
1651 |
case 0: |
|
1652 |
throw new IllegalArgumentException("mismatched braces"); |
|
1653 |
||
1654 |
case 1: |
|
1655 |
String elem = value.substring(start, i); |
|
1656 |
expandBraces(prefix + elem + suffix, results); |
|
1657 |
return; |
|
1658 |
||
1659 |
default: |
|
1660 |
depth--; |
|
1661 |
} |
|
1662 |
break; |
|
1663 |
} |
|
1664 |
} |
|
1665 |
if (depth > 0) |
|
1666 |
throw new IllegalArgumentException("mismatched braces"); |
|
1667 |
results.add(value); |
|
1668 |
} |
|
1669 |
||
1670 |
int getMatchingBrace(String value, int offset) { |
|
1671 |
int depth = 1; |
|
1672 |
for (int i = offset + 1; i < value.length(); i++) { |
|
1673 |
switch (value.charAt(i)) { |
|
1674 |
case '{': |
|
1675 |
depth++; |
|
1676 |
break; |
|
1677 |
||
1678 |
case '}': |
|
1679 |
if (--depth == 0) |
|
1680 |
return i; |
|
1681 |
break; |
|
1682 |
} |
|
1683 |
} |
|
1684 |
throw new IllegalArgumentException("mismatched braces"); |
|
1685 |
} |
|
1686 |
||
1687 |
@Override |
|
1688 |
boolean isSet() { |
|
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1689 |
return (moduleTable != null); |
36526 | 1690 |
} |
1691 |
||
1692 |
@Override |
|
1693 |
Collection<Path> getPaths() { |
|
44690
aec722d1b538
8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents:
44573
diff
changeset
|
1694 |
if (paths == null) { |
aec722d1b538
8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents:
44573
diff
changeset
|
1695 |
// This may occur for a complex setting with --module-source-path option |
aec722d1b538
8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents:
44573
diff
changeset
|
1696 |
// i.e. one that cannot be represented by a simple series of paths. |
aec722d1b538
8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents:
44573
diff
changeset
|
1697 |
throw new IllegalStateException("paths not available"); |
aec722d1b538
8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents:
44573
diff
changeset
|
1698 |
} |
aec722d1b538
8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents:
44573
diff
changeset
|
1699 |
return paths; |
36526 | 1700 |
} |
1701 |
||
1702 |
@Override |
|
1703 |
void setPaths(Iterable<? extends Path> files) throws IOException { |
|
44690
aec722d1b538
8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents:
44573
diff
changeset
|
1704 |
Map<String, List<Path>> map = new LinkedHashMap<>(); |
aec722d1b538
8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents:
44573
diff
changeset
|
1705 |
List<Path> newPaths = new ArrayList<>(); |
aec722d1b538
8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents:
44573
diff
changeset
|
1706 |
for (Path file : files) { |
aec722d1b538
8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents:
44573
diff
changeset
|
1707 |
add(map, file, null); |
aec722d1b538
8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents:
44573
diff
changeset
|
1708 |
newPaths.add(file); |
aec722d1b538
8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents:
44573
diff
changeset
|
1709 |
} |
aec722d1b538
8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents:
44573
diff
changeset
|
1710 |
|
aec722d1b538
8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents:
44573
diff
changeset
|
1711 |
initModuleTable(map); |
47702
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
1712 |
explicit = true; |
44690
aec722d1b538
8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents:
44573
diff
changeset
|
1713 |
paths = Collections.unmodifiableList(newPaths); |
36526 | 1714 |
} |
1715 |
||
1716 |
@Override |
|
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1717 |
void setPathsForModule(String name, Iterable<? extends Path> paths) throws IOException { |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1718 |
List<Path> validPaths = checkPaths(paths); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1719 |
|
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1720 |
if (moduleTable == null) |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1721 |
moduleTable = new ModuleTable(); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1722 |
|
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1723 |
ModuleLocationHandler l = moduleTable.get(name); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1724 |
if (l == null) { |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1725 |
l = new ModuleLocationHandler(this, |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1726 |
location.getName() + "[" + name + "]", |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1727 |
name, |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1728 |
validPaths, |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1729 |
true); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1730 |
moduleTable.add(l); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1731 |
} else { |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1732 |
l.searchPath = validPaths; |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1733 |
moduleTable.updatePaths(l); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1734 |
} |
47702
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
1735 |
explicit = true; |
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1736 |
} |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1737 |
|
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1738 |
private List<Path> checkPaths(Iterable<? extends Path> paths) throws IOException { |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1739 |
Objects.requireNonNull(paths); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1740 |
List<Path> validPaths = new ArrayList<>(); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1741 |
for (Path p : paths) { |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1742 |
validPaths.add(checkDirectory(p)); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1743 |
} |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1744 |
return validPaths; |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1745 |
} |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1746 |
|
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1747 |
@Override |
42261
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41861
diff
changeset
|
1748 |
Location getLocationForModule(String name) { |
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1749 |
return (moduleTable == null) ? null : moduleTable.get(name); |
36526 | 1750 |
} |
1751 |
||
1752 |
@Override |
|
44063
5f0cf4126949
8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents:
44021
diff
changeset
|
1753 |
Location getLocationForModule(Path file) { |
5f0cf4126949
8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents:
44021
diff
changeset
|
1754 |
return (moduleTable == null) ? null : moduleTable.get(file); |
36526 | 1755 |
} |
1756 |
||
1757 |
@Override |
|
42261
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41861
diff
changeset
|
1758 |
Iterable<Set<Location>> listLocationsForModules() { |
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1759 |
if (moduleTable == null) |
36526 | 1760 |
return Collections.emptySet(); |
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1761 |
|
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1762 |
return Collections.singleton(moduleTable.locations()); |
36526 | 1763 |
} |
1764 |
||
44822 | 1765 |
@Override |
1766 |
boolean contains(Path file) throws IOException { |
|
1767 |
return (moduleTable == null) ? false : moduleTable.contains(file); |
|
1768 |
} |
|
1769 |
||
36526 | 1770 |
} |
1771 |
||
1772 |
private class SystemModulesLocationHandler extends BasicLocationHandler { |
|
37944
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
1773 |
private Path systemJavaHome; |
36526 | 1774 |
private Path modules; |
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1775 |
private ModuleTable moduleTable; |
36526 | 1776 |
|
1777 |
SystemModulesLocationHandler() { |
|
1778 |
super(StandardLocation.SYSTEM_MODULES, Option.SYSTEM); |
|
37944
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
1779 |
systemJavaHome = Locations.javaHome; |
36526 | 1780 |
} |
1781 |
||
1782 |
@Override |
|
1783 |
boolean handleOption(Option option, String value) { |
|
1784 |
if (!options.contains(option)) { |
|
1785 |
return false; |
|
1786 |
} |
|
1787 |
||
47702
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
1788 |
explicit = true; |
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
1789 |
|
36526 | 1790 |
if (value == null) { |
37944
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
1791 |
systemJavaHome = Locations.javaHome; |
36526 | 1792 |
} else if (value.equals("none")) { |
37944
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
1793 |
systemJavaHome = null; |
36526 | 1794 |
} else { |
37944
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
1795 |
update(getPath(value)); |
36526 | 1796 |
} |
1797 |
||
1798 |
modules = null; |
|
1799 |
return true; |
|
1800 |
} |
|
1801 |
||
1802 |
@Override |
|
1803 |
Collection<Path> getPaths() { |
|
37944
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
1804 |
return (systemJavaHome == null) ? null : Collections.singleton(systemJavaHome); |
36526 | 1805 |
} |
1806 |
||
1807 |
@Override |
|
1808 |
void setPaths(Iterable<? extends Path> files) throws IOException { |
|
1809 |
if (files == null) { |
|
37944
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
1810 |
systemJavaHome = null; |
36526 | 1811 |
} else { |
47702
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
1812 |
explicit = true; |
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
1813 |
|
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1814 |
Path dir = checkSingletonDirectory(files); |
36526 | 1815 |
update(dir); |
1816 |
} |
|
1817 |
} |
|
1818 |
||
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1819 |
@Override |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1820 |
void setPathsForModule(String name, Iterable<? extends Path> paths) throws IOException { |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1821 |
List<Path> checkedPaths = checkPaths(paths); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1822 |
initSystemModules(); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1823 |
ModuleLocationHandler l = moduleTable.get(name); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1824 |
if (l == null) { |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1825 |
l = new ModuleLocationHandler(this, |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1826 |
location.getName() + "[" + name + "]", |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1827 |
name, |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1828 |
checkedPaths, |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1829 |
true); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1830 |
moduleTable.add(l); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1831 |
} else { |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1832 |
l.searchPath = checkedPaths; |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1833 |
moduleTable.updatePaths(l); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1834 |
} |
47702
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
1835 |
explicit = true; |
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1836 |
} |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1837 |
|
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1838 |
private List<Path> checkPaths(Iterable<? extends Path> paths) throws IOException { |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1839 |
Objects.requireNonNull(paths); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1840 |
List<Path> validPaths = new ArrayList<>(); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1841 |
for (Path p : paths) { |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1842 |
validPaths.add(checkDirectory(p)); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1843 |
} |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1844 |
return validPaths; |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1845 |
} |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1846 |
|
36526 | 1847 |
private void update(Path p) { |
42404
c4a34c2a656c
8169816: Move src.zip and jrt-fs.jar under the lib directory
mchung
parents:
42261
diff
changeset
|
1848 |
if (!isCurrentPlatform(p) && !Files.exists(p.resolve("lib").resolve("jrt-fs.jar")) && |
c4a34c2a656c
8169816: Move src.zip and jrt-fs.jar under the lib directory
mchung
parents:
42261
diff
changeset
|
1849 |
!Files.exists(systemJavaHome.resolve("modules"))) |
36526 | 1850 |
throw new IllegalArgumentException(p.toString()); |
37944
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
1851 |
systemJavaHome = p; |
36526 | 1852 |
modules = null; |
1853 |
} |
|
1854 |
||
1855 |
private boolean isCurrentPlatform(Path p) { |
|
1856 |
try { |
|
37944
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
1857 |
return Files.isSameFile(p, Locations.javaHome); |
36526 | 1858 |
} catch (IOException ex) { |
1859 |
throw new IllegalArgumentException(p.toString(), ex); |
|
1860 |
} |
|
1861 |
} |
|
1862 |
||
1863 |
@Override |
|
42261
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41861
diff
changeset
|
1864 |
Location getLocationForModule(String name) throws IOException { |
36526 | 1865 |
initSystemModules(); |
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1866 |
return moduleTable.get(name); |
36526 | 1867 |
} |
1868 |
||
1869 |
@Override |
|
44063
5f0cf4126949
8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents:
44021
diff
changeset
|
1870 |
Location getLocationForModule(Path file) throws IOException { |
43772
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
1871 |
initSystemModules(); |
44063
5f0cf4126949
8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents:
44021
diff
changeset
|
1872 |
return moduleTable.get(file); |
43772
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
1873 |
} |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
1874 |
|
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
1875 |
@Override |
42261
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41861
diff
changeset
|
1876 |
Iterable<Set<Location>> listLocationsForModules() throws IOException { |
36526 | 1877 |
initSystemModules(); |
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1878 |
return Collections.singleton(moduleTable.locations()); |
36526 | 1879 |
} |
1880 |
||
44822 | 1881 |
@Override |
1882 |
boolean contains(Path file) throws IOException { |
|
1883 |
initSystemModules(); |
|
1884 |
return moduleTable.contains(file); |
|
1885 |
} |
|
1886 |
||
36526 | 1887 |
private void initSystemModules() throws IOException { |
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1888 |
if (moduleTable != null) |
36526 | 1889 |
return; |
1890 |
||
37944
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
1891 |
if (systemJavaHome == null) { |
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1892 |
moduleTable = new ModuleTable(); |
36526 | 1893 |
return; |
1894 |
} |
|
1895 |
||
1896 |
if (modules == null) { |
|
1897 |
try { |
|
1898 |
URI jrtURI = URI.create("jrt:/"); |
|
1899 |
FileSystem jrtfs; |
|
1900 |
||
37944
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
1901 |
if (isCurrentPlatform(systemJavaHome)) { |
36526 | 1902 |
jrtfs = FileSystems.getFileSystem(jrtURI); |
1903 |
} else { |
|
1904 |
try { |
|
1905 |
Map<String, String> attrMap = |
|
37944
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
1906 |
Collections.singletonMap("java.home", systemJavaHome.toString()); |
36526 | 1907 |
jrtfs = FileSystems.newFileSystem(jrtURI, attrMap); |
1908 |
} catch (ProviderNotFoundException ex) { |
|
37944
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
1909 |
URL javaHomeURL = systemJavaHome.resolve("jrt-fs.jar").toUri().toURL(); |
36526 | 1910 |
ClassLoader currentLoader = Locations.class.getClassLoader(); |
1911 |
URLClassLoader fsLoader = |
|
1912 |
new URLClassLoader(new URL[] {javaHomeURL}, currentLoader); |
|
1913 |
||
1914 |
jrtfs = FileSystems.newFileSystem(jrtURI, Collections.emptyMap(), fsLoader); |
|
1915 |
||
1916 |
closeables.add(fsLoader); |
|
1917 |
} |
|
1918 |
||
1919 |
closeables.add(jrtfs); |
|
1920 |
} |
|
1921 |
||
1922 |
modules = jrtfs.getPath("/modules"); |
|
1923 |
} catch (FileSystemNotFoundException | ProviderNotFoundException e) { |
|
37944
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
1924 |
modules = systemJavaHome.resolve("modules"); |
36526 | 1925 |
if (!Files.exists(modules)) |
1926 |
throw new IOException("can't find system classes", e); |
|
1927 |
} |
|
1928 |
} |
|
1929 |
||
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1930 |
moduleTable = new ModuleTable(); |
36526 | 1931 |
try (DirectoryStream<Path> stream = Files.newDirectoryStream(modules, Files::isDirectory)) { |
1932 |
for (Path entry : stream) { |
|
1933 |
String moduleName = entry.getFileName().toString(); |
|
1934 |
String name = location.getName() + "[" + moduleName + "]"; |
|
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1935 |
ModuleLocationHandler h = new ModuleLocationHandler(this, |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1936 |
name, moduleName, Collections.singletonList(entry), false); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1937 |
moduleTable.add(h); |
36526 | 1938 |
} |
1939 |
} |
|
1940 |
} |
|
1941 |
} |
|
1942 |
||
43772
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
1943 |
private class PatchModulesLocationHandler extends BasicLocationHandler { |
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1944 |
private final ModuleTable moduleTable = new ModuleTable(); |
43772
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
1945 |
|
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
1946 |
PatchModulesLocationHandler() { |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
1947 |
super(StandardLocation.PATCH_MODULE_PATH, Option.PATCH_MODULE); |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
1948 |
} |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
1949 |
|
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
1950 |
@Override |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
1951 |
boolean handleOption(Option option, String value) { |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
1952 |
if (!options.contains(option)) { |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
1953 |
return false; |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
1954 |
} |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
1955 |
|
47702
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
1956 |
explicit = true; |
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
1957 |
|
44063
5f0cf4126949
8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents:
44021
diff
changeset
|
1958 |
moduleTable.clear(); |
5f0cf4126949
8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents:
44021
diff
changeset
|
1959 |
|
43772
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
1960 |
// Allow an extended syntax for --patch-module consisting of a series |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
1961 |
// of values separated by NULL characters. This is to facilitate |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
1962 |
// supporting deferred file manager options on the command line. |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
1963 |
// See Option.PATCH_MODULE for the code that composes these multiple |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
1964 |
// values. |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
1965 |
for (String v : value.split("\0")) { |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
1966 |
int eq = v.indexOf('='); |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
1967 |
if (eq > 0) { |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
1968 |
String moduleName = v.substring(0, eq); |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
1969 |
SearchPath mPatchPath = new SearchPath() |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
1970 |
.addFiles(v.substring(eq + 1)); |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
1971 |
String name = location.getName() + "[" + moduleName + "]"; |
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1972 |
ModuleLocationHandler h = new ModuleLocationHandler(this, name, |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1973 |
moduleName, mPatchPath, false); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1974 |
moduleTable.add(h); |
43772
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
1975 |
} else { |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
1976 |
// Should not be able to get here; |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
1977 |
// this should be caught and handled in Option.PATCH_MODULE |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
1978 |
log.error(Errors.LocnInvalidArgForXpatch(value)); |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
1979 |
} |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
1980 |
} |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
1981 |
|
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
1982 |
return true; |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
1983 |
} |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
1984 |
|
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
1985 |
@Override |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
1986 |
boolean isSet() { |
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
1987 |
return !moduleTable.isEmpty(); |
43772
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
1988 |
} |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
1989 |
|
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
1990 |
@Override |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
1991 |
Collection<Path> getPaths() { |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
1992 |
throw new UnsupportedOperationException(); |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
1993 |
} |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
1994 |
|
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
1995 |
@Override |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
1996 |
void setPaths(Iterable<? extends Path> files) throws IOException { |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
1997 |
throw new UnsupportedOperationException(); |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
1998 |
} |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
1999 |
|
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
2000 |
@Override // defined by LocationHandler |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
2001 |
void setPathsForModule(String moduleName, Iterable<? extends Path> files) throws IOException { |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
2002 |
throw new UnsupportedOperationException(); // not yet |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
2003 |
} |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
2004 |
|
43772
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
2005 |
@Override |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
2006 |
Location getLocationForModule(String name) throws IOException { |
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
2007 |
return moduleTable.get(name); |
43772
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
2008 |
} |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
2009 |
|
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
2010 |
@Override |
44063
5f0cf4126949
8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents:
44021
diff
changeset
|
2011 |
Location getLocationForModule(Path file) throws IOException { |
5f0cf4126949
8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents:
44021
diff
changeset
|
2012 |
return moduleTable.get(file); |
43772
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
2013 |
} |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
2014 |
|
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
2015 |
@Override |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
2016 |
Iterable<Set<Location>> listLocationsForModules() throws IOException { |
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
2017 |
return Collections.singleton(moduleTable.locations()); |
43772
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
2018 |
} |
44822 | 2019 |
|
2020 |
@Override |
|
2021 |
boolean contains(Path file) throws IOException { |
|
2022 |
return moduleTable.contains(file); |
|
2023 |
} |
|
43772
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
2024 |
} |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
2025 |
|
10818 | 2026 |
Map<Location, LocationHandler> handlersForLocation; |
11314 | 2027 |
Map<Option, LocationHandler> handlersForOption; |
10818 | 2028 |
|
2029 |
void initHandlers() { |
|
22163 | 2030 |
handlersForLocation = new HashMap<>(); |
2031 |
handlersForOption = new EnumMap<>(Option.class); |
|
10818 | 2032 |
|
36526 | 2033 |
BasicLocationHandler[] handlers = { |
10818 | 2034 |
new BootClassPathLocationHandler(), |
2035 |
new ClassPathLocationHandler(), |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40302
diff
changeset
|
2036 |
new SimpleLocationHandler(StandardLocation.SOURCE_PATH, Option.SOURCE_PATH), |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40302
diff
changeset
|
2037 |
new SimpleLocationHandler(StandardLocation.ANNOTATION_PROCESSOR_PATH, Option.PROCESSOR_PATH), |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40302
diff
changeset
|
2038 |
new SimpleLocationHandler(StandardLocation.ANNOTATION_PROCESSOR_MODULE_PATH, Option.PROCESSOR_MODULE_PATH), |
36526 | 2039 |
new OutputLocationHandler(StandardLocation.CLASS_OUTPUT, Option.D), |
2040 |
new OutputLocationHandler(StandardLocation.SOURCE_OUTPUT, Option.S), |
|
2041 |
new OutputLocationHandler(StandardLocation.NATIVE_HEADER_OUTPUT, Option.H), |
|
2042 |
new ModuleSourcePathLocationHandler(), |
|
43772
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
2043 |
new PatchModulesLocationHandler(), |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40302
diff
changeset
|
2044 |
new ModulePathLocationHandler(StandardLocation.UPGRADE_MODULE_PATH, Option.UPGRADE_MODULE_PATH), |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40302
diff
changeset
|
2045 |
new ModulePathLocationHandler(StandardLocation.MODULE_PATH, Option.MODULE_PATH), |
36526 | 2046 |
new SystemModulesLocationHandler(), |
10818 | 2047 |
}; |
10 | 2048 |
|
36526 | 2049 |
for (BasicLocationHandler h : handlers) { |
10818 | 2050 |
handlersForLocation.put(h.location, h); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
2051 |
for (Option o : h.options) { |
10818 | 2052 |
handlersForOption.put(o, h); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
2053 |
} |
10 | 2054 |
} |
10818 | 2055 |
} |
2056 |
||
29780
8f8e54a1fa20
8076420: Consolidate javac file handling in javac.file package
jjg
parents:
29291
diff
changeset
|
2057 |
boolean handleOption(Option option, String value) { |
43772
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
2058 |
LocationHandler h = handlersForOption.get(option); |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43771
diff
changeset
|
2059 |
return (h == null ? false : h.handleOption(option, value)); |
36526 | 2060 |
} |
2061 |
||
2062 |
boolean hasLocation(Location location) { |
|
2063 |
LocationHandler h = getHandler(location); |
|
2064 |
return (h == null ? false : h.isSet()); |
|
10818 | 2065 |
} |
2066 |
||
47702
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
2067 |
boolean hasExplicitLocation(Location location) { |
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
2068 |
LocationHandler h = getHandler(location); |
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
2069 |
return (h == null ? false : h.isExplicit()); |
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
2070 |
} |
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
2071 |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
2072 |
Collection<Path> getLocation(Location location) { |
10818 | 2073 |
LocationHandler h = getHandler(location); |
36526 | 2074 |
return (h == null ? null : h.getPaths()); |
10 | 2075 |
} |
2076 |
||
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
2077 |
Path getOutputLocation(Location location) { |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
2078 |
if (!location.isOutputLocation()) { |
10818 | 2079 |
throw new IllegalArgumentException(); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
2080 |
} |
10818 | 2081 |
LocationHandler h = getHandler(location); |
2082 |
return ((OutputLocationHandler) h).outputDir; |
|
2083 |
} |
|
10 | 2084 |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
2085 |
void setLocation(Location location, Iterable<? extends Path> files) throws IOException { |
10818 | 2086 |
LocationHandler h = getHandler(location); |
2087 |
if (h == null) { |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
2088 |
if (location.isOutputLocation()) { |
10818 | 2089 |
h = new OutputLocationHandler(location); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
2090 |
} else { |
10818 | 2091 |
h = new SimpleLocationHandler(location); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
2092 |
} |
10818 | 2093 |
handlersForLocation.put(location, h); |
2094 |
} |
|
36526 | 2095 |
h.setPaths(files); |
2096 |
} |
|
2097 |
||
42261
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41861
diff
changeset
|
2098 |
Location getLocationForModule(Location location, String name) throws IOException { |
36526 | 2099 |
LocationHandler h = getHandler(location); |
42261
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41861
diff
changeset
|
2100 |
return (h == null ? null : h.getLocationForModule(name)); |
36526 | 2101 |
} |
2102 |
||
44063
5f0cf4126949
8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents:
44021
diff
changeset
|
2103 |
Location getLocationForModule(Location location, Path file) throws IOException { |
36526 | 2104 |
LocationHandler h = getHandler(location); |
44063
5f0cf4126949
8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents:
44021
diff
changeset
|
2105 |
return (h == null ? null : h.getLocationForModule(file)); |
36526 | 2106 |
} |
2107 |
||
44019
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
2108 |
void setLocationForModule(Location location, String moduleName, |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
2109 |
Iterable<? extends Path> files) throws IOException { |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
2110 |
LocationHandler h = getHandler(location); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
2111 |
if (h == null) { |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
2112 |
if (location.isOutputLocation()) { |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
2113 |
h = new OutputLocationHandler(location); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
2114 |
} else { |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
2115 |
h = new ModulePathLocationHandler(location); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
2116 |
} |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
2117 |
handlersForLocation.put(location, h); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
2118 |
} |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
2119 |
h.setPathsForModule(moduleName, files); |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
2120 |
} |
284fa2ebd030
8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
43772
diff
changeset
|
2121 |
|
36526 | 2122 |
String inferModuleName(Location location) { |
2123 |
LocationHandler h = getHandler(location); |
|
2124 |
return (h == null ? null : h.inferModuleName()); |
|
2125 |
} |
|
2126 |
||
42261
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41861
diff
changeset
|
2127 |
Iterable<Set<Location>> listLocationsForModules(Location location) throws IOException { |
36526 | 2128 |
LocationHandler h = getHandler(location); |
42261
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41861
diff
changeset
|
2129 |
return (h == null ? null : h.listLocationsForModules()); |
10818 | 2130 |
} |
2131 |
||
44822 | 2132 |
boolean contains(Location location, Path file) throws IOException { |
2133 |
LocationHandler h = getHandler(location); |
|
2134 |
if (h == null) |
|
2135 |
throw new IllegalArgumentException("unknown location"); |
|
2136 |
return h.contains(file); |
|
2137 |
} |
|
2138 |
||
10818 | 2139 |
protected LocationHandler getHandler(Location location) { |
29291
076c277565f7
8073550: java* tools: replace obj.getClass hacks with Assert.checkNonNull or Objects.requireNonNull
mcimadamore
parents:
29053
diff
changeset
|
2140 |
Objects.requireNonNull(location); |
36526 | 2141 |
return (location instanceof LocationHandler) |
2142 |
? (LocationHandler) location |
|
2143 |
: handlersForLocation.get(location); |
|
10818 | 2144 |
} |
2145 |
||
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
2146 |
/** |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
2147 |
* Is this the name of an archive file? |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
2148 |
*/ |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
2149 |
private boolean isArchive(Path file) { |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
2150 |
String n = StringUtils.toLowerCase(file.getFileName().toString()); |
1208 | 2151 |
return fsInfo.isFile(file) |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
2152 |
&& (n.endsWith(".jar") || n.endsWith(".zip")); |
10 | 2153 |
} |
4937
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
2154 |
|
36526 | 2155 |
static Path normalize(Path p) { |
2156 |
try { |
|
2157 |
return p.toRealPath(); |
|
2158 |
} catch (IOException e) { |
|
2159 |
return p.toAbsolutePath().normalize(); |
|
2160 |
} |
|
2161 |
} |
|
10 | 2162 |
} |