changeset 19573:c5621b8c5c91

Replace jmod --os-name/--os-arch option with --target-platform
author mchung
date Wed, 26 Apr 2017 19:28:35 -0700
parents a3eb50edd55f
children be341882bfba
files src/jdk.jlink/share/classes/jdk/tools/jlink/internal/Platform.java src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ReleaseInfoPlugin.java src/jdk.jlink/share/classes/jdk/tools/jmod/JmodTask.java src/jdk.jlink/share/classes/jdk/tools/jmod/resources/jmod.properties test/tools/jlink/IntegrationTest.java test/tools/jlink/plugins/SystemModuleDescriptors/UserModuleTest.java
diffstat 6 files changed, 31 insertions(+), 48 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/Platform.java	Wed Apr 26 21:09:44 2017 +0100
+++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/Platform.java	Wed Apr 26 19:28:35 2017 -0700
@@ -63,7 +63,7 @@
      */
     public static Platform getTargetPlatform(ResourcePoolModule module) {
         String targetPlatform = module.targetPlatform();
-        if (targetPlatform == null) {
+        if (targetPlatform != null) {
             return toPlatform(targetPlatform);
         } else {
             return Platform.UNKNOWN;
--- a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ReleaseInfoPlugin.java	Wed Apr 26 21:09:44 2017 +0100
+++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ReleaseInfoPlugin.java	Wed Apr 26 19:28:35 2017 -0700
@@ -40,6 +40,7 @@
 import java.util.stream.Collectors;
 import jdk.tools.jlink.internal.ModuleSorter;
 import jdk.tools.jlink.internal.Utils;
+import jdk.tools.jlink.plugin.PluginException;
 import jdk.tools.jlink.plugin.ResourcePool;
 import jdk.tools.jlink.plugin.ResourcePoolBuilder;
 import jdk.tools.jlink.plugin.ResourcePoolEntry;
@@ -132,20 +133,20 @@
     public ResourcePool transform(ResourcePool in, ResourcePoolBuilder out) {
         in.transformAndCopy(Function.identity(), out);
 
-        Optional<ResourcePoolModule> javaBase = in.moduleView().findModule("java.base");
-        javaBase.ifPresent(mod -> {
-            // fill release information available from transformed "java.base" module!
-            ModuleDescriptor desc = mod.descriptor();
-            desc.version().ifPresent(s -> release.put("JAVA_VERSION",
-                    quote(parseVersion(s.toString()))));
-            desc.version().ifPresent(s -> release.put("JAVA_FULL_VERSION",
-                    quote(s.toString())));
+        ResourcePoolModule javaBase = in.moduleView().findModule("java.base")
+                                                     .orElse(null);
+        if (javaBase == null || javaBase.targetPlatform() == null) {
+            throw new PluginException("ModuleTarget attribute is missing for java.base module");
+        }
 
-            String targetPlatform = mod.targetPlatform();
-            String[] values = targetPlatform.split("-");
-            release.put("OS_NAME", quote(values[0]));
-            release.put("OS_ARCH", quote(values[1]));
-        });
+        // fill release information available from transformed "java.base" module!
+        ModuleDescriptor desc = javaBase.descriptor();
+        desc.version().ifPresent(s -> release.put("JAVA_VERSION",
+                                                  quote(parseVersion(s.toString()))));
+        desc.version().ifPresent(s -> release.put("JAVA_FULL_VERSION",
+                                                  quote(s.toString())));
+
+        release.put("TARGET_PLATFORM", quote(javaBase.targetPlatform()));
 
         // put topological sorted module names separated by space
         release.put("MODULES",  new ModuleSorter(in.moduleView())
@@ -154,7 +155,8 @@
 
         // create a TOP level ResourcePoolEntry for "release" file.
         out.add(ResourcePoolEntry.create("/java.base/release",
-            ResourcePoolEntry.Type.TOP, releaseFileContent()));
+                                         ResourcePoolEntry.Type.TOP,
+                                         releaseFileContent()));
         return out.build();
     }
 
--- a/src/jdk.jlink/share/classes/jdk/tools/jmod/JmodTask.java	Wed Apr 26 21:09:44 2017 +0100
+++ b/src/jdk.jlink/share/classes/jdk/tools/jmod/JmodTask.java	Wed Apr 26 19:28:35 2017 -0700
@@ -177,8 +177,7 @@
         ModuleFinder moduleFinder;
         Version moduleVersion;
         String mainClass;
-        String osName;
-        String osArch;
+        String targetPlatform;
         Pattern modulesToHash;
         ModuleResolution moduleResolution;
         boolean dryrun;
@@ -463,8 +462,7 @@
 
         final Version moduleVersion = options.moduleVersion;
         final String mainClass = options.mainClass;
-        final String osName = options.osName;
-        final String osArch = options.osArch;
+        final String targetPlatform = options.targetPlatform;
         final List<PathMatcher> excludes = options.excludes;
         final ModuleResolution moduleResolution = options.moduleResolution;
 
@@ -560,13 +558,9 @@
                 if (mainClass != null)
                     extender.mainClass(mainClass);
 
-                // --os-name, --os-arch
-                if (osName != null || osArch != null) {
-                    String value = "";
-                    if (osName != null) value += osName;
-                    value += "-";
-                    if (osArch != null) value += osArch;
-                    extender.targetPlatform(value);
+                // --target-platform
+                if (targetPlatform != null) {
+                    extender.targetPlatform(targetPlatform);
                 }
 
                 // --module-version
@@ -1358,15 +1352,10 @@
                         .withRequiredArg()
                         .withValuesConvertedBy(new ModuleVersionConverter());
 
-        OptionSpec<String> osName
-                = parser.accepts("os-name", getMessage("main.opt.os-name"))
+        OptionSpec<String> targetPlatform
+                = parser.accepts("target-platform", getMessage("main.opt.target-platform"))
                         .withRequiredArg()
-                        .describedAs(getMessage("main.opt.os-name.arg"));
-
-        OptionSpec<String> osArch
-                = parser.accepts("os-arch", getMessage("main.opt.os-arch"))
-                        .withRequiredArg()
-                        .describedAs(getMessage("main.opt.os-arch.arg"));
+                        .describedAs(getMessage("main.opt.target-platform.arg"));
 
         OptionSpec<Void> doNotResolveByDefault
                 = parser.accepts("do-not-resolve-by-default",
@@ -1431,10 +1420,8 @@
                 options.moduleVersion = getLastElement(opts.valuesOf(moduleVersion));
             if (opts.has(mainClass))
                 options.mainClass = getLastElement(opts.valuesOf(mainClass));
-            if (opts.has(osName))
-                options.osName = getLastElement(opts.valuesOf(osName));
-            if (opts.has(osArch))
-                options.osArch = getLastElement(opts.valuesOf(osArch));
+            if (opts.has(targetPlatform))
+                options.targetPlatform = getLastElement(opts.valuesOf(targetPlatform));
             if (opts.has(warnIfResolved))
                 options.moduleResolution = getLastElement(opts.valuesOf(warnIfResolved));
             if (opts.has(doNotResolveByDefault)) {
--- a/src/jdk.jlink/share/classes/jdk/tools/jmod/resources/jmod.properties	Wed Apr 26 21:09:44 2017 +0100
+++ b/src/jdk.jlink/share/classes/jdk/tools/jmod/resources/jmod.properties	Wed Apr 26 19:28:35 2017 -0700
@@ -64,10 +64,8 @@
 main.opt.main-class=Main class
 main.opt.main-class.arg=class-name
 main.opt.man-pages=Location of man pages
-main.opt.os-name=Operating system name
-main.opt.os-name.arg=os-name
-main.opt.os-arch=Operating system architecture
-main.opt.os-arch.arg=os-arch
+main.opt.target-platform=Target platform
+main.opt.target-platform.arg=target-platform
 main.opt.module-path=Module path
 main.opt.hash-modules=Compute and record hashes to tie a packaged module\
 \ with modules matching the given <regex-pattern> and depending upon it directly\
--- a/test/tools/jlink/IntegrationTest.java	Wed Apr 26 21:09:44 2017 +0100
+++ b/test/tools/jlink/IntegrationTest.java	Wed Apr 26 19:28:35 2017 -0700
@@ -208,10 +208,7 @@
 
         checkReleaseProperty(props, "JAVA_VERSION");
         checkReleaseProperty(props, "JAVA_FULL_VERSION");
-        checkReleaseProperty(props, "OS_NAME");
-        checkReleaseProperty(props, "OS_ARCH");
-        // OS_VERSION is added from makefile. We're testing API-way to create image here!
-        // checkReleaseProperty(props, "OS_VERSION");
+        checkReleaseProperty(props, "TARGET_PLATFORM");
 
         if (!Files.exists(output.resolve("toto.txt"))) {
             throw new AssertionError("Post processing not called");
--- a/test/tools/jlink/plugins/SystemModuleDescriptors/UserModuleTest.java	Wed Apr 26 21:09:44 2017 +0100
+++ b/test/tools/jlink/plugins/SystemModuleDescriptors/UserModuleTest.java	Wed Apr 26 19:28:35 2017 -0700
@@ -229,8 +229,7 @@
         Stream.of(modules).forEach(mn ->
             assertTrue(jmod("create",
                 "--class-path", MODS_DIR.resolve(mn).toString(),
-                "--os-name", osName,
-                "--os-arch", osArch,
+                "--target-platform", mt.targetPlatform(),
                 "--main-class", mn.replace('m', 'p') + ".Main",
                 JMODS_DIR.resolve(mn + ".jmod").toString()) == 0)
         );