author | prr |
Fri, 25 May 2018 12:12:24 -0700 | |
changeset 50347 | b2f046ae8eb6 |
parent 47399 | fb677b3f0888 |
permissions | -rw-r--r-- |
36511 | 1 |
/** |
2 |
* Copyright (c) 2015, 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 |
|
26 |
* @summary Negative tests for jlink |
|
27 |
* @bug 8130861 |
|
43796
c204d2d789dc
8174718: "Module <name>'s descriptor returns inconsistent package set" confusing
sundar
parents:
43729
diff
changeset
|
28 |
* @bug 8174718 |
47399
fb677b3f0888
8189671: jlink should clearly report error when an automatic module is used
sundar
parents:
47216
diff
changeset
|
29 |
* @bug 8189671 |
36511 | 30 |
* @author Andrei Eremeev |
31 |
* @library ../lib |
|
32 |
* @modules java.base/jdk.internal.jimage |
|
33 |
* java.base/jdk.internal.module |
|
34 |
* jdk.jdeps/com.sun.tools.classfile |
|
35 |
* jdk.jlink/jdk.tools.jlink.internal |
|
36 |
* jdk.jlink/jdk.tools.jmod |
|
37 |
* jdk.jlink/jdk.tools.jimage |
|
38 |
* jdk.compiler |
|
39 |
* @build tests.* |
|
40 |
* @run testng JLinkNegativeTest |
|
41 |
*/ |
|
42 |
||
47399
fb677b3f0888
8189671: jlink should clearly report error when an automatic module is used
sundar
parents:
47216
diff
changeset
|
43 |
import java.io.File; |
fb677b3f0888
8189671: jlink should clearly report error when an automatic module is used
sundar
parents:
47216
diff
changeset
|
44 |
import java.io.FileOutputStream; |
36511 | 45 |
import java.io.IOException; |
46 |
import java.io.OutputStream; |
|
47 |
import java.lang.module.ModuleDescriptor; |
|
48 |
import java.nio.file.FileVisitResult; |
|
49 |
import java.nio.file.Files; |
|
50 |
import java.nio.file.Path; |
|
51 |
import java.nio.file.Paths; |
|
52 |
import java.nio.file.SimpleFileVisitor; |
|
53 |
import java.nio.file.attribute.BasicFileAttributes; |
|
54 |
import java.util.Arrays; |
|
55 |
import java.util.Collections; |
|
56 |
import java.util.List; |
|
43796
c204d2d789dc
8174718: "Module <name>'s descriptor returns inconsistent package set" confusing
sundar
parents:
43729
diff
changeset
|
57 |
import java.util.Set; |
47399
fb677b3f0888
8189671: jlink should clearly report error when an automatic module is used
sundar
parents:
47216
diff
changeset
|
58 |
import java.util.jar.JarEntry; |
fb677b3f0888
8189671: jlink should clearly report error when an automatic module is used
sundar
parents:
47216
diff
changeset
|
59 |
import java.util.jar.JarOutputStream; |
36511 | 60 |
|
61 |
import jdk.internal.module.ModuleInfoWriter; |
|
62 |
import org.testng.SkipException; |
|
63 |
import org.testng.annotations.BeforeClass; |
|
64 |
import org.testng.annotations.Test; |
|
65 |
import tests.Helper; |
|
66 |
import tests.JImageGenerator; |
|
67 |
import tests.JImageGenerator.InMemoryFile; |
|
68 |
import tests.Result; |
|
69 |
||
70 |
@Test |
|
71 |
public class JLinkNegativeTest { |
|
72 |
||
73 |
private Helper helper; |
|
74 |
||
75 |
@BeforeClass |
|
76 |
public void setUp() throws IOException { |
|
77 |
helper = Helper.newHelper(); |
|
78 |
if (helper == null) { |
|
79 |
throw new SkipException("Not run"); |
|
80 |
} |
|
81 |
helper.generateDefaultModules(); |
|
82 |
} |
|
83 |
||
84 |
private void deleteDirectory(Path dir) throws IOException { |
|
85 |
Files.walkFileTree(dir, new SimpleFileVisitor<Path>() { |
|
86 |
@Override |
|
87 |
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { |
|
88 |
Files.delete(file); |
|
89 |
return FileVisitResult.CONTINUE; |
|
90 |
} |
|
91 |
||
92 |
@Override |
|
93 |
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { |
|
94 |
Files.delete(dir); |
|
95 |
return FileVisitResult.CONTINUE; |
|
96 |
} |
|
97 |
}); |
|
98 |
} |
|
99 |
||
100 |
public void testModuleNotExist() { |
|
101 |
helper.generateDefaultImage("failure1").assertFailure("Error: Module failure1 not found"); |
|
102 |
} |
|
103 |
||
104 |
public void testNotExistInAddMods() { |
|
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
36511
diff
changeset
|
105 |
// cannot find jmod from --add-modules |
36511 | 106 |
JImageGenerator.getJLinkTask() |
107 |
.modulePath(".") |
|
108 |
.addMods("not_exist") |
|
109 |
.output(helper.getImageDir().resolve("failure2")) |
|
110 |
.call().assertFailure("Error: Module not_exist not found"); |
|
111 |
} |
|
112 |
||
113 |
public void test() throws IOException { |
|
114 |
helper.generateDefaultJModule("failure3"); |
|
115 |
Path image = helper.generateDefaultImage("failure3").assertSuccess(); |
|
116 |
JImageGenerator.getJLinkTask() |
|
117 |
.modulePath(helper.defaultModulePath()) |
|
118 |
.output(image) |
|
119 |
.addMods("leaf1") |
|
120 |
.limitMods("leaf1") |
|
121 |
.call().assertFailure("Error: directory already exists: .*failure3.image(\n|\r|.)*"); |
|
122 |
} |
|
123 |
||
124 |
public void testOutputIsFile() throws IOException { |
|
125 |
// output == file |
|
126 |
Path image = helper.createNewImageDir("failure4"); |
|
127 |
Files.createFile(image); |
|
128 |
JImageGenerator.getJLinkTask() |
|
129 |
.modulePath(helper.defaultModulePath()) |
|
130 |
.output(image) |
|
131 |
.addMods("leaf1") |
|
132 |
.call().assertFailure("Error: directory already exists: .*failure4.image(\n|\r|.)*"); |
|
133 |
} |
|
134 |
||
135 |
public void testModuleNotFound() { |
|
136 |
// limit module is not found |
|
137 |
Path imageFile = helper.createNewImageDir("test"); |
|
138 |
JImageGenerator.getJLinkTask() |
|
139 |
.output(imageFile) |
|
140 |
.addMods("leaf1") |
|
141 |
.limitMods("leaf1") |
|
142 |
.limitMods("failure5") |
|
143 |
.modulePath(helper.defaultModulePath()) |
|
144 |
.call().assertFailure("Error: Module failure5 not found"); |
|
145 |
} |
|
146 |
||
147 |
public void testJmodIsDir() throws IOException { |
|
148 |
Path imageFile = helper.createNewImageDir("test"); |
|
149 |
Path dirJmod = helper.createNewJmodFile("dir"); |
|
150 |
Files.createDirectory(dirJmod); |
|
151 |
try { |
|
152 |
JImageGenerator.getJLinkTask() |
|
153 |
.output(imageFile) |
|
154 |
.addMods("dir") |
|
155 |
.modulePath(helper.defaultModulePath()) |
|
156 |
.call().assertFailure("Error: Module dir not found"); |
|
157 |
} finally { |
|
158 |
deleteDirectory(dirJmod); |
|
159 |
} |
|
160 |
} |
|
161 |
||
162 |
public void testJarIsDir() throws IOException { |
|
163 |
Path imageFile = helper.createNewImageDir("test"); |
|
164 |
Path dirJar = helper.createNewJarFile("dir"); |
|
165 |
Files.createDirectory(dirJar); |
|
166 |
try { |
|
167 |
JImageGenerator.getJLinkTask() |
|
168 |
.output(imageFile) |
|
169 |
.addMods("dir") |
|
170 |
.modulePath(helper.defaultModulePath()) |
|
171 |
.call().assertFailure("Error: Module dir not found"); |
|
172 |
} finally { |
|
173 |
deleteDirectory(dirJar); |
|
174 |
} |
|
175 |
} |
|
176 |
||
177 |
public void testMalformedJar() throws IOException { |
|
178 |
Path imageFile = helper.createNewImageDir("test"); |
|
179 |
Path jar = helper.createNewJarFile("not_zip"); |
|
180 |
Files.createFile(jar); |
|
181 |
try { |
|
182 |
JImageGenerator.getJLinkTask() |
|
183 |
.output(imageFile) |
|
184 |
.addMods("not_zip") |
|
185 |
.modulePath(helper.defaultModulePath()) |
|
45004
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44359
diff
changeset
|
186 |
.call().assertFailure("Error: Error reading"); |
36511 | 187 |
} finally { |
188 |
deleteDirectory(jar); |
|
189 |
} |
|
190 |
} |
|
191 |
||
192 |
public void testMalformedJmod() throws IOException { |
|
193 |
Path imageFile = helper.createNewImageDir("test"); |
|
194 |
Path jmod = helper.createNewJmodFile("not_zip"); |
|
195 |
Files.createFile(jmod); |
|
196 |
try { |
|
197 |
JImageGenerator.getJLinkTask() |
|
198 |
.output(imageFile) |
|
199 |
.addMods("not_zip") |
|
200 |
.modulePath(helper.defaultModulePath()) |
|
44359
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43796
diff
changeset
|
201 |
.call().assertFailure("Error: java.io.IOException: Invalid JMOD file"); |
36511 | 202 |
} finally { |
203 |
deleteDirectory(jmod); |
|
204 |
} |
|
205 |
} |
|
206 |
||
47399
fb677b3f0888
8189671: jlink should clearly report error when an automatic module is used
sundar
parents:
47216
diff
changeset
|
207 |
private static File createJarFile(File dir, String filename, String pkg, String name) throws IOException { |
fb677b3f0888
8189671: jlink should clearly report error when an automatic module is used
sundar
parents:
47216
diff
changeset
|
208 |
File jarFile = new File(dir, filename + ".jar"); |
fb677b3f0888
8189671: jlink should clearly report error when an automatic module is used
sundar
parents:
47216
diff
changeset
|
209 |
|
fb677b3f0888
8189671: jlink should clearly report error when an automatic module is used
sundar
parents:
47216
diff
changeset
|
210 |
try (JarOutputStream output = new JarOutputStream(new FileOutputStream(jarFile))) { |
fb677b3f0888
8189671: jlink should clearly report error when an automatic module is used
sundar
parents:
47216
diff
changeset
|
211 |
JarEntry entry = new JarEntry(filename + "/" + pkg + "/" + name); |
fb677b3f0888
8189671: jlink should clearly report error when an automatic module is used
sundar
parents:
47216
diff
changeset
|
212 |
output.putNextEntry(entry); |
fb677b3f0888
8189671: jlink should clearly report error when an automatic module is used
sundar
parents:
47216
diff
changeset
|
213 |
} |
fb677b3f0888
8189671: jlink should clearly report error when an automatic module is used
sundar
parents:
47216
diff
changeset
|
214 |
|
fb677b3f0888
8189671: jlink should clearly report error when an automatic module is used
sundar
parents:
47216
diff
changeset
|
215 |
return jarFile; |
fb677b3f0888
8189671: jlink should clearly report error when an automatic module is used
sundar
parents:
47216
diff
changeset
|
216 |
} |
fb677b3f0888
8189671: jlink should clearly report error when an automatic module is used
sundar
parents:
47216
diff
changeset
|
217 |
|
fb677b3f0888
8189671: jlink should clearly report error when an automatic module is used
sundar
parents:
47216
diff
changeset
|
218 |
public void testAutomaticModuleAsRoot() throws IOException { |
fb677b3f0888
8189671: jlink should clearly report error when an automatic module is used
sundar
parents:
47216
diff
changeset
|
219 |
Path imageFile = helper.createNewImageDir("test"); |
fb677b3f0888
8189671: jlink should clearly report error when an automatic module is used
sundar
parents:
47216
diff
changeset
|
220 |
String jarName = "myautomod"; |
fb677b3f0888
8189671: jlink should clearly report error when an automatic module is used
sundar
parents:
47216
diff
changeset
|
221 |
File jarFile = createJarFile(new File("jars"), jarName, "com/acme", "Bar.class"); |
fb677b3f0888
8189671: jlink should clearly report error when an automatic module is used
sundar
parents:
47216
diff
changeset
|
222 |
try { |
fb677b3f0888
8189671: jlink should clearly report error when an automatic module is used
sundar
parents:
47216
diff
changeset
|
223 |
JImageGenerator.getJLinkTask() |
fb677b3f0888
8189671: jlink should clearly report error when an automatic module is used
sundar
parents:
47216
diff
changeset
|
224 |
.output(imageFile) |
fb677b3f0888
8189671: jlink should clearly report error when an automatic module is used
sundar
parents:
47216
diff
changeset
|
225 |
.addMods(jarName) |
fb677b3f0888
8189671: jlink should clearly report error when an automatic module is used
sundar
parents:
47216
diff
changeset
|
226 |
.modulePath(helper.defaultModulePath()) |
fb677b3f0888
8189671: jlink should clearly report error when an automatic module is used
sundar
parents:
47216
diff
changeset
|
227 |
.call().assertFailure("Error: automatic module cannot be used with jlink: " + jarName); |
fb677b3f0888
8189671: jlink should clearly report error when an automatic module is used
sundar
parents:
47216
diff
changeset
|
228 |
} finally { |
fb677b3f0888
8189671: jlink should clearly report error when an automatic module is used
sundar
parents:
47216
diff
changeset
|
229 |
jarFile.delete(); |
fb677b3f0888
8189671: jlink should clearly report error when an automatic module is used
sundar
parents:
47216
diff
changeset
|
230 |
} |
fb677b3f0888
8189671: jlink should clearly report error when an automatic module is used
sundar
parents:
47216
diff
changeset
|
231 |
} |
fb677b3f0888
8189671: jlink should clearly report error when an automatic module is used
sundar
parents:
47216
diff
changeset
|
232 |
|
fb677b3f0888
8189671: jlink should clearly report error when an automatic module is used
sundar
parents:
47216
diff
changeset
|
233 |
public void testAutomaticModuleAsDependency() throws IOException { |
fb677b3f0888
8189671: jlink should clearly report error when an automatic module is used
sundar
parents:
47216
diff
changeset
|
234 |
Path imageFile = helper.createNewImageDir("test"); |
fb677b3f0888
8189671: jlink should clearly report error when an automatic module is used
sundar
parents:
47216
diff
changeset
|
235 |
String autoJarName = "myautomod"; |
fb677b3f0888
8189671: jlink should clearly report error when an automatic module is used
sundar
parents:
47216
diff
changeset
|
236 |
File autoJarFile = createJarFile(new File("jars"), autoJarName, "com/acme", "Bar.class"); |
fb677b3f0888
8189671: jlink should clearly report error when an automatic module is used
sundar
parents:
47216
diff
changeset
|
237 |
String rootMod = "autodepender"; |
fb677b3f0888
8189671: jlink should clearly report error when an automatic module is used
sundar
parents:
47216
diff
changeset
|
238 |
helper.generateDefaultJModule(rootMod, autoJarName).assertSuccess(); |
fb677b3f0888
8189671: jlink should clearly report error when an automatic module is used
sundar
parents:
47216
diff
changeset
|
239 |
try { |
fb677b3f0888
8189671: jlink should clearly report error when an automatic module is used
sundar
parents:
47216
diff
changeset
|
240 |
JImageGenerator.getJLinkTask() |
fb677b3f0888
8189671: jlink should clearly report error when an automatic module is used
sundar
parents:
47216
diff
changeset
|
241 |
.output(imageFile) |
fb677b3f0888
8189671: jlink should clearly report error when an automatic module is used
sundar
parents:
47216
diff
changeset
|
242 |
.addMods(rootMod) |
fb677b3f0888
8189671: jlink should clearly report error when an automatic module is used
sundar
parents:
47216
diff
changeset
|
243 |
.modulePath(helper.defaultModulePath()) |
fb677b3f0888
8189671: jlink should clearly report error when an automatic module is used
sundar
parents:
47216
diff
changeset
|
244 |
.call().assertFailure("Error: automatic module cannot be used with jlink: " + autoJarName); |
fb677b3f0888
8189671: jlink should clearly report error when an automatic module is used
sundar
parents:
47216
diff
changeset
|
245 |
} finally { |
fb677b3f0888
8189671: jlink should clearly report error when an automatic module is used
sundar
parents:
47216
diff
changeset
|
246 |
autoJarFile.delete(); |
fb677b3f0888
8189671: jlink should clearly report error when an automatic module is used
sundar
parents:
47216
diff
changeset
|
247 |
} |
fb677b3f0888
8189671: jlink should clearly report error when an automatic module is used
sundar
parents:
47216
diff
changeset
|
248 |
} |
fb677b3f0888
8189671: jlink should clearly report error when an automatic module is used
sundar
parents:
47216
diff
changeset
|
249 |
|
36511 | 250 |
// Temporarily exclude; the jmod tool can no longer be used to create a jmod |
251 |
// with a class in the unnamed package. Find another way, or remove. |
|
252 |
// public void testAddDefaultPackage() throws IOException { |
|
253 |
// String moduleName = "hacked1"; |
|
254 |
// Path module = helper.generateModuleCompiledClasses(helper.getJmodSrcDir(), helper.getJmodClassesDir(), |
|
255 |
// moduleName, Arrays.asList("hacked1.Main", "A", "B"), "leaf1"); |
|
256 |
// JImageGenerator |
|
257 |
// .getJModTask() |
|
258 |
// .addClassPath(module) |
|
259 |
// .jmod(helper.getJmodDir().resolve(moduleName + ".jmod")) |
|
260 |
// .create().assertSuccess(); |
|
261 |
// Path image = helper.generateDefaultImage(moduleName).assertSuccess(); |
|
262 |
// helper.checkImage(image, moduleName, null, null); |
|
263 |
// } |
|
264 |
||
265 |
public void testAddSomeTopLevelFiles() throws IOException { |
|
266 |
String moduleName = "hacked2"; |
|
267 |
Path module = helper.generateModuleCompiledClasses(helper.getJmodSrcDir(), helper.getJmodClassesDir(), |
|
268 |
moduleName); |
|
269 |
Files.createFile(module.resolve("top-level-file")); |
|
270 |
Path jmod = JImageGenerator |
|
271 |
.getJModTask() |
|
272 |
.addClassPath(module) |
|
273 |
.jmod(helper.getJmodDir().resolve(moduleName + ".jmod")) |
|
274 |
.create().assertSuccess(); |
|
275 |
try { |
|
276 |
Path image = helper.generateDefaultImage(moduleName).assertSuccess(); |
|
277 |
helper.checkImage(image, moduleName, null, null); |
|
278 |
} finally { |
|
279 |
deleteDirectory(jmod); |
|
280 |
} |
|
281 |
} |
|
282 |
||
283 |
public void testAddNonStandardSection() throws IOException { |
|
284 |
String moduleName = "hacked3"; |
|
285 |
Path module = helper.generateDefaultJModule(moduleName).assertSuccess(); |
|
286 |
JImageGenerator.addFiles(module, new InMemoryFile("unknown/A.class", new byte[0])); |
|
287 |
try { |
|
288 |
Result result = helper.generateDefaultImage(moduleName); |
|
41352 | 289 |
System.err.println(result.getMessage()); |
290 |
if (result.getExitCode() == 0) { |
|
36511 | 291 |
throw new AssertionError("Crash expected"); |
292 |
} |
|
293 |
} finally { |
|
294 |
deleteDirectory(module); |
|
295 |
} |
|
296 |
} |
|
297 |
||
298 |
@Test(enabled = true) |
|
299 |
public void testSectionsAreFiles() throws IOException { |
|
41352 | 300 |
String moduleName = "hacked4"; |
36511 | 301 |
Path jmod = helper.generateDefaultJModule(moduleName).assertSuccess(); |
302 |
JImageGenerator.addFiles(jmod, |
|
43729
21db38703675
8174739: Rename JMOD section name for native libraries from native to lib
mchung
parents:
43712
diff
changeset
|
303 |
new InMemoryFile("/lib", new byte[0]), |
36511 | 304 |
new InMemoryFile("/conf", new byte[0]), |
305 |
new InMemoryFile("/bin", new byte[0])); |
|
306 |
try { |
|
307 |
Result result = helper.generateDefaultImage(moduleName); |
|
41352 | 308 |
System.err.println(result.getMessage()); |
309 |
if (result.getExitCode() == 0) { |
|
36511 | 310 |
throw new AssertionError("Crash expected"); |
311 |
} |
|
312 |
} finally { |
|
313 |
deleteDirectory(jmod); |
|
314 |
} |
|
315 |
} |
|
316 |
||
317 |
public void testDuplicateModule1() throws IOException { |
|
318 |
String moduleName1 = "dupRes1Jmod1"; |
|
319 |
String moduleName2 = "dupRes1Jmod2"; |
|
320 |
List<String> classNames = Arrays.asList("java.A", "javax.B"); |
|
321 |
Path module1 = helper.generateModuleCompiledClasses( |
|
322 |
helper.getJmodSrcDir(), helper.getJmodClassesDir(), moduleName1, classNames); |
|
323 |
Path module2 = helper.generateModuleCompiledClasses( |
|
324 |
helper.getJmodSrcDir(), helper.getJmodClassesDir(), moduleName2, classNames); |
|
325 |
||
326 |
try (OutputStream out = Files.newOutputStream(module2.resolve("module-info.class"))) { |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42338
diff
changeset
|
327 |
ModuleInfoWriter.write(ModuleDescriptor.newModule(moduleName1) |
36511 | 328 |
.requires("java.base").build(), out); |
329 |
} |
|
330 |
||
331 |
Path jmod1 = JImageGenerator.getJModTask() |
|
332 |
.addClassPath(module1) |
|
333 |
.jmod(helper.createNewJmodFile(moduleName1)) |
|
334 |
.create() |
|
335 |
.assertSuccess(); |
|
336 |
Path jmod2 = JImageGenerator.getJModTask() |
|
337 |
.addClassPath(module2) |
|
338 |
.jmod(helper.createNewJmodFile(moduleName2)) |
|
339 |
.create() |
|
340 |
.assertSuccess(); |
|
341 |
try { |
|
342 |
helper.generateDefaultImage(moduleName1) |
|
343 |
.assertFailure("Error: Two versions of module dupRes1Jmod1 found in"); |
|
344 |
} finally { |
|
345 |
deleteDirectory(jmod1); |
|
346 |
deleteDirectory(jmod2); |
|
347 |
} |
|
348 |
} |
|
349 |
||
350 |
public void testDuplicateModule2() throws IOException { |
|
351 |
String moduleName = "dupRes2Jmod"; |
|
352 |
List<String> classNames = Arrays.asList("java.A", "javax.B"); |
|
353 |
Path module1 = helper.generateModuleCompiledClasses( |
|
354 |
helper.getJmodSrcDir(), helper.getJmodClassesDir(), moduleName, classNames); |
|
355 |
Path module2 = helper.generateModuleCompiledClasses( |
|
356 |
helper.getJarSrcDir(), helper.getJarClassesDir(), moduleName, classNames); |
|
357 |
||
358 |
Path jmod = JImageGenerator.getJModTask() |
|
359 |
.addClassPath(module1) |
|
360 |
.jmod(helper.createNewJmodFile(moduleName)) |
|
361 |
.create() |
|
362 |
.assertSuccess(); |
|
363 |
Path jar = JImageGenerator.createJarFile(helper.getJarDir().resolve(moduleName + ".jar"), module2); |
|
364 |
Path newJar = helper.getJmodDir().resolve(jar.getFileName()); |
|
365 |
Files.move(jar, newJar); |
|
366 |
try { |
|
367 |
helper.generateDefaultImage(moduleName) |
|
368 |
.assertFailure("Error: Two versions of module dupRes2Jmod found in"); |
|
369 |
} finally { |
|
370 |
deleteDirectory(jmod); |
|
371 |
deleteDirectory(newJar); |
|
372 |
} |
|
373 |
} |
|
374 |
||
375 |
public void testDuplicateModule3() throws IOException { |
|
376 |
String moduleName1 = "dupRes3Jar1"; |
|
377 |
String moduleName2 = "dupRes3Jar2"; |
|
378 |
List<String> classNames = Arrays.asList("java.A", "javax.B"); |
|
379 |
Path module1 = helper.generateModuleCompiledClasses( |
|
380 |
helper.getJarSrcDir(), helper.getJarClassesDir(), moduleName1, classNames); |
|
381 |
Path module2 = helper.generateModuleCompiledClasses( |
|
382 |
helper.getJarSrcDir(), helper.getJarClassesDir(), moduleName2, classNames); |
|
383 |
||
384 |
try (OutputStream out = Files.newOutputStream(module2.resolve("module-info.class"))) { |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42338
diff
changeset
|
385 |
ModuleInfoWriter.write(ModuleDescriptor.newModule(moduleName1) |
36511 | 386 |
.requires("java.base").build(), out); |
387 |
} |
|
388 |
||
389 |
Path jar1 = JImageGenerator.createJarFile(helper.getJarDir().resolve(moduleName1 + ".jar"), module1); |
|
390 |
Path jar2 = JImageGenerator.createJarFile(helper.getJarDir().resolve(moduleName2 + ".jar"), module2); |
|
391 |
try { |
|
392 |
helper.generateDefaultImage(moduleName1) |
|
393 |
.assertFailure("Error: Two versions of module dupRes3Jar1 found in"); |
|
394 |
} finally { |
|
395 |
deleteDirectory(jar1); |
|
396 |
deleteDirectory(jar2); |
|
397 |
} |
|
398 |
} |
|
43796
c204d2d789dc
8174718: "Module <name>'s descriptor returns inconsistent package set" confusing
sundar
parents:
43729
diff
changeset
|
399 |
|
c204d2d789dc
8174718: "Module <name>'s descriptor returns inconsistent package set" confusing
sundar
parents:
43729
diff
changeset
|
400 |
public void testInconsistentModuleInfo() throws IOException { |
c204d2d789dc
8174718: "Module <name>'s descriptor returns inconsistent package set" confusing
sundar
parents:
43729
diff
changeset
|
401 |
String moduleName = "inconsistentJar"; |
c204d2d789dc
8174718: "Module <name>'s descriptor returns inconsistent package set" confusing
sundar
parents:
43729
diff
changeset
|
402 |
List<String> classNames = Arrays.asList("xorg.acme.internal.B"); |
c204d2d789dc
8174718: "Module <name>'s descriptor returns inconsistent package set" confusing
sundar
parents:
43729
diff
changeset
|
403 |
Path module = helper.generateModuleCompiledClasses( |
c204d2d789dc
8174718: "Module <name>'s descriptor returns inconsistent package set" confusing
sundar
parents:
43729
diff
changeset
|
404 |
helper.getJarSrcDir(), helper.getJarClassesDir(), moduleName, classNames); |
c204d2d789dc
8174718: "Module <name>'s descriptor returns inconsistent package set" confusing
sundar
parents:
43729
diff
changeset
|
405 |
|
c204d2d789dc
8174718: "Module <name>'s descriptor returns inconsistent package set" confusing
sundar
parents:
43729
diff
changeset
|
406 |
try (OutputStream out = Files.newOutputStream(module.resolve("module-info.class"))) { |
c204d2d789dc
8174718: "Module <name>'s descriptor returns inconsistent package set" confusing
sundar
parents:
43729
diff
changeset
|
407 |
ModuleInfoWriter.write(ModuleDescriptor.newModule(moduleName) |
c204d2d789dc
8174718: "Module <name>'s descriptor returns inconsistent package set" confusing
sundar
parents:
43729
diff
changeset
|
408 |
.requires("java.base") |
c204d2d789dc
8174718: "Module <name>'s descriptor returns inconsistent package set" confusing
sundar
parents:
43729
diff
changeset
|
409 |
.packages(Set.of("org.acme.internal")) |
c204d2d789dc
8174718: "Module <name>'s descriptor returns inconsistent package set" confusing
sundar
parents:
43729
diff
changeset
|
410 |
.build(), out); |
c204d2d789dc
8174718: "Module <name>'s descriptor returns inconsistent package set" confusing
sundar
parents:
43729
diff
changeset
|
411 |
} |
c204d2d789dc
8174718: "Module <name>'s descriptor returns inconsistent package set" confusing
sundar
parents:
43729
diff
changeset
|
412 |
|
c204d2d789dc
8174718: "Module <name>'s descriptor returns inconsistent package set" confusing
sundar
parents:
43729
diff
changeset
|
413 |
Path jar = JImageGenerator.createJarFile(helper.getJarDir().resolve(moduleName + ".jar"), module); |
c204d2d789dc
8174718: "Module <name>'s descriptor returns inconsistent package set" confusing
sundar
parents:
43729
diff
changeset
|
414 |
try { |
c204d2d789dc
8174718: "Module <name>'s descriptor returns inconsistent package set" confusing
sundar
parents:
43729
diff
changeset
|
415 |
helper.generateDefaultImage(moduleName) |
c204d2d789dc
8174718: "Module <name>'s descriptor returns inconsistent package set" confusing
sundar
parents:
43729
diff
changeset
|
416 |
.assertFailure("Module inconsistentJar's descriptor indicates the set of packages is : " + |
c204d2d789dc
8174718: "Module <name>'s descriptor returns inconsistent package set" confusing
sundar
parents:
43729
diff
changeset
|
417 |
"[org.acme.internal], but module contains packages: [xorg.acme.internal]"); |
c204d2d789dc
8174718: "Module <name>'s descriptor returns inconsistent package set" confusing
sundar
parents:
43729
diff
changeset
|
418 |
} finally { |
c204d2d789dc
8174718: "Module <name>'s descriptor returns inconsistent package set" confusing
sundar
parents:
43729
diff
changeset
|
419 |
deleteDirectory(jar); |
c204d2d789dc
8174718: "Module <name>'s descriptor returns inconsistent package set" confusing
sundar
parents:
43729
diff
changeset
|
420 |
} |
c204d2d789dc
8174718: "Module <name>'s descriptor returns inconsistent package set" confusing
sundar
parents:
43729
diff
changeset
|
421 |
} |
36511 | 422 |
} |