changeset 14170:7187c680d9d0

Bug fix in jar tool when replacing module-info.class
author chegar
date Thu, 01 Oct 2015 16:23:20 +0100
parents 521434b30dce
children 55a274769894
files src/jdk.jartool/share/classes/sun/tools/jar/Main.java test/tools/jar/modularJar/Basic.java
diffstat 2 files changed, 40 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.jartool/share/classes/sun/tools/jar/Main.java	Thu Oct 01 14:42:10 2015 +0100
+++ b/src/jdk.jartool/share/classes/sun/tools/jar/Main.java	Thu Oct 01 16:23:20 2015 +0100
@@ -801,7 +801,7 @@
                     return false;
                 }
             } else if (isModuleInfoEntry
-                       && ((newModuleInfo == null) || (ename != null)
+                       && ((newModuleInfo != null) || (ename != null)
                            || moduleVersion != null || dependenciesToHash != null)) {
                 if (newModuleInfo == null) {
                     // Update existing module-info.class
--- a/test/tools/jar/modularJar/Basic.java	Thu Oct 01 14:42:10 2015 +0100
+++ b/test/tools/jar/modularJar/Basic.java	Thu Oct 01 16:23:20 2015 +0100
@@ -179,7 +179,7 @@
             .assertSuccess();
         java(mp, FOO.moduleName + "/" + FOO.mainClass)
             .assertSuccess()
-            .resultChecker(r -> assertModuleData(r, FOO) );
+            .resultChecker(r -> assertModuleData(r, FOO));
 
         try (InputStream fis = Files.newInputStream(modularJar);
              JarInputStream jis = new JarInputStream(fis)) {
@@ -317,6 +317,44 @@
     }
 
     @Test
+    public void partialUpdateFooModuleInfo() throws IOException {
+        Path mp = Paths.get("partialUpdateFooModuleInfo");
+        createTestDir(mp);
+        Path modClasses = MODULE_CLASSES.resolve(FOO.moduleName);
+        Path modularJar = mp.resolve(FOO.moduleName + ".jar");
+        Path barModInfo = MODULE_CLASSES.resolve(BAR.moduleName);
+
+        jar("--create",
+            "--file=" + modularJar.toString(),
+            "--main-class=" + FOO.mainClass,
+            "--module-version=" + FOO.version,
+            "--no-manifest",
+            "-C", modClasses.toString(), ".")
+            .assertSuccess();
+        jar("--update",
+            "--file=" + modularJar.toString(),
+            "--no-manifest",
+            "-C", barModInfo.toString(), "module-info.class")  // stuff in bar's info
+            .assertSuccess();
+        jar("-p",
+            "--file=" + modularJar.toString())
+            .assertSuccess()
+            .resultChecker(r -> {
+                // Expect similar output: "Name:bar,  Requires: foo,...
+                // Conceals: jdk.test.foo, jdk.test.foo.internal"
+                Pattern p = Pattern.compile("\\s+Name:\\s+bar\\s+Requires:\\s+foo");
+                assertTrue(p.matcher(r.output).find(),
+                           "Expecting to find \"Name: bar, Requires: foo,...\"",
+                           "in output, but did not: [" + r.output + "]");
+                p = Pattern.compile(
+                        "Conceals:\\s+jdk.test.foo\\s+jdk.test.foo.internal");
+                assertTrue(p.matcher(r.output).find(),
+                           "Expecting to find \"Conceals: jdk.test.foo,...\"",
+                           "in output, but did not: [" + r.output + "]");
+            });
+    }
+
+    @Test
     public void dependencesFooBar() throws IOException {
         Path mp = Paths.get("dependencesFooBar");
         createTestDir(mp);