Wednesday, January 27, 2010

Rosetta Stone for Java Build Tools

A previous post introduced the idea behind Easter's Eggs: quality examples that I'll use for reference and am sharing with the world.

My latest effort is a modest work in progress. The idea is to build a Rosetta Stone example for Java build tools. In particular: Ant, Ivy, Maven, Gant, and Gradle.

It's called Easter's Eggs for Build Tools and is hosted on GitHub. (You can download without an account.)

My main motivation is that most build tools have solid examples, but when dealing with build issues, chances are, I'm in a hurry. I don't have time to understand some new, contrived example. And for new tools, I don't care about bells and whistles. I just want to see something that works!

Consequently, I decided to develop the same examples across different tools.

Currently, it features only a simple project containing a POJO, a Hibernate mapping, and an integration test. This project is expressed in several forms, and the test should pass in each one. (Consult the respective README.txt)

I don't envision many more projects, but I'd like to develop a multi-project example and probably a war file.

Some of the examples took serious effort, as I'm a newbie to some of these tools. I sincerely hope this helps someone who is looking for a foothold.

Feedback is always welcome.

Monday, January 25, 2010

Syntax Highlighting on Blogger

A big shout-out to your friend and mine, Ken Sipe, for his recent post on adding syntax highlighting to Blogger. (And many thanks to Alex Gorbatchev for the original work.)

Some notes:

My experience matches Ken's, in that it is best to put the links just before the </head> tag.

The highlighting doesn't take effect when writing the post, or in preview mode (presumably because the templating engine isn't emitting the head section). You have to publish it.

One trick for initial testing is to add highlighting to an older post that contains code, and republish.

Finally, don't limit yourself to the list on this excellent post. Chances are, your language has support (e.g. Groovy).

5 Words on Test Organization

Instead of this:

void testCallListReportData() {
controller.programService = programService
def program = Program.findByName(Keys.PROGRAM_ABC)
assertEquals Keys.PROGRAM_ABC, program.name
def student = Student.findByLastName(Keys.STUDENT)
assertEquals Keys.STUDENT, student.lastName
mockParams.id = program.id
def reportData = controller.callListReportData()
assertEquals Keys.PROGRAM_ABC, mockParams['PROGRAM_NAME']
assertNotNull reportData
def thisMap = reportData[0]
assertEquals student.fullName(), thisMap['STUDENT_NAME']
assertEquals Keys.CONTACT_EMAIL, thisMap['CONTACT_EMAIL']
}

Prefer this:

void testCallListReportData() {
controller.programService = programService
def program = Program.findByName(Keys.PROGRAM_ABC)
assertEquals Keys.PROGRAM_ABC, program.name
def student = Student.findByLastName(Keys.STUDENT)
assertEquals Keys.STUDENT, student.lastName
mockParams.id = program.id

// test
def reportData = controller.callListReportData()

assertEquals Keys.PROGRAM_ABC, mockParams['PROGRAM_NAME']
assertNotNull reportData
def thisMap = reportData[0]
assertEquals student.fullName(), thisMap['STUDENT_NAME']
assertEquals Keys.CONTACT_EMAIL, thisMap['CONTACT_EMAIL']
}

Monday, January 11, 2010

Easter's Eggs for Groovy

This blog receives many hits for "Groovy file" and "Groovy IO". To help newbies with Groovy, and for my own reference, I've started a small project over on GitHub called Easter's Eggs for Groovy. (Note: You don't need an account to download the project.)

No, these eggs are not hidden tricks to unlock functionality. Define an "egg" to be a small example to get you started with an idea. This project has some basic eggs for Groovy. It is by no means exhaustive, but does offer the following:
  • eggs for Groovy collection methods, regex's, and IO
  • examples of testing in Groovy. In fact, most of the code is in the tests!
  • a build structure using Gant
Please let me know if there are any examples you'd like to see, or if this is useful for you.

Friday, January 8, 2010

Grails tip for internet connections

I encountered the following issue when configuring Grails, and am posting in case it helps anyone via The Google. Thanks to Matt Taylor for the info.

If you receive this error message for a grails command:

Error reading remote plugin list [Connection timed out: connect], building locally...
Unable to list plugins, please check you have a valid internet connection:
Connection timed out: connect

you may think the plugin site is down. Probably not: it's more likely that you're behind a proxy server. Try this command:

grails set-proxy

To determine the values requested, do the following steps:
  • In FireFox, go to Tools -> Options -> Advanced -> Settings and find the value for 'Automatic proxy configuration URL'
  • View the URL and determine the values used for your IP
Enjoy!