changeset 40939:7262d01be07b

8163320: JAVA_VERSION in release file should come from java.base module Reviewed-by: mchung
author sundar
date Tue, 13 Sep 2016 20:59:43 +0530
parents 5b0977acc842
children 1413b2ff89e4
files jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/builder/DefaultImageBuilder.java jdk/test/tools/jlink/IntegrationTest.java
diffstat 2 files changed, 45 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/builder/DefaultImageBuilder.java	Tue Sep 13 14:47:29 2016 +0100
+++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/builder/DefaultImageBuilder.java	Tue Sep 13 20:59:43 2016 +0530
@@ -55,6 +55,7 @@
 import java.util.Optional;
 import java.util.Properties;
 import java.util.Set;
+import java.util.stream.Collectors;
 import jdk.tools.jlink.internal.BasicImageWriter;
 import jdk.tools.jlink.internal.plugins.FileCopierPlugin.SymImageFile;
 import jdk.tools.jlink.internal.ExecutableImage;
@@ -159,7 +160,7 @@
             }
             i++;
         }
-        props.setProperty("MODULES", builder.toString());
+        props.setProperty("MODULES", quote(builder.toString()));
     }
 
     @Override
@@ -217,19 +218,38 @@
         }
     }
 
+    // Parse version string and return a string that includes only version part
+    // leaving "pre", "build" information. See also: java.lang.Runtime.Version.
+    private static String parseVersion(String str) {
+        return Runtime.Version.parse(str).
+            version().
+            stream().
+            map(Object::toString).
+            collect(Collectors.joining("."));
+    }
+
+    private static String quote(String str) {
+        return "\"" + str + "\"";
+    }
+
     private Properties releaseProperties(ResourcePool pool) throws IOException {
         Properties props = new Properties();
         Optional<ResourcePoolModule> javaBase = pool.moduleView().findModule("java.base");
         javaBase.ifPresent(mod -> {
             // fill release information available from transformed "java.base" module!
             ModuleDescriptor desc = mod.descriptor();
-            desc.osName().ifPresent(s -> props.setProperty("OS_NAME", s));
-            desc.osVersion().ifPresent(s -> props.setProperty("OS_VERSION", s));
-            desc.osArch().ifPresent(s -> props.setProperty("OS_ARCH", s));
-            props.setProperty("JAVA_VERSION", System.getProperty("java.version"));
+            desc.osName().ifPresent(s -> {
+                props.setProperty("OS_NAME", quote(s));
+                this.targetOsName = s;
+            });
+            desc.osVersion().ifPresent(s -> props.setProperty("OS_VERSION", quote(s)));
+            desc.osArch().ifPresent(s -> props.setProperty("OS_ARCH", quote(s)));
+            desc.version().ifPresent(s -> props.setProperty("JAVA_VERSION",
+                    quote(parseVersion(s.toString()))));
+            desc.version().ifPresent(s -> props.setProperty("JAVA_FULL_VERSION",
+                    quote(s.toString())));
         });
 
-        this.targetOsName = props.getProperty("OS_NAME");
         if (this.targetOsName == null) {
             throw new PluginException("TargetPlatform attribute is missing for java.base module");
         }
--- a/jdk/test/tools/jlink/IntegrationTest.java	Tue Sep 13 14:47:29 2016 +0100
+++ b/jdk/test/tools/jlink/IntegrationTest.java	Tue Sep 13 20:59:43 2016 +0530
@@ -210,25 +210,29 @@
             props.load(reader);
         }
 
-        if (props.getProperty("JAVA_VERSION") == null) {
-            throw new AssertionError("release file does not contain JAVA_VERSION");
-        }
-
-        if (props.getProperty("OS_NAME") == null) {
-            throw new AssertionError("release file does not contain OS_NAME");
-        }
-
-        if (props.getProperty("OS_ARCH") == null) {
-            throw new AssertionError("release file does not contain OS_ARCH");
-        }
-
-        if (props.getProperty("OS_VERSION") == null) {
-            throw new AssertionError("release file does not contain OS_VERSION");
-        }
+        checkReleaseProperty(props, "JAVA_VERSION");
+        checkReleaseProperty(props, "JAVA_FULL_VERSION");
+        checkReleaseProperty(props, "OS_NAME");
+        checkReleaseProperty(props, "OS_ARCH");
+        checkReleaseProperty(props, "OS_VERSION");
 
         if (!Files.exists(output.resolve("toto.txt"))) {
             throw new AssertionError("Post processing not called");
         }
 
     }
+
+    static void checkReleaseProperty(Properties props, String name) {
+        if (! props.containsKey(name)) {
+            throw new AssertionError("release file does not contain property : " + name);
+        }
+
+        // property value is of min. length 3 and double quoted at the ends.
+        String value = props.getProperty(name);
+        if (value.length() < 3 ||
+            value.charAt(0) != '"' ||
+            value.charAt(value.length() - 1) != '"') {
+            throw new AssertionError("release property " + name + " is not quoted property");
+        }
+    }
 }