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 Test the recording and checking of module hashes
27 * @author Andrei Eremeev
28 * @library /lib/testlibrary
29 * @modules java.base/jdk.internal.module
30 * jdk.jlink/jdk.tools.jlink.internal
31 * jdk.jlink/jdk.tools.jmod
32 * jdk.compiler
33 * @build CompilerUtils
34 * @run testng HashesTest
35 */
36
37 import java.io.IOException;
38 import java.io.InputStream;
39 import java.lang.module.ModuleDescriptor;
40 import java.lang.module.ModuleFinder;
41 import java.lang.module.ModuleReader;
42 import java.lang.module.ModuleReference;
43 import java.lang.reflect.Method;
44 import java.nio.file.FileVisitResult;
45 import java.nio.file.Files;
46 import java.nio.file.Path;
47 import java.nio.file.Paths;
48 import java.nio.file.SimpleFileVisitor;
49 import java.nio.file.attribute.BasicFileAttributes;
50 import java.util.ArrayList;
51 import java.util.Arrays;
52 import java.util.Collections;
53 import java.util.List;
54 import java.util.Optional;
55 import java.util.Set;
56 import java.util.stream.Collectors;
57
58 import jdk.internal.module.ConfigurableModuleFinder;
59 import jdk.internal.module.ModuleHashes;
60 import org.testng.annotations.BeforeTest;
61 import org.testng.annotations.Test;
62
63 import static org.testng.Assert.*;
64
65 public class HashesTest {
66
67 private final Path testSrc = Paths.get(System.getProperty("test.src"));
68 private final Path modSrc = testSrc.resolve("src");
69 private final Path mods = Paths.get("mods");
70 private final Path jmods = Paths.get("jmods");
71 private final String[] modules = new String[] { "m1", "m2", "m3"};
72
73 private static Method hashesMethod;
74 @BeforeTest
75 private void setup() throws Exception {
76 if (Files.exists(jmods)) {
77 deleteDirectory(jmods);
78 }
79 Files.createDirectories(jmods);
80
81 // build m2, m3 required by m1
82 compileModule("m2", modSrc);
83 jmod("m2");
84
85 compileModule("m3", modSrc);
187 Path msrc = src.resolve(moduleName);
188 assertTrue(CompilerUtils.compile(msrc, mods, "--module-source-path", src.toString()));
189 }
190
191 private void jmod(String moduleName, String... options) throws IOException {
192 Path mclasses = mods.resolve(moduleName);
193 Path outfile = jmods.resolve(moduleName + ".jmod");
194 List<String> args = new ArrayList<>();
195 args.add("create");
196 Collections.addAll(args, options);
197 Collections.addAll(args, "--class-path", mclasses.toString(),
198 outfile.toString());
199
200 if (Files.exists(outfile))
201 Files.delete(outfile);
202
203 runJmod(args);
204 }
205
206 private void runJmod(List<String> args) {
207 int rc = jdk.tools.jmod.Main.run(args.toArray(new String[args.size()]), System.out);
208 System.out.println("jmod options: " + args.stream().collect(Collectors.joining(" ")));
209 if (rc != 0) {
210 throw new AssertionError("Jmod failed: rc = " + rc);
211 }
212 }
213 }
|
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 Test the recording and checking of module hashes
27 * @author Andrei Eremeev
28 * @library /lib/testlibrary
29 * @modules java.base/jdk.internal.module
30 * jdk.jlink
31 * jdk.compiler
32 * @build CompilerUtils
33 * @run testng HashesTest
34 */
35
36 import java.io.IOException;
37 import java.io.InputStream;
38 import java.lang.module.ModuleDescriptor;
39 import java.lang.module.ModuleFinder;
40 import java.lang.module.ModuleReader;
41 import java.lang.module.ModuleReference;
42 import java.lang.reflect.Method;
43 import java.nio.file.FileVisitResult;
44 import java.nio.file.Files;
45 import java.nio.file.Path;
46 import java.nio.file.Paths;
47 import java.nio.file.SimpleFileVisitor;
48 import java.nio.file.attribute.BasicFileAttributes;
49 import java.util.ArrayList;
50 import java.util.Arrays;
51 import java.util.Collections;
52 import java.util.List;
53 import java.util.Optional;
54 import java.util.Set;
55 import java.util.spi.ToolProvider;
56 import java.util.stream.Collectors;
57
58 import jdk.internal.module.ConfigurableModuleFinder;
59 import jdk.internal.module.ModuleHashes;
60 import org.testng.annotations.BeforeTest;
61 import org.testng.annotations.Test;
62
63 import static org.testng.Assert.*;
64
65 public class HashesTest {
66 static final ToolProvider JMOD_TOOL = ToolProvider.findFirst("jmod").get();
67
68 private final Path testSrc = Paths.get(System.getProperty("test.src"));
69 private final Path modSrc = testSrc.resolve("src");
70 private final Path mods = Paths.get("mods");
71 private final Path jmods = Paths.get("jmods");
72 private final String[] modules = new String[] { "m1", "m2", "m3"};
73
74 private static Method hashesMethod;
75 @BeforeTest
76 private void setup() throws Exception {
77 if (Files.exists(jmods)) {
78 deleteDirectory(jmods);
79 }
80 Files.createDirectories(jmods);
81
82 // build m2, m3 required by m1
83 compileModule("m2", modSrc);
84 jmod("m2");
85
86 compileModule("m3", modSrc);
188 Path msrc = src.resolve(moduleName);
189 assertTrue(CompilerUtils.compile(msrc, mods, "--module-source-path", src.toString()));
190 }
191
192 private void jmod(String moduleName, String... options) throws IOException {
193 Path mclasses = mods.resolve(moduleName);
194 Path outfile = jmods.resolve(moduleName + ".jmod");
195 List<String> args = new ArrayList<>();
196 args.add("create");
197 Collections.addAll(args, options);
198 Collections.addAll(args, "--class-path", mclasses.toString(),
199 outfile.toString());
200
201 if (Files.exists(outfile))
202 Files.delete(outfile);
203
204 runJmod(args);
205 }
206
207 private void runJmod(List<String> args) {
208 int rc = JMOD_TOOL.run(System.out, System.out, args.toArray(new String[args.size()]));
209 System.out.println("jmod options: " + args.stream().collect(Collectors.joining(" ")));
210 if (rc != 0) {
211 throw new AssertionError("Jmod failed: rc = " + rc);
212 }
213 }
214 }
|