From fea363c67da8fc8975bd7c0c07fe3fe373ae8142 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sun, 5 Jan 2014 06:58:31 +0000 Subject: [PATCH] * make sure the the original args array is available during runtime for debugging purposes --- .../sourceforge/filebot/cli/ArgumentBean.java | 11 +++ .../filebot/cli/ArgumentProcessor.java | 70 ++++++++++--------- .../sourceforge/filebot/cli/ScriptShell.java | 5 +- 3 files changed, 51 insertions(+), 35 deletions(-) diff --git a/source/net/sourceforge/filebot/cli/ArgumentBean.java b/source/net/sourceforge/filebot/cli/ArgumentBean.java index cd247f4c..1ffcb8aa 100644 --- a/source/net/sourceforge/filebot/cli/ArgumentBean.java +++ b/source/net/sourceforge/filebot/cli/ArgumentBean.java @@ -1,5 +1,6 @@ package net.sourceforge.filebot.cli; +import static java.util.Arrays.*; import static java.util.Collections.*; import static net.sourceforge.tuned.FileUtilities.*; @@ -172,4 +173,14 @@ public class ArgumentBean { return Level.parse(log.toUpperCase()); } + private final String[] array; + + public ArgumentBean(String... array) { + this.array = array; + } + + public List getArray() { + return unmodifiableList(asList(array)); + } + } diff --git a/source/net/sourceforge/filebot/cli/ArgumentProcessor.java b/source/net/sourceforge/filebot/cli/ArgumentProcessor.java index 76d9dce6..4b3bb3ee 100644 --- a/source/net/sourceforge/filebot/cli/ArgumentProcessor.java +++ b/source/net/sourceforge/filebot/cli/ArgumentProcessor.java @@ -41,7 +41,7 @@ public class ArgumentProcessor { } public ArgumentBean parse(String[] args) throws CmdLineException { - ArgumentBean bean = new ArgumentBean(); + ArgumentBean bean = new ArgumentBean(args); CmdLineParser parser = new CmdLineParser(bean); parser.parseArgument(args); return bean; @@ -126,7 +126,13 @@ public class ArgumentProcessor { CLILogger.finest("Done ヾ(@⌒ー⌒@)ノ"); return 0; } catch (Throwable e) { - CLILogger.log(Level.SEVERE, String.format("%s: %s", getRootCause(e).getClass().getSimpleName(), getRootCauseMessage(e)), getRootCause(e).getClass() == Exception.class ? null : getRootCause(e)); + if (e.getClass() == Exception.class) { + CLILogger.log(Level.SEVERE, String.format("%s: %s", getRootCause(e).getClass().getSimpleName(), getRootCauseMessage(e))); + } else if (e.getClass() == IllegalArgumentException.class) { + CLILogger.log(Level.SEVERE, String.format("%s: %s", getRootCause(e).getClass().getSimpleName(), String.format("%s %s", getRootCauseMessage(e), args.getArray()))); + } else { + CLILogger.log(Level.SEVERE, String.format("%s: %s", getRootCause(e).getClass().getSimpleName(), getRootCauseMessage(e)), getRootCause(e)); + } CLILogger.finest("Failure (°_°)"); return -1; } @@ -159,42 +165,38 @@ public class ArgumentProcessor { } @Override - public URI getScriptLocation(String input) { + public URI getScriptLocation(String input) throws Exception { try { return new URL(input).toURI(); } catch (Exception _) { - try { - // system:in - if (input.equals("system:in")) { - return new URI("system", "in", null); - } - - // g:println 'hello world' - if (input.startsWith("g:")) { - return new URI("g", input.substring(2), null); - } - - // fn:sortivo / svn:sortivo - if (Pattern.matches("\\w+:.+", input)) { - String scheme = input.substring(0, input.indexOf(':')); - if (getResourceTemplate(scheme) != null) { - return new URI(scheme, input.substring(scheme.length() + 1, input.length()), null); - } - } - - File file = new File(input); - if (baseScheme != null && !file.isAbsolute()) { - return new URI(baseScheme.getScheme(), String.format(baseScheme.getSchemeSpecificPart(), input), null); - } - - // X:/foo/bar.groovy - if (!file.isFile()) { - throw new FileNotFoundException(file.getPath()); - } - return file.getAbsoluteFile().toURI(); - } catch (Exception e) { - throw new IllegalArgumentException(e); + // system:in + if (input.equals("system:in")) { + return new URI("system", "in", null); } + + // g:println 'hello world' + if (input.startsWith("g:")) { + return new URI("g", input.substring(2), null); + } + + // fn:sortivo / svn:sortivo + if (Pattern.matches("\\w+:.+", input)) { + String scheme = input.substring(0, input.indexOf(':')); + if (getResourceTemplate(scheme) != null) { + return new URI(scheme, input.substring(scheme.length() + 1, input.length()), null); + } + } + + File file = new File(input); + if (baseScheme != null && !file.isAbsolute()) { + return new URI(baseScheme.getScheme(), String.format(baseScheme.getSchemeSpecificPart(), input), null); + } + + // X:/foo/bar.groovy + if (!file.isFile()) { + throw new FileNotFoundException(file.getPath()); + } + return file.getAbsoluteFile().toURI(); } } diff --git a/source/net/sourceforge/filebot/cli/ScriptShell.java b/source/net/sourceforge/filebot/cli/ScriptShell.java index 2efe79ba..4db6b30e 100644 --- a/source/net/sourceforge/filebot/cli/ScriptShell.java +++ b/source/net/sourceforge/filebot/cli/ScriptShell.java @@ -60,7 +60,7 @@ public class ScriptShell { public static interface ScriptProvider { - public URI getScriptLocation(String input); + public URI getScriptLocation(String input) throws Exception; public Script fetchScript(URI uri) throws Exception; } @@ -103,6 +103,9 @@ public class ScriptShell { throw e.getException(); } } catch (Throwable e) { + while (e.getClass() == ScriptException.class && e.getCause() != null) { + e = e.getCause(); + } throw StackTraceUtils.deepSanitize(e); // make Groovy stack human-readable } }