Upgrading Groovy

This post is mainly a note to my self. At work I use a Linux Mint distro, but the bundled version of groovy is 1.7.10 and I needed some stuff only present in 2.0.0, thus I had to upgrade. I’m not that into linux (or any other OS for that matter), so it took me a while to figure out how. Then my computer crashed and I had to do it over, but I had not made any notes during my previous attempt. Luckily Google was my friend and I was able to find out quite quickly. This will be my notes now:

First download groovy 2.0.0 from http://groovy.codehaus.org/Download

Then, in a command prompt, execute the following

# cd /usr/lib/
# sudo unzip /groovy-binary-2.0.0.zip
# sudo update-alternatives --install "/usr/bin/groovy" "groovy" "/usr/lib/groovy-2.0.0/bin/groovy" 1
# sudo update-alternatives --install "/usr/bin/groovyc" "groovyc" "/usr/lib/groovy-2.0.0/bin/groovyc" 1
# sudo update-alternatives --install "/usr/bin/groovyConsole" "groovyConsole" "/usr/lib/groovy-2.0.0/bin/groovyConsole" 1
# sudo update-alternatives --install "/usr/bin/groovysh" "groovysh" "/usr/lib/groovy-2.0.0/bin/groovysh" 1
# sudo update-alternatives --install "/usr/bin/java2groovy" "java2groovy" "/usr/lib/groovy-2.0.0/bin/java2groovy" 1
# sudo update-alternatives --config groovy

Test that everything went well

# groovy -v
Groovy Version: 2.0.0 JVM: 1.6.0_26 Vendor: Sun Microsystems Inc. OS: Linux

(use google for details about “sudo” and “update-alternatives”)


Friday puzzle

My good friend Frank just sent me this email (I did translate to English though). I had never seen the algorithm before, so it gave me a good laugh. Now I need to share it. It’s written in Groovy:

If you just need to get some blood through the neural cells after the pork roast, try to figure out the code below.

Hint: a classic sort algorithm, but which one?


import java.util.concurrent.*

def list = new CopyOnWriteArrayList()

def task = { n ->
t = {
} // job in a closure
t as Callable // return block as a callable }

def workers = []

[5, 3, 7, 2, 1, 1, 3, 4].each { n ->

def executor = Executors.newFixedThreadPool(workers.size());
def futures = executor.invokeAll(workers, 10, TimeUnit.SECONDS);

println list # the sorted list

So, what is it? Eh’? Eh’? :o)