8174209: Renumber the compress levels
authorsundar
Tue, 14 Feb 2017 07:33:49 +0530
changeset 43791 116beb9c53a5
parent 43790 b9e56c7fba7e
child 43792 05d6b8f2eff5
8174209: Renumber the compress levels Reviewed-by: alanb, jlaskey, mchung, redestad
jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/DefaultCompressPlugin.java
jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/resources/plugins.properties
jdk/test/tools/jlink/IntegrationTest.java
jdk/test/tools/jlink/plugins/CompressorPluginTest.java
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/DefaultCompressPlugin.java	Mon Feb 13 20:32:06 2017 +0100
+++ b/jdk/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 = new StringSharingPlugin(resFilter);
+                    ss = null;
+                    zip = null;
                     break;
                 case LEVEL_1:
-                    zip = new ZipPlugin(resFilter);
+                    ss = new StringSharingPlugin(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/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/resources/plugins.properties	Mon Feb 13 20:32:06 2017 +0100
+++ b/jdk/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/jdk/test/tools/jlink/IntegrationTest.java	Mon Feb 13 20:32:06 2017 +0100
+++ b/jdk/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/jdk/test/tools/jlink/plugins/CompressorPluginTest.java	Mon Feb 13 20:32:06 2017 +0100
+++ b/jdk/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");
-        checkCompress(classes, new DefaultCompressPlugin(),
-                options2,
-                new ResourceDecompressorFactory[]{
-                    new ZipDecompressorFactory(),
-                    new StringSharingDecompressorFactory()
-                });
-
-        // compress level 2 == ZIP + String sharing + filter
+        // 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()
-                }, 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 -> {