changeset 15249:0c64168d5972

Update jmod tool to allow the OS name/arch/version be set
author alanb
date Mon, 15 Feb 2016 17:37:42 +0000
parents 3460276898d9
children acb358e088e2
files src/jdk.jlink/share/classes/jdk/tools/jmod/JmodTask.java src/jdk.jlink/share/classes/jdk/tools/jmod/resources/jmod.properties
diffstat 2 files changed, 55 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.jlink/share/classes/jdk/tools/jmod/JmodTask.java	Mon Feb 15 08:01:31 2016 -0800
+++ b/src/jdk.jlink/share/classes/jdk/tools/jmod/JmodTask.java	Mon Feb 15 17:37:42 2016 +0000
@@ -29,7 +29,6 @@
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -174,6 +173,9 @@
         ModuleFinder moduleFinder;
         Version moduleVersion;
         String mainClass;
+        String osName;
+        String osArch;
+        String osVersion;
         Pattern dependenciesToHash;
         List<PathMatcher> excludes;
     }
@@ -293,8 +295,8 @@
                 throw new IOException("error opening jmod file", x);
             }
 
-            try (FileInputStream fis = new FileInputStream(options.jmodFile.toFile())) {
-                boolean found = printModuleDescriptor(fis);
+            try (InputStream in = Files.newInputStream(options.jmodFile)) {
+                boolean found = printModuleDescriptor(in);
                 if (!found)
                     throw new CommandException("err.module.descriptor.not.found");
                 return found;
@@ -313,11 +315,11 @@
                   .collect(joining(", ", prefix, suffix));
     }
 
-    private boolean printModuleDescriptor(FileInputStream fis)
+    private boolean printModuleDescriptor(InputStream in)
         throws IOException
     {
         final String mi = Section.CLASSES.jmodDir() + "/" + MODULE_INFO;
-        try (BufferedInputStream bis = new BufferedInputStream(fis);
+        try (BufferedInputStream bis = new BufferedInputStream(in);
              ZipInputStream zis = new ZipInputStream(bis)) {
 
             ZipEntry e;
@@ -366,6 +368,18 @@
                         s.forEach(p -> sb.append("\n  ").append(p));
                     }
 
+                    Optional<String> osname = md.osName();
+                    if (osname.isPresent())
+                        sb.append("\nOperating system name:\n  " + osname.get());
+
+                    Optional<String> osarch = md.osArch();
+                    if (osarch.isPresent())
+                        sb.append("\nOperating system architecture:\n  " + osarch.get());
+
+                    Optional<String> osversion = md.osVersion();
+                    if (osversion.isPresent())
+                        sb.append("\nOperating system version:\n  " + osversion.get());
+
                     try {
                         Method m = ModuleDescriptor.class.getDeclaredMethod("hashes");
                         m.setAccessible(true);
@@ -384,7 +398,7 @@
                     } catch (ReflectiveOperationException x) {
                         throw new InternalError(x);
                     }
-                    out.print(sb.toString());
+                    out.println(sb.toString());
                     return true;
                 }
             }
@@ -407,13 +421,16 @@
     }
 
     private class JmodFileWriter {
+        final ModuleFinder moduleFinder = options.moduleFinder;
         final List<Path> cmds = options.cmds;
         final List<Path> libs = options.libs;
         final List<Path> configs = options.configs;
         final List<Path> classpath = options.classpath;
         final Version moduleVersion = options.moduleVersion;
         final String mainClass = options.mainClass;
-        final ModuleFinder moduleFinder = options.moduleFinder;
+        final String osName = options.osName;
+        final String osArch = options.osArch;
+        final String osVersion = options.osVersion;
         final Pattern dependenciesToHash = options.dependenciesToHash;
         final List<PathMatcher> excludes = options.excludes;
 
@@ -513,6 +530,10 @@
                 if (mainClass != null)
                     extender.mainClass(mainClass);
 
+                // --os-name, --os-arch, --os-version
+                if (osName != null || osArch != null || osVersion != null)
+                    extender.targetPlatform(osName, osArch, osVersion);
+
                 // --module-version
                 if (moduleVersion != null)
                     extender.version(moduleVersion);
@@ -992,6 +1013,21 @@
                         .withRequiredArg()
                         .withValuesConvertedBy(new ModuleVersionConverter());
 
+        OptionSpec<String> osName
+                = parser.accepts("os-name", getMessage("main.opt.os-name"))
+                        .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"));
+
+        OptionSpec<String> osVersion
+                = parser.accepts("os-version", getMessage("main.opt.os-version"))
+                        .withRequiredArg()
+                        .describedAs(getMessage("main.opt.os-version.arg"));
+
         OptionSpec<Void> version
                 = parser.accepts("version", getMessage("main.opt.version"));
 
@@ -1048,6 +1084,12 @@
                 options.moduleVersion = opts.valueOf(moduleVersion);
             if (opts.has(mainClass))
                 options.mainClass = opts.valueOf(mainClass);
+            if (opts.has(osName))
+                options.osName = opts.valueOf(osName);
+            if (opts.has(osArch))
+                options.osArch = opts.valueOf(osArch);
+            if (opts.has(osVersion))
+                options.osVersion = opts.valueOf(osVersion);
             if (opts.has(hashDependencies)) {
                 options.dependenciesToHash = opts.valueOf(hashDependencies);
                 // if storing hashes of dependencies then the module path is required
--- a/src/jdk.jlink/share/classes/jdk/tools/jmod/resources/jmod.properties	Mon Feb 15 08:01:31 2016 -0800
+++ b/src/jdk.jlink/share/classes/jdk/tools/jmod/resources/jmod.properties	Mon Feb 15 17:37:42 2016 +0000
@@ -23,6 +23,12 @@
 main.opt.modulepath=Module path
 main.opt.main-class=Main class
 main.opt.main-class.arg=class-name
+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.os-version=Operating system version
+main.opt.os-version.arg=os-version
 main.opt.hash-dependencies=Compute and record hashes of dependencies matched by the pattern
 main.opt.cmdfile=Read options from the specified file