Command line parsing example in Groovy

Here is an example using CliBuilder. I wrote it as an example for my stackoverflow question.

#!/usr/bin/groovy def cli = new CliBuilder(usage: ‘cliTest -s sdkdir {projectName}’, header: ‘Command line parameter parsing test in Groovy’) cli.s longOpt: ‘sdkdir’, args: 1, ‘sdkdir usage info, REQUIRED’ cli.h longOpt: ‘help’, ‘print usage information’ def opt = cli.parse(args) def errMsg . . . → Read More: Command line parsing example in Groovy

Delete temporary files older than 7 days

Another Groovy script to solve a practical problem: delete temporary files older than 7 days. I stop after 10000 files, so I can put this script in the cron and be sure it won’t run for too long.

Everything is hardcoded: my base path is /var/www and I look for tmp and templates_c directories. . . . → Read More: Delete temporary files older than 7 days

Remove a dependency from pom.xml

I wrote another simple Groovy script to remove one or more dependencies from a pom.xml – Here is how to use it:

$ pomRm rdbms org.datanucleus:datanucleus-rdbms:3.0.4 $ pomRm rdbms rm org.datanucleus:datanucleus-rdbms:3.0.4 REMOVED

The first form just lists the matching artifacts, without changing the pom.xml, while adding ‘rm’ in the command line as second parameter, actually . . . → Read More: Remove a dependency from pom.xml

Check and Modify Artifacts versions in a pom.xml

Taking advantage of the easy XML processing, built in regular expressions I wrote a short script in Groovy to check and modify artifacts version in a pom.xml (Maven).

For example to show all dependencies with the word datanucleus in it, and display them in compact form (groupId:artifactId:version)

$ pomVersions datanucleus com.google.appengine.orm:datanucleus-appengine:2.0.0-RC2 org.datanucleus:datanucleus-core:3.0.4 org.datanucleus:datanucleus-api-jpa:3.0.4 org.datanucleus:datanucleus-rdbms:3.0.4

I . . . → Read More: Check and Modify Artifacts versions in a pom.xml

Groovy Baby!

In the last few days I’m trying to learn Groovy, and until now is surprisingly easy. The great part is that it can access all the Java classes and libraries natively, but without all Java boilerplate and verbosity.

I’m starting to think to use Groovy instead of Perl for my scripting needs, for instance . . . → Read More: Groovy Baby!

my Emacs init.el

This post is just to have a copy of my init.el. I will keep it updated. Last update 18 March 2012.

(add-to-list ‘load-path "~/.emacs.d/elisp") (load "php-mode") ; (load "groovy-mode") ; turn on syntax highlighting (global-font-lock-mode 1) ; use groovy-mode when file ends in .groovy or has #!/bin/groovy at start (autoload ‘groovy-mode "groovy-mode" "Major mode for . . . → Read More: my Emacs init.el