this.addArgument("class", Class.class, "The main, entry point type or runnable class");
this.addOption("cl", String.class, "Use the class loader from the groovy environment using the name specified", "");
}
public Object execute(GroovyCLIContext ctx, CommandLineArgumentsStandard arguments) {
EntryPoint point = (EntryPoint) ctx.getUI().getDomain().getVariable("entry");
EntryPointType type = (EntryPointType) ctx.getUI().getDomain().getVariable("epcli");
ClassLoader original = null;
PassedOption cl = arguments.getOption("cl");
if (cl != null && ctx.getUI().getDomain().getVariable((String) cl.getValue()) instanceof ClassLoader) {
original = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader((ClassLoader)ctx.getUI().getDomain().getVariable((String) cl.getValue()));
}
String mainClass = (String) arguments.getArgument(0).getValue();
try {
point.boot(ClassCache.getFor(ReflectionUtil.getClass(mainClass)), type, mainClass);
return new ExecutionResults(mainClass, null);
} catch (Throwable e) {
return new ExecutionResults(mainClass, e);
} finally {
if (original != null) Thread.currentThread().setContextClassLoader(original);