--- a/test/langtools/tools/jdeps/MultiReleaseJar.java Mon Sep 10 16:40:59 2018 +0200
+++ b/test/langtools/tools/jdeps/MultiReleaseJar.java Mon Sep 10 12:48:57 2018 -0700
@@ -27,7 +27,7 @@
* @summary Tests for jdeps tool with multi-release jar files
* @modules jdk.jdeps/com.sun.tools.jdeps
* @library mrjar mrjar/base mrjar/9 mrjar/10 mrjar/v9 mrjar/v10
- * @build test.* p.* q.*
+ * @build test.* p.* q.* foo/*
* @run testng MultiReleaseJar
*/
@@ -37,11 +37,9 @@
import org.testng.annotations.Test;
import java.io.File;
-import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;
import java.nio.file.Paths;
-import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;
public class MultiReleaseJar {
@@ -54,10 +52,10 @@
public void initialize() throws Exception {
String testClassPath = System.getProperty("test.class.path", "");
mrjar = Stream.of(testClassPath.split(File.pathSeparator))
- .map(Paths::get)
- .filter(e -> e.endsWith("mrjar"))
- .findAny()
- .orElseThrow(() -> new InternalError("mrjar not found"));
+ .map(Paths::get)
+ .filter(e -> e.endsWith("mrjar"))
+ .findAny()
+ .orElseThrow(() -> new InternalError("mrjar not found"));
testJdk = System.getProperty("test.jdk");
fileSep = System.getProperty("file.separator");
cmdPath = Paths.get(testJdk, "bin");
@@ -65,10 +63,16 @@
@Test
public void basic() throws Exception {
- // build the jar file
+ // build Version.jar, Version_9.jar and main.jar
Result r = run("jar -cf Version.jar -C base test --release 9 -C 9 test --release 10 -C 10 test");
checkResult(r);
+ r = run("jar -cf Version_9.jar -C base test --release 9 -C 9 test");
+ checkResult(r);
+
+ r = run("jar -cf Main.jar test/Main.class");
+ checkResult(r);
+
// try out a bunch of things
r = run("jdeps --multi-release 9 -v missing.jar");
checkResult(r, false, "Warning: Path does not exist: missing.jar");
@@ -78,31 +82,31 @@
r = run("jdeps --multi-release base -v Version.jar");
checkResult(r, true,
- "Version.jar ->",
- "test.Version",
- "test.Version"
+ "Version.jar ->",
+ "test.Version",
+ "test.Version"
);
r = run("jdeps --multi-release 9 -v Version.jar");
checkResult(r, true,
- "Version.jar ->",
- "9/test.NonPublic",
- "9/test.NonPublic",
- "9/test.Version",
- "9/test.Version",
- "9/test.Version",
- "9/test.Version"
+ "Version.jar ->",
+ "9/test.NonPublic",
+ "9/test.NonPublic",
+ "9/test.Version",
+ "9/test.Version",
+ "9/test.Version",
+ "9/test.Version"
);
r = run("jdeps --multi-release 10 -v Version.jar");
checkResult(r, true,
- "Version.jar ->",
- "10/test.Version",
- "10/test.Version",
- "10/test.Version",
- "10/test.Version",
- "9/test.NonPublic",
- "9/test.NonPublic"
+ "Version.jar ->",
+ "10/test.Version",
+ "10/test.Version",
+ "10/test.Version",
+ "10/test.Version",
+ "9/test.NonPublic",
+ "9/test.NonPublic"
);
r = run("jdeps --multi-release 8 -v Version.jar");
@@ -111,82 +115,90 @@
r = run("jdeps --multi-release 9.1 -v Version.jar");
checkResult(r, false, "Error: invalid argument for option: 9.1");
- r = run("jdeps -v -R -cp Version.jar test/Main.class");
+ runJdeps("test/Main.class");
+ runJdeps("Main.jar");
+ }
+
+
+ private void runJdeps(String path) throws Exception {
+ Result r = run("jdeps -v -R -cp Version.jar " + path);
checkResult(r, false, "--multi-release option is not set");
- r = run("jdeps -v -R -cp Version.jar -multi-release 9 test/Main.class");
+ r = run("jdeps -v -R -cp Version.jar -multi-release 9 " + path);
checkResult(r, false,
- "Error: unknown option: -multi-release",
- "Usage: jdeps <options> <path",
- "use --help"
+ "Error: unknown option: -multi-release",
+ "Usage: jdeps <options> <path",
+ "use --help"
);
- r = run("jdeps -v -R -cp Version.jar --multi-release 9 test/Main.class");
+ r = run("jdeps -v -R -cp Version.jar --multi-release 9 " + path);
+
+ String name = path;
+ int index = path.lastIndexOf('/');
+ if (index >= 0) {
+ name = path.substring(index + 1, path.length());
+ }
checkResult(r, true,
- "Main.class ->",
- "Main.class ->",
- "test.Main",
- "test.Main",
- "test.Main",
- "Version.jar ->",
- "9/test.NonPublic",
- "9/test.NonPublic",
- "9/test.Version",
- "9/test.Version",
- "9/test.Version",
- "9/test.Version"
+ name + " ->",
+ name + " ->",
+ "test.Main",
+ "test.Main",
+ "test.Main",
+ "Version.jar ->",
+ "9/test.NonPublic",
+ "9/test.NonPublic",
+ "9/test.Version",
+ "9/test.Version",
+ "9/test.Version",
+ "9/test.Version"
);
- r = run("jdeps -v -R -cp Version.jar --multi-release 10 test/Main.class");
+ r = run("jdeps -v -R -cp Version.jar --multi-release 10 " + path);
checkResult(r, true,
- "Main.class ->",
- "Main.class ->",
- "test.Main",
- "test.Main",
- "test.Main",
- "Version.jar ->",
- "10/test.Version",
- "10/test.Version",
- "10/test.Version",
- "10/test.Version",
- "9/test.NonPublic",
- "9/test.NonPublic"
+ name + " ->",
+ name + " ->",
+ "test.Main",
+ "test.Main",
+ "test.Main",
+ "Version.jar ->",
+ "10/test.Version",
+ "10/test.Version",
+ "10/test.Version",
+ "10/test.Version",
+ "9/test.NonPublic",
+ "9/test.NonPublic"
);
- r = run("jdeps -v -R -cp Version.jar --multi-release base test/Main.class");
+ r = run("jdeps -v -R -cp Version.jar --multi-release base " + path);
checkResult(r, true,
- "Main.class ->",
- "Main.class ->",
- "test.Main",
- "test.Main",
- "test.Main",
- "Version.jar ->",
- "test.Version",
- "test.Version"
+ name + " ->",
+ name + " ->",
+ "test.Main",
+ "test.Main",
+ "test.Main",
+ "Version.jar ->",
+ "test.Version",
+ "test.Version"
);
- r = run("jdeps -v -R -cp Version.jar --multi-release 9.1 test/Main.class");
+ r = run("jdeps -v -R -cp Version.jar --multi-release 9.1 " + path);
checkResult(r, false, "Error: invalid argument for option: 9.1");
- // Rebuild jar without version 10
- r = run("jar -cf Version.jar -C base test --release 9 -C 9 test");
- checkResult(r);
-
- // but ask for version 10
- r = run("jdeps -v -R -cp Version.jar --multi-release 10 test/Main.class");
+ // Version_9.jar does not have any version 10 entry
+ r = run("jdeps -v -R -cp Version_9.jar --multi-release 10 " + path);
checkResult(r, true,
- "Main.class ->",
- "Main.class ->",
- "test.Main",
- "test.Main",
- "test.Main",
- "Version.jar ->",
- "9/test.NonPublic",
- "9/test.NonPublic",
- "9/test.Version",
- "9/test.Version",
- "9/test.Version",
- "9/test.Version"
+ name + " ->",
+ name + " ->",
+ "test.Main",
+ "test.Main",
+ "test.Main",
+ "Version_9.jar ->",
+ "9/test.NonPublic",
+ "9/test.NonPublic",
+ "9/test.Version",
+ "9/test.Version",
+ "9/test.Version",
+ "9/test.Version"
);
}
@@ -198,27 +210,72 @@
r = run("jdeps -v -R -cp PQ.jar --multi-release base PQ.jar");
checkResult(r, true,
- "PQ.jar -> java.base",
- "p.Foo"
+ "PQ.jar -> java.base",
+ "p.Foo"
);
r = run("jdeps -v -R -cp PQ.jar --multi-release 9 PQ.jar");
checkResult(r, true,
- "PQ.jar -> java.base",
- "9/p.Foo",
- "9/p.Foo",
- "9/q.Bar"
+ "PQ.jar -> java.base",
+ "9/p.Foo",
+ "9/p.Foo",
+ "9/q.Bar"
);
r = run("jdeps -v -R -cp PQ.jar --multi-release 10 PQ.jar");
checkResult(r, true,
- "PQ.jar -> java.base",
- "10/q.Bar",
- "10/q.Bar",
- "10/q.Gee",
- "9/p.Foo",
- "9/p.Foo"
+ "PQ.jar -> java.base",
+ "10/q.Bar",
+ "10/q.Bar",
+ "10/q.Gee",
+ "9/p.Foo",
+ "9/p.Foo"
+ );
+ }
+
+ @Test
+ public void modularJar() throws Exception {
+ Result r = run("jar -cf foo.jar -C base p");
+ checkResult(r);
+
+ Path foo = Paths.get(System.getProperty("test.classes")).resolve("modules").resolve("foo");
+ r = run("jar -uf foo.jar --release 9 -C " + foo.toString() + " module-info.class --release 10 -C v10 q");
+ checkResult(r);
+
+ r = run("jdeps -v --multi-release 10 --module-path foo.jar -m foo");
+ checkResult(r, true,
+ "foo", // module name
+ "foo.jar", // the path to foo.jar
+ "requires mandated java.base", // module dependences
+ "foo -> java.base",
+ "10/q.Bar",
+ "10/q.Bar",
+ "10/q.Gee",
+ "p.Foo"
+ );
+
+ r = run("jdeps --multi-release 9 --module-path foo.jar Main.jar");
+ checkResult(r, true,
+ "Main.jar ->",
+ "test",
+ "foo", // module name
+ "foo.jar", // the path to foo.jar
+ "requires mandated java.base", // module dependences
+ "foo -> java.base",
+ "p"
+ );
+
+ r = run("jdeps --multi-release 10 --module-path foo.jar Main.jar");
+ checkResult(r, true,
+ "Main.jar ->",
+ "test",
+ "foo", // module name
+ "foo.jar", // the path to foo.jar
+ "requires mandated java.base", // module dependences
+ "foo -> java.base",
+ "p",
+ "q"
);
}