changeset 14821:85beaf633296

Handle architecture in VM selection.
author jfdenise
date Wed, 23 Dec 2015 10:33:24 +0100
parents 135353aa285a
children aa701826525c
files src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ExcludeVMPlugin.java test/jdk/jigsaw/tools/jlink/plugins/ExcludeVMPluginTest.java
diffstat 2 files changed, 53 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ExcludeVMPlugin.java	Wed Dec 23 09:13:09 2015 +0100
+++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ExcludeVMPlugin.java	Wed Dec 23 10:33:24 2015 +0100
@@ -33,10 +33,12 @@
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.TreeSet;
 import java.util.function.Predicate;
+import java.util.stream.Collectors;
 import jdk.tools.jlink.plugin.PluginOption;
 import jdk.tools.jlink.plugin.PluginOption.Builder;
 import jdk.tools.jlink.plugin.TransformerPlugin;
@@ -87,12 +89,12 @@
     private static final String SERVER = "server";
     private static final String MINIMAL = "minimal";
 
-    public static final PluginOption NAME_OPTION =
-        new Builder(NAME)
-                .description(PluginsResourceBundle.getDescription(NAME))
-                .argumentDescription(PluginsResourceBundle.getArgument(NAME))
-                .showHelp(true)
-                .build();
+    public static final PluginOption NAME_OPTION
+            = new Builder(NAME)
+            .description(PluginsResourceBundle.getDescription(NAME))
+            .argumentDescription(PluginsResourceBundle.getArgument(NAME))
+            .showHelp(true)
+            .build();
     private Predicate<String> predicate;
     private Jvm target;
     private boolean keepAll;
@@ -102,6 +104,20 @@
         return NAME;
     }
 
+    /**
+     * VM paths:
+     * /java.base/native/{architecture}/{server|client|minimal}/{shared lib}
+     * e.g.: /java.base/native/amd64/server/libjvm.so
+     * /java.base/native/server/libjvm.dylib
+     */
+    private List<Pool.ModuleData> getVMs(Pool in) {
+        String jvmlib = jvmlib();
+        List<Pool.ModuleData> ret = in.getModule("java.base").getContent().stream().filter((t) -> {
+            return t.getPath().endsWith("/" + jvmlib);
+        }).collect(Collectors.toList());
+        return ret;
+    }
+
     @Override
     public void visit(Pool in, Pool out) {
         String jvmlib = jvmlib();
@@ -109,17 +125,18 @@
         TreeSet<Jvm> removed = new TreeSet<>(new JvmComparator());
         if (!keepAll) {
             // First retrieve all available VM names and removed VM
+            List<Pool.ModuleData> jvms = getVMs(in);
             for (Jvm jvm : Jvm.values()) {
-                Pool.ModuleData file = in.get("/java.base/native/" + jvm.getName() + "/" + jvmlib);
-                if (file != null) {
-                    existing.add(jvm);
-                    if (isRemoved(file)) {
-                        removed.add(jvm);
+                for (Pool.ModuleData md : jvms) {
+                    if (md.getPath().endsWith("/" + jvm.getName() + "/" + jvmlib)) {
+                        existing.add(jvm);
+                        if (isRemoved(md)) {
+                            removed.add(jvm);
+                        }
                     }
                 }
             }
         }
-
         // Check that target exists
         if (!keepAll) {
             if (!existing.contains(target)) {
@@ -180,17 +197,17 @@
                 }
                 case CLIENT: {
                     target = Jvm.CLIENT;
-                    exclude = "/java.base/native/server/*,/java.base/native/minimal/*";
+                    exclude = "/java.base/native*server/*,/java.base/native*minimal/*";
                     break;
                 }
                 case SERVER: {
                     target = Jvm.SERVER;
-                    exclude = "/java.base/native/client/*,/java.base/native/minimal/*";
+                    exclude = "/java.base/native*client/*,/java.base/native*minimal/*";
                     break;
                 }
                 case MINIMAL: {
                     target = Jvm.MINIMAL;
-                    exclude = "/java.base/native/server/*,/java.base/native/client/*";
+                    exclude = "/java.base/native*server/*,/java.base/native*client/*";
                     break;
                 }
                 default: {
--- a/test/jdk/jigsaw/tools/jlink/plugins/ExcludeVMPluginTest.java	Wed Dec 23 09:13:09 2015 +0100
+++ b/test/jdk/jigsaw/tools/jlink/plugins/ExcludeVMPluginTest.java	Wed Dec 23 10:33:24 2015 +0100
@@ -46,9 +46,12 @@
 
     private static final String TAG = "# orig in test\n";
 
-    private static final String[] CLIENT = {"/java.base/native/client/" + jvmlib(),};
-    private static final String[] SERVER = {"/java.base/native/server/" + jvmlib()};
-    private static final String[] MINIMAL = {"/java.base/native/minimal/" + jvmlib()};
+    private static final String[] ARCHITECTURES = {"/", "/amd64/", "/i386/", "/arm/",
+        "/aarch64/", "/toto/"};
+
+    private static final String[] CLIENT = {"client/" + jvmlib(),};
+    private static final String[] SERVER = {"server/" + jvmlib()};
+    private static final String[] MINIMAL = {"minimal/" + jvmlib()};
     private static final String[] ALL = {CLIENT[0], SERVER[0], MINIMAL[0]};
     private static final String JVM_CFG_ALL = TAG + "-server KNOWN\n-client KNOWN\n-minimal KNOWN\n";
     private static final String JVM_CFG_CLIENT = TAG + "-client KNOWN\n";
@@ -147,6 +150,20 @@
 
     public void checkVM(String vm, String[] input, String jvmcfg, String[] expectedOutput, String expectdJvmCfg) throws Exception {
 
+        for (String arch : ARCHITECTURES) {
+            String[] winput = new String[input.length];
+            String[] woutput = new String[expectedOutput.length];
+            for (int i = 0; i < input.length; i++) {
+                winput[i] = "/java.base/native" + arch + input[i];
+            }
+            for (int i = 0; i < expectedOutput.length; i++) {
+                woutput[i] = "/java.base/native" + arch + expectedOutput[i];
+            }
+            doCheckVM(vm, winput, jvmcfg, woutput, expectdJvmCfg);
+        }
+    }
+
+    private void doCheckVM(String vm, String[] input, String jvmcfg, String[] expectedOutput, String expectdJvmCfg) throws Exception {
         // Create a pool with jvm.cfg and the input paths.
         byte[] jvmcfgContent = jvmcfg.getBytes();
         Pool pool = new PoolImpl();
@@ -173,7 +190,7 @@
         }
 
         if (out.getContent().size() != (expectedOutput.length + 1)) {
-            for(ModuleData m : out.getContent()) {
+            for (ModuleData m : out.getContent()) {
                 System.err.println(m.getPath());
             }
             throw new Exception("Invalid output size " + out.getContent().size() + " expected " + (expectedOutput.length + 1));