|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
4 | 4 | *
|
5 | 5 | * This code is free software; you can redistribute it and/or modify it
|
|
23 | 23 |
|
24 | 24 | /**
|
25 | 25 | * @test
|
| 26 | + * @bug 8142968 8253751 |
26 | 27 | * @library /test/lib
|
27 | 28 | * @build AutomaticModulesTest
|
28 | 29 | * jdk.test.lib.util.JarUtils
|
|
42 | 43 | import java.lang.module.ResolvedModule;
|
43 | 44 | import java.nio.file.Files;
|
44 | 45 | import java.nio.file.Path;
|
45 |
| -import java.nio.file.Paths; |
46 | 46 | import java.util.Optional;
|
47 | 47 | import java.util.Set;
|
48 | 48 | import java.util.jar.Attributes;
|
|
60 | 60 | @Test
|
61 | 61 | public class AutomaticModulesTest {
|
62 | 62 |
|
63 |
| - private static final Path USER_DIR |
64 |
| - = Paths.get(System.getProperty("user.dir")); |
| 63 | + private static final Path USER_DIR = Path.of(System.getProperty("user.dir")); |
65 | 64 |
|
66 | 65 | @DataProvider(name = "jarnames")
|
67 | 66 | public Object[][] createJarNames() {
|
@@ -166,7 +165,6 @@ public void testBadNames(String fn, String ignore) throws IOException {
|
166 | 165 | ModuleFinder.of(dir).findAll();
|
167 | 166 | }
|
168 | 167 |
|
169 |
| - |
170 | 168 | @DataProvider(name = "modulenames")
|
171 | 169 | public Object[][] createModuleNames() {
|
172 | 170 | return new Object[][] {
|
@@ -910,6 +908,72 @@ public void testInConfiguration6() throws IOException {
|
910 | 908 | assertTrue(auto3.reads().contains(base));
|
911 | 909 | }
|
912 | 910 |
|
| 911 | + /** |
| 912 | + * Basic test for a module requiring an automatic module in a parent |
| 913 | + * configuration. If an explicit module in a child configuration reads an |
| 914 | + * automatic module in a parent configuration then it should read all |
| 915 | + * automatic modules in the parent configuration. |
| 916 | + */ |
| 917 | + public void testInConfiguration7() throws Exception { |
| 918 | + // m1 requires auto1 |
| 919 | + ModuleDescriptor descriptor1 = ModuleDescriptor.newModule("m1") |
| 920 | + .requires("auto1") |
| 921 | + .build(); |
| 922 | + |
| 923 | + Path dir1 = Files.createTempDirectory(USER_DIR, "mods"); |
| 924 | + createDummyJarFile(dir1.resolve("auto1.jar"), "p1/C.class"); |
| 925 | + createDummyJarFile(dir1.resolve("auto2.jar"), "p2/C.class"); |
| 926 | + |
| 927 | + // module finder locates m1, auto1, and auto2 |
| 928 | + ModuleFinder finder1 = ModuleFinder.compose(ModuleUtils.finderOf(descriptor1), |
| 929 | + ModuleFinder.of(dir1)); |
| 930 | + |
| 931 | + Configuration parent = ModuleLayer.boot().configuration(); |
| 932 | + ResolvedModule base = parent.findModule("java.base").orElseThrow(); |
| 933 | + |
| 934 | + Configuration cf1 = resolve(parent, finder1, "m1"); |
| 935 | + assertTrue(cf1.modules().size() == 3); |
| 936 | + |
| 937 | + ResolvedModule m1 = cf1.findModule("m1").orElseThrow(); |
| 938 | + ResolvedModule auto1 = cf1.findModule("auto1").orElseThrow(); |
| 939 | + ResolvedModule auto2 = cf1.findModule("auto2").orElseThrow(); |
| 940 | + |
| 941 | + assertTrue(m1.reads().size() == 3); |
| 942 | + assertTrue(m1.reads().contains(base)); |
| 943 | + assertTrue(m1.reads().contains(auto1)); |
| 944 | + assertTrue(m1.reads().contains(auto2)); |
| 945 | + |
| 946 | + assertTrue(auto1.reads().contains(base)); |
| 947 | + assertTrue(auto1.reads().contains(m1)); |
| 948 | + assertTrue(auto1.reads().contains(auto2)); |
| 949 | + |
| 950 | + assertTrue(auto2.reads().contains(base)); |
| 951 | + assertTrue(auto2.reads().contains(m1)); |
| 952 | + assertTrue(auto2.reads().contains(auto1)); |
| 953 | + |
| 954 | + // m2 requires auto1 |
| 955 | + ModuleDescriptor descriptor2 = ModuleDescriptor.newModule("m2") |
| 956 | + .requires("auto1") |
| 957 | + .build(); |
| 958 | + |
| 959 | + Path dir2 = Files.createTempDirectory(USER_DIR, "mods"); |
| 960 | + createDummyJarFile(dir1.resolve("auto3.jar"), "p3/C.class"); |
| 961 | + |
| 962 | + // module finder locates m2 and auto3 |
| 963 | + ModuleFinder finder2 = ModuleFinder.compose(ModuleUtils.finderOf(descriptor2), |
| 964 | + ModuleFinder.of(dir2)); |
| 965 | + |
| 966 | + Configuration cf2 = resolve(cf1, finder2, "m2"); |
| 967 | + assertTrue(cf2.modules().size() == 1); // auto3 should not be resolved |
| 968 | + |
| 969 | + ResolvedModule m2 = cf2.findModule("m2").orElseThrow(); |
| 970 | + |
| 971 | + assertTrue(m2.reads().size() == 3); |
| 972 | + assertTrue(m2.reads().contains(base)); |
| 973 | + assertTrue(m2.reads().contains(auto1)); |
| 974 | + assertTrue(m2.reads().contains(auto2)); |
| 975 | + } |
| 976 | + |
913 | 977 | /**
|
914 | 978 | * Basic test of a configuration created with automatic modules
|
915 | 979 | * a requires b* and c*
|
@@ -1105,7 +1169,7 @@ static Path createDummyJarFile(Path jarfile, Manifest man, String... entries)
|
1105 | 1169 | Files.createFile(file);
|
1106 | 1170 | }
|
1107 | 1171 |
|
1108 |
| - Path[] paths = Stream.of(entries).map(Paths::get).toArray(Path[]::new); |
| 1172 | + Path[] paths = Stream.of(entries).map(Path::of).toArray(Path[]::new); |
1109 | 1173 | JarUtils.createJarFile(jarfile, man, dir, paths);
|
1110 | 1174 | return jarfile;
|
1111 | 1175 | }
|
|
0 commit comments