Saturday, April 3, 2010

Roo Replay

During the Roo demo at Spring Casual Class I made a mistake, when running Roo Shell in a different directory than had been planned. So, the Roo artifacts were created where I did not want. When I noticed the error I quit Roo Shell, moved to the correct directory and warned: "We'll have a replay of the commands", taking the opportunity to reinforce how it's really quick to build software with Roo Shell.

And "Don't tell me that it has a replay command" came from the middle of the audience. Yes I do - I could have used the log.roo file and script command. At that the time I preferred to do it all again by Roo Shell, but I briefly touched on the "replay". This feature, in my opinion, is one of the most valuable and has helped me a lot during the projects, and during my learning curve with Roo. Let's talk about it, and also make for the example I used during Spring Casual Class.

Every time we execute commands by Roo Shell we have a history, recorded in the log.roo, which is located in the root of the project. This file can be used to repeat previously executed commands (in the same or another project). The steps are:  

1 - Create a copy of the log.roo with another name, keeping the extension and save it in the root of the project which should be executed. 
2 - Edit the file, removing commands that do not matter, renaming fields and classes as needed. We can also add new commands. 
3 - Open the Roo Shell and run: script yourfile.roo

The commands will run on your project and the file will be updated with log.roo latter commands.

Try it out: 

1 - Create some directory 
2 - Save the content below is such directory as a file named casualclass.roo 
3 - cd to such directory an run Roo Shell, and then type : script casualclass.roo

project --topLevelPackage globalcode.casualclass
persistence setup --database HYPERSONIC_IN_MEMORY --provider HIBERNATE
entity --class ~.model.DesiredTalks
field string --fieldName description --sizeMin 5 --sizeMax 40 --notNull
field date --fieldName bestDate --type java.util.Date --persistenceType JPA_DATE --future
finder list --class ~.model.
finder add findDesiredTalksByDescriptionLike
controller all --package ~.web
perform eclipse