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 * @bug 8142968 8166568
27 * @summary Basic test for jmod
28 * @library /lib/testlibrary
29 * @modules jdk.compiler
30 * jdk.jlink
31 * @build jdk.testlibrary.FileUtils CompilerUtils
32 * @run testng JmodTest
33 */
34
35 import java.io.*;
36 import java.lang.module.ModuleDescriptor;
37 import java.lang.reflect.Method;
38 import java.nio.file.*;
39 import java.util.*;
40 import java.util.function.Consumer;
41 import java.util.regex.Pattern;
42 import java.util.spi.ToolProvider;
43 import java.util.stream.Stream;
44 import jdk.testlibrary.FileUtils;
45 import org.testng.annotations.BeforeTest;
46 import org.testng.annotations.Test;
97 assertTrue(compileModule("apa", classesDir));
98 Path libDir = apaDir.resolve("lib");
99 createFiles(libDir, List.of("foo/bar/libfoo.so"));
100 try {
101 Path link = Files.createSymbolicLink(
102 libDir.resolve("baz"), libDir.resolve("foo").toAbsolutePath());
103 assertTrue(Files.exists(link));
104 } catch (UnsupportedOperationException uoe) {
105 // OS does not support symlinks. Nothing to test!
106 return;
107 }
108
109 Path jmod = MODS_DIR.resolve("apa.jmod");
110 jmod("create",
111 "--libs=", libDir.toString(),
112 "--class-path", classesDir.toString(),
113 jmod.toString())
114 .assertSuccess();
115 }
116
117 @Test
118 public void testList() throws IOException {
119 String cp = EXPLODED_DIR.resolve("foo").resolve("classes").toString();
120 jmod("create",
121 "--class-path", cp,
122 MODS_DIR.resolve("foo.jmod").toString())
123 .assertSuccess();
124
125 jmod("list",
126 MODS_DIR.resolve("foo.jmod").toString())
127 .assertSuccess()
128 .resultChecker(r -> {
129 // asserts dependent on the exact contents of foo
130 assertContains(r.output, CLASSES_PREFIX + "module-info.class");
131 assertContains(r.output, CLASSES_PREFIX + "jdk/test/foo/Foo.class");
132 assertContains(r.output, CLASSES_PREFIX + "jdk/test/foo/internal/Message.class");
133 assertContains(r.output, CLASSES_PREFIX + "jdk/test/foo/resources/foo.properties");
134 });
135 }
136
|
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 * @bug 8142968 8166568 8166286 8170618
27 * @summary Basic test for jmod
28 * @library /lib/testlibrary
29 * @modules jdk.compiler
30 * jdk.jlink
31 * @build jdk.testlibrary.FileUtils CompilerUtils
32 * @run testng JmodTest
33 */
34
35 import java.io.*;
36 import java.lang.module.ModuleDescriptor;
37 import java.lang.reflect.Method;
38 import java.nio.file.*;
39 import java.util.*;
40 import java.util.function.Consumer;
41 import java.util.regex.Pattern;
42 import java.util.spi.ToolProvider;
43 import java.util.stream.Stream;
44 import jdk.testlibrary.FileUtils;
45 import org.testng.annotations.BeforeTest;
46 import org.testng.annotations.Test;
97 assertTrue(compileModule("apa", classesDir));
98 Path libDir = apaDir.resolve("lib");
99 createFiles(libDir, List.of("foo/bar/libfoo.so"));
100 try {
101 Path link = Files.createSymbolicLink(
102 libDir.resolve("baz"), libDir.resolve("foo").toAbsolutePath());
103 assertTrue(Files.exists(link));
104 } catch (UnsupportedOperationException uoe) {
105 // OS does not support symlinks. Nothing to test!
106 return;
107 }
108
109 Path jmod = MODS_DIR.resolve("apa.jmod");
110 jmod("create",
111 "--libs=", libDir.toString(),
112 "--class-path", classesDir.toString(),
113 jmod.toString())
114 .assertSuccess();
115 }
116
117 // JDK-8170618 - jmod should validate if any exported or open package is missing
118 @Test
119 public void testMissingPackages() throws IOException {
120 Path apaDir = EXPLODED_DIR.resolve("apa");
121 Path classesDir = EXPLODED_DIR.resolve("apa").resolve("classes");
122 if (Files.exists(classesDir))
123 FileUtils.deleteFileTreeWithRetry(classesDir);
124 assertTrue(compileModule("apa", classesDir));
125 FileUtils.deleteFileTreeWithRetry(classesDir.resolve("jdk"));
126 Path jmod = MODS_DIR.resolve("apa.jmod");
127 jmod("create",
128 "--class-path", classesDir.toString(),
129 jmod.toString())
130 .assertFailure()
131 .resultChecker(r -> {
132 assertContains(r.output, "Packages that are exported or open in apa are not present: [jdk.test.apa]");
133 });
134 if (Files.exists(classesDir))
135 FileUtils.deleteFileTreeWithRetry(classesDir);
136 }
137
138 @Test
139 public void testList() throws IOException {
140 String cp = EXPLODED_DIR.resolve("foo").resolve("classes").toString();
141 jmod("create",
142 "--class-path", cp,
143 MODS_DIR.resolve("foo.jmod").toString())
144 .assertSuccess();
145
146 jmod("list",
147 MODS_DIR.resolve("foo.jmod").toString())
148 .assertSuccess()
149 .resultChecker(r -> {
150 // asserts dependent on the exact contents of foo
151 assertContains(r.output, CLASSES_PREFIX + "module-info.class");
152 assertContains(r.output, CLASSES_PREFIX + "jdk/test/foo/Foo.class");
153 assertContains(r.output, CLASSES_PREFIX + "jdk/test/foo/internal/Message.class");
154 assertContains(r.output, CLASSES_PREFIX + "jdk/test/foo/resources/foo.properties");
155 });
156 }
157
|