* make sure the the original args array is available during runtime for debugging purposes

This commit is contained in:
Reinhard Pointner 2014-01-05 06:58:31 +00:00
parent 7d814d7b77
commit fea363c67d
3 changed files with 51 additions and 35 deletions

View File

@ -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<String> getArray() {
return unmodifiableList(asList(array));
}
}

View File

@ -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();
}
}

View File

@ -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
}
}