What Happened to Maven Registry?

Alright, mvnregistry.com, it was once an index of the Maven 2 repository. It was a Rails application, it was something I put together in my own spare time, and it was a tool that filled a personal requirement. It was also an attempt to prove to myself that the idea was worth pursuing. It was a simple Ruby script that traversed all of the POM files and populated a MySQL database. It worked well for a while, but the downfall came when I tried to put a comment form on the front page.

Conclusion, don’t home comment forms unless it is you full time job to maintain them. There are solutions like Akismet, but because it was a super part-time effort, I just didn’t have the time or patience to bother playing catch up with Romanian porn spammers. In the end, someone hijacked the site via the comments, putting a JS redirect to a really terrible porn site. I had no choice but to turn that particular application off.

Parsing Repository was a PITA
To me, it pointed to some problems with the Maven Repository, for starters, POM interpolation might be an interesting fancy feature in Maven 2, but it made parsing metadata a chore. The decision to allow for variable substitution in a pom.xml file reduces the portability of the format, it becomes less of a description and more a descriptive templating language. The pom.xml should be complete, and the interpolation should be a convenience. A variable reference should never show up in the repository. Maybe they’ve addressed this, I’m not sure because I haven’t really paid too much attention to Maven in the past few months – I’ve had other priorities (and that was another reason for shutting down mvnregistry.com)

The other reason that parsing was problematic was because there were a lot of projects with such a bare minimum of information in the pom.xml it wasn’t useful. There were more than a few projects out there that didn’t even bother with a description. To me, this is a failure to really deliver on the promise of the technology. Maven could be creating this interesting semantic picture of software as components, it is and it isn’t. Maven’s a mixed bag in many respects. Two years on from the Dev Notebook, and I’m still very much on the fence about the quality of the tool.

Lastly, there were a large number of duplicated groups – a mixture of approaches. Some groups continue to not use group ids that follow domain names, others do.

maybe later…

Maven registry.com might come back shortly, but it’s low on my priority list. In the meantime go check out http://www.mvnrepository.com

Adding a Reference to a CSS or Javascript Page in Wicket 2.0

Assume that you were developing a site in Wicket that made heavy use of both the Protoype and the Scriptaculous libraries. Sometimes you’ll be using Prototype scripts directly in your HTML files, and at other times, you’ll be using prepackaged functionality like wicket-contrib-scriptaculous. You want to add a reference to the Prototype and Scriptaculous scripts to every single page on your site, how would you do that?

Page Inheritance
When you create a Wicket application you usually make liberal use of inheritance to give every page in your application a common set of components. You may also make use of abstract Section pages which are the super classe for every page in a given section. These section pages would take care of adding common sectional navigation and the top-most page would be responsible for setting up all common elemenets. Since Prototype and Scriptaculous are going to be universal elements, you will add IHeaderContributors somewhere in the AppPage class from the diagram below:

From the diagram: your application extends Wicket’s WebPage class with an AppPage class. This AppPage class adds a universal border to all pages on the site. A concrete HomePage class extends the AppPage class and, lastly, there are two sections (A and B) which each maintain a separate abtract section class to add section-specific navigation and components.

Where do we Add Prototype and Scriptaculous?
If you were going to add a reference to prototype.js and scriptaculous.js, you would do so in one of two places. A.) In the section of the AppPage.html. OR, B.) In the constructor of the AppPage.java class. Let’s look at both options. Adding these references to the constructor of AppPage means that the references will be available to every page which extends AppPage.

Adding a Reference to the AppPage.html

If you were going to add a reference to the AppPage.html file, you would add the following:

<script type=”text/javascript” src=”resource/js/prototype.js”></script>

In this scenario, you will need to make sure that “prototype.js” is available under the resource/js/prototype.js path in the web application. Wicket will take care of prepending the content path to this reference.

Adding a Reference to the AppPage Class
To add a reference to the AppPage class, add some HeaderContributors. A HeaderContriburor is an implementation of IBehavior and can be added with the add() command

public AppPage() {
new AppBorder(this, “border”);
new FeedbackPanel(this, “status”);

add( HeaderContributor.forJavaScript(ScriptaculousAjaxHandler.class,”prototype.js”) );
add( HeaderContributor.forJavaScript(ScriptaculousAjaxHandler.class,”scriptaculous.js”) );

There are two convenience methods provided by HeaderContributor – forJavascript and forCss. Boh functions take a Class and the name of a resource. When using this method, the Javascript resources is stored on the classpath as a resource in the same package as the ScriptaculousAjaxHandler. The ScriptaculousAjaxHandler is a class that is bundled with wicket-contrib-scriptaculous.

Chad Fowler: The Big Rewrite

I’ve seen a number of organizations over the years contemplate “The Big Rewrite”

From Chad’s “The Big Rewrite”:

“You’ve got an existing, successful software product. You’ve hit the ceiling on extensibility and maintainability. Your project platform is inflexible, and your application is a software house of cards that can’t support another new feature.”

And from, Software As Spec:

Based on my own experiences and conversations with thousands of software developers around the planet, I unscientifically conclude that almost all production software is in such bad shape that it would be nearly useless as a guide to re-implementing itself. Now take this already bad picture, and extract only those products that are big, complex, and fragile enough to need a major rewrite, and the odds of success with this approach are significantly worse.

Retrieving Typed Configuration with Commons Configuration

Typed configuration is very straightfoward with Commons Configuration. One of my pet peeves is having to translate numeric configuration parameters from String instances to the corresponding primitive type. The following example loads configuration from the test.properties file:

       // import the necessary classes...
      import java.net.URL;
      import org.apache.commons.configuration.Configuration;
      import org.apache.commons.configuration.ConfigurationFactory;

      // Load your configuration from the classpath...
      Configuration config = new PropertiesConfiguration( "test.properties" );
      // Retrieve configuration parameters
      float timeout = config.getFloat("timeout"));
      String region = config.getString("region"));
      String name = config.getString("name"));
      int speed = config.getInt("speed"));

The test.properties file has the format of a standard Java properties file, with a key and value on each new line:

      name=This is an Example

If you need to convert to an Object instead of a primitive, you’ll need to supply a default value to be used if the configuration parameters is not available. For example, the following code would set timeout to Float.NaN and speed to 0 if these parameters were not present in the specified properties file.

       Float timeout = config.getFloat( "timeout", Float.NaN );
      Integer speed = config.getInteger( "speed", new Integer( 0 ) );