Geertjan is a DZone Zone Leader and has posted 464 posts at DZone. You can read more from them at their website. View Full User Profile

Ode to Build Scripts

01.23.2008
| 5377 views |
  • submit to reddit
I was reading the Code to Joy blog today because of an interesting blog entry about Groovy and JFugue, who are two of my friends in the programming world. It's very cool to see how they relate: simplified Java with simplified Midi! The best of both worlds. In the comments Guillaume from Groovy writes: "A couple years ago, I played with the idea of an Ant build listener that played JFugue little tunes when certain targets were started and finished, to have an audible indication of what was going on."

And then I remembered my recent explorations of the org.apache.tools.ant.module.spi.AntLogger class. That, according to the Javadoc is "a pluggable logger that can listen to AntEvents during one or more AntSessions". You can incorporate that into a NetBeans module, install it in NetBeans IDE, and then the IDE (being modular) is influenced by the installed module. So, inspired by Guillaume, here is my JFugified Antlogger:

public class SuccessfulBuildLogger extends org.apache.tools.ant.module.spi.AntLogger {

@Override
public boolean interestedInSession(AntSession session) {
return true;
}

@Override
public boolean interestedInAllScripts(AntSession session) {
return true;
}

@Override
public void buildFinished(AntEvent event) {
Throwable t = event.getException();
Player player = new Player();
if (t != null) {
//There is an exception, so write message and play notes:
event.getSession().println(t.toString(), true, null);
Pattern pattern1 = new Pattern("I[60] E E F G");
player.play(pattern1);
} else {
//Play different notes when there is no exception:
Pattern pattern2 = new Pattern("I[60] G F E D");
player.play(pattern2);
}
}

}

The above implies I have a NetBeans module suite (which is a container for modules), which in this case contains a library wrapper for JFugue, together with a functionality module that provides the above class. I've extended the module so that the user can use the NetBeans IDE Options window to type in a different pattern of JFugue notes (even with syntax coloring and code completion, in a JEditorPane), but I encountered a problem with JFugue that I'm trying to get fixed first. Something about a sequencer not being found. I think in the past that meant that I needed to restart, or something like that, or maybe my disk is full, or something like that.

Anyway, I now hear one pattern when the build succeeds and another when it fails, for every project in NetBeans IDE. Hurray!

 

Published at DZone with permission of its author, Geertjan Wielenga.