Avoiding manual merge when generating plugin.xml with Xtext/Xtend

In our project we do generate graphical editors for Graphiti based on DSL-models specifiying these editors. That works all fine when generating the source code (.java and .xtend). However, for Graphiti and the editor to work, there also have to be some additions / modifications to the plugin.xml of the editor’s defining plugin.

While there is no issue in generating any text file (and such some .xml) with Xtend, the default mechanism has two characteristics that require a manual merge:

  • Artefacts are generated into src-gen/, plugin.xml is one level higher
  • No merging support of existing files with generated files out-of-the-box

While it is probably possible to modify the code generator infrastructure that Xtext provides out-of-the box, we chose a simpler way: Why not generate the extensions that we use in separate in the src-gen directory and then use another mechanism to merge in with plugin.xml?

Eclipse allows you to add custom builders to your project through the project properties. There are basically two that you can configure: An external program or an ANT Build. An external program was not feasible, since we would like the same configuration to work on different platforms (WIN,Mac,Linux) and you would require absolute pathes to binaries.

But the same can be done with an ant. So in our projects we do have a new ANT script2013-01-11_09h40_56that recognizes the merged sections and upon build, throws them out and replaces them with the contents of one or more “fragment” files that end with “copymetoplugin.xml” from src-gen:



Hier is the pom fragment to update the XML from Tycho:



Leave a Reply

Your email address will not be published. Required fields are marked *