Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what's the correct way to develop at the repl using groovy

I'm new to working with Groovy. I'm used to Python and Clojure where I could do most of my coding at the REPL. I'm trying to do the same with Groovy, but I'm not sure if I've found a way that matches up.

The Groovy Eclipse plugin provides a couple of interactive modes but neither seems to cut it for me.

The first way loads a Groovy script into the Groovy Console. The console appears to me as a weak editor without any of the amenities of Eclipse, such as tab completion. There are some nice introspection capabilities, but it doesn't really feel like interactive development.

The second way starts a Groovy Shell in the console tab of Eclipse. So this gives me the REPL I want, but it feels really clunky running in Eclipse. There's no tab completion. And I have to type "go" after entering in code I want it to evaluate.

The Groovy Eclipse plugin wasn't cutting it, but the Groovy shell included in the stand alone distribution of Groovy works great. It does tab completion (except for classnames), and it evaluates code right after you type it in. It's the one that documented here.

I dug a little deeper into the differences between the REPL that runs in Eclipse and the one that runs from the stand alone distribution using the groovysh script. The one from Eclipse is an instance of 'groovy.ui.InteractiveShell' and the one from the groovysh script is and instance of 'org.codehaus.groovy.tools.shell.Main'. And I found the following code in the groovysh script

if [ "x$OLDSHELL" != "x" ]; then </br>
    startGroovy groovy.ui.InteractiveShell "$@"
else
    startGroovy org.codehaus.groovy.tools.shell.Main "$@"
fi

The above code and this thread tell me groovy.ui.InteractiveShell is going away.

Perhaps there are plans to integrate the new shell more tightly into Eclipse in the future?

Anyways, I was able to hack it out so that I could call the groovysh script with the classpaths needed for working with code from my Eclipse project. Now I can develop happily at the REPL. But it's messy and I'm using the jars in the Groovy stand-alone distribution for starting up Groovy instead of the ones used my Eclipse project. I figure there might be a better way.

Has anyone found a good way integrate the REPL the gets started from the groovysh script and a project in Eclipse. Or have you found an overall better way to develop with a Groovy REPL?

like image 342
harishtella Avatar asked Nov 05 '22 03:11

harishtella


1 Answers

Not much effort has gone into integrating groovysh into groovy-eclipse. The main reason is that groovysh uses all sorts of non-display characters to specify things like color, completion, and caret placement. The Eclipse console does not handle these and spits them out as garbage. Furthermore, the current shell implementation from Groovy does not run very well on windows when inside Eclipse. There are some incompatibilities with the jline library.

If we were to do some integration with groovysh, it would be a large undertaking and a large rewrite. I am not against doing something like this, but so far no one has asked for the feature (you are the first that I am aware of).

What is wrong with running groovysh from the command line while you work in Eclipse? (This is not a rhetorical question, I really do want to know what features are missing.) This is the technique that most Groovy developers use when working inside of Eclipse.

like image 88
Andrew Eisenberg Avatar answered Nov 15 '22 07:11

Andrew Eisenberg