changeset 16725:735dfe90bf33

8174209: Renumber the compress levels Reviewed-by: alanb, jlaskey, mchung, redestad
author sundar
date Tue, 14 Feb 2017 07:33:49 +0530
parents a9986a4dff27
children 46052e3e5372
files src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/DefaultCompressPlugin.java src/jdk.jlink/share/classes/jdk/tools/jlink/resources/plugins.properties test/tools/jlink/IntegrationTest.java test/tools/jlink/plugins/CompressorPluginTest.java
diffstat 4 files changed, 51 insertions(+), 70 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/DefaultCompressPlugin.java	Mon Feb 13 20:32:06 2017 +0100
+++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/DefaultCompressPlugin.java	Tue Feb 14 07:33:49 2017 +0530
@@ -25,6 +25,7 @@
 package jdk.tools.jlink.internal.plugins;
 
 import java.util.Map;
+import java.util.function.Function;
 
 import jdk.tools.jlink.internal.ResourcePoolManager.ResourcePoolImpl;
 import jdk.tools.jlink.plugin.ResourcePool;
@@ -64,9 +65,10 @@
             return ss.transform(in, out);
         } else if (zip != null) {
             return zip.transform(in, out);
+        } else {
+            in.transformAndCopy(Function.identity(), out);
+            return out.build();
         }
-
-        return out.build();
     }
 
     @Override
@@ -103,21 +105,20 @@
         if (level != null) {
             switch (level) {
                 case LEVEL_0:
+                    ss = null;
+                    zip = null;
+                    break;
+                case LEVEL_1:
                     ss = new StringSharingPlugin(resFilter);
                     break;
-                case LEVEL_1:
-                    zip = new ZipPlugin(resFilter);
-                    break;
                 case LEVEL_2:
-                    ss = new StringSharingPlugin(resFilter);
                     zip = new ZipPlugin(resFilter);
                     break;
                 default:
                     throw new IllegalArgumentException("Invalid compression level " + level);
             }
         } else {
-            ss = new StringSharingPlugin(resFilter);
-            zip = new ZipPlugin(resFilter);
+            throw new IllegalArgumentException("Invalid compression level " + level);
         }
     }
 }
--- a/src/jdk.jlink/share/classes/jdk/tools/jlink/resources/plugins.properties	Mon Feb 13 20:32:06 2017 +0100
+++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/resources/plugins.properties	Tue Feb 14 07:33:49 2017 +0530
@@ -40,9 +40,9 @@
 
 compress.description=\
 Compress all resources in the output image.\n\
-Level 0: constant string sharing\n\
-Level 1: ZIP\n\
-Level 2: both.\n\
+Level 0: No compression\n\
+Level 1: Constant string sharing\n\
+Level 2: ZIP.\n\
 An optional <pattern-list> filter can be specified to list the pattern of\n\
 files to be included.
 
@@ -148,8 +148,10 @@
 \      --disable-plugin <pluginname>     Disable the plugin mentioned
 
 plugin.opt.compress=\
-\  -c, --compress=<0|1|2>                Enable compression of resources\n\
-\                                        More details in --list-plugins option
+\  -c, --compress=<0|1|2>                Enable compression of resources:\n\
+\                                          Level 0: No compression\n\
+\                                          Level 1: Constant string sharing\n\
+\                                          Level 2: ZIP
 
 plugin.opt.strip-debug=\
 \  -G, --strip-debug                     Strip debug information
--- a/test/tools/jlink/IntegrationTest.java	Mon Feb 13 20:32:06 2017 +0100
+++ b/test/tools/jlink/IntegrationTest.java	Tue Feb 14 07:33:49 2017 +0530
@@ -145,7 +145,7 @@
             throw new Exception("Plugin should be null");
         }
 
-        Plugin p2 = Jlink.newPlugin("compress", Collections.emptyMap(), null);
+        Plugin p2 = Jlink.newPlugin("compress", Map.of("compress", "1"), null);
         if (p2 == null) {
             throw new Exception("Plugin should not be null");
         }
--- a/test/tools/jlink/plugins/CompressorPluginTest.java	Mon Feb 13 20:32:06 2017 +0100
+++ b/test/tools/jlink/plugins/CompressorPluginTest.java	Tue Feb 14 07:33:49 2017 +0530
@@ -93,80 +93,53 @@
                 new ResourceDecompressorFactory[]{
                     new StringSharingDecompressorFactory()});
 
-        // compress == ZIP + String sharing
-        Properties options = new Properties();
-        options.setProperty(ZipPlugin.NAME, "");
-        checkCompress(classes, new DefaultCompressPlugin(), options,
+        // compress level 0 == no compression
+        Properties options0 = new Properties();
+        options0.setProperty(DefaultCompressPlugin.NAME,
+                "0");
+        checkCompress(classes, new DefaultCompressPlugin(),
+                options0,
                 new ResourceDecompressorFactory[]{
-                    new ZipDecompressorFactory(),
+                });
+
+        // compress level 1 == String sharing
+        Properties options1 = new Properties();
+        options1.setProperty(DefaultCompressPlugin.NAME, "1");
+        checkCompress(classes, new DefaultCompressPlugin(),
+                options1,
+                new ResourceDecompressorFactory[]{
                     new StringSharingDecompressorFactory()
                 });
 
-        // compress == ZIP + String sharing + filter
-        options.setProperty(DefaultCompressPlugin.FILTER,
+        // compress level 1 == String sharing + filter
+        options1.setProperty(DefaultCompressPlugin.FILTER,
                 "**Exception.class");
-        checkCompress(classes, new DefaultCompressPlugin(), options,
+        options1.setProperty(DefaultCompressPlugin.NAME, "1");
+        checkCompress(classes, new DefaultCompressPlugin(),
+                options1,
                 new ResourceDecompressorFactory[]{
-                    new ZipDecompressorFactory(),
                     new StringSharingDecompressorFactory()
                 }, Collections.singletonList(".*Exception.class"));
 
-        // compress level 1 == ZIP
-        Properties options1 = new Properties();
-        options1.setProperty(DefaultCompressPlugin.NAME,
-                "1");
+        // compress level 2 == ZIP
+        Properties options2 = new Properties();
+        options2.setProperty(DefaultCompressPlugin.FILTER,
+                "**Exception.class");
+        options2.setProperty(DefaultCompressPlugin.NAME, "2");
         checkCompress(classes, new DefaultCompressPlugin(),
-                options1,
-                new ResourceDecompressorFactory[]{
-                    new ZipDecompressorFactory()
-                });
-
-        // compress level 1 == ZIP
-        options1.setProperty(DefaultCompressPlugin.FILTER,
-                "**Exception.class");
-        checkCompress(classes, new DefaultCompressPlugin(),
-                options1,
+                options2,
                 new ResourceDecompressorFactory[]{
                     new ZipDecompressorFactory()
                 }, Collections.singletonList(".*Exception.class"));
 
-        // compress level 2 == ZIP + String sharing
-        Properties options2 = new Properties();
-        options2.setProperty(DefaultCompressPlugin.NAME,
-                "2");
+        // compress level 2 == ZIP + filter
+        options2.setProperty(DefaultCompressPlugin.FILTER,
+                "**Exception.class");
+        options2.setProperty(DefaultCompressPlugin.NAME, "2");
         checkCompress(classes, new DefaultCompressPlugin(),
                 options2,
                 new ResourceDecompressorFactory[]{
                     new ZipDecompressorFactory(),
-                    new StringSharingDecompressorFactory()
-                });
-
-        // compress level 2 == ZIP + String sharing + filter
-        options2.setProperty(DefaultCompressPlugin.FILTER,
-                "**Exception.class");
-        checkCompress(classes, new DefaultCompressPlugin(),
-                options2,
-                new ResourceDecompressorFactory[]{
-                    new ZipDecompressorFactory(),
-                    new StringSharingDecompressorFactory()
-                }, Collections.singletonList(".*Exception.class"));
-
-        // compress level 0 == String sharing
-        Properties options0 = new Properties();
-        options0.setProperty(DefaultCompressPlugin.NAME, "0");
-        checkCompress(classes, new DefaultCompressPlugin(),
-                options0,
-                new ResourceDecompressorFactory[]{
-                    new StringSharingDecompressorFactory()
-                });
-
-        // compress level 0 == String sharing + filter
-        options0.setProperty(DefaultCompressPlugin.FILTER,
-                "**Exception.class");
-        checkCompress(classes, new DefaultCompressPlugin(),
-                options0,
-                new ResourceDecompressorFactory[]{
-                    new StringSharingDecompressorFactory()
                 }, Collections.singletonList(".*Exception.class"));
     }
 
@@ -234,6 +207,11 @@
             Properties config,
             ResourceDecompressorFactory[] factories,
             List<String> includes) throws Exception {
+        if (factories.length == 0) {
+            // no compression, nothing to check!
+            return;
+        }
+
         long[] original = new long[1];
         long[] compressed = new long[1];
         resources.entries().forEach(resource -> {