|
|
@ -91,13 +91,17 @@ public class ScriptCommand implements Command {
|
|
|
|
private void run(Object main, String[] args) throws Exception {
|
|
|
|
private void run(Object main, String[] args) throws Exception {
|
|
|
|
if (main instanceof Command) {
|
|
|
|
if (main instanceof Command) {
|
|
|
|
((Command) main).run(args);
|
|
|
|
((Command) main).run(args);
|
|
|
|
} else if (main instanceof OptionHandler) {
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (main instanceof OptionHandler) {
|
|
|
|
((OptionHandler) getMain()).run(args);
|
|
|
|
((OptionHandler) getMain()).run(args);
|
|
|
|
} else if (main instanceof Closure) {
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (main instanceof Closure) {
|
|
|
|
((Closure<?>) main).call((Object[]) args);
|
|
|
|
((Closure<?>) main).call((Object[]) args);
|
|
|
|
} else if (main instanceof Runnable) {
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (main instanceof Runnable) {
|
|
|
|
((Runnable) main).run();
|
|
|
|
((Runnable) main).run();
|
|
|
|
} else if (main instanceof Script) {
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (main instanceof Script) {
|
|
|
|
Script script = (Script) this.main;
|
|
|
|
Script script = (Script) this.main;
|
|
|
|
script.setProperty("args", args);
|
|
|
|
script.setProperty("args", args);
|
|
|
|
if (this.main instanceof GroovyObjectSupport) {
|
|
|
|
if (this.main instanceof GroovyObjectSupport) {
|
|
|
@ -135,13 +139,15 @@ public class ScriptCommand implements Command {
|
|
|
|
if (this.main == null) {
|
|
|
|
if (this.main == null) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
this.main = getMainClass().newInstance();
|
|
|
|
this.main = getMainClass().newInstance();
|
|
|
|
} catch (Exception e) {
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Exception e) {
|
|
|
|
throw new IllegalStateException("Cannot create main class: " + this.name,
|
|
|
|
throw new IllegalStateException("Cannot create main class: " + this.name,
|
|
|
|
e);
|
|
|
|
e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (this.main instanceof OptionHandler) {
|
|
|
|
if (this.main instanceof OptionHandler) {
|
|
|
|
((OptionHandler) this.main).options();
|
|
|
|
((OptionHandler) this.main).options();
|
|
|
|
} else if (this.main instanceof GroovyObjectSupport) {
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (this.main instanceof GroovyObjectSupport) {
|
|
|
|
GroovyObjectSupport object = (GroovyObjectSupport) this.main;
|
|
|
|
GroovyObjectSupport object = (GroovyObjectSupport) this.main;
|
|
|
|
MetaClass metaClass = object.getMetaClass();
|
|
|
|
MetaClass metaClass = object.getMetaClass();
|
|
|
|
MetaMethod options = metaClass.getMetaMethod("options", null);
|
|
|
|
MetaMethod options = metaClass.getMetaMethod("options", null);
|
|
|
@ -160,9 +166,11 @@ public class ScriptCommand implements Command {
|
|
|
|
Class<?>[] classes;
|
|
|
|
Class<?>[] classes;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
classes = compiler.compile(source);
|
|
|
|
classes = compiler.compile(source);
|
|
|
|
} catch (CompilationFailedException e) {
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (CompilationFailedException e) {
|
|
|
|
throw new IllegalStateException("Could not compile script", e);
|
|
|
|
throw new IllegalStateException("Could not compile script", e);
|
|
|
|
} catch (IOException e) {
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (IOException e) {
|
|
|
|
throw new IllegalStateException("Could not compile script", e);
|
|
|
|
throw new IllegalStateException("Could not compile script", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.mainClass = classes[0];
|
|
|
|
this.mainClass = classes[0];
|
|
|
@ -185,18 +193,21 @@ public class ScriptCommand implements Command {
|
|
|
|
if (url != null) {
|
|
|
|
if (url != null) {
|
|
|
|
if (url.toString().startsWith("file:")) {
|
|
|
|
if (url.toString().startsWith("file:")) {
|
|
|
|
file = new File(url.toString().substring("file:".length()));
|
|
|
|
file = new File(url.toString().substring("file:".length()));
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
// probably in JAR file
|
|
|
|
// probably in JAR file
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
file = File.createTempFile(name, ".groovy");
|
|
|
|
file = File.createTempFile(name, ".groovy");
|
|
|
|
file.deleteOnExit();
|
|
|
|
file.deleteOnExit();
|
|
|
|
FileUtil.copy(url, file, null);
|
|
|
|
FileUtil.copy(url, file, null);
|
|
|
|
} catch (IOException e) {
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (IOException e) {
|
|
|
|
throw new IllegalStateException(
|
|
|
|
throw new IllegalStateException(
|
|
|
|
"Could not create temp file for source: " + name);
|
|
|
|
"Could not create temp file for source: " + name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
String home = System.getProperty("SPRING_HOME", System.getenv("SPRING_HOME"));
|
|
|
|
String home = System.getProperty("SPRING_HOME", System.getenv("SPRING_HOME"));
|
|
|
|
if (home == null) {
|
|
|
|
if (home == null) {
|
|
|
|
home = ".";
|
|
|
|
home = ".";
|
|
|
|