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