author | jlahoda |
Mon, 06 Nov 2017 13:10:43 +0100 | |
changeset 47702 | cf8310446245 |
parent 47363 | 77c792d06646 |
child 51615 | afbb33428df7 |
permissions | -rw-r--r-- |
44019 | 1 |
/* |
2 |
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. |
|
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 { }"); |
|
163 |
// fm.setLocationFromPaths(locn, List.of(src1)); |
|
164 |
fm.handleOption("--module-source-path", List.of(src1.toString()).iterator()); |
|
165 |
||
166 |
Location m = fm.getLocationForModule(locn, "m"); |
|
167 |
checkEqual("default setting", |
|
168 |
fm.getLocationAsPaths(m), src1.resolve("m")); |
|
169 |
||
170 |
Path override1 = Files.createDirectories(base.resolve("override1")); |
|
171 |
tb.writeJavaFiles(override1, "module m { }"); |
|
172 |
fm.setLocationForModule(locn, "m", List.of(override1)); |
|
173 |
checkEqual("override setting 1", |
|
174 |
fm.getLocationAsPaths(m), override1); |
|
175 |
||
47363
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
176 |
checkEqual("override setting 1b", |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
177 |
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
|
178 |
override1); |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
179 |
|
44019 | 180 |
Path override2 = Files.createDirectories(base.resolve("override2")); |
181 |
tb.writeJavaFiles(override2, "module m { }"); |
|
182 |
fm.setLocationFromPaths(m, List.of(override2)); |
|
183 |
checkEqual("override setting 2", |
|
184 |
fm.getLocationAsPaths(m), override2); |
|
185 |
||
186 |
Path src2 = Files.createDirectories(base.resolve("src2")); |
|
187 |
Path src2_m = src2.resolve("m"); |
|
188 |
tb.writeJavaFiles(src2_m, "module m { }"); |
|
189 |
// fm.setLocationFromPaths(locn, List.of(src2)); |
|
190 |
fm.handleOption("--module-source-path", List.of(src2.toString()).iterator()); |
|
191 |
||
47363
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
192 |
m = fm.getLocationForModule(locn, "m"); |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
193 |
|
44019 | 194 |
checkEqual("updated setting", |
195 |
fm.getLocationAsPaths(m), src2.resolve("m")); |
|
196 |
} |
|
197 |
} |
|
198 |
||
199 |
@Test |
|
200 |
public void testOutput(Path base) throws IOException { |
|
201 |
try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) { |
|
202 |
Location locn = StandardLocation.CLASS_OUTPUT; |
|
203 |
||
204 |
Path out1 = Files.createDirectories(base.resolve("out1")); |
|
205 |
fm.setLocationFromPaths(locn, List.of(out1)); |
|
206 |
||
207 |
Location m = fm.getLocationForModule(locn, "m"); |
|
208 |
checkEqual("default setting", |
|
209 |
fm.getLocationAsPaths(m), out1.resolve("m")); |
|
210 |
||
211 |
Path override1 = Files.createDirectories(base.resolve("override1")); |
|
212 |
fm.setLocationForModule(locn, "m", List.of(override1)); |
|
213 |
checkEqual("override setting 1", |
|
214 |
fm.getLocationAsPaths(m), override1); |
|
215 |
||
47363
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
216 |
checkEqual("override setting 1b", |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
217 |
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
|
218 |
override1); |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
219 |
|
47702
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
220 |
try (StandardJavaFileManager fm2 = comp.getStandardFileManager(null, null, null)) { |
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
221 |
fm2.setLocationForModule(locn, "m", List.of(override1)); |
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
222 |
checkEqual("override setting 1", |
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
223 |
fm2.getLocationAsPaths(m), override1); |
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
224 |
|
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
225 |
Location firstLocation = |
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
226 |
fm2.listLocationsForModules(locn).iterator().next().iterator().next(); |
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
227 |
|
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
228 |
checkEqual("override setting 1b", |
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
229 |
fm2.getLocationAsPaths(firstLocation), |
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
230 |
override1); |
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
231 |
} |
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47363
diff
changeset
|
232 |
|
44019 | 233 |
Path override2 = Files.createDirectories(base.resolve("override2")); |
234 |
fm.setLocationFromPaths(m, List.of(override2)); |
|
235 |
checkEqual("override setting 2", |
|
236 |
fm.getLocationAsPaths(m), override2); |
|
237 |
||
238 |
Path out2 = Files.createDirectories(base.resolve("out2")); |
|
239 |
fm.setLocationFromPaths(locn, List.of(out2)); |
|
240 |
||
47363
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
241 |
m = fm.getLocationForModule(locn, "m"); |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
242 |
|
44019 | 243 |
checkEqual("updated setting", |
244 |
fm.getLocationAsPaths(m), out2.resolve("m")); |
|
245 |
} |
|
246 |
} |
|
247 |
||
248 |
@Test |
|
249 |
public void testOutput_invalid(Path base) throws IOException { |
|
250 |
try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) { |
|
251 |
Location locn = StandardLocation.CLASS_OUTPUT; |
|
252 |
// set a top default |
|
253 |
Path out1 = Files.createDirectories(base.resolve("out1")); |
|
254 |
fm.setLocationFromPaths(locn, List.of(out1)); |
|
255 |
// getLocnForModule |
|
256 |
Location m = fm.getLocationForModule(locn, "m"); |
|
257 |
checkEqual("default setting", |
|
258 |
fm.getLocationAsPaths(m), out1.resolve("m")); |
|
259 |
||
260 |
checkException("empty arg list", |
|
261 |
IllegalArgumentException.class, "empty path for directory", |
|
262 |
() -> fm.setLocationFromPaths(m, Collections.emptyList())); |
|
263 |
||
264 |
Path out2 = Files.createDirectories(base.resolve("out2")); |
|
265 |
checkException("empty arg list", |
|
266 |
IllegalArgumentException.class, "path too long for directory", |
|
267 |
() -> fm.setLocationFromPaths(m, List.of(out2, out2))); |
|
268 |
||
269 |
Path notExist = base.resolve("notExist"); |
|
270 |
checkException("not exist", |
|
271 |
FileNotFoundException.class, notExist + ": does not exist", |
|
272 |
() -> fm.setLocationFromPaths(m, List.of(notExist))); |
|
273 |
||
274 |
Path file = Files.createFile(base.resolve("file.txt")); |
|
275 |
checkException("not exist", |
|
276 |
IOException.class, file + ": not a directory", |
|
277 |
() -> fm.setLocationFromPaths(m, List.of(file))); |
|
278 |
} |
|
279 |
} |
|
280 |
||
281 |
@Test |
|
282 |
public void testOutput_nested(Path base) throws IOException { |
|
283 |
try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) { |
|
284 |
Location locn = StandardLocation.CLASS_OUTPUT; |
|
285 |
||
286 |
Path out1 = Files.createDirectories(base.resolve("out1")); |
|
287 |
fm.setLocationForModule(locn, "m", List.of(out1)); |
|
288 |
||
289 |
Location m = fm.getLocationForModule(locn, "m"); |
|
290 |
checkEqual("initial setting", |
|
291 |
fm.getLocationAsPaths(m), out1); |
|
292 |
||
293 |
Path out2 = Files.createDirectories(base.resolve("out2")); |
|
294 |
checkException("create nested module", |
|
295 |
UnsupportedOperationException.class, "not supported for CLASS_OUTPUT[m]", |
|
296 |
() -> fm.setLocationForModule(m, "x", List.of(out2))); |
|
297 |
} |
|
298 |
} |
|
299 |
||
300 |
@Test |
|
301 |
public void testSystemModules(Path base) throws IOException { |
|
302 |
try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) { |
|
303 |
Location locn = StandardLocation.SYSTEM_MODULES; |
|
304 |
||
305 |
Location javaCompiler = fm.getLocationForModule(locn, "java.compiler"); |
|
306 |
// cannot easily verify default setting: could be jrt: or exploded image |
|
307 |
||
308 |
Path override1 = Files.createDirectories(base.resolve("override1")); |
|
309 |
fm.setLocationForModule(locn, "java.compiler", List.of(override1)); |
|
310 |
checkEqual("override setting 1", |
|
311 |
fm.getLocationAsPaths(javaCompiler), override1); |
|
312 |
||
47363
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
313 |
checkEqual("override setting 1b", |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
314 |
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
|
315 |
override1); |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
316 |
|
44019 | 317 |
Path override2 = Files.createDirectories(base.resolve("override2")); |
318 |
fm.setLocationFromPaths(javaCompiler, List.of(override2)); |
|
319 |
checkEqual("override setting 2", |
|
320 |
fm.getLocationAsPaths(javaCompiler), override2); |
|
321 |
} |
|
322 |
} |
|
323 |
||
47363
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
324 |
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
|
325 |
for (Set<Location> locs : locations) { |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
326 |
for (Location loc : locs) { |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
327 |
try { |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
328 |
if (moduleName.equals(fm.inferModuleName(loc))) { |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
329 |
return loc; |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
330 |
} |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
331 |
} catch (IOException ex) { |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
332 |
throw new IllegalStateException(ex); |
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 |
} |
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 |
throw new IllegalStateException(); |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
338 |
} |
77c792d06646
8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents:
47216
diff
changeset
|
339 |
|
44019 | 340 |
@Test |
341 |
public void testTemplate(Path base) { |
|
342 |
// set a top default |
|
343 |
// getLocnForModule |
|
344 |
// set a value |
|
345 |
// getLocnForModule |
|
346 |
// reset |
|
347 |
// getLocationForModule |
|
348 |
} |
|
349 |
||
350 |
interface RunnableWithException { |
|
351 |
public void run() throws Exception; |
|
352 |
} |
|
353 |
||
354 |
void checkException(String message, |
|
355 |
Class<? extends Throwable> expectedException, String expectedMessage, |
|
356 |
RunnableWithException r) { |
|
357 |
try { |
|
358 |
r.run(); |
|
359 |
error(message + ": expected exception not thrown: " + expectedException); |
|
360 |
} catch (Exception | Error t) { |
|
361 |
if (expectedException.isAssignableFrom(t.getClass())) { |
|
362 |
checkEqual("exception message", |
|
363 |
t.getMessage(), expectedMessage); |
|
364 |
||
365 |
} else { |
|
366 |
error(message + ": unexpected exception\n" |
|
367 |
+ "expect: " + expectedException + "\n" |
|
368 |
+ " found: " + t); |
|
369 |
} |
|
370 |
} |
|
371 |
} |
|
372 |
||
373 |
void checkEqual(String message, Iterable<? extends Path> found, Path... expect) { |
|
374 |
List<Path> fList = asList(found); |
|
375 |
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
|
376 |
if (!Objects.equals(fList, eList)) { |
44019 | 377 |
error(message + ": lists not equal\n" |
378 |
+ "expect: " + eList + "\n" |
|
379 |
+ " found: " + fList); |
|
380 |
} |
|
381 |
} |
|
382 |
||
383 |
void checkEqual(String message, String found, String expect) { |
|
384 |
if (!Objects.equals(found, expect)) { |
|
385 |
error(message + ": strings not equal\n" |
|
386 |
+ "expect: " + expect + "\n" |
|
387 |
+ " found: " + found); |
|
388 |
} |
|
389 |
} |
|
390 |
||
391 |
List<Path> asList(Iterable<? extends Path> a) { |
|
392 |
List<Path> list = new ArrayList<>(); |
|
393 |
for (Path p : a) { |
|
394 |
list.add(p); |
|
395 |
} |
|
396 |
return list; |
|
397 |
} |
|
398 |
} |
|
399 |