Friday, July 17, 2009

Greasemonkey for Maven 2

Few things are more tedious than crawling through hundreds of lines of Maven 2 output to discover which test failed, mojo didn't execute correctly, or error was thrown during integration tests. After using git for my primary version control tool, I'm spoiled with its lovely full-color output, so why can't I have that for Maven 2?

Turns out, there is a ticket open in the Maven JIRA project for this, but so far, there doesn't seem much traction, and fixing it for me now would involve forking Maven again, which I'd rather not. Therefore, I decided to take the Greasemonkey approach and write a wrapper around the Maven output so that I can format it exactly how I want.

Introducing the Console Colorizer, a command line tool for wrapping Maven execution, then feeding its output through a Lexer that adds VT100 color codes where appropriate. This approach is suprior to the usual colorizing the logging output, because I can match any text and highlight it any way I want. Going a bit farther, I could even detect certain bits of output and execute arbitrary code, like sending a Growl or IM notification. All this without modifying any Maven Java code.

Compare this raw Maven 2 output:


With this:


It is so much easier to see that the test failed, and what warnings your Maven plugins are complaining about. This tool works by wrapping the Maven main execution and running the System.out through a JFlex lexer. The lexer is nice because it allows me to define tokens via regular expressions, yet remain very fast and compact. A few VT100 codes allow me to add the coloring.

Of course, this same technique could be applied to any Java program, or any program at all if you really wanted to, but for now, I think it'll do nicely to clean up Maven 2 a bit.

9 comments:

  1. I couldn't see a ready made jar to download - did I miss it or do I need to build from source?

    ReplyDelete
  2. Sorry for the noise, just found the source download

    ReplyDelete
  3. Hi,
    I have a colorized version of Maven available:
    http://www.ehsavoie.com/2009/07/maven-en-couleurs.html which will colorize using the log level. Maybe we could inject your lexer in the logger.
    I think the real interest in colorization lies in the Unit tests results so I will propose a patch to surefire.

    I hope to be able to

    ReplyDelete
  4. I love the idea behind this as Maven would definitely be cooler with colorized logging. I tried it on my iTerm and it kinda shows up with colorization on the INFO, but not on the whole line.

    http://www.flickr.com/photos/mraible/3834879949/

    Another thing I noticed is I had to delete /usr/bin/mvn on OS X to get this to work.

    ReplyDelete
  5. @ehsavoie, cool, but not all output goes through the logger, so you still need to grab the raw output.

    @matt, what is happening is it is bolding the tag, but setting the rest of the line to the default color. This works fine on most terminals (osx terminal and gnome terminal tested so far), but obviously not on iterm. We should probably just force the whole line a certain color, then make it configurable via a properties file in the home directory or something.

    BTW, if using this at all, I just committed a fix to make it way, way faster; only 1.5% slower than plain maven on a simple build ran 10 times.

    ReplyDelete
  6. Well... round about every blog posts online don't have much originality as I found on yours.. Just keep updating much useful information so that reader like me would come back over and over again.
    Dissertation help

    ReplyDelete
  7. Don moved this to :

    https://github.com/mrdon/maven-trap

    ReplyDelete
  8. Many professional athletes wear Oakley sunglasses because of their high quality craftsmanship and this brand's dedication to finding ways to improve their designs and technology.Southern cheap ray ban sunglassesis the home of Oakley, which was founded in 1975 by Jim Jannard. Jannard was a motorcycle enthusiast who developed special rubber handgrips for off road motorcyclists. After focusing on selling handgrips and motorcycle parts for about a decade, he began selling motorcycle goggles sporting his own designs. His goggles were made from high-impact plastic, which were much lighter and more durable than the glass goggles that were the standard at the time. When these started to become popular, Jannard and a team of young salespeople developed a revolutionary type of protective eyewear;

    ReplyDelete
  9. Maybe you will update the link... please!

    ReplyDelete