changeset 52723:f24ae8376e71

8210454: jar tool does not allow setting the module version without also setting the main class Reviewed-by: alanb, mchung, chegar
author lancea
date Wed, 28 Nov 2018 14:49:19 -0500
parents 19de50eb561d
children 0bdbf854472f
files src/jdk.jartool/share/classes/sun/tools/jar/Main.java test/jdk/tools/jar/modularJar/Basic.java
diffstat 2 files changed, 47 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.jartool/share/classes/sun/tools/jar/Main.java	Wed Nov 28 11:09:27 2018 -0800
+++ b/src/jdk.jartool/share/classes/sun/tools/jar/Main.java	Wed Nov 28 14:49:19 2018 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1996, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -693,7 +693,7 @@
             usageError(getMsg("error.bad.cflag"));
             return false;
         } else if (uflag) {
-            if ((mname != null) || (ename != null)) {
+            if ((mname != null) || (ename != null) || moduleVersion != null) {
                 /* just want to update the manifest */
                 return true;
             } else {
--- a/test/jdk/tools/jar/modularJar/Basic.java	Wed Nov 28 11:09:27 2018 -0800
+++ b/test/jdk/tools/jar/modularJar/Basic.java	Wed Nov 28 14:49:19 2018 -0500
@@ -46,7 +46,7 @@
 
 /*
  * @test
- * @bug 8167328 8171830 8165640 8174248 8176772 8196748 8191533
+ * @bug 8167328 8171830 8165640 8174248 8176772 8196748 8191533 8210454
  * @library /test/lib
  * @modules jdk.compiler
  *          jdk.jartool
@@ -878,6 +878,50 @@
         }
     }
 
+    /**
+     * Validate that you can update a jar only specifying --module-version
+     * @throws IOException
+     */
+    @Test
+    public void updateFooModuleVersion() throws IOException {
+        Path mp = Paths.get("updateFooModuleVersion");
+        createTestDir(mp);
+        Path modClasses = MODULE_CLASSES.resolve(FOO.moduleName);
+        Path modularJar = mp.resolve(FOO.moduleName + ".jar");
+        String newFooVersion = "87.0";
+
+        jar("--create",
+            "--file=" + modularJar.toString(),
+            "--main-class=" + FOO.mainClass,
+            "--module-version=" + FOO.version,
+            "--no-manifest",
+            "-C", modClasses.toString(), ".")
+            .assertSuccess();
+
+        jarWithStdin(modularJar.toFile(), "--describe-module")
+                .assertSuccess()
+                .resultChecker(r ->
+                        assertTrue(r.output.contains(FOO.moduleName + "@" + FOO.version),
+                                "Expected to find ", FOO.moduleName + "@" + FOO.version,
+                                " in [", r.output, "]")
+                );
+
+        jar("--update",
+            "--file=" + modularJar.toString(),
+            "--module-version=" + newFooVersion)
+            .assertSuccess();
+
+        for (String option : new String[]  {"--describe-module", "-d" }) {
+            jarWithStdin(modularJar.toFile(),
+                         option)
+                         .assertSuccess()
+                         .resultChecker(r ->
+                             assertTrue(r.output.contains(FOO.moduleName + "@" + newFooVersion),
+                                "Expected to find ", FOO.moduleName + "@" + newFooVersion,
+                                " in [", r.output, "]")
+                );
+        }
+    }
 
     @DataProvider(name = "autoNames")
     public Object[][] autoNames() {