Thursday, August 13, 2009

EMF Tips #1: How the hell do I generate my 28 models?

Recently Ed pointed me to a "hidden" feature in EMF which I always thought I was missing. I take this as an opportunity to launch a series of EMF blogs with hints around EMF, starting with:

How the hell do I generate my 28 models?

In CDO and Net4j together we have 28 models, many of them being test or example models. It has always been a hazzle to regenerate them for new versions of EMF having been published. The best approach I was aware of is a manual loop like this:

I always wished there was a view with all genmodels so that I could select multiple genmodels and regenerate them with a single click. I had such a view in GenFw and even an incremental genmodel generator.

I bet you didn't know the default key binding Shift+Alt+G (M2+M3+G)? I didn't! Go figure:

A dialog opens that lists all genmodels in the workspace. The next page lets you select the sub models to be regenerated:

Before you switch to the second page be sure that all the genmodels selectedin page one can be opened with the genmodel editor without errors. Otherwise the wizard could indefinitely block the UI. Apart from this little lesson it works great and will spare me a lot of dumb effort in the future. Kudos to Marcelo for this neat (but somehow hidden) feature!


  1. Another nice way to automate this is to call the generator programmatically in a (build) script. We do this in Xtext and unless you need JMerge you don't need to run it within Eclipse.
    Also found with help from Ed :-)

    Btw.: Great idea to post a list of EMF tips, I'm looking forward to the upcoming posts.

  2. The reason it's hidden is because we don't have a perspective and adding to the main toolbar in, say, the Java perspective is an Eclipse no-no. We tried to make it so that users could enable a button by customizing the toolbar, but that wasn't possible for a pure command (you needed an action set).

    Of course, people would learn about these things if the losers in EMF Core would just publish a New and Noteworthy. I resolved to do it a couple of times, but I always ran out of time and it fell through the cracks.

    Blocking the UI is definitely a bug. Please open a bugzilla with a test case, and we'll make it better.

    Thanks for blogging about this!

  3. You could also write a groovy monkey script for your project from within Eclipse. With the use of the Eclipse Plugin spy, you could find out what the EMF UI is using to gen your models programmatically and then write the script to do it yourself. I think it would be useful if you have a subset of models to frequently regenerate.

  4. Whooo, nice tip.

    i will just prevent people that this is only available since Eclipse 3.5.


  5. nice! looking forward to more such goodies!

  6. Hello Eike,

    I am in the process of submitting a builder for EMF that will take care of that.

    It has all the nice features like dependency tracking, validation etc., which you may find in the EMF, EMFT newsgroups.

    What you are describing here is exactly something I am trying to tackle with.

    I would really appriciate if you could send me a psf of your worspace.

    Hasan Ceylan

  7. Hi Hasan,

    There's the old setup:

    And the new Buckminster-based setup:

    Let me know if that works ;-)

  8. Hello Eike,

    Thanks for super-fast repy ;) That's the open source developer community ...! ;)

    The psf on the wiki for anonymous users is out-of-date.

    Altough I am not familiar with buckminster
    I'll try that...

  9. buckminster worked like a charm Eike, thanks...