Griffon 0.9 sneak peek: command line updates - No Fluff Just Stuff

Griffon 0.9 sneak peek: command line updates

Posted by: Andres Almiray on July 1, 2010

It's been a month a half since the last Griffon release, we're getting ready for another one, but this time it's going to be a big one. There are many updates, fixes and changes in the upcoming 0.9 release so I'll make my best to post a daily update to let you know what's coming up.

The first updates I'd like to talk about are the command line additions. There are two new features inspired by Gradle:

1. Command expansion

The gradle command has this neat trick of allowing a command target to be expanded if you write it in shorthand notation using camel case. For example gradle pP expands to gradle packageProject (if such target exists anyway). This certainly saves you some keystrokes. The griffon command now has the same command expansion ability. I'm glad to say that this feature was contributed by the Hackergarten group while having an "on tour" meeting at Jazoon 2010.

Remember to write just about enough characters to let the target recognizing algorithm to resolve the name unambiguously, otherwise you'll be given a choice with the matching options, as shown next when invoking griffon rA
$ griffon rA
Welcome to Griffon 0.9 - http://griffon.codehaus.org/
Licensed under Apache Standard License 2.0
Griffon home is set to: /usr/local/griffon

Base Directory: /private/tmp/bar
Resolving dependencies...
Dependencies resolved in 656ms.
Multiple options please select:
[1] /usr/local/griffon/scripts/RunApp.groovy
[2] /usr/local/griffon/scripts/RunApplet.groovy
Enter # [1,2]

It's worth mentioning that if you write out the full name of a target then it will work as before, even if there is multiple potential matches. This means that typing griffon run-app will invoke the RunApp script and will not give you a choice between RunApp and RunApplet.

2. Command suggestion

There might have been times when one of your fingers decided to strike the wrong key and you ended up with a typo. It is somewhat expensive to invoke the griffon command with the wrong target, as you pay the price for JVM startup and end up with an error message. Well not anymore! Straight from the recent Grails 1.3.2 release comes another command matching algorithm proposed by Seth Schroeder (Groovy cosine similarity in Grails). The algorithm kicks in if a command target is not recognized, even if the previous command expansion feature did not resolve to a known script. Here's some sample output
$ griffon applet
Welcome to Griffon 0.9 - http://griffon.codehaus.org/
Licensed under Apache Standard License 2.0
Griffon home is set to: /usr/local/griffon

Base Directory: /private/tmp/bar
Resolving dependencies...
Dependencies resolved in 435ms.
Running pre-compiled script
Script 'Applet' not found, did you mean:
   1) RunApplet
   2) App
   3) RunApp
   4) TestApp
   5) CreateApp_
Please make a selection or enter Q to quit: 

You might have noticed the App script as option #2. It is an alias for RunApp, so that you can type griffon a and run the application; otherwise you'll be given a list of choices as the previous griffon rA example demonstrated.

3. Command wrapper

Here comes another feature inspired by Gradle. Projects built with Gradle have the option to embed a command wrapper called gradlew. This command wrapper takes care of downloading a suitable gradle distribution and execute it. This means that the project is self contained in terms of its build, so that you can freely redistribute it in source form to anyone; they will be able to build your project without needing Gradle pre-installed on their system, as long as they rely on the wrapper to call the build targets.

Well, Griffon 0.9 comes with a command wrapper too, aptly named griffonw. The wrapper and its required files will be added to every application and/or plugin created with this release and onwards. Given that the wrapper downloads, installs and runs a fully working Griffon distribution means that you can apply both features #1 and #2 with it as well.

4. Interactive mode

This is not really a new feature but a reminder that you can run the griffon command in interactive form, which means you pay the cost for JVM startup once. This mode can be invoked by typing griffon interactive. Here's the output of a sample session invoking the following commands: compile, cl (shorthand for clean), and applet
$ griffon interactive
Welcome to Griffon 0.9 - http://griffon.codehaus.org/
Licensed under Apache Standard License 2.0
Griffon home is set to: /usr/local/griffon

Base Directory: /private/tmp/bar
--------------------------------------------------------
Interactive mode ready. Enter a Griffon command or type "exit" to quit interactive mode (hit ENTER to run the last command):
compile
Resolving dependencies...
Dependencies resolved in 400ms.
Running script /usr/local/griffon/scripts/Compile.groovy
Environment set to development
    [mkdir] Created dir: /Users/aalmiray/.griffon/0.9/projects/bar/classes
    [mkdir] Created dir: /Users/aalmiray/.griffon/0.9/projects/bar/plugin-classes
    [mkdir] Created dir: /Users/aalmiray/.griffon/0.9/projects/bar/test-classes/shared
    [mkdir] Created dir: /Users/aalmiray/.griffon/0.9/projects/bar/test-resources
  [groovyc] Compiling 12 source files to /Users/aalmiray/.griffon/0.9/projects/bar/classes
  [groovyc] Compiling 5 source files to /Users/aalmiray/.griffon/0.9/projects/bar/classes
--------------------------------------------------------
Command Compile completed in 2896ms
--------------------------------------------------------
Interactive mode ready. Enter a Griffon command or type "exit" to quit interactive mode (hit ENTER to run the last command):
cl
Resolving dependencies...
Dependencies resolved in 2ms.
Running script /usr/local/griffon/scripts/Clean.groovy
Environment set to development
   [delete] Deleting directory /Users/aalmiray/.griffon/0.9/projects/bar/classes
   [delete] Deleting directory /Users/aalmiray/.griffon/0.9/projects/bar/plugin-classes
   [delete] Deleting directory /Users/aalmiray/.griffon/0.9/projects/bar/test-classes
   [delete] Deleting directory /Users/aalmiray/.griffon/0.9/projects/bar/test-resources
--------------------------------------------------------
Command Cl completed in 1018ms
--------------------------------------------------------
Interactive mode ready. Enter a Griffon command or type "exit" to quit interactive mode (hit ENTER to run the last command):
applet
Resolving dependencies...
Dependencies resolved in 1ms.
Running pre-compiled script
Script 'Applet' not found, did you mean:
   1) RunApplet
   2) App
   3) RunApp
   4) TestApp
   5) CreateApp_
Please make a selection or enter Q to quit: 


That's all for today and the command line. Stay tuned for more Griffon 0.9 goodies!

Keep on Groovying!
Andres Almiray

About Andres Almiray

Andres is a Java/Groovy developer and a Java Champion with more than 20 years of experience in software design and development. He has been involved in web and desktop application development since the early days of Java. Andres is a true believer in open source and has participated on popular projects like Groovy, Griffon, and DbUnit, as well as starting his own projects (Json-lib, EZMorph, GraphicsBuilder, JideBuilder). Founding member of the Griffon framework and Hackergarten community event. https://ch.linkedin.com/in/aalmiray

Why Attend the NFJS Tour?

  • » Cutting-Edge Technologies
  • » Agile Practices
  • » Peer Exchange

Current Topics:

  • Languages on the JVM: Scala, Groovy, Clojure
  • Enterprise Java
  • Core Java, Java 8
  • Agility
  • Testing: Geb, Spock, Easyb
  • REST
  • NoSQL: MongoDB, Cassandra
  • Hadoop
  • Spring 4
  • Cloud
  • Automation Tools: Gradle, Git, Jenkins, Sonar
  • HTML5, CSS3, AngularJS, jQuery, Usability
  • Mobile Apps - iPhone and Android
  • More...
Learn More »