author | jjg |
Fri, 02 Dec 2016 14:15:43 -0800 | |
changeset 42414 | 0ae183c295a0 |
parent 42408 | d6f09ae68eab |
child 42814 | 058fc03646d9 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
36526 | 2 |
* Copyright (c) 2003, 2016, 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; |
27579 | 32 |
import java.io.UncheckedIOException; |
36526 | 33 |
import java.net.URI; |
4937
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
34 |
import java.net.URL; |
36526 | 35 |
import java.net.URLClassLoader; |
36 |
import java.nio.file.DirectoryIteratorException; |
|
37 |
import java.nio.file.DirectoryStream; |
|
38 |
import java.nio.file.FileSystem; |
|
39 |
import java.nio.file.FileSystemNotFoundException; |
|
40 |
import java.nio.file.FileSystems; |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
41 |
import java.nio.file.Files; |
41861
8c58faf4f03b
8132562: javac fails with CLASSPATH with double-quotes as an environment variable
vromero
parents:
41637
diff
changeset
|
42 |
import java.nio.file.InvalidPathException; |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
43 |
import java.nio.file.Path; |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
44 |
import java.nio.file.Paths; |
36526 | 45 |
import java.nio.file.ProviderNotFoundException; |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
46 |
import java.util.ArrayList; |
10818 | 47 |
import java.util.Arrays; |
48 |
import java.util.Collection; |
|
49 |
import java.util.Collections; |
|
50 |
import java.util.EnumMap; |
|
51 |
import java.util.EnumSet; |
|
10 | 52 |
import java.util.HashMap; |
53 |
import java.util.HashSet; |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
54 |
import java.util.Iterator; |
36526 | 55 |
import java.util.LinkedHashMap; |
10818 | 56 |
import java.util.LinkedHashSet; |
36526 | 57 |
import java.util.List; |
10 | 58 |
import java.util.Map; |
29291
076c277565f7
8073550: java* tools: replace obj.getClass hacks with Assert.checkNonNull or Objects.requireNonNull
mcimadamore
parents:
29053
diff
changeset
|
59 |
import java.util.Objects; |
36526 | 60 |
import java.util.NoSuchElementException; |
10 | 61 |
import java.util.Set; |
36526 | 62 |
import java.util.regex.Matcher; |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
63 |
import java.util.regex.Pattern; |
27579 | 64 |
import java.util.stream.Collectors; |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
65 |
import java.util.stream.Stream; |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
66 |
|
36526 | 67 |
import javax.lang.model.SourceVersion; |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
68 |
import javax.tools.JavaFileManager; |
10 | 69 |
import javax.tools.JavaFileManager.Location; |
41861
8c58faf4f03b
8132562: javac fails with CLASSPATH with double-quotes as an environment variable
vromero
parents:
41637
diff
changeset
|
70 |
import javax.tools.JavaFileObject; |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
71 |
import javax.tools.StandardJavaFileManager; |
37944
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
72 |
import javax.tools.StandardJavaFileManager.PathFactory; |
10818 | 73 |
import javax.tools.StandardLocation; |
10 | 74 |
|
731
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
171
diff
changeset
|
75 |
import com.sun.tools.javac.code.Lint; |
11314 | 76 |
import com.sun.tools.javac.main.Option; |
36526 | 77 |
import com.sun.tools.javac.resources.CompilerProperties.Errors; |
78 |
import com.sun.tools.javac.resources.CompilerProperties.Warnings; |
|
37848
3c8ff4204d2d
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36526
diff
changeset
|
79 |
import com.sun.tools.javac.util.DefinedBy; |
3c8ff4204d2d
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36526
diff
changeset
|
80 |
import com.sun.tools.javac.util.DefinedBy.Api; |
41440 | 81 |
import com.sun.tools.javac.util.JDK9Wrappers; |
1486 | 82 |
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
|
83 |
import com.sun.tools.javac.util.Log; |
41254
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
41155
diff
changeset
|
84 |
import com.sun.tools.javac.jvm.ModuleNameReader; |
36526 | 85 |
import com.sun.tools.javac.util.Pair; |
22153
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
14360
diff
changeset
|
86 |
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
|
87 |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
88 |
import static javax.tools.StandardLocation.PLATFORM_CLASS_PATH; |
10 | 89 |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40302
diff
changeset
|
90 |
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
|
91 |
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
|
92 |
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
|
93 |
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
|
94 |
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
|
95 |
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
|
96 |
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
|
97 |
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
|
98 |
|
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
99 |
/** |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
100 |
* 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
|
101 |
* 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
|
102 |
* path (in {@code Collection<String>} form). |
10 | 103 |
* |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
104 |
* <p> |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
105 |
* <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
|
106 |
* 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
|
107 |
* notice.</b> |
10 | 108 |
*/ |
10818 | 109 |
public class Locations { |
10 | 110 |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
111 |
/** |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
112 |
* The log to use for warning output |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
113 |
*/ |
10 | 114 |
private Log log; |
115 |
||
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
116 |
/** |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
117 |
* Access to (possibly cached) file info |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
118 |
*/ |
1208 | 119 |
private FSInfo fsInfo; |
10 | 120 |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
121 |
/** |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
122 |
* Whether to warn about non-existent path elements |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
123 |
*/ |
10818 | 124 |
private boolean warn; |
125 |
||
36526 | 126 |
private ModuleNameReader moduleNameReader; |
127 |
||
37944
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
128 |
private PathFactory pathFactory = Paths::get; |
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
129 |
|
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
130 |
static final Path javaHome = FileSystems.getDefault().getPath(System.getProperty("java.home")); |
36526 | 131 |
static final Path thisSystemModules = javaHome.resolve("lib").resolve("modules"); |
132 |
||
133 |
Map<Path, FileSystem> fileSystems = new LinkedHashMap<>(); |
|
134 |
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
|
135 |
private Map<String,String> fsEnv = Collections.emptyMap(); |
27579 | 136 |
|
29780
8f8e54a1fa20
8076420: Consolidate javac file handling in javac.file package
jjg
parents:
29291
diff
changeset
|
137 |
Locations() { |
10818 | 138 |
initHandlers(); |
10 | 139 |
} |
140 |
||
37944
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
141 |
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
|
142 |
try { |
8c58faf4f03b
8132562: javac fails with CLASSPATH with double-quotes as an environment variable
vromero
parents:
41637
diff
changeset
|
143 |
return pathFactory.getPath(first, more); |
8c58faf4f03b
8132562: javac fails with CLASSPATH with double-quotes as an environment variable
vromero
parents:
41637
diff
changeset
|
144 |
} catch (InvalidPathException ipe) { |
8c58faf4f03b
8132562: javac fails with CLASSPATH with double-quotes as an environment variable
vromero
parents:
41637
diff
changeset
|
145 |
throw new IllegalArgumentException(ipe); |
8c58faf4f03b
8132562: javac fails with CLASSPATH with double-quotes as an environment variable
vromero
parents:
41637
diff
changeset
|
146 |
} |
37944
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
147 |
} |
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
148 |
|
36526 | 149 |
public void close() throws IOException { |
150 |
ListBuffer<IOException> list = new ListBuffer<>(); |
|
151 |
closeables.forEach(closeable -> { |
|
152 |
try { |
|
153 |
closeable.close(); |
|
154 |
} catch (IOException ex) { |
|
155 |
list.add(ex); |
|
156 |
} |
|
157 |
}); |
|
158 |
if (list.nonEmpty()) { |
|
159 |
IOException ex = new IOException(); |
|
160 |
for (IOException e: list) |
|
161 |
ex.addSuppressed(e); |
|
162 |
throw ex; |
|
163 |
} |
|
164 |
} |
|
165 |
||
41637 | 166 |
void update(Log log, boolean warn, FSInfo fsInfo) { |
10813
95b39a692cd0
7101146: Paths should more directly managed by BaseFileManager
jjg
parents:
8424
diff
changeset
|
167 |
this.log = log; |
41637 | 168 |
this.warn = warn; |
10813
95b39a692cd0
7101146: Paths should more directly managed by BaseFileManager
jjg
parents:
8424
diff
changeset
|
169 |
this.fsInfo = fsInfo; |
10 | 170 |
} |
171 |
||
37944
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
172 |
void setPathFactory(PathFactory f) { |
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
173 |
pathFactory = f; |
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
174 |
} |
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
175 |
|
29780
8f8e54a1fa20
8076420: Consolidate javac file handling in javac.file package
jjg
parents:
29291
diff
changeset
|
176 |
boolean isDefaultBootClassPath() { |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
177 |
BootClassPathLocationHandler h |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
178 |
= (BootClassPathLocationHandler) getHandler(PLATFORM_CLASS_PATH); |
10818 | 179 |
return h.isDefault(); |
10 | 180 |
} |
181 |
||
1486 | 182 |
/** |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
183 |
* 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
|
184 |
* |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
185 |
* @param searchPath The search path to be split |
1486 | 186 |
* @return The elements of the path |
187 |
*/ |
|
37944
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
188 |
private Iterable<Path> getPathEntries(String searchPath) { |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
189 |
return getPathEntries(searchPath, null); |
1486 | 190 |
} |
10 | 191 |
|
1486 | 192 |
/** |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
193 |
* 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
|
194 |
* 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
|
195 |
* emptyPathDefault. |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
196 |
* |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
197 |
* @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
|
198 |
* @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
|
199 |
* empty path elements |
1486 | 200 |
* @return The elements of the path |
201 |
*/ |
|
37944
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
202 |
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
|
203 |
ListBuffer<Path> entries = new ListBuffer<>(); |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
204 |
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
|
205 |
if (s.isEmpty()) { |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
206 |
if (emptyPathDefault != null) { |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
207 |
entries.add(emptyPathDefault); |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
208 |
} |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
209 |
} else { |
37944
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
210 |
entries.add(getPath(s)); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
211 |
} |
10 | 212 |
} |
1486 | 213 |
return entries; |
10 | 214 |
} |
215 |
||
41155
93dad90c22c1
8156568: Update javac to support compiling against a modular JAR that is a multi-release JAR
sadayapalam
parents:
40762
diff
changeset
|
216 |
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
|
217 |
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
|
218 |
} |
93dad90c22c1
8156568: Update javac to support compiling against a modular JAR that is a multi-release JAR
sadayapalam
parents:
40762
diff
changeset
|
219 |
|
10818 | 220 |
/** |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
221 |
* 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
|
222 |
* can be expanded. |
10818 | 223 |
*/ |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
224 |
private class SearchPath extends LinkedHashSet<Path> { |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
225 |
|
10 | 226 |
private static final long serialVersionUID = 0; |
227 |
||
228 |
private boolean expandJarClassPaths = false; |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
229 |
private final Set<Path> canonicalValues = new HashSet<>(); |
10 | 230 |
|
27118
3c8314271af7
8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents:
25874
diff
changeset
|
231 |
public SearchPath expandJarClassPaths(boolean x) { |
10 | 232 |
expandJarClassPaths = x; |
233 |
return this; |
|
234 |
} |
|
235 |
||
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
236 |
/** |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
237 |
* 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
|
238 |
*/ |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
239 |
private Path emptyPathDefault = null; |
10 | 240 |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
241 |
public SearchPath emptyPathDefault(Path x) { |
10 | 242 |
emptyPathDefault = x; |
243 |
return this; |
|
244 |
} |
|
245 |
||
27118
3c8314271af7
8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents:
25874
diff
changeset
|
246 |
public SearchPath addDirectories(String dirs, boolean warn) { |
8424
5e31b2eb5aa3
6485027: javac incorrectly handles relative paths in manifest classpath
jjg
parents:
8034
diff
changeset
|
247 |
boolean prev = expandJarClassPaths; |
5e31b2eb5aa3
6485027: javac incorrectly handles relative paths in manifest classpath
jjg
parents:
8034
diff
changeset
|
248 |
expandJarClassPaths = true; |
5e31b2eb5aa3
6485027: javac incorrectly handles relative paths in manifest classpath
jjg
parents:
8034
diff
changeset
|
249 |
try { |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
250 |
if (dirs != null) { |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
251 |
for (Path dir : getPathEntries(dirs)) { |
8424
5e31b2eb5aa3
6485027: javac incorrectly handles relative paths in manifest classpath
jjg
parents:
8034
diff
changeset
|
252 |
addDirectory(dir, warn); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
253 |
} |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
254 |
} |
8424
5e31b2eb5aa3
6485027: javac incorrectly handles relative paths in manifest classpath
jjg
parents:
8034
diff
changeset
|
255 |
return this; |
5e31b2eb5aa3
6485027: javac incorrectly handles relative paths in manifest classpath
jjg
parents:
8034
diff
changeset
|
256 |
} finally { |
5e31b2eb5aa3
6485027: javac incorrectly handles relative paths in manifest classpath
jjg
parents:
8034
diff
changeset
|
257 |
expandJarClassPaths = prev; |
5e31b2eb5aa3
6485027: javac incorrectly handles relative paths in manifest classpath
jjg
parents:
8034
diff
changeset
|
258 |
} |
10 | 259 |
} |
260 |
||
27118
3c8314271af7
8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents:
25874
diff
changeset
|
261 |
public SearchPath addDirectories(String dirs) { |
10 | 262 |
return addDirectories(dirs, warn); |
263 |
} |
|
264 |
||
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
265 |
private void addDirectory(Path dir, boolean warn) { |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
266 |
if (!Files.isDirectory(dir)) { |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
267 |
if (warn) { |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
268 |
log.warning(Lint.LintCategory.PATH, |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
269 |
"dir.path.element.not.found", dir); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
270 |
} |
10 | 271 |
return; |
272 |
} |
|
273 |
||
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
274 |
try (Stream<Path> s = Files.list(dir)) { |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
275 |
s.filter(dirEntry -> isArchive(dirEntry)) |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
276 |
.forEach(dirEntry -> addFile(dirEntry, warn)); |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
277 |
} catch (IOException ignore) { |
10 | 278 |
} |
279 |
} |
|
280 |
||
27118
3c8314271af7
8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents:
25874
diff
changeset
|
281 |
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
|
282 |
if (files != null) { |
10818 | 283 |
addFiles(getPathEntries(files, emptyPathDefault), warn); |
284 |
} |
|
285 |
return this; |
|
286 |
} |
|
287 |
||
27118
3c8314271af7
8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents:
25874
diff
changeset
|
288 |
public SearchPath addFiles(String files) { |
10818 | 289 |
return addFiles(files, warn); |
290 |
} |
|
291 |
||
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
292 |
public SearchPath addFiles(Iterable<? extends Path> files, boolean warn) { |
10818 | 293 |
if (files != null) { |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
294 |
for (Path file : files) { |
10 | 295 |
addFile(file, warn); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
296 |
} |
7335
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
6151
diff
changeset
|
297 |
} |
10 | 298 |
return this; |
299 |
} |
|
300 |
||
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
301 |
public SearchPath addFiles(Iterable<? extends Path> files) { |
10 | 302 |
return addFiles(files, warn); |
303 |
} |
|
304 |
||
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
305 |
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
|
306 |
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
|
307 |
// discard duplicates |
10 | 308 |
return; |
309 |
} |
|
310 |
||
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
311 |
if (!fsInfo.exists(file)) { |
10 | 312 |
/* No such file or directory exists */ |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
313 |
if (warn) { |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
314 |
log.warning(Lint.LintCategory.PATH, |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
315 |
"path.element.not.found", file); |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
316 |
} |
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7336
diff
changeset
|
317 |
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
|
318 |
return; |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7336
diff
changeset
|
319 |
} |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7336
diff
changeset
|
320 |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
321 |
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
|
322 |
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
|
323 |
/* 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
|
324 |
return; |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7336
diff
changeset
|
325 |
} |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7336
diff
changeset
|
326 |
|
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7336
diff
changeset
|
327 |
if (fsInfo.isFile(file)) { |
10 | 328 |
/* File is an ordinary file. */ |
40513
39b67170b045
8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
40308
diff
changeset
|
329 |
if ( !file.getFileName().toString().endsWith(".jmod") |
39b67170b045
8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
40308
diff
changeset
|
330 |
&& !file.endsWith("modules")) { |
39b67170b045
8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
40308
diff
changeset
|
331 |
if (!isArchive(file)) { |
39b67170b045
8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
40308
diff
changeset
|
332 |
/* 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
|
333 |
it looks like a valid zip file. */ |
39b67170b045
8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
40308
diff
changeset
|
334 |
try { |
39b67170b045
8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
40308
diff
changeset
|
335 |
FileSystems.newFileSystem(file, null).close(); |
39b67170b045
8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
40308
diff
changeset
|
336 |
if (warn) { |
39b67170b045
8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
40308
diff
changeset
|
337 |
log.warning(Lint.LintCategory.PATH, |
39b67170b045
8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
40308
diff
changeset
|
338 |
"unexpected.archive.file", file); |
39b67170b045
8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
40308
diff
changeset
|
339 |
} |
39b67170b045
8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
40308
diff
changeset
|
340 |
} catch (IOException | ProviderNotFoundException e) { |
39b67170b045
8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
40308
diff
changeset
|
341 |
// FIXME: include e.getLocalizedMessage in warning |
39b67170b045
8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
40308
diff
changeset
|
342 |
if (warn) { |
39b67170b045
8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
40308
diff
changeset
|
343 |
log.warning(Lint.LintCategory.PATH, |
39b67170b045
8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
40308
diff
changeset
|
344 |
"invalid.archive.file", file); |
39b67170b045
8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
40308
diff
changeset
|
345 |
} |
39b67170b045
8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
40308
diff
changeset
|
346 |
return; |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
347 |
} |
40513
39b67170b045
8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
40308
diff
changeset
|
348 |
} else { |
39b67170b045
8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
40308
diff
changeset
|
349 |
if (fsInfo.getJarFSProvider() == null) { |
39b67170b045
8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
40308
diff
changeset
|
350 |
log.error(Errors.NoZipfsForArchive(file)); |
39b67170b045
8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
40308
diff
changeset
|
351 |
return ; |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
352 |
} |
10 | 353 |
} |
354 |
} |
|
355 |
} |
|
356 |
||
357 |
/* 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
|
358 |
conforming to archive naming convention */ |
10 | 359 |
super.add(file); |
1208 | 360 |
canonicalValues.add(canonFile); |
10 | 361 |
|
36526 | 362 |
if (expandJarClassPaths && fsInfo.isFile(file) && !file.endsWith("modules")) { |
10 | 363 |
addJarClassPath(file, warn); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
364 |
} |
10 | 365 |
} |
366 |
||
367 |
// Adds referenced classpath elements from a jar's Class-Path |
|
368 |
// Manifest entry. In some future release, we may want to |
|
369 |
// update this code to recognize URLs rather than simple |
|
370 |
// 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
|
371 |
private void addJarClassPath(Path jarFile, boolean warn) { |
10 | 372 |
try { |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
373 |
for (Path f : fsInfo.getJarClassPath(jarFile)) { |
1208 | 374 |
addFile(f, warn); |
10 | 375 |
} |
376 |
} catch (IOException e) { |
|
5007
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4937
diff
changeset
|
377 |
log.error("error.reading.file", jarFile, JavacFileManager.getMessage(e)); |
10 | 378 |
} |
379 |
} |
|
380 |
} |
|
381 |
||
10818 | 382 |
/** |
36526 | 383 |
* Base class for handling support for the representation of Locations. |
384 |
* |
|
385 |
* Locations are (by design) opaque handles that can easily be implemented |
|
386 |
* by enums like StandardLocation. Within JavacFileManager, each Location |
|
387 |
* has an associated LocationHandler, which provides much of the appropriate |
|
388 |
* functionality for the corresponding Location. |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
389 |
* |
10818 | 390 |
* @see #initHandlers |
391 |
* @see #getHandler |
|
392 |
*/ |
|
393 |
protected abstract class LocationHandler { |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
394 |
|
36526 | 395 |
/** |
396 |
* @see JavaFileManager#handleOption |
|
397 |
*/ |
|
398 |
abstract boolean handleOption(Option option, String value); |
|
399 |
||
400 |
/** |
|
401 |
* @see StandardJavaFileManager#hasLocation |
|
402 |
*/ |
|
403 |
boolean isSet() { |
|
404 |
return (getPaths() != null); |
|
405 |
} |
|
406 |
||
407 |
/** |
|
408 |
* @see StandardJavaFileManager#getLocation |
|
409 |
*/ |
|
410 |
abstract Collection<Path> getPaths(); |
|
411 |
||
412 |
/** |
|
413 |
* @see StandardJavaFileManager#setLocation |
|
414 |
*/ |
|
415 |
abstract void setPaths(Iterable<? extends Path> files) throws IOException; |
|
416 |
||
417 |
/** |
|
42261
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41861
diff
changeset
|
418 |
* @see JavaFileManager#getLocationForModule(Location, String) |
36526 | 419 |
*/ |
42261
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41861
diff
changeset
|
420 |
Location getLocationForModule(String moduleName) throws IOException { |
36526 | 421 |
return null; |
422 |
} |
|
423 |
||
424 |
/** |
|
42261
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41861
diff
changeset
|
425 |
* @see JavaFileManager#getLocationForModule(Location, JavaFileObject, String) |
36526 | 426 |
*/ |
42261
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41861
diff
changeset
|
427 |
Location getLocationForModule(Path dir) { |
36526 | 428 |
return null; |
429 |
} |
|
430 |
||
431 |
/** |
|
432 |
* @see JavaFileManager#inferModuleName |
|
433 |
*/ |
|
434 |
String inferModuleName() { |
|
435 |
return null; |
|
436 |
} |
|
437 |
||
438 |
/** |
|
42261
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41861
diff
changeset
|
439 |
* @see JavaFileManager#listLocationsForModules |
36526 | 440 |
*/ |
42261
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41861
diff
changeset
|
441 |
Iterable<Set<Location>> listLocationsForModules() throws IOException { |
36526 | 442 |
return null; |
443 |
} |
|
444 |
} |
|
445 |
||
446 |
/** |
|
447 |
* A LocationHandler for a given Location, and associated set of options. |
|
448 |
*/ |
|
449 |
private abstract class BasicLocationHandler extends LocationHandler { |
|
450 |
||
10818 | 451 |
final Location location; |
11314 | 452 |
final Set<Option> options; |
7335
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
6151
diff
changeset
|
453 |
|
10818 | 454 |
/** |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
455 |
* 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
|
456 |
* option to the corresponding handler. |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
457 |
* |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
458 |
* @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
|
459 |
* @param options the options affecting this location |
10818 | 460 |
* @see #initHandlers |
461 |
*/ |
|
36526 | 462 |
protected BasicLocationHandler(Location location, Option... options) { |
10818 | 463 |
this.location = location; |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
464 |
this.options = options.length == 0 |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
465 |
? EnumSet.noneOf(Option.class) |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
466 |
: EnumSet.copyOf(Arrays.asList(options)); |
10818 | 467 |
} |
468 |
} |
|
469 |
||
470 |
/** |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
471 |
* General purpose implementation for output locations, such as -d/CLASS_OUTPUT and |
36526 | 472 |
* -s/SOURCE_OUTPUT. All options are treated as equivalent (i.e. aliases.) |
473 |
* The value is a single file, possibly null. |
|
10818 | 474 |
*/ |
36526 | 475 |
private class OutputLocationHandler extends BasicLocationHandler { |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
476 |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
477 |
private Path outputDir; |
36526 | 478 |
private Map<String, Location> moduleLocations; |
10818 | 479 |
|
11314 | 480 |
OutputLocationHandler(Location location, Option... options) { |
10818 | 481 |
super(location, options); |
482 |
} |
|
483 |
||
484 |
@Override |
|
11314 | 485 |
boolean handleOption(Option option, String value) { |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
486 |
if (!options.contains(option)) { |
10818 | 487 |
return false; |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
488 |
} |
10 | 489 |
|
10818 | 490 |
// TODO: could/should validate outputDir exists and is a directory |
491 |
// need to decide how best to report issue for benefit of |
|
492 |
// direct API call on JavaFileManager.handleOption(specifies IAE) |
|
493 |
// vs. command line decoding. |
|
37944
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
494 |
outputDir = (value == null) ? null : getPath(value); |
10818 | 495 |
return true; |
496 |
} |
|
497 |
||
498 |
@Override |
|
36526 | 499 |
Collection<Path> getPaths() { |
10818 | 500 |
return (outputDir == null) ? null : Collections.singleton(outputDir); |
501 |
} |
|
10 | 502 |
|
10818 | 503 |
@Override |
36526 | 504 |
void setPaths(Iterable<? extends Path> files) throws IOException { |
10818 | 505 |
if (files == null) { |
506 |
outputDir = null; |
|
507 |
} else { |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
508 |
Iterator<? extends Path> pathIter = files.iterator(); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
509 |
if (!pathIter.hasNext()) { |
10818 | 510 |
throw new IllegalArgumentException("empty path for directory"); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
511 |
} |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
512 |
Path dir = pathIter.next(); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
513 |
if (pathIter.hasNext()) { |
10818 | 514 |
throw new IllegalArgumentException("path too long for directory"); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
515 |
} |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
516 |
if (!Files.exists(dir)) { |
10818 | 517 |
throw new FileNotFoundException(dir + ": does not exist"); |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
518 |
} else if (!Files.isDirectory(dir)) { |
10818 | 519 |
throw new IOException(dir + ": not a directory"); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
520 |
} |
10818 | 521 |
outputDir = dir; |
522 |
} |
|
36526 | 523 |
moduleLocations = null; |
524 |
} |
|
525 |
||
526 |
@Override |
|
42261
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41861
diff
changeset
|
527 |
Location getLocationForModule(String name) { |
36526 | 528 |
if (moduleLocations == null) |
529 |
moduleLocations = new HashMap<>(); |
|
530 |
Location l = moduleLocations.get(name); |
|
531 |
if (l == null) { |
|
532 |
l = new ModuleLocationHandler(location.getName() + "[" + name + "]", |
|
533 |
name, |
|
534 |
Collections.singleton(outputDir.resolve(name)), |
|
535 |
true, false); |
|
536 |
moduleLocations.put(name, l); |
|
537 |
} |
|
538 |
return l; |
|
10818 | 539 |
} |
10 | 540 |
} |
541 |
||
10818 | 542 |
/** |
36526 | 543 |
* General purpose implementation for search path locations, |
544 |
* such as -sourcepath/SOURCE_PATH and -processorPath/ANNOTATION_PROCESSOR_PATH. |
|
545 |
* All options are treated as equivalent (i.e. aliases.) |
|
10818 | 546 |
* The value is an ordered set of files and/or directories. |
547 |
*/ |
|
36526 | 548 |
private class SimpleLocationHandler extends BasicLocationHandler { |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
549 |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
550 |
protected Collection<Path> searchPath; |
10 | 551 |
|
11314 | 552 |
SimpleLocationHandler(Location location, Option... options) { |
10818 | 553 |
super(location, options); |
554 |
} |
|
10 | 555 |
|
10818 | 556 |
@Override |
11314 | 557 |
boolean handleOption(Option option, String value) { |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
558 |
if (!options.contains(option)) { |
10818 | 559 |
return false; |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
560 |
} |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
561 |
searchPath = value == null ? null |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
562 |
: Collections.unmodifiableCollection(createPath().addFiles(value)); |
10818 | 563 |
return true; |
564 |
} |
|
565 |
||
566 |
@Override |
|
36526 | 567 |
Collection<Path> getPaths() { |
10818 | 568 |
return searchPath; |
569 |
} |
|
10 | 570 |
|
10818 | 571 |
@Override |
36526 | 572 |
void setPaths(Iterable<? extends Path> files) { |
27118
3c8314271af7
8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents:
25874
diff
changeset
|
573 |
SearchPath p; |
10818 | 574 |
if (files == null) { |
575 |
p = computePath(null); |
|
576 |
} else { |
|
14360
2a8304e421ed
6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents:
14259
diff
changeset
|
577 |
p = createPath().addFiles(files); |
10818 | 578 |
} |
579 |
searchPath = Collections.unmodifiableCollection(p); |
|
580 |
} |
|
14360
2a8304e421ed
6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents:
14259
diff
changeset
|
581 |
|
27118
3c8314271af7
8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents:
25874
diff
changeset
|
582 |
protected SearchPath computePath(String value) { |
14360
2a8304e421ed
6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents:
14259
diff
changeset
|
583 |
return createPath().addFiles(value); |
2a8304e421ed
6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents:
14259
diff
changeset
|
584 |
} |
2a8304e421ed
6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents:
14259
diff
changeset
|
585 |
|
27118
3c8314271af7
8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents:
25874
diff
changeset
|
586 |
protected SearchPath createPath() { |
3c8314271af7
8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents:
25874
diff
changeset
|
587 |
return new SearchPath(); |
14360
2a8304e421ed
6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents:
14259
diff
changeset
|
588 |
} |
10 | 589 |
} |
590 |
||
10818 | 591 |
/** |
36526 | 592 |
* Subtype of SimpleLocationHandler for -classpath/CLASS_PATH. |
593 |
* If no value is given, a default is provided, based on system properties and other values. |
|
10818 | 594 |
*/ |
595 |
private class ClassPathLocationHandler extends SimpleLocationHandler { |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
596 |
|
10818 | 597 |
ClassPathLocationHandler() { |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40302
diff
changeset
|
598 |
super(StandardLocation.CLASS_PATH, Option.CLASS_PATH); |
10818 | 599 |
} |
600 |
||
601 |
@Override |
|
36526 | 602 |
Collection<Path> getPaths() { |
10818 | 603 |
lazy(); |
604 |
return searchPath; |
|
605 |
} |
|
606 |
||
607 |
@Override |
|
27118
3c8314271af7
8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents:
25874
diff
changeset
|
608 |
protected SearchPath computePath(String value) { |
10818 | 609 |
String cp = value; |
10 | 610 |
|
10818 | 611 |
// CLASSPATH environment variable when run from `javac'. |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
612 |
if (cp == null) { |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
613 |
cp = System.getProperty("env.class.path"); |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
614 |
} |
10818 | 615 |
|
616 |
// If invoked via a java VM (not the javac launcher), use the |
|
617 |
// platform class path |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
618 |
if (cp == null && System.getProperty("application.home") == null) { |
10818 | 619 |
cp = System.getProperty("java.class.path"); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
620 |
} |
10818 | 621 |
|
622 |
// Default to current working directory. |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
623 |
if (cp == null) { |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
624 |
cp = "."; |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
625 |
} |
10818 | 626 |
|
14360
2a8304e421ed
6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents:
14259
diff
changeset
|
627 |
return createPath().addFiles(cp); |
2a8304e421ed
6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents:
14259
diff
changeset
|
628 |
} |
2a8304e421ed
6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents:
14259
diff
changeset
|
629 |
|
2a8304e421ed
6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents:
14259
diff
changeset
|
630 |
@Override |
27118
3c8314271af7
8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents:
25874
diff
changeset
|
631 |
protected SearchPath createPath() { |
3c8314271af7
8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents:
25874
diff
changeset
|
632 |
return new SearchPath() |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
633 |
.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
|
634 |
.emptyPathDefault(getPath(".")); // Empty path elt ==> current directory |
14360
2a8304e421ed
6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents:
14259
diff
changeset
|
635 |
} |
10818 | 636 |
|
637 |
private void lazy() { |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
638 |
if (searchPath == null) { |
36526 | 639 |
setPaths(null); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
640 |
} |
10818 | 641 |
} |
10 | 642 |
} |
643 |
||
10818 | 644 |
/** |
36526 | 645 |
* Custom subtype of LocationHandler for PLATFORM_CLASS_PATH. |
646 |
* Various options are supported for different components of the |
|
647 |
* platform class path. |
|
648 |
* Setting a value with setLocation overrides all existing option values. |
|
649 |
* Setting any option overrides any value set with setLocation, and |
|
650 |
* reverts to using default values for options that have not been set. |
|
651 |
* Setting -bootclasspath or -Xbootclasspath overrides any existing |
|
652 |
* value for -Xbootclasspath/p: and -Xbootclasspath/a:. |
|
10818 | 653 |
*/ |
36526 | 654 |
private class BootClassPathLocationHandler extends BasicLocationHandler { |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
655 |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
656 |
private Collection<Path> searchPath; |
22163 | 657 |
final Map<Option, String> optionValues = new EnumMap<>(Option.class); |
10818 | 658 |
|
659 |
/** |
|
27579 | 660 |
* Is the bootclasspath the default? |
10818 | 661 |
*/ |
27579 | 662 |
private boolean isDefault; |
10818 | 663 |
|
664 |
BootClassPathLocationHandler() { |
|
665 |
super(StandardLocation.PLATFORM_CLASS_PATH, |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40302
diff
changeset
|
666 |
Option.BOOT_CLASS_PATH, Option.XBOOTCLASSPATH, |
11314 | 667 |
Option.XBOOTCLASSPATH_PREPEND, |
668 |
Option.XBOOTCLASSPATH_APPEND, |
|
669 |
Option.ENDORSEDDIRS, Option.DJAVA_ENDORSED_DIRS, |
|
670 |
Option.EXTDIRS, Option.DJAVA_EXT_DIRS); |
|
10818 | 671 |
} |
672 |
||
673 |
boolean isDefault() { |
|
674 |
lazy(); |
|
27579 | 675 |
return isDefault; |
10818 | 676 |
} |
677 |
||
678 |
@Override |
|
11314 | 679 |
boolean handleOption(Option option, String value) { |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
680 |
if (!options.contains(option)) { |
10818 | 681 |
return false; |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
682 |
} |
10 | 683 |
|
10818 | 684 |
option = canonicalize(option); |
685 |
optionValues.put(option, value); |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40302
diff
changeset
|
686 |
if (option == BOOT_CLASS_PATH) { |
10818 | 687 |
optionValues.remove(XBOOTCLASSPATH_PREPEND); |
688 |
optionValues.remove(XBOOTCLASSPATH_APPEND); |
|
689 |
} |
|
690 |
searchPath = null; // reset to "uninitialized" |
|
691 |
return true; |
|
692 |
} |
|
693 |
// where |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
694 |
// 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
|
695 |
// level |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
696 |
private Option canonicalize(Option option) { |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
697 |
switch (option) { |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
698 |
case XBOOTCLASSPATH: |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40302
diff
changeset
|
699 |
return Option.BOOT_CLASS_PATH; |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
700 |
case DJAVA_ENDORSED_DIRS: |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
701 |
return Option.ENDORSEDDIRS; |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
702 |
case DJAVA_EXT_DIRS: |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
703 |
return Option.EXTDIRS; |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
704 |
default: |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
705 |
return option; |
10818 | 706 |
} |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
707 |
} |
10 | 708 |
|
10818 | 709 |
@Override |
36526 | 710 |
Collection<Path> getPaths() { |
10 | 711 |
lazy(); |
10818 | 712 |
return searchPath; |
713 |
} |
|
714 |
||
715 |
@Override |
|
36526 | 716 |
void setPaths(Iterable<? extends Path> files) { |
10818 | 717 |
if (files == null) { |
718 |
searchPath = null; // reset to "uninitialized" |
|
719 |
} else { |
|
27579 | 720 |
isDefault = false; |
27118
3c8314271af7
8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents:
25874
diff
changeset
|
721 |
SearchPath p = new SearchPath().addFiles(files, false); |
10818 | 722 |
searchPath = Collections.unmodifiableCollection(p); |
723 |
optionValues.clear(); |
|
724 |
} |
|
10 | 725 |
} |
10818 | 726 |
|
27579 | 727 |
SearchPath computePath() throws IOException { |
27118
3c8314271af7
8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents:
25874
diff
changeset
|
728 |
SearchPath path = new SearchPath(); |
10818 | 729 |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40302
diff
changeset
|
730 |
String bootclasspathOpt = optionValues.get(BOOT_CLASS_PATH); |
10818 | 731 |
String endorseddirsOpt = optionValues.get(ENDORSEDDIRS); |
732 |
String extdirsOpt = optionValues.get(EXTDIRS); |
|
733 |
String xbootclasspathPrependOpt = optionValues.get(XBOOTCLASSPATH_PREPEND); |
|
734 |
String xbootclasspathAppendOpt = optionValues.get(XBOOTCLASSPATH_APPEND); |
|
735 |
path.addFiles(xbootclasspathPrependOpt); |
|
736 |
||
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
737 |
if (endorseddirsOpt != null) { |
10818 | 738 |
path.addDirectories(endorseddirsOpt); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
739 |
} else { |
10818 | 740 |
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
|
741 |
} |
10818 | 742 |
|
743 |
if (bootclasspathOpt != null) { |
|
744 |
path.addFiles(bootclasspathOpt); |
|
745 |
} else { |
|
746 |
// Standard system classes for this compiler's release. |
|
36526 | 747 |
Collection<Path> systemClasses = systemClasses(); |
27579 | 748 |
if (systemClasses != null) { |
749 |
path.addFiles(systemClasses, false); |
|
750 |
} else { |
|
751 |
// fallback to the value of sun.boot.class.path |
|
752 |
String files = System.getProperty("sun.boot.class.path"); |
|
753 |
path.addFiles(files, false); |
|
10818 | 754 |
} |
755 |
} |
|
756 |
||
757 |
path.addFiles(xbootclasspathAppendOpt); |
|
758 |
||
759 |
// Strictly speaking, standard extensions are not bootstrap |
|
760 |
// classes, but we treat them identically, so we'll pretend |
|
761 |
// that they are. |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
762 |
if (extdirsOpt != null) { |
10818 | 763 |
path.addDirectories(extdirsOpt); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
764 |
} else { |
27579 | 765 |
// Add lib/jfxrt.jar to the search path |
36526 | 766 |
Path jfxrt = javaHome.resolve("lib/jfxrt.jar"); |
27858 | 767 |
if (Files.exists(jfxrt)) { |
27579 | 768 |
path.addFile(jfxrt, false); |
769 |
} |
|
10818 | 770 |
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
|
771 |
} |
10818 | 772 |
|
27579 | 773 |
isDefault = |
774 |
(xbootclasspathPrependOpt == null) |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
775 |
&& (bootclasspathOpt == null) |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
776 |
&& (xbootclasspathAppendOpt == null); |
10818 | 777 |
|
778 |
return path; |
|
779 |
} |
|
780 |
||
27579 | 781 |
/** |
782 |
* Return a collection of files containing system classes. |
|
783 |
* Returns {@code null} if not running on a modular image. |
|
784 |
* |
|
785 |
* @throws UncheckedIOException if an I/O errors occurs |
|
786 |
*/ |
|
36526 | 787 |
private Collection<Path> systemClasses() throws IOException { |
788 |
// Return "modules" jimage file if available |
|
789 |
if (Files.isRegularFile(thisSystemModules)) { |
|
40302
8c0d8d2c3519
8143048: Re-examine dependency on property sun.boot.class.path
jlahoda
parents:
38536
diff
changeset
|
790 |
return Collections.singleton(thisSystemModules); |
27579 | 791 |
} |
792 |
||
793 |
// Exploded module image |
|
36526 | 794 |
Path modules = javaHome.resolve("modules"); |
27579 | 795 |
if (Files.isDirectory(modules.resolve("java.base"))) { |
29053
5c1f1d6b40f6
8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
28707
diff
changeset
|
796 |
try (Stream<Path> listedModules = Files.list(modules)) { |
40302
8c0d8d2c3519
8143048: Re-examine dependency on property sun.boot.class.path
jlahoda
parents:
38536
diff
changeset
|
797 |
return listedModules.collect(Collectors.toList()); |
29053
5c1f1d6b40f6
8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
28707
diff
changeset
|
798 |
} |
27579 | 799 |
} |
800 |
||
801 |
// not a modular image that we know about |
|
802 |
return null; |
|
803 |
} |
|
804 |
||
10818 | 805 |
private void lazy() { |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
806 |
if (searchPath == null) { |
27579 | 807 |
try { |
10818 | 808 |
searchPath = Collections.unmodifiableCollection(computePath()); |
27579 | 809 |
} catch (IOException e) { |
810 |
// TODO: need better handling here, e.g. javac Abort? |
|
811 |
throw new UncheckedIOException(e); |
|
812 |
} |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
813 |
} |
10818 | 814 |
} |
10 | 815 |
} |
816 |
||
36526 | 817 |
/** |
818 |
* A LocationHander to represent modules found from a module-oriented |
|
819 |
* location such as MODULE_SOURCE_PATH, UPGRADE_MODULE_PATH, |
|
820 |
* SYSTEM_MODULES and MODULE_PATH. |
|
821 |
* |
|
822 |
* 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
|
823 |
* {@code --patch-module <module>=<path> } parameter. |
36526 | 824 |
*/ |
825 |
private class ModuleLocationHandler extends LocationHandler implements Location { |
|
826 |
protected final String name; |
|
827 |
protected final String moduleName; |
|
828 |
protected final Collection<Path> searchPath; |
|
829 |
protected final Collection<Path> searchPathWithOverrides; |
|
830 |
protected final boolean output; |
|
831 |
||
832 |
ModuleLocationHandler(String name, String moduleName, Collection<Path> searchPath, |
|
833 |
boolean output, boolean allowOverrides) { |
|
834 |
this.name = name; |
|
835 |
this.moduleName = moduleName; |
|
836 |
this.searchPath = searchPath; |
|
837 |
this.output = output; |
|
838 |
||
37848
3c8ff4204d2d
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36526
diff
changeset
|
839 |
if (allowOverrides && patchMap != null) { |
3c8ff4204d2d
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36526
diff
changeset
|
840 |
SearchPath mPatch = patchMap.get(moduleName); |
3c8ff4204d2d
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36526
diff
changeset
|
841 |
if (mPatch != null) { |
3c8ff4204d2d
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36526
diff
changeset
|
842 |
SearchPath sp = new SearchPath(); |
3c8ff4204d2d
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36526
diff
changeset
|
843 |
sp.addAll(mPatch); |
3c8ff4204d2d
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36526
diff
changeset
|
844 |
sp.addAll(searchPath); |
3c8ff4204d2d
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36526
diff
changeset
|
845 |
searchPathWithOverrides = sp; |
36526 | 846 |
} else { |
37848
3c8ff4204d2d
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36526
diff
changeset
|
847 |
searchPathWithOverrides = searchPath; |
36526 | 848 |
} |
849 |
} else { |
|
850 |
searchPathWithOverrides = searchPath; |
|
851 |
} |
|
852 |
} |
|
853 |
||
37848
3c8ff4204d2d
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36526
diff
changeset
|
854 |
@Override @DefinedBy(Api.COMPILER) |
36526 | 855 |
public String getName() { |
856 |
return name; |
|
857 |
} |
|
858 |
||
37848
3c8ff4204d2d
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36526
diff
changeset
|
859 |
@Override @DefinedBy(Api.COMPILER) |
36526 | 860 |
public boolean isOutputLocation() { |
861 |
return output; |
|
862 |
} |
|
863 |
||
864 |
@Override // defined by LocationHandler |
|
865 |
boolean handleOption(Option option, String value) { |
|
866 |
throw new UnsupportedOperationException(); |
|
867 |
} |
|
868 |
||
869 |
@Override // defined by LocationHandler |
|
870 |
Collection<Path> getPaths() { |
|
871 |
// For now, we always return searchPathWithOverrides. This may differ from the |
|
872 |
// JVM behavior if there is a module-info.class to be found in the overriding |
|
873 |
// classes. |
|
874 |
return searchPathWithOverrides; |
|
875 |
} |
|
876 |
||
877 |
@Override // defined by LocationHandler |
|
878 |
void setPaths(Iterable<? extends Path> files) throws IOException { |
|
879 |
throw new UnsupportedOperationException(); |
|
880 |
} |
|
881 |
||
882 |
@Override // defined by LocationHandler |
|
883 |
String inferModuleName() { |
|
884 |
return moduleName; |
|
885 |
} |
|
886 |
} |
|
887 |
||
888 |
/** |
|
889 |
* A LocationHandler for simple module-oriented search paths, |
|
890 |
* like UPGRADE_MODULE_PATH and MODULE_PATH. |
|
891 |
*/ |
|
892 |
private class ModulePathLocationHandler extends SimpleLocationHandler { |
|
42414
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
42408
diff
changeset
|
893 |
private Map<String, ModuleLocationHandler> pathModules; |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
42408
diff
changeset
|
894 |
|
36526 | 895 |
ModulePathLocationHandler(Location location, Option... options) { |
896 |
super(location, options); |
|
897 |
} |
|
898 |
||
899 |
@Override |
|
900 |
public boolean handleOption(Option option, String value) { |
|
901 |
if (!options.contains(option)) { |
|
902 |
return false; |
|
903 |
} |
|
904 |
setPaths(value == null ? null : getPathEntries(value)); |
|
905 |
return true; |
|
906 |
} |
|
907 |
||
908 |
@Override |
|
42414
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
42408
diff
changeset
|
909 |
public Location getLocationForModule(String moduleName) { |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
42408
diff
changeset
|
910 |
initPathModules(); |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
42408
diff
changeset
|
911 |
return pathModules.get(moduleName); |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
42408
diff
changeset
|
912 |
} |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
42408
diff
changeset
|
913 |
|
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
42408
diff
changeset
|
914 |
@Override |
42261
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41861
diff
changeset
|
915 |
Iterable<Set<Location>> listLocationsForModules() { |
36526 | 916 |
if (searchPath == null) |
917 |
return Collections.emptyList(); |
|
918 |
||
919 |
return () -> new ModulePathIterator(); |
|
920 |
} |
|
921 |
||
922 |
@Override |
|
923 |
void setPaths(Iterable<? extends Path> paths) { |
|
924 |
if (paths != null) { |
|
925 |
for (Path p: paths) { |
|
926 |
checkValidModulePathEntry(p); |
|
927 |
} |
|
928 |
} |
|
929 |
super.setPaths(paths); |
|
930 |
} |
|
931 |
||
42414
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
42408
diff
changeset
|
932 |
private void initPathModules() { |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
42408
diff
changeset
|
933 |
if (pathModules != null) { |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
42408
diff
changeset
|
934 |
return; |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
42408
diff
changeset
|
935 |
} |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
42408
diff
changeset
|
936 |
|
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
42408
diff
changeset
|
937 |
pathModules = new LinkedHashMap<>(); |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
42408
diff
changeset
|
938 |
|
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
42408
diff
changeset
|
939 |
for (Set<Location> set : listLocationsForModules()) { |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
42408
diff
changeset
|
940 |
for (Location locn : set) { |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
42408
diff
changeset
|
941 |
if (locn instanceof ModuleLocationHandler) { |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
42408
diff
changeset
|
942 |
ModuleLocationHandler h = (ModuleLocationHandler) locn; |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
42408
diff
changeset
|
943 |
pathModules.put(h.moduleName, h); |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
42408
diff
changeset
|
944 |
} |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
42408
diff
changeset
|
945 |
} |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
42408
diff
changeset
|
946 |
} |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
42408
diff
changeset
|
947 |
} |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
42408
diff
changeset
|
948 |
|
36526 | 949 |
private void checkValidModulePathEntry(Path p) { |
950 |
if (Files.isDirectory(p)) { |
|
951 |
// either an exploded module or a directory of modules |
|
952 |
return; |
|
953 |
} |
|
954 |
||
955 |
String name = p.getFileName().toString(); |
|
956 |
int lastDot = name.lastIndexOf("."); |
|
957 |
if (lastDot > 0) { |
|
958 |
switch (name.substring(lastDot)) { |
|
959 |
case ".jar": |
|
960 |
case ".jmod": |
|
961 |
return; |
|
962 |
} |
|
963 |
} |
|
964 |
throw new IllegalArgumentException(p.toString()); |
|
965 |
} |
|
966 |
||
967 |
class ModulePathIterator implements Iterator<Set<Location>> { |
|
968 |
Iterator<Path> pathIter = searchPath.iterator(); |
|
969 |
int pathIndex = 0; |
|
970 |
Set<Location> next = null; |
|
971 |
||
972 |
@Override |
|
973 |
public boolean hasNext() { |
|
974 |
if (next != null) |
|
975 |
return true; |
|
976 |
||
977 |
while (next == null) { |
|
978 |
if (pathIter.hasNext()) { |
|
979 |
Path path = pathIter.next(); |
|
980 |
if (Files.isDirectory(path)) { |
|
981 |
next = scanDirectory(path); |
|
982 |
} else { |
|
983 |
next = scanFile(path); |
|
984 |
} |
|
985 |
pathIndex++; |
|
986 |
} else |
|
987 |
return false; |
|
988 |
} |
|
989 |
return true; |
|
990 |
} |
|
991 |
||
992 |
@Override |
|
993 |
public Set<Location> next() { |
|
994 |
hasNext(); |
|
995 |
if (next != null) { |
|
996 |
Set<Location> result = next; |
|
997 |
next = null; |
|
998 |
return result; |
|
999 |
} |
|
1000 |
throw new NoSuchElementException(); |
|
1001 |
} |
|
1002 |
||
1003 |
private Set<Location> scanDirectory(Path path) { |
|
1004 |
Set<Path> paths = new LinkedHashSet<>(); |
|
1005 |
Path moduleInfoClass = null; |
|
1006 |
try (DirectoryStream<Path> stream = Files.newDirectoryStream(path)) { |
|
1007 |
for (Path entry: stream) { |
|
1008 |
if (entry.endsWith("module-info.class")) { |
|
1009 |
moduleInfoClass = entry; |
|
1010 |
break; // no need to continue scanning |
|
1011 |
} |
|
1012 |
paths.add(entry); |
|
1013 |
} |
|
1014 |
} catch (DirectoryIteratorException | IOException ignore) { |
|
1015 |
log.error(Errors.LocnCantReadDirectory(path)); |
|
1016 |
return Collections.emptySet(); |
|
1017 |
} |
|
1018 |
||
1019 |
if (moduleInfoClass != null) { |
|
1020 |
// It's an exploded module directly on the module path. |
|
1021 |
// We can't infer module name from the directory name, so have to |
|
1022 |
// read module-info.class. |
|
1023 |
try { |
|
1024 |
String moduleName = readModuleName(moduleInfoClass); |
|
1025 |
String name = location.getName() |
|
1026 |
+ "[" + pathIndex + ":" + moduleName + "]"; |
|
1027 |
ModuleLocationHandler l = new ModuleLocationHandler(name, moduleName, |
|
1028 |
Collections.singleton(path), false, true); |
|
1029 |
return Collections.singleton(l); |
|
1030 |
} catch (ModuleNameReader.BadClassFile e) { |
|
1031 |
log.error(Errors.LocnBadModuleInfo(path)); |
|
1032 |
return Collections.emptySet(); |
|
1033 |
} catch (IOException e) { |
|
1034 |
log.error(Errors.LocnCantReadFile(path)); |
|
1035 |
return Collections.emptySet(); |
|
1036 |
} |
|
1037 |
} |
|
1038 |
||
1039 |
// A directory of modules |
|
1040 |
Set<Location> result = new LinkedHashSet<>(); |
|
1041 |
int index = 0; |
|
1042 |
for (Path entry : paths) { |
|
1043 |
Pair<String,Path> module = inferModuleName(entry); |
|
1044 |
if (module == null) { |
|
1045 |
// diagnostic reported if necessary; skip to next |
|
1046 |
continue; |
|
1047 |
} |
|
1048 |
String moduleName = module.fst; |
|
1049 |
Path modulePath = module.snd; |
|
1050 |
String name = location.getName() |
|
1051 |
+ "[" + pathIndex + "." + (index++) + ":" + moduleName + "]"; |
|
1052 |
ModuleLocationHandler l = new ModuleLocationHandler(name, moduleName, |
|
1053 |
Collections.singleton(modulePath), false, true); |
|
1054 |
result.add(l); |
|
1055 |
} |
|
1056 |
return result; |
|
1057 |
} |
|
1058 |
||
1059 |
private Set<Location> scanFile(Path path) { |
|
1060 |
Pair<String,Path> module = inferModuleName(path); |
|
1061 |
if (module == null) { |
|
1062 |
// diagnostic reported if necessary |
|
1063 |
return Collections.emptySet(); |
|
1064 |
} |
|
1065 |
String moduleName = module.fst; |
|
1066 |
Path modulePath = module.snd; |
|
1067 |
String name = location.getName() |
|
1068 |
+ "[" + pathIndex + ":" + moduleName + "]"; |
|
1069 |
ModuleLocationHandler l = new ModuleLocationHandler(name, moduleName, |
|
1070 |
Collections.singleton(modulePath), false, true); |
|
1071 |
return Collections.singleton(l); |
|
1072 |
} |
|
1073 |
||
1074 |
private Pair<String,Path> inferModuleName(Path p) { |
|
1075 |
if (Files.isDirectory(p)) { |
|
1076 |
if (Files.exists(p.resolve("module-info.class"))) { |
|
1077 |
String name = p.getFileName().toString(); |
|
1078 |
if (SourceVersion.isName(name)) |
|
1079 |
return new Pair<>(name, p); |
|
1080 |
} |
|
1081 |
return null; |
|
1082 |
} |
|
1083 |
||
38536
42569f7fe4e6
8154824: Compiler should handle java.nio.file.FileSystemNotFoundException gracefully and not abort
sadayapalam
parents:
38519
diff
changeset
|
1084 |
if (p.getFileName().toString().endsWith(".jar") && fsInfo.exists(p)) { |
41155
93dad90c22c1
8156568: Update javac to support compiling against a modular JAR that is a multi-release JAR
sadayapalam
parents:
40762
diff
changeset
|
1085 |
URI uri = URI.create("jar:" + p.toUri()); |
93dad90c22c1
8156568: Update javac to support compiling against a modular JAR that is a multi-release JAR
sadayapalam
parents:
40762
diff
changeset
|
1086 |
try (FileSystem fs = FileSystems.newFileSystem(uri, fsEnv, null)) { |
36526 | 1087 |
Path moduleInfoClass = fs.getPath("module-info.class"); |
1088 |
if (Files.exists(moduleInfoClass)) { |
|
1089 |
String moduleName = readModuleName(moduleInfoClass); |
|
1090 |
return new Pair<>(moduleName, p); |
|
1091 |
} |
|
1092 |
} catch (ModuleNameReader.BadClassFile e) { |
|
1093 |
log.error(Errors.LocnBadModuleInfo(p)); |
|
1094 |
return null; |
|
1095 |
} catch (IOException e) { |
|
1096 |
log.error(Errors.LocnCantReadFile(p)); |
|
1097 |
return null; |
|
40513
39b67170b045
8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
40308
diff
changeset
|
1098 |
} catch (ProviderNotFoundException e) { |
39b67170b045
8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
40308
diff
changeset
|
1099 |
log.error(Errors.NoZipfsForArchive(p)); |
39b67170b045
8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
40308
diff
changeset
|
1100 |
return null; |
36526 | 1101 |
} |
1102 |
||
1103 |
//automatic module: |
|
1104 |
String fn = p.getFileName().toString(); |
|
1105 |
//from ModulePath.deriveModuleDescriptor: |
|
1106 |
||
1107 |
// drop .jar |
|
1108 |
String mn = fn.substring(0, fn.length()-4); |
|
1109 |
||
1110 |
// find first occurrence of -${NUMBER}. or -${NUMBER}$ |
|
1111 |
Matcher matcher = Pattern.compile("-(\\d+(\\.|$))").matcher(mn); |
|
1112 |
if (matcher.find()) { |
|
1113 |
int start = matcher.start(); |
|
1114 |
||
1115 |
mn = mn.substring(0, start); |
|
1116 |
} |
|
1117 |
||
1118 |
// finally clean up the module name |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41861
diff
changeset
|
1119 |
mn = mn.replaceAll("(\\.|\\d)*$", "") // remove trailing version |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41861
diff
changeset
|
1120 |
.replaceAll("[^A-Za-z0-9]", ".") // replace non-alphanumeric |
36526 | 1121 |
.replaceAll("(\\.)(\\1)+", ".") // collapse repeating dots |
1122 |
.replaceAll("^\\.", "") // drop leading dots |
|
1123 |
.replaceAll("\\.$", ""); // drop trailing dots |
|
1124 |
||
1125 |
||
1126 |
if (!mn.isEmpty()) { |
|
1127 |
return new Pair<>(mn, p); |
|
1128 |
} |
|
1129 |
||
1130 |
log.error(Errors.LocnCantGetModuleNameForJar(p)); |
|
1131 |
return null; |
|
1132 |
} |
|
1133 |
||
1134 |
if (p.getFileName().toString().endsWith(".jmod")) { |
|
1135 |
try { |
|
41440 | 1136 |
// check if the JMOD file is valid |
1137 |
JDK9Wrappers.JmodFile.checkMagic(p); |
|
1138 |
||
1139 |
// No JMOD file system. Use JarFileSystem to |
|
1140 |
// workaround for now |
|
36526 | 1141 |
FileSystem fs = fileSystems.get(p); |
1142 |
if (fs == null) { |
|
1143 |
URI uri = URI.create("jar:" + p.toUri()); |
|
1144 |
fs = FileSystems.newFileSystem(uri, Collections.emptyMap(), null); |
|
1145 |
try { |
|
1146 |
Path moduleInfoClass = fs.getPath("classes/module-info.class"); |
|
1147 |
String moduleName = readModuleName(moduleInfoClass); |
|
1148 |
Path modulePath = fs.getPath("classes"); |
|
1149 |
fileSystems.put(p, fs); |
|
1150 |
closeables.add(fs); |
|
1151 |
fs = null; // prevent fs being closed in the finally clause |
|
1152 |
return new Pair<>(moduleName, modulePath); |
|
1153 |
} finally { |
|
1154 |
if (fs != null) |
|
1155 |
fs.close(); |
|
1156 |
} |
|
1157 |
} |
|
1158 |
} catch (ModuleNameReader.BadClassFile e) { |
|
1159 |
log.error(Errors.LocnBadModuleInfo(p)); |
|
40513
39b67170b045
8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
40308
diff
changeset
|
1160 |
} catch (IOException | ProviderNotFoundException e) { |
36526 | 1161 |
log.error(Errors.LocnCantReadFile(p)); |
1162 |
return null; |
|
1163 |
} |
|
1164 |
} |
|
1165 |
||
38519 | 1166 |
if (warn && false) { // temp disable, when enabled, massage examples.not-yet.txt suitably. |
36526 | 1167 |
log.warning(Warnings.LocnUnknownFileOnModulePath(p)); |
1168 |
} |
|
1169 |
return null; |
|
1170 |
} |
|
1171 |
||
1172 |
private String readModuleName(Path path) throws IOException, ModuleNameReader.BadClassFile { |
|
1173 |
if (moduleNameReader == null) |
|
1174 |
moduleNameReader = new ModuleNameReader(); |
|
1175 |
return moduleNameReader.readModuleName(path); |
|
1176 |
} |
|
1177 |
} |
|
1178 |
||
1179 |
} |
|
1180 |
||
1181 |
private class ModuleSourcePathLocationHandler extends BasicLocationHandler { |
|
1182 |
||
1183 |
private Map<String, Location> moduleLocations; |
|
1184 |
private Map<Path, Location> pathLocations; |
|
1185 |
||
1186 |
ModuleSourcePathLocationHandler() { |
|
1187 |
super(StandardLocation.MODULE_SOURCE_PATH, |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40302
diff
changeset
|
1188 |
Option.MODULE_SOURCE_PATH); |
36526 | 1189 |
} |
1190 |
||
1191 |
@Override |
|
1192 |
boolean handleOption(Option option, String value) { |
|
1193 |
init(value); |
|
1194 |
return true; |
|
1195 |
} |
|
1196 |
||
1197 |
void init(String value) { |
|
1198 |
Collection<String> segments = new ArrayList<>(); |
|
1199 |
for (String s: value.split(File.pathSeparator)) { |
|
1200 |
expandBraces(s, segments); |
|
1201 |
} |
|
1202 |
||
1203 |
Map<String, Collection<Path>> map = new LinkedHashMap<>(); |
|
1204 |
final String MARKER = "*"; |
|
1205 |
for (String seg: segments) { |
|
1206 |
int markStart = seg.indexOf(MARKER); |
|
1207 |
if (markStart == -1) { |
|
37944
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
1208 |
add(map, getPath(seg), null); |
36526 | 1209 |
} else { |
1210 |
if (markStart == 0 || !isSeparator(seg.charAt(markStart - 1))) { |
|
1211 |
throw new IllegalArgumentException("illegal use of " + MARKER + " in " + seg); |
|
1212 |
} |
|
37944
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
1213 |
Path prefix = getPath(seg.substring(0, markStart - 1)); |
36526 | 1214 |
Path suffix; |
1215 |
int markEnd = markStart + MARKER.length(); |
|
1216 |
if (markEnd == seg.length()) { |
|
1217 |
suffix = null; |
|
1218 |
} else if (!isSeparator(seg.charAt(markEnd)) |
|
1219 |
|| seg.indexOf(MARKER, markEnd) != -1) { |
|
1220 |
throw new IllegalArgumentException("illegal use of " + MARKER + " in " + seg); |
|
1221 |
} else { |
|
37944
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
1222 |
suffix = getPath(seg.substring(markEnd + 1)); |
36526 | 1223 |
} |
1224 |
add(map, prefix, suffix); |
|
1225 |
} |
|
1226 |
} |
|
1227 |
||
1228 |
moduleLocations = new LinkedHashMap<>(); |
|
1229 |
pathLocations = new LinkedHashMap<>(); |
|
1230 |
map.forEach((k, v) -> { |
|
1231 |
String name = location.getName() + "[" + k + "]"; |
|
1232 |
ModuleLocationHandler h = new ModuleLocationHandler(name, k, v, false, false); |
|
1233 |
moduleLocations.put(k, h); |
|
1234 |
v.forEach(p -> pathLocations.put(normalize(p), h)); |
|
1235 |
}); |
|
1236 |
} |
|
1237 |
||
1238 |
private boolean isSeparator(char ch) { |
|
1239 |
// allow both separators on Windows |
|
1240 |
return (ch == File.separatorChar) || (ch == '/'); |
|
1241 |
} |
|
1242 |
||
1243 |
void add(Map<String, Collection<Path>> map, Path prefix, Path suffix) { |
|
1244 |
if (!Files.isDirectory(prefix)) { |
|
1245 |
if (warn) { |
|
1246 |
String key = Files.exists(prefix) |
|
1247 |
? "dir.path.element.not.directory" |
|
1248 |
: "dir.path.element.not.found"; |
|
1249 |
log.warning(Lint.LintCategory.PATH, key, prefix); |
|
1250 |
} |
|
1251 |
return; |
|
1252 |
} |
|
1253 |
try (DirectoryStream<Path> stream = Files.newDirectoryStream(prefix, path -> Files.isDirectory(path))) { |
|
1254 |
for (Path entry: stream) { |
|
1255 |
Path path = (suffix == null) ? entry : entry.resolve(suffix); |
|
1256 |
if (Files.isDirectory(path)) { |
|
1257 |
String name = entry.getFileName().toString(); |
|
1258 |
Collection<Path> paths = map.get(name); |
|
1259 |
if (paths == null) |
|
1260 |
map.put(name, paths = new ArrayList<>()); |
|
1261 |
paths.add(path); |
|
1262 |
} |
|
1263 |
} |
|
1264 |
} catch (IOException e) { |
|
1265 |
// TODO? What to do? |
|
1266 |
System.err.println(e); |
|
1267 |
} |
|
1268 |
} |
|
1269 |
||
1270 |
private void expandBraces(String value, Collection<String> results) { |
|
1271 |
int depth = 0; |
|
1272 |
int start = -1; |
|
1273 |
String prefix = null; |
|
1274 |
String suffix = null; |
|
1275 |
for (int i = 0; i < value.length(); i++) { |
|
1276 |
switch (value.charAt(i)) { |
|
1277 |
case '{': |
|
1278 |
depth++; |
|
1279 |
if (depth == 1) { |
|
1280 |
prefix = value.substring(0, i); |
|
1281 |
suffix = value.substring(getMatchingBrace(value, i) + 1); |
|
1282 |
start = i + 1; |
|
1283 |
} |
|
1284 |
break; |
|
1285 |
||
1286 |
case ',': |
|
1287 |
if (depth == 1) { |
|
1288 |
String elem = value.substring(start, i); |
|
1289 |
expandBraces(prefix + elem + suffix, results); |
|
1290 |
start = i + 1; |
|
1291 |
} |
|
1292 |
break; |
|
1293 |
||
1294 |
case '}': |
|
1295 |
switch (depth) { |
|
1296 |
case 0: |
|
1297 |
throw new IllegalArgumentException("mismatched braces"); |
|
1298 |
||
1299 |
case 1: |
|
1300 |
String elem = value.substring(start, i); |
|
1301 |
expandBraces(prefix + elem + suffix, results); |
|
1302 |
return; |
|
1303 |
||
1304 |
default: |
|
1305 |
depth--; |
|
1306 |
} |
|
1307 |
break; |
|
1308 |
} |
|
1309 |
} |
|
1310 |
if (depth > 0) |
|
1311 |
throw new IllegalArgumentException("mismatched braces"); |
|
1312 |
results.add(value); |
|
1313 |
} |
|
1314 |
||
1315 |
int getMatchingBrace(String value, int offset) { |
|
1316 |
int depth = 1; |
|
1317 |
for (int i = offset + 1; i < value.length(); i++) { |
|
1318 |
switch (value.charAt(i)) { |
|
1319 |
case '{': |
|
1320 |
depth++; |
|
1321 |
break; |
|
1322 |
||
1323 |
case '}': |
|
1324 |
if (--depth == 0) |
|
1325 |
return i; |
|
1326 |
break; |
|
1327 |
} |
|
1328 |
} |
|
1329 |
throw new IllegalArgumentException("mismatched braces"); |
|
1330 |
} |
|
1331 |
||
1332 |
@Override |
|
1333 |
boolean isSet() { |
|
1334 |
return (moduleLocations != null); |
|
1335 |
} |
|
1336 |
||
1337 |
@Override |
|
1338 |
Collection<Path> getPaths() { |
|
1339 |
throw new UnsupportedOperationException(); |
|
1340 |
} |
|
1341 |
||
1342 |
@Override |
|
1343 |
void setPaths(Iterable<? extends Path> files) throws IOException { |
|
1344 |
throw new UnsupportedOperationException(); |
|
1345 |
} |
|
1346 |
||
1347 |
@Override |
|
42261
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41861
diff
changeset
|
1348 |
Location getLocationForModule(String name) { |
36526 | 1349 |
return (moduleLocations == null) ? null : moduleLocations.get(name); |
1350 |
} |
|
1351 |
||
1352 |
@Override |
|
42261
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41861
diff
changeset
|
1353 |
Location getLocationForModule(Path dir) { |
36526 | 1354 |
return (pathLocations == null) ? null : pathLocations.get(dir); |
1355 |
} |
|
1356 |
||
1357 |
@Override |
|
42261
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41861
diff
changeset
|
1358 |
Iterable<Set<Location>> listLocationsForModules() { |
36526 | 1359 |
if (moduleLocations == null) |
1360 |
return Collections.emptySet(); |
|
1361 |
Set<Location> locns = new LinkedHashSet<>(); |
|
1362 |
moduleLocations.forEach((k, v) -> locns.add(v)); |
|
1363 |
return Collections.singleton(locns); |
|
1364 |
} |
|
1365 |
||
1366 |
} |
|
1367 |
||
1368 |
private class SystemModulesLocationHandler extends BasicLocationHandler { |
|
37944
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
1369 |
private Path systemJavaHome; |
36526 | 1370 |
private Path modules; |
1371 |
private Map<String, ModuleLocationHandler> systemModules; |
|
1372 |
||
1373 |
SystemModulesLocationHandler() { |
|
1374 |
super(StandardLocation.SYSTEM_MODULES, Option.SYSTEM); |
|
37944
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
1375 |
systemJavaHome = Locations.javaHome; |
36526 | 1376 |
} |
1377 |
||
1378 |
@Override |
|
1379 |
boolean handleOption(Option option, String value) { |
|
1380 |
if (!options.contains(option)) { |
|
1381 |
return false; |
|
1382 |
} |
|
1383 |
||
1384 |
if (value == null) { |
|
37944
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
1385 |
systemJavaHome = Locations.javaHome; |
36526 | 1386 |
} else if (value.equals("none")) { |
37944
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
1387 |
systemJavaHome = null; |
36526 | 1388 |
} else { |
37944
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
1389 |
update(getPath(value)); |
36526 | 1390 |
} |
1391 |
||
1392 |
modules = null; |
|
1393 |
return true; |
|
1394 |
} |
|
1395 |
||
1396 |
@Override |
|
1397 |
Collection<Path> getPaths() { |
|
37944
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
1398 |
return (systemJavaHome == null) ? null : Collections.singleton(systemJavaHome); |
36526 | 1399 |
} |
1400 |
||
1401 |
@Override |
|
1402 |
void setPaths(Iterable<? extends Path> files) throws IOException { |
|
1403 |
if (files == null) { |
|
37944
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
1404 |
systemJavaHome = null; |
36526 | 1405 |
} else { |
1406 |
Iterator<? extends Path> pathIter = files.iterator(); |
|
1407 |
if (!pathIter.hasNext()) { |
|
1408 |
throw new IllegalArgumentException("empty path for directory"); // TODO: FIXME |
|
1409 |
} |
|
1410 |
Path dir = pathIter.next(); |
|
1411 |
if (pathIter.hasNext()) { |
|
1412 |
throw new IllegalArgumentException("path too long for directory"); // TODO: FIXME |
|
1413 |
} |
|
1414 |
if (!Files.exists(dir)) { |
|
1415 |
throw new FileNotFoundException(dir + ": does not exist"); |
|
1416 |
} else if (!Files.isDirectory(dir)) { |
|
1417 |
throw new IOException(dir + ": not a directory"); |
|
1418 |
} |
|
1419 |
update(dir); |
|
1420 |
} |
|
1421 |
} |
|
1422 |
||
1423 |
private void update(Path p) { |
|
42404
c4a34c2a656c
8169816: Move src.zip and jrt-fs.jar under the lib directory
mchung
parents:
42261
diff
changeset
|
1424 |
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
|
1425 |
!Files.exists(systemJavaHome.resolve("modules"))) |
36526 | 1426 |
throw new IllegalArgumentException(p.toString()); |
37944
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
1427 |
systemJavaHome = p; |
36526 | 1428 |
modules = null; |
1429 |
} |
|
1430 |
||
1431 |
private boolean isCurrentPlatform(Path p) { |
|
1432 |
try { |
|
37944
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
1433 |
return Files.isSameFile(p, Locations.javaHome); |
36526 | 1434 |
} catch (IOException ex) { |
1435 |
throw new IllegalArgumentException(p.toString(), ex); |
|
1436 |
} |
|
1437 |
} |
|
1438 |
||
1439 |
@Override |
|
42261
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41861
diff
changeset
|
1440 |
Location getLocationForModule(String name) throws IOException { |
36526 | 1441 |
initSystemModules(); |
1442 |
return systemModules.get(name); |
|
1443 |
} |
|
1444 |
||
1445 |
@Override |
|
42261
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41861
diff
changeset
|
1446 |
Iterable<Set<Location>> listLocationsForModules() throws IOException { |
36526 | 1447 |
initSystemModules(); |
1448 |
Set<Location> locns = new LinkedHashSet<>(); |
|
1449 |
for (Location l: systemModules.values()) |
|
1450 |
locns.add(l); |
|
1451 |
return Collections.singleton(locns); |
|
1452 |
} |
|
1453 |
||
1454 |
private void initSystemModules() throws IOException { |
|
1455 |
if (systemModules != null) { |
|
1456 |
return; |
|
1457 |
} |
|
1458 |
||
37944
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
1459 |
if (systemJavaHome == null) { |
36526 | 1460 |
systemModules = Collections.emptyMap(); |
1461 |
return; |
|
1462 |
} |
|
1463 |
||
1464 |
if (modules == null) { |
|
1465 |
try { |
|
1466 |
URI jrtURI = URI.create("jrt:/"); |
|
1467 |
FileSystem jrtfs; |
|
1468 |
||
37944
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
1469 |
if (isCurrentPlatform(systemJavaHome)) { |
36526 | 1470 |
jrtfs = FileSystems.getFileSystem(jrtURI); |
1471 |
} else { |
|
1472 |
try { |
|
1473 |
Map<String, String> attrMap = |
|
37944
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
1474 |
Collections.singletonMap("java.home", systemJavaHome.toString()); |
36526 | 1475 |
jrtfs = FileSystems.newFileSystem(jrtURI, attrMap); |
1476 |
} catch (ProviderNotFoundException ex) { |
|
37944
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
1477 |
URL javaHomeURL = systemJavaHome.resolve("jrt-fs.jar").toUri().toURL(); |
36526 | 1478 |
ClassLoader currentLoader = Locations.class.getClassLoader(); |
1479 |
URLClassLoader fsLoader = |
|
1480 |
new URLClassLoader(new URL[] {javaHomeURL}, currentLoader); |
|
1481 |
||
1482 |
jrtfs = FileSystems.newFileSystem(jrtURI, Collections.emptyMap(), fsLoader); |
|
1483 |
||
1484 |
closeables.add(fsLoader); |
|
1485 |
} |
|
1486 |
||
1487 |
closeables.add(jrtfs); |
|
1488 |
} |
|
1489 |
||
1490 |
modules = jrtfs.getPath("/modules"); |
|
1491 |
} catch (FileSystemNotFoundException | ProviderNotFoundException e) { |
|
37944
1153fab98d25
8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents:
37848
diff
changeset
|
1492 |
modules = systemJavaHome.resolve("modules"); |
36526 | 1493 |
if (!Files.exists(modules)) |
1494 |
throw new IOException("can't find system classes", e); |
|
1495 |
} |
|
1496 |
} |
|
1497 |
||
1498 |
systemModules = new LinkedHashMap<>(); |
|
1499 |
try (DirectoryStream<Path> stream = Files.newDirectoryStream(modules, Files::isDirectory)) { |
|
1500 |
for (Path entry : stream) { |
|
1501 |
String moduleName = entry.getFileName().toString(); |
|
1502 |
String name = location.getName() + "[" + moduleName + "]"; |
|
1503 |
ModuleLocationHandler h = new ModuleLocationHandler(name, moduleName, |
|
1504 |
Collections.singleton(entry), false, true); |
|
1505 |
systemModules.put(moduleName, h); |
|
1506 |
} |
|
1507 |
} |
|
1508 |
} |
|
1509 |
} |
|
1510 |
||
10818 | 1511 |
Map<Location, LocationHandler> handlersForLocation; |
11314 | 1512 |
Map<Option, LocationHandler> handlersForOption; |
10818 | 1513 |
|
1514 |
void initHandlers() { |
|
22163 | 1515 |
handlersForLocation = new HashMap<>(); |
1516 |
handlersForOption = new EnumMap<>(Option.class); |
|
10818 | 1517 |
|
36526 | 1518 |
BasicLocationHandler[] handlers = { |
10818 | 1519 |
new BootClassPathLocationHandler(), |
1520 |
new ClassPathLocationHandler(), |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40302
diff
changeset
|
1521 |
new SimpleLocationHandler(StandardLocation.SOURCE_PATH, Option.SOURCE_PATH), |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40302
diff
changeset
|
1522 |
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
|
1523 |
new SimpleLocationHandler(StandardLocation.ANNOTATION_PROCESSOR_MODULE_PATH, Option.PROCESSOR_MODULE_PATH), |
36526 | 1524 |
new OutputLocationHandler(StandardLocation.CLASS_OUTPUT, Option.D), |
1525 |
new OutputLocationHandler(StandardLocation.SOURCE_OUTPUT, Option.S), |
|
1526 |
new OutputLocationHandler(StandardLocation.NATIVE_HEADER_OUTPUT, Option.H), |
|
1527 |
new ModuleSourcePathLocationHandler(), |
|
1528 |
// TODO: should UPGRADE_MODULE_PATH be merged with SYSTEM_MODULES? |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40302
diff
changeset
|
1529 |
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
|
1530 |
new ModulePathLocationHandler(StandardLocation.MODULE_PATH, Option.MODULE_PATH), |
36526 | 1531 |
new SystemModulesLocationHandler(), |
10818 | 1532 |
}; |
10 | 1533 |
|
36526 | 1534 |
for (BasicLocationHandler h : handlers) { |
10818 | 1535 |
handlersForLocation.put(h.location, h); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
1536 |
for (Option o : h.options) { |
10818 | 1537 |
handlersForOption.put(o, h); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
1538 |
} |
10 | 1539 |
} |
10818 | 1540 |
} |
1541 |
||
36526 | 1542 |
private Map<String, SearchPath> patchMap; |
1543 |
||
29780
8f8e54a1fa20
8076420: Consolidate javac file handling in javac.file package
jjg
parents:
29291
diff
changeset
|
1544 |
boolean handleOption(Option option, String value) { |
36526 | 1545 |
switch (option) { |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40302
diff
changeset
|
1546 |
case PATCH_MODULE: |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40302
diff
changeset
|
1547 |
if (value == null) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40302
diff
changeset
|
1548 |
patchMap = null; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40302
diff
changeset
|
1549 |
} else { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40302
diff
changeset
|
1550 |
// Allow an extended syntax for --patch-module consisting of a series |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40302
diff
changeset
|
1551 |
// of values separated by NULL characters. This is to facilitate |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40302
diff
changeset
|
1552 |
// supporting deferred file manager options on the command line. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40302
diff
changeset
|
1553 |
// See Option.PATCH_MODULE for the code that composes these multiple |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40302
diff
changeset
|
1554 |
// values. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40302
diff
changeset
|
1555 |
for (String v : value.split("\0")) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40302
diff
changeset
|
1556 |
int eq = v.indexOf('='); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40302
diff
changeset
|
1557 |
if (eq > 0) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40302
diff
changeset
|
1558 |
String mName = v.substring(0, eq); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40302
diff
changeset
|
1559 |
SearchPath mPatchPath = new SearchPath() |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40302
diff
changeset
|
1560 |
.addFiles(v.substring(eq + 1)); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40302
diff
changeset
|
1561 |
boolean ok = true; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40302
diff
changeset
|
1562 |
for (Path p : mPatchPath) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40302
diff
changeset
|
1563 |
Path mi = p.resolve("module-info.class"); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40302
diff
changeset
|
1564 |
if (Files.exists(mi)) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40302
diff
changeset
|
1565 |
log.error(Errors.LocnModuleInfoNotAllowedOnPatchPath(mi)); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40302
diff
changeset
|
1566 |
ok = false; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40302
diff
changeset
|
1567 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40302
diff
changeset
|
1568 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40302
diff
changeset
|
1569 |
if (ok) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40302
diff
changeset
|
1570 |
if (patchMap == null) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40302
diff
changeset
|
1571 |
patchMap = new LinkedHashMap<>(); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40302
diff
changeset
|
1572 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40302
diff
changeset
|
1573 |
patchMap.put(mName, mPatchPath); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40302
diff
changeset
|
1574 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40302
diff
changeset
|
1575 |
} else { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40302
diff
changeset
|
1576 |
// Should not be able to get here; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40302
diff
changeset
|
1577 |
// this should be caught and handled in Option.PATCH_MODULE |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40302
diff
changeset
|
1578 |
log.error(Errors.LocnInvalidArgForXpatch(value)); |
36526 | 1579 |
} |
1580 |
} |
|
1581 |
} |
|
1582 |
return true; |
|
1583 |
default: |
|
1584 |
LocationHandler h = handlersForOption.get(option); |
|
1585 |
return (h == null ? false : h.handleOption(option, value)); |
|
1586 |
} |
|
1587 |
} |
|
1588 |
||
1589 |
boolean hasLocation(Location location) { |
|
1590 |
LocationHandler h = getHandler(location); |
|
1591 |
return (h == null ? false : h.isSet()); |
|
10818 | 1592 |
} |
1593 |
||
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
1594 |
Collection<Path> getLocation(Location location) { |
10818 | 1595 |
LocationHandler h = getHandler(location); |
36526 | 1596 |
return (h == null ? null : h.getPaths()); |
10 | 1597 |
} |
1598 |
||
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
1599 |
Path getOutputLocation(Location location) { |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
1600 |
if (!location.isOutputLocation()) { |
10818 | 1601 |
throw new IllegalArgumentException(); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
1602 |
} |
10818 | 1603 |
LocationHandler h = getHandler(location); |
1604 |
return ((OutputLocationHandler) h).outputDir; |
|
1605 |
} |
|
10 | 1606 |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
1607 |
void setLocation(Location location, Iterable<? extends Path> files) throws IOException { |
10818 | 1608 |
LocationHandler h = getHandler(location); |
1609 |
if (h == null) { |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
1610 |
if (location.isOutputLocation()) { |
10818 | 1611 |
h = new OutputLocationHandler(location); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
1612 |
} else { |
10818 | 1613 |
h = new SimpleLocationHandler(location); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
1614 |
} |
10818 | 1615 |
handlersForLocation.put(location, h); |
1616 |
} |
|
36526 | 1617 |
h.setPaths(files); |
1618 |
} |
|
1619 |
||
42261
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41861
diff
changeset
|
1620 |
Location getLocationForModule(Location location, String name) throws IOException { |
36526 | 1621 |
LocationHandler h = getHandler(location); |
42261
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41861
diff
changeset
|
1622 |
return (h == null ? null : h.getLocationForModule(name)); |
36526 | 1623 |
} |
1624 |
||
42261
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41861
diff
changeset
|
1625 |
Location getLocationForModule(Location location, Path dir) { |
36526 | 1626 |
LocationHandler h = getHandler(location); |
42261
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41861
diff
changeset
|
1627 |
return (h == null ? null : h.getLocationForModule(dir)); |
36526 | 1628 |
} |
1629 |
||
1630 |
String inferModuleName(Location location) { |
|
1631 |
LocationHandler h = getHandler(location); |
|
1632 |
return (h == null ? null : h.inferModuleName()); |
|
1633 |
} |
|
1634 |
||
42261
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41861
diff
changeset
|
1635 |
Iterable<Set<Location>> listLocationsForModules(Location location) throws IOException { |
36526 | 1636 |
LocationHandler h = getHandler(location); |
42261
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41861
diff
changeset
|
1637 |
return (h == null ? null : h.listLocationsForModules()); |
10818 | 1638 |
} |
1639 |
||
1640 |
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
|
1641 |
Objects.requireNonNull(location); |
36526 | 1642 |
return (location instanceof LocationHandler) |
1643 |
? (LocationHandler) location |
|
1644 |
: handlersForLocation.get(location); |
|
10818 | 1645 |
} |
1646 |
||
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
1647 |
/** |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
1648 |
* Is this the name of an archive file? |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
1649 |
*/ |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
1650 |
private boolean isArchive(Path file) { |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
1651 |
String n = StringUtils.toLowerCase(file.getFileName().toString()); |
1208 | 1652 |
return fsInfo.isFile(file) |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
1653 |
&& (n.endsWith(".jar") || n.endsWith(".zip")); |
10 | 1654 |
} |
4937
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
1655 |
|
36526 | 1656 |
static Path normalize(Path p) { |
1657 |
try { |
|
1658 |
return p.toRealPath(); |
|
1659 |
} catch (IOException e) { |
|
1660 |
return p.toAbsolutePath().normalize(); |
|
1661 |
} |
|
1662 |
} |
|
1663 |
||
10 | 1664 |
} |