Trigger solution rebuild programmtically

Hey MPS enthuasiasts!

Has someone found a way to programmatically trigger a rebuild all command on a solution/language?

I just want to test (blackbox) the correct output of my generator, which is text. Therefore, I added a DSL script in a solution which contains all combinations.

Now, I just wanted to make a string.compare with the output of the generator and my expected result.

Thankfully, I got a tip resulting in the following code. I added it in a NodeTestCase

new MakeActionImpl(new MakeActionParameters(project).modules(project.getProjectModules())).executeAction();

 

Unfortunately, it results in the following error:

java.lang.IllegalStateException: should be called outside of command
at jetbrains.mps.ide.make.actions.MakeActionImpl.executeAction(MakeActionImpl.java:35)

Thanks for your help!

17 comments
Comment actions Permalink

Hi there,

 

How are you invoking that piece of code?

Seems, by the error message, that you are you using ".executeCommand()"? Can you try using ".runWriteAction()" instead?

 

Regards,

Sérgio Ribeiro

Porto - Portugal

 

1
Comment actions Permalink

I've just discovered that NodesTestCase has a property that indicates whether the test should be run in a command/write action. Try setting it to false in the Inspector.

0
Comment actions Permalink

From Lisson S.

new MakeActionImpl(new MakeActionParameters(project).modules(...).cleanMake(true)).executeAction()
-1
Comment actions Permalink

Hi all,

what should I import in my plugin to so that I could invoke this:

new MakeActionImpl(new MakeActionParameters(project).modules(project.getProjectModules())).executeAction();

Thanks!

0
Comment actions Permalink

You will need the models containing the used classes (use Conrol + R), I think it is j.m.ide.make.actions in your case, and most likely the smodel language.

0
Comment actions Permalink

Yes! That worked! thanks!

0
Comment actions Permalink

Hi, One more question:

Is there a way by which one can only build model instead of the whole project?

In the following statement I can only give project as a parameter to the MakeActionParameter().

new MakeActionImpl(new MakeActionParameters(project).modules(project.getProjectModules())).executeAction();
0
Comment actions Permalink

I guess you just call new MakeActionParameters(project).models() instead of modules and pass in the desired models.

0
Comment actions Permalink

Yes but the real problem is I can't access project instance within my plugin. I have "model" as an "action context parameter" but I couldn't add project as parameter there. Also, I tried to get the project from the model but I couldn't find any way to do that.

0
Comment actions Permalink

You need to add a dependency on j.m.ide.actions@java_stub into your plugin model. This model holds the MPSCommonDataKeys class, which contains most of the relevant keys to use here.

0
Comment actions Permalink

BTW, there are more keys available, please see https://confluence.jetbrains.com/display/MPSD20171/Plugin#Plugin-Constructionparameters for full listing.

Vaclav

0
Comment actions Permalink

Hi Vaclav, thanks that worked!

 

0
Comment actions Permalink

Hi again,


When I used the recommended statement in my plugin to build my project, it didn't seem to do anything. Even no errors are generated.

0
Comment actions Permalink

Could it be because your catch clause is empty and so the error gets swallowed?

0
Comment actions Permalink

Hi Vaclav,

Thanks for your help. I really appreciate it. Yes you were right the exception was being swallowed by the catch clause.

So as expected now I'm getting the same exception "IllegalStateException" as decribed above. And I tried the solution as described above (if I understood it correctly) and use the "write" action for synchronization but I'm still getting the same error.

Thanks again!

0
Comment actions Permalink

It worked when I set the "excute outside command" to true in the plugin.

0
Comment actions Permalink

Hi Vaclav,

I have one more problem. In my plugin, I want to use rebuild command in a loop. Every time I make few changes in the model and then rebuild the model again. When I use my plugin, it rebuilds but the result is not intended. It looks like it is rebuilding just one time. And updating the same result every time.

 


0

Please sign in to leave a comment.