Run MakeAction several times programmatically

Hey guys,

inside an action, I want to manipulate my model and then rebuild (i.e. run the generators) the model programmatically several times in a loop. I call the model manipulation and the MakeAction inside two separate Runnables that I call with invokeAndWait. It looks somehow like this:

for (...) {

ApplicationManager.getApplication().invokeAndWait(new Runnable() {
  public void run() {
    ApplicationManager.getApplication().runWriteAction(new Runnable() {
      public void run() {
        // Manipulate model
      }
    });
  }
}, ModalityState.any());

ApplicationManager.getApplication().invokeAndWait(new Runnable() {
  public void run() {
     // Rebuild model
MakeActionParameters cleanMake = new MakeActionParameters(this.mpsProject).models(models).cleanMake(true);
MakeActionImpl buildAction = new MakeActionImpl(cleanMake);
buildAction.executeAction();
  }
}, ModalityState.any());
}

I can see that the Runnables are called several times and in the correct order, but the Make action (the generators) only runs once at the end as if it was completely asynchronous. Is there a way to wait for the MakeAction to be finished?

 

2 comments
Comment actions Permalink

In case you need complete generation process (with generators applied, text generated, and all auxiliary make targets respected), then I'd go with another Make service, not the one available by default in the IDE (aka WorkbenchMakeService). It's asynchronous and not well suited for script-initiated make. Try BuildMakeService instead, although you'd need to duplicate some of MakeActionImpl class (which is not bad anyway, as it's a UI action and not suited for script execution either).

If you need to run few generators only (e.g. no textgen or auxiliary make targets), there's an answer describing use of GenerationFacade API for this purpose.

2
Comment actions Permalink

Hey Tikhomirov, that sounds woth trying. Thanks for your suggestions, I will have a look at it. Cheers,

Arne

0

Please sign in to leave a comment.