in xbean-telnet/src/main/java/org/apache/xbean/command/GroovySh.java [34:77]
public int main(String[] args, InputStream in, PrintStream out) {
GroovyShell shell = new GroovyShell();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
String version = GroovySystem.getVersion();
out.println("Lets get Groovy!");
out.println("================");
out.println("Version: " + version + " JVM: " + System.getProperty("java.vm.version"));
out.println("Hit carriage return twice to execute a command");
out.println("The command 'quit' will terminate the shell");
int counter = 1;
while (true) {
StringBuffer buffer = new StringBuffer();
while (true) {
out.print("groovy> ");
String line;
try {
line = reader.readLine();
} catch (IOException e) {
out.println("Caught: " + e);
e.printStackTrace();
return -1;
}
if (line != null) {
buffer.append(line);
buffer.append('\n');
}
if (line == null || line.trim().length() == 0) {
break;
}
}
String command = buffer.toString().trim();
if (command == null || command.equals("quit")) {
break;
}
try {
Object answer = shell.evaluate(command, "CommandLine" + counter++ + ".groovy");
out.println(InvokerHelper.inspect(answer));
} catch (Exception e) {
out.println("Caught: " + e);
e.printStackTrace();
}
}
return 0;
}