TestGUI.java:
package groovy.ui;
import java.lang.reflect.Field;
import java.net.URL;
import groovy.lang.GroovyClassLoader;
import groovy.lang.GroovyShell;
public class TestGUI extends Console
{
public static void main(String[] args)
{
TestGUI gui = new TestGUI();
gui.run();
}
public TestGUI()
{
super();
try
{
setup();
}
catch (Exception e)
{
e.printStackTrace();
}
}
public void setup() throws Exception
{
Field shell =
Console.class.getDeclaredField("shell");
shell.setAccessible(true);
shell.set(this, new OurGroovyShell());
}
}
OurGroovyShell.java:
package groovy.ui;
import java.util.List;
import org.codehaus.groovy.control.CompilationFailedException;
import groovy.lang.GroovyShell;
public class OurGroovyShell extends GroovyShell
{
public Object run(String scriptText,
String fileName, List list)
throws CompilationFailedException
{
scriptText = "import whatever.*\n" + scriptText;
String[] args = new String[list.size()];
list.toArray(args);
return run(scriptText, fileName, args);
}
}
Fairly simple in the end. I was fooling around a bit to get this to work at first. This was done with Groovy 1.6.2.
No comments:
Post a Comment