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