8160359: Improve jlink logging for cases when a plugin throws exception

Reviewed-by: jlaskey, redestad
This commit is contained in:
Athijegannathan Sundararajan 2016-11-30 19:28:10 +05:30
parent 2034cb4c6e
commit e6e9bbfcdb
8 changed files with 44 additions and 10 deletions

View File

@ -268,7 +268,15 @@ public final class ImagePluginStack {
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 @@ public final class ImagePluginStack {
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);

View File

@ -298,7 +298,15 @@ public final class Jlink {
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);
}
}

View File

@ -74,7 +74,15 @@ public final class PluginRepository {
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;
}

View File

@ -421,7 +421,15 @@ public final class TaskHelper {
// 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)) {

View File

@ -55,7 +55,7 @@ public final class ExcludeJmodSectionPlugin implements Plugin {
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 @@ public final class ExcludeJmodSectionPlugin implements Plugin {
filters.add(Type.HEADER_FILE);
break;
default:
throw new PluginException("Invalid section name: " + arg);
throw new IllegalArgumentException("Invalid section name: " + arg);
}
}

View File

@ -26,6 +26,7 @@ package jdk.tools.jlink.internal.plugins;
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 @@ public final class OrderResourcesPlugin implements Plugin {
try {
lines = Files.readAllLines(file.toPath());
} catch (IOException ex) {
throw new PluginException(ex);
throw new UncheckedIOException(ex);
}
for (String line : lines) {

View File

@ -115,7 +115,7 @@ public final class ReleaseInfoPlugin implements Plugin {
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()));
}

View File

@ -26,6 +26,7 @@ package jdk.tools.jlink.internal.plugins;
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.List;
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 @@ public class ResourceFilter implements Predicate<String> {
try {
lines = Files.readAllLines(file.toPath());
} catch (IOException ex) {
throw new PluginException(ex);
throw new UncheckedIOException(ex);
}
lines.stream().forEach((line) -> {