1 /* |
1 /* |
2 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
52 @Test |
52 @Test |
53 public class ModulesInCustomFileSystem { |
53 public class ModulesInCustomFileSystem { |
54 private static final Path HERE = Paths.get(""); |
54 private static final Path HERE = Paths.get(""); |
55 |
55 |
56 /** |
56 /** |
57 * Test exploded modules in a JAR file system. |
57 * Test exploded modules in a Zip file system. |
58 */ |
58 */ |
59 public void testExplodedModulesInJarFileSystem() throws Exception { |
59 public void testExplodedModulesInZipFileSystem() throws Exception { |
60 Path m1 = findModuleDirectory("m1"); |
60 Path m1 = findModuleDirectory("m1"); |
61 Path m2 = findModuleDirectory("m2"); |
61 Path m2 = findModuleDirectory("m2"); |
62 Path mlib = m1.getParent(); |
62 Path mlib = m1.getParent(); |
63 assertEquals(mlib, m2.getParent()); |
63 assertEquals(mlib, m2.getParent()); |
64 |
64 |
65 // create JAR file containing m1/** and m2/** |
65 // create JAR file containing m1/** and m2/** |
66 Path jar = Files.createTempDirectory(HERE, "mlib").resolve("modules.jar"); |
66 Path jar = Files.createTempDirectory(HERE, "mlib").resolve("modules.jar"); |
67 JarUtils.createJarFile(jar, mlib); |
67 JarUtils.createJarFile(jar, mlib); |
68 testJarFileSystem(jar); |
68 testZipFileSystem(jar); |
69 } |
69 } |
70 |
70 |
71 /** |
71 /** |
72 * Test modular JARs in a JAR file system |
72 * Test modular JARs in a Zip file system. |
73 */ |
73 */ |
74 public void testModularJARsInJarFileSystem() throws Exception { |
74 public void testModularJARsInZipFileSystem() throws Exception { |
75 Path m1 = findModuleDirectory("m1"); |
75 Path m1 = findModuleDirectory("m1"); |
76 Path m2 = findModuleDirectory("m2"); |
76 Path m2 = findModuleDirectory("m2"); |
77 Path contents = Files.createTempDirectory(HERE, "contents"); |
77 Path contents = Files.createTempDirectory(HERE, "contents"); |
78 JarUtils.createJarFile(contents.resolve("m1.jar"), m1); |
78 JarUtils.createJarFile(contents.resolve("m1.jar"), m1); |
79 JarUtils.createJarFile(contents.resolve("m2.jar"), m2); |
79 JarUtils.createJarFile(contents.resolve("m2.jar"), m2); |
80 |
80 |
81 // create JAR file containing m1.jar and m2.jar |
81 // create JAR file containing m1.jar and m2.jar |
82 Path jar = Files.createTempDirectory(HERE, "mlib").resolve("modules.jar"); |
82 Path jar = Files.createTempDirectory(HERE, "mlib").resolve("modules.jar"); |
83 JarUtils.createJarFile(jar, contents); |
83 JarUtils.createJarFile(jar, contents); |
84 testJarFileSystem(jar); |
84 testZipFileSystem(jar); |
85 } |
85 } |
86 |
86 |
87 /** |
87 /** |
88 * Opens a JAR file as a file system |
88 * Opens a JAR file as a file system |
89 */ |
89 */ |
90 private void testJarFileSystem(Path jar) throws Exception { |
90 private void testZipFileSystem(Path zip) throws Exception { |
91 ClassLoader scl = ClassLoader.getSystemClassLoader(); |
91 try (FileSystem fs = FileSystems.newFileSystem(zip)) { |
92 try (FileSystem fs = FileSystems.newFileSystem(jar, scl)) { |
|
93 // ModuleFinder to find modules in top-level directory |
92 // ModuleFinder to find modules in top-level directory |
94 Path top = fs.getPath("/"); |
93 Path top = fs.getPath("/"); |
95 ModuleFinder finder = ModuleFinder.of(top); |
94 ModuleFinder finder = ModuleFinder.of(top); |
96 |
95 |
97 // list the modules |
96 // list the modules |