changeset 42330:bd999576b78d

8160359: Improve jlink logging for cases when a plugin throws exception Reviewed-by: jlaskey, redestad
author sundar
date Wed, 30 Nov 2016 19:28:10 +0530
parents c964d4aca91a
children 85c6abf55d70
files jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ImagePluginStack.java jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/Jlink.java jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/PluginRepository.java jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/TaskHelper.java jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ExcludeJmodSectionPlugin.java jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/OrderResourcesPlugin.java jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ReleaseInfoPlugin.java jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ResourceFilter.java
diffstat 8 files changed, 44 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ImagePluginStack.java	Wed Nov 30 03:49:55 2016 -0800
+++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ImagePluginStack.java	Wed Nov 30 19:28:10 2016 +0530
@@ -268,7 +268,15 @@
                             resources.getStringTable());
                 }
             }
-            resPool = p.transform(resPool, resMgr.resourcePoolBuilder());
+            try {
+                resPool = p.transform(resPool, resMgr.resourcePoolBuilder());
+            } catch (PluginException pe) {
+                if (JlinkTask.DEBUG) {
+                    System.err.println("Plugin " + p.getName() + " threw exception during transform");
+                    pe.printStackTrace();
+                }
+                throw pe;
+            }
             if (resPool.isEmpty()) {
                 throw new Exception("Invalid resource pool for plugin " + p);
             }
@@ -444,6 +452,7 @@
                         res = res.copyWithContent(bytes);
                     } catch (IOException ex) {
                         if (JlinkTask.DEBUG) {
+                            System.err.println("IOException while reading resource: " + res.path());
                             ex.printStackTrace();
                         }
                         throw new PluginException(ex);
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/Jlink.java	Wed Nov 30 03:49:55 2016 -0800
+++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/Jlink.java	Wed Nov 30 19:28:10 2016 +0530
@@ -298,7 +298,15 @@
         List<Plugin> bootPlugins = PluginRepository.getPlugins(Layer.boot());
         for (Plugin bp : bootPlugins) {
             if (Utils.isAutoEnabled(bp)) {
-                bp.configure(Collections.emptyMap());
+                try {
+                    bp.configure(Collections.emptyMap());
+                } catch (IllegalArgumentException e) {
+                    if (JlinkTask.DEBUG) {
+                        System.err.println("Plugin " + bp.getName() + " threw exception with config: {}");
+                        e.printStackTrace();
+                    }
+                    throw e;
+                }
                 plugins.add(bp);
             }
         }
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/PluginRepository.java	Wed Nov 30 03:49:55 2016 -0800
+++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/PluginRepository.java	Wed Nov 30 19:28:10 2016 +0530
@@ -74,7 +74,15 @@
         Objects.requireNonNull(pluginsLayer);
         Plugin plugin = getPlugin(name, pluginsLayer);
         if (plugin != null) {
-            plugin.configure(config);
+            try {
+                plugin.configure(config);
+            } catch (IllegalArgumentException e) {
+                if (JlinkTask.DEBUG) {
+                    System.err.println("Plugin " + plugin.getName() + " threw exception with config: " + config);
+                    e.printStackTrace();
+                }
+                throw e;
+            }
         }
         return plugin;
     }
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/TaskHelper.java	Wed Nov 30 03:49:55 2016 -0800
+++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/TaskHelper.java	Wed Nov 30 19:28:10 2016 +0530
@@ -421,7 +421,15 @@
                 // we call configure once for each occurrence. It is upto the plugin
                 // to 'merge' and/or 'override' arguments.
                 for (Map<String, String> map : argsMaps) {
-                    plugin.configure(Collections.unmodifiableMap(map));
+                    try {
+                        plugin.configure(Collections.unmodifiableMap(map));
+                    } catch (IllegalArgumentException e) {
+                        if (JlinkTask.DEBUG) {
+                            System.err.println("Plugin " + plugin.getName() + " threw exception with config: " + map);
+                            e.printStackTrace();
+                        }
+                        throw e;
+                    }
                 }
 
                 if (!Utils.isDisabled(plugin)) {
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ExcludeJmodSectionPlugin.java	Wed Nov 30 03:49:55 2016 -0800
+++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ExcludeJmodSectionPlugin.java	Wed Nov 30 19:28:10 2016 +0530
@@ -55,7 +55,7 @@
     public void configure(Map<String, String> config) {
         String arg = config.get(NAME);
         if (arg.isEmpty()) {
-            throw new PluginException("Section name must be specified");
+            throw new IllegalArgumentException("Section name must be specified");
         }
 
         switch (arg) {
@@ -66,7 +66,7 @@
                 filters.add(Type.HEADER_FILE);
                 break;
             default:
-                throw new PluginException("Invalid section name: " + arg);
+                throw new IllegalArgumentException("Invalid section name: " + arg);
         }
     }
 
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/OrderResourcesPlugin.java	Wed Nov 30 03:49:55 2016 -0800
+++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/OrderResourcesPlugin.java	Wed Nov 30 19:28:10 2016 +0530
@@ -26,6 +26,7 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.io.UncheckedIOException;
 import java.nio.file.FileSystem;
 import java.nio.file.Files;
 import java.nio.file.PathMatcher;
@@ -177,7 +178,7 @@
                     try {
                         lines = Files.readAllLines(file.toPath());
                     } catch (IOException ex) {
-                        throw new PluginException(ex);
+                        throw new UncheckedIOException(ex);
                     }
 
                     for (String line : lines) {
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ReleaseInfoPlugin.java	Wed Nov 30 03:49:55 2016 -0800
+++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ReleaseInfoPlugin.java	Wed Nov 30 19:28:10 2016 +0530
@@ -115,7 +115,7 @@
                 try (FileInputStream fis = new FileInputStream(operation)) {
                     props.load(fis);
                 } catch (IOException exp) {
-                    throw new RuntimeException(exp);
+                    throw new UncheckedIOException(exp);
                 }
                 props.forEach((k, v) -> release.put(k.toString(), v.toString()));
             }
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ResourceFilter.java	Wed Nov 30 03:49:55 2016 -0800
+++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ResourceFilter.java	Wed Nov 30 19:28:10 2016 +0530
@@ -26,6 +26,7 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.io.UncheckedIOException;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.PathMatcher;
@@ -35,7 +36,6 @@
 import java.util.Objects;
 import java.util.function.Predicate;
 import jdk.tools.jlink.internal.Utils;
-import jdk.tools.jlink.plugin.PluginException;
 
 /**
  *
@@ -62,7 +62,7 @@
                     try {
                         lines = Files.readAllLines(file.toPath());
                     } catch (IOException ex) {
-                        throw new PluginException(ex);
+                        throw new UncheckedIOException(ex);
                     }
 
                     lines.stream().forEach((line) -> {