author | jjg |
Fri, 31 Aug 2018 14:54:42 -0700 | |
changeset 51615 | afbb33428df7 |
parent 47702 | cf8310446245 |
permissions | -rw-r--r-- |
44019 | 1 |
/* |
51615
afbb33428df7
8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents:
47702
diff
changeset
|
2 |
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. |
44019 | 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 |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
||
24 |
/** |
|
25 |
* @test |
|
47363
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
26 |
* @bug 8173914 8188035 |
44019 | 27 |
* @summary JavaFileManager.setLocationForModule |
28 |
* @modules jdk.compiler/com.sun.tools.javac.api |
|
29 |
* jdk.compiler/com.sun.tools.javac.main |
|
30 |
* @library /tools/lib |
|
31 |
* @build toolbox.JavacTask toolbox.TestRunner toolbox.ToolBox SetLocationForModule |
|
32 |
* @run main SetLocationForModule |
|
33 |
*/ |
|
34 |
||
35 |
||
36 |
import java.io.FileNotFoundException; |
|
37 |
import java.io.IOException; |
|
38 |
import java.nio.file.Files; |
|
39 |
import java.nio.file.Path; |
|
40 |
import java.nio.file.Paths; |
|
41 |
import java.util.ArrayList; |
|
42 |
import java.util.Collections; |
|
43 |
import java.util.List; |
|
44 |
import java.util.Objects; |
|
47363
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
45 |
import java.util.Set; |
44019 | 46 |
|
47 |
import javax.tools.JavaCompiler; |
|
47363
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
48 |
import javax.tools.JavaFileManager; |
44019 | 49 |
import javax.tools.JavaFileManager.Location; |
50 |
import javax.tools.StandardJavaFileManager; |
|
51 |
import javax.tools.StandardLocation; |
|
52 |
import javax.tools.ToolProvider; |
|
53 |
||
54 |
import toolbox.JavacTask; |
|
55 |
import toolbox.TestRunner; |
|
56 |
import toolbox.TestRunner.Test; |
|
57 |
import toolbox.ToolBox; |
|
58 |
||
59 |
public class SetLocationForModule extends TestRunner { |
|
60 |
||
61 |
public static void main(String... args) throws Exception { |
|
62 |
new SetLocationForModule().runTests(m -> new Object[] { Paths.get(m.getName()) }); |
|
63 |
} |
|
64 |
||
65 |
public SetLocationForModule() { |
|
66 |
super(System.err); |
|
67 |
} |
|
68 |
||
69 |
private final JavaCompiler comp = ToolProvider.getSystemJavaCompiler(); |
|
70 |
private final ToolBox tb = new ToolBox(); |
|
71 |
||
72 |
@Test |
|
73 |
public void testBasic(Path base) throws IOException { |
|
74 |
try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) { |
|
75 |
Location[] locns = { |
|
76 |
StandardLocation.SOURCE_PATH, |
|
77 |
StandardLocation.CLASS_PATH, |
|
78 |
StandardLocation.PLATFORM_CLASS_PATH, |
|
79 |
}; |
|
80 |
// set a value |
|
81 |
Path out = Files.createDirectories(base.resolve("out")); |
|
82 |
for (Location locn : locns) { |
|
83 |
checkException("unsupported for location", |
|
84 |
IllegalArgumentException.class, |
|
85 |
"location is not an output location or a module-oriented location: " + locn, |
|
86 |
() -> fm.setLocationForModule(locn, "m", List.of(out))); |
|
87 |
} |
|
88 |
} |
|
89 |
} |
|
90 |
||
91 |
@Test |
|
92 |
public void testModulePath(Path base) throws IOException { |
|
93 |
try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) { |
|
94 |
Path src = base.resolve("src"); |
|
95 |
Path src_m = src.resolve("m"); |
|
96 |
tb.writeJavaFiles(src_m, "module m { }"); |
|
97 |
||
98 |
Location locn = StandardLocation.MODULE_PATH; |
|
99 |
||
100 |
Path modules1 = Files.createDirectories(base.resolve("modules1")); |
|
101 |
new JavacTask(tb) |
|
102 |
.outdir(modules1) |
|
103 |
.options("--module-source-path", src.toString()) |
|
104 |
.files(tb.findJavaFiles(src)) |
|
105 |
.run(); |
|
106 |
fm.setLocationFromPaths(locn, List.of(modules1)); |
|
107 |
||
108 |
Location m = fm.getLocationForModule(locn, "m"); |
|
109 |
checkEqual("default setting", |
|
110 |
fm.getLocationAsPaths(m), modules1.resolve("m")); |
|
111 |
||
112 |
Path override1 = Files.createDirectories(base.resolve("override1")); |
|
113 |
fm.setLocationForModule(locn, "m", List.of(override1)); |
|
114 |
checkEqual("override setting 1", |
|
115 |
fm.getLocationAsPaths(m), override1); |
|
116 |
||
47363
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
117 |
checkEqual("override setting 1b", |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
118 |
fm.getLocationAsPaths(fm.listLocationsForModules(locn).iterator().next().iterator().next()), |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
119 |
override1); |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
120 |
|
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
121 |
try (StandardJavaFileManager fm2 = comp.getStandardFileManager(null, null, null)) { |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
122 |
fm2.setLocationForModule(locn, "m", List.of(override1)); |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
123 |
checkEqual("override setting 2", |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
124 |
fm2.getLocationAsPaths(m), override1); |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
125 |
|
47702
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
126 |
Location firstLocation = |
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
127 |
fm2.listLocationsForModules(locn).iterator().next().iterator().next(); |
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
128 |
|
47363
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
129 |
checkEqual("override setting 2b", |
47702
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
130 |
fm2.getLocationAsPaths(firstLocation), |
47363
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
131 |
override1); |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
132 |
} |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
133 |
|
44019 | 134 |
Path override2 = Files.createDirectories(base.resolve("override2")); |
135 |
fm.setLocationFromPaths(m, List.of(override2)); |
|
47363
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
136 |
checkEqual("override setting 3", |
44019 | 137 |
fm.getLocationAsPaths(m), override2); |
138 |
||
139 |
Path modules2 = Files.createDirectories(base.resolve("modules2")); |
|
47363
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
140 |
new JavacTask(tb) |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
141 |
.outdir(modules2) |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
142 |
.options("--module-source-path", src.toString()) |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
143 |
.files(tb.findJavaFiles(src)) |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
144 |
.run(); |
44019 | 145 |
fm.setLocationFromPaths(locn, List.of(modules2)); |
146 |
||
47363
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
147 |
m = fm.getLocationForModule(locn, "m"); |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
148 |
|
44019 | 149 |
checkEqual("updated setting", |
150 |
fm.getLocationAsPaths(m), modules2.resolve("m")); |
|
151 |
} |
|
152 |
} |
|
153 |
||
154 |
@Test |
|
155 |
public void testModuleSourcePath(Path base) throws IOException { |
|
156 |
try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) { |
|
157 |
||
158 |
Location locn = StandardLocation.MODULE_SOURCE_PATH; |
|
159 |
||
160 |
Path src1 = Files.createDirectories(base.resolve("src1")); |
|
161 |
Path src1_m = src1.resolve("m"); |
|
162 |
tb.writeJavaFiles(src1_m, "module m { }"); |
|
51615
afbb33428df7
8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents:
47702
diff
changeset
|
163 |
fm.setLocationFromPaths(locn, List.of(src1)); |
44019 | 164 |
|
165 |
Location m = fm.getLocationForModule(locn, "m"); |
|
166 |
checkEqual("default setting", |
|
167 |
fm.getLocationAsPaths(m), src1.resolve("m")); |
|
168 |
||
169 |
Path override1 = Files.createDirectories(base.resolve("override1")); |
|
170 |
tb.writeJavaFiles(override1, "module m { }"); |
|
171 |
fm.setLocationForModule(locn, "m", List.of(override1)); |
|
172 |
checkEqual("override setting 1", |
|
173 |
fm.getLocationAsPaths(m), override1); |
|
174 |
||
47363
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
175 |
checkEqual("override setting 1b", |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
176 |
fm.getLocationAsPaths(fm.listLocationsForModules(locn).iterator().next().iterator().next()), |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
177 |
override1); |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
178 |
|
44019 | 179 |
Path override2 = Files.createDirectories(base.resolve("override2")); |
180 |
tb.writeJavaFiles(override2, "module m { }"); |
|
181 |
fm.setLocationFromPaths(m, List.of(override2)); |
|
182 |
checkEqual("override setting 2", |
|
183 |
fm.getLocationAsPaths(m), override2); |
|
184 |
||
185 |
Path src2 = Files.createDirectories(base.resolve("src2")); |
|
186 |
Path src2_m = src2.resolve("m"); |
|
187 |
tb.writeJavaFiles(src2_m, "module m { }"); |
|
51615
afbb33428df7
8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents:
47702
diff
changeset
|
188 |
fm.setLocationFromPaths(locn, List.of(src2)); |
44019 | 189 |
|
47363
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
190 |
m = fm.getLocationForModule(locn, "m"); |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
191 |
|
44019 | 192 |
checkEqual("updated setting", |
193 |
fm.getLocationAsPaths(m), src2.resolve("m")); |
|
194 |
} |
|
195 |
} |
|
196 |
||
197 |
@Test |
|
198 |
public void testOutput(Path base) throws IOException { |
|
199 |
try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) { |
|
200 |
Location locn = StandardLocation.CLASS_OUTPUT; |
|
201 |
||
202 |
Path out1 = Files.createDirectories(base.resolve("out1")); |
|
203 |
fm.setLocationFromPaths(locn, List.of(out1)); |
|
204 |
||
205 |
Location m = fm.getLocationForModule(locn, "m"); |
|
206 |
checkEqual("default setting", |
|
207 |
fm.getLocationAsPaths(m), out1.resolve("m")); |
|
208 |
||
209 |
Path override1 = Files.createDirectories(base.resolve("override1")); |
|
210 |
fm.setLocationForModule(locn, "m", List.of(override1)); |
|
211 |
checkEqual("override setting 1", |
|
212 |
fm.getLocationAsPaths(m), override1); |
|
213 |
||
47363
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
214 |
checkEqual("override setting 1b", |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
215 |
fm.getLocationAsPaths(fm.listLocationsForModules(locn).iterator().next().iterator().next()), |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
216 |
override1); |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
217 |
|
47702
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
218 |
try (StandardJavaFileManager fm2 = comp.getStandardFileManager(null, null, null)) { |
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
219 |
fm2.setLocationForModule(locn, "m", List.of(override1)); |
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
220 |
checkEqual("override setting 1", |
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
221 |
fm2.getLocationAsPaths(m), override1); |
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
222 |
|
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
223 |
Location firstLocation = |
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
224 |
fm2.listLocationsForModules(locn).iterator().next().iterator().next(); |
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
225 |
|
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
226 |
checkEqual("override setting 1b", |
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
227 |
fm2.getLocationAsPaths(firstLocation), |
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
228 |
override1); |
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
229 |
} |
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
230 |
|
44019 | 231 |
Path override2 = Files.createDirectories(base.resolve("override2")); |
232 |
fm.setLocationFromPaths(m, List.of(override2)); |
|
233 |
checkEqual("override setting 2", |
|
234 |
fm.getLocationAsPaths(m), override2); |
|
235 |
||
236 |
Path out2 = Files.createDirectories(base.resolve("out2")); |
|
237 |
fm.setLocationFromPaths(locn, List.of(out2)); |
|
238 |
||
47363
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
239 |
m = fm.getLocationForModule(locn, "m"); |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
240 |
|
44019 | 241 |
checkEqual("updated setting", |
242 |
fm.getLocationAsPaths(m), out2.resolve("m")); |
|
243 |
} |
|
244 |
} |
|
245 |
||
246 |
@Test |
|
247 |
public void testOutput_invalid(Path base) throws IOException { |
|
248 |
try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) { |
|
249 |
Location locn = StandardLocation.CLASS_OUTPUT; |
|
250 |
// set a top default |
|
251 |
Path out1 = Files.createDirectories(base.resolve("out1")); |
|
252 |
fm.setLocationFromPaths(locn, List.of(out1)); |
|
253 |
// getLocnForModule |
|
254 |
Location m = fm.getLocationForModule(locn, "m"); |
|
255 |
checkEqual("default setting", |
|
256 |
fm.getLocationAsPaths(m), out1.resolve("m")); |
|
257 |
||
258 |
checkException("empty arg list", |
|
259 |
IllegalArgumentException.class, "empty path for directory", |
|
260 |
() -> fm.setLocationFromPaths(m, Collections.emptyList())); |
|
261 |
||
262 |
Path out2 = Files.createDirectories(base.resolve("out2")); |
|
263 |
checkException("empty arg list", |
|
264 |
IllegalArgumentException.class, "path too long for directory", |
|
265 |
() -> fm.setLocationFromPaths(m, List.of(out2, out2))); |
|
266 |
||
267 |
Path notExist = base.resolve("notExist"); |
|
268 |
checkException("not exist", |
|
269 |
FileNotFoundException.class, notExist + ": does not exist", |
|
270 |
() -> fm.setLocationFromPaths(m, List.of(notExist))); |
|
271 |
||
272 |
Path file = Files.createFile(base.resolve("file.txt")); |
|
273 |
checkException("not exist", |
|
274 |
IOException.class, file + ": not a directory", |
|
275 |
() -> fm.setLocationFromPaths(m, List.of(file))); |
|
276 |
} |
|
277 |
} |
|
278 |
||
279 |
@Test |
|
280 |
public void testOutput_nested(Path base) throws IOException { |
|
281 |
try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) { |
|
282 |
Location locn = StandardLocation.CLASS_OUTPUT; |
|
283 |
||
284 |
Path out1 = Files.createDirectories(base.resolve("out1")); |
|
285 |
fm.setLocationForModule(locn, "m", List.of(out1)); |
|
286 |
||
287 |
Location m = fm.getLocationForModule(locn, "m"); |
|
288 |
checkEqual("initial setting", |
|
289 |
fm.getLocationAsPaths(m), out1); |
|
290 |
||
291 |
Path out2 = Files.createDirectories(base.resolve("out2")); |
|
292 |
checkException("create nested module", |
|
293 |
UnsupportedOperationException.class, "not supported for CLASS_OUTPUT[m]", |
|
294 |
() -> fm.setLocationForModule(m, "x", List.of(out2))); |
|
295 |
} |
|
296 |
} |
|
297 |
||
298 |
@Test |
|
299 |
public void testSystemModules(Path base) throws IOException { |
|
300 |
try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) { |
|
301 |
Location locn = StandardLocation.SYSTEM_MODULES; |
|
302 |
||
303 |
Location javaCompiler = fm.getLocationForModule(locn, "java.compiler"); |
|
304 |
// cannot easily verify default setting: could be jrt: or exploded image |
|
305 |
||
306 |
Path override1 = Files.createDirectories(base.resolve("override1")); |
|
307 |
fm.setLocationForModule(locn, "java.compiler", List.of(override1)); |
|
308 |
checkEqual("override setting 1", |
|
309 |
fm.getLocationAsPaths(javaCompiler), override1); |
|
310 |
||
47363
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
311 |
checkEqual("override setting 1b", |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
312 |
fm.getLocationAsPaths(findLocation(fm, fm.listLocationsForModules(locn), "java.compiler")), |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
313 |
override1); |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
314 |
|
44019 | 315 |
Path override2 = Files.createDirectories(base.resolve("override2")); |
316 |
fm.setLocationFromPaths(javaCompiler, List.of(override2)); |
|
317 |
checkEqual("override setting 2", |
|
318 |
fm.getLocationAsPaths(javaCompiler), override2); |
|
319 |
} |
|
320 |
} |
|
321 |
||
47363
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
322 |
private Location findLocation(JavaFileManager fm, Iterable<Set<Location>> locations, String moduleName) { |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
323 |
for (Set<Location> locs : locations) { |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
324 |
for (Location loc : locs) { |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
325 |
try { |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
326 |
if (moduleName.equals(fm.inferModuleName(loc))) { |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
327 |
return loc; |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
328 |
} |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
329 |
} catch (IOException ex) { |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
330 |
throw new IllegalStateException(ex); |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
331 |
} |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
332 |
} |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
333 |
} |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
334 |
|
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
335 |
throw new IllegalStateException(); |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
336 |
} |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
337 |
|
44019 | 338 |
@Test |
339 |
public void testTemplate(Path base) { |
|
340 |
// set a top default |
|
341 |
// getLocnForModule |
|
342 |
// set a value |
|
343 |
// getLocnForModule |
|
344 |
// reset |
|
345 |
// getLocationForModule |
|
346 |
} |
|
347 |
||
348 |
interface RunnableWithException { |
|
349 |
public void run() throws Exception; |
|
350 |
} |
|
351 |
||
352 |
void checkException(String message, |
|
353 |
Class<? extends Throwable> expectedException, String expectedMessage, |
|
354 |
RunnableWithException r) { |
|
355 |
try { |
|
356 |
r.run(); |
|
357 |
error(message + ": expected exception not thrown: " + expectedException); |
|
358 |
} catch (Exception | Error t) { |
|
359 |
if (expectedException.isAssignableFrom(t.getClass())) { |
|
360 |
checkEqual("exception message", |
|
361 |
t.getMessage(), expectedMessage); |
|
362 |
||
363 |
} else { |
|
364 |
error(message + ": unexpected exception\n" |
|
365 |
+ "expect: " + expectedException + "\n" |
|
366 |
+ " found: " + t); |
|
367 |
} |
|
368 |
} |
|
369 |
} |
|
370 |
||
371 |
void checkEqual(String message, Iterable<? extends Path> found, Path... expect) { |
|
372 |
List<Path> fList = asList(found); |
|
373 |
List<Path> eList = List.of(expect); |
|
47363
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
374 |
if (!Objects.equals(fList, eList)) { |
44019 | 375 |
error(message + ": lists not equal\n" |
376 |
+ "expect: " + eList + "\n" |
|
377 |
+ " found: " + fList); |
|
378 |
} |
|
379 |
} |
|
380 |
||
381 |
void checkEqual(String message, String found, String expect) { |
|
382 |
if (!Objects.equals(found, expect)) { |
|
383 |
error(message + ": strings not equal\n" |
|
384 |
+ "expect: " + expect + "\n" |
|
385 |
+ " found: " + found); |
|
386 |
} |
|
387 |
} |
|
388 |
||
389 |
List<Path> asList(Iterable<? extends Path> a) { |
|
390 |
List<Path> list = new ArrayList<>(); |
|
391 |
for (Path p : a) { |
|
392 |
list.add(p); |
|
393 |
} |
|
394 |
return list; |
|
395 |
} |
|
396 |
} |
|
397 |