mardi 21 juin 2011

Comparing pom.xml files while waiting for indigo




I know you're all waiting for the Indigo release final bits ! These 0 and 1 are finding their way on the mirrors as I'm writing to make sure we'll get the smoothest release ever ;)

So, you ends up waiting ... In the meantime, I'm going to show you a nice piece of technology which is not going to be a new feature is Indigo ... as it's been around a few years already ;)

Maybe you had a look at Maven/Tycho, it definitely gained momentum this year, it's completely based on these pom.xml< files. I used them a few times already and even with the Minerva project (which helps a lot) I'm already in a love/hate relationship with those files.

"When the wise man point at the model, the idiot looks at the XML "

Hopefully Maven is providing an XSD here : http://maven.apache.org/maven-v4_0_0.xsd which you can use to initiate an EMF model :




Starting from an XSD is never as cool as starting from Ecore, but at least the EMF project can provide you an automatic mapping. And here is the mapped Ecore :




If you want a cleaner model you can tweak the mapping.

Using the genmodel you'll get the corresponding Java code. From now EMF is now able to load and save pom.xml files transparently and you can work with them using the Java API or the EMF reflective API.

What for ? To leverage all the great components around here, for instance, EMF compare is then able to use this and compare the model and not the XML serialization.


Ok, It probably took you less than five minutes to read this, if you're not a Friend of Eclipse you still have to wait for the release. As a sidenote, it did not take me more than 5 minutes to prepare it ;)

If you did not checked out EMF&co, you should really have a look !


2 commentaires:

manandbytes a dit…

Whenever I read something about EMF, I'm always wondering 'What for?". It's cool to generate a diff for two POM using EMF, but what benefits it may bring to some real-life plugin that extends, let say, an M2E?

Cédric Brun a dit…

EMF is usable as a plain java Jar and could be usefull for Maven itself, providing an XML agnostic model (POM could be XML, having a specific syntax..). Once you've your EMF model instead of a your home made pojo model a whole new world is opened with components you can reuse Lets focus a bit more on the comparison like in my blog post, EMF compare for instance can guaranty you're model consistency accross several files, meaning if you want to commit a pom.xml file which depends on a change made in another one, EMF Compare will tell you to commit the other one at the same time.

And that's just an example.