Compile project programmatically?

Hi,

I'm currently trying to invoke project compilation programmatically by using CompilerManager.compile inside a Runnable which is passed as an argument to Application.invokeAndWait.

val compileRunnable = new Runnable() {
def run() {        
  CompilerManager.getInstance(project).compile(projectModule, myCallback)      
}
ApplicationManager.getApplication().invokeAndWait(compileRunnable, ModalityState.defaultModalityState())



The strange thing, I get no errors, but also no output (class) files emitted. Am I doing anything wrong/missing something or is there even an easier way to do it?

Thanks in advance,

Phil

8 comments
Comment actions Permalink

So far, I found out (my bad) that compilation actually happens, yet, too late. Is it possible to trigger immediate compilation?

Thanks again,

Phil

0
Comment actions Permalink

No. The callback parameter is there so that you could continue the activity of your plugin after the compilation ends.

0
Comment actions Permalink

Just for curiosity, if the fragment from the first post is executed within actionPerformed of an AnAction, will the compilation be delayed, until the current action has been completed?

0
Comment actions Permalink

After searching around little, I found this thread (http://devnet.jetbrains.com/message/5482024#548202), which actually contains a solution to my problem.
I implemented a custom Listener, which implements AnActionListener and ApplicationComponent, to trigger compilation inside the beforeActionPerformed method.
I then registered my Listener in the plugin.xml file under applicationComponent. However, due to some yet unknown reason, my Listener does no react on any executed action, which, from my understanding, it is supposed to.
Has there anything changed in the API or am doing something else wrong?

Thanks,

Phil

0
Comment actions Permalink

I'd say that triggering compilation inside the beforeActionPerformed() method is one of the worst possible ways to abuse our API. :) Why isn't the callback an acceptable solution for you?

0
Comment actions Permalink

I see :).
Well, the point is, that I don't really know how to solve my problem with the Callback.

As soon as I call my action, inside actionPerformed I currently attempt to trigger compilation via CompileManager.compile. However, the point is, it does not execute compile until my own action hash finished executin actionPerformed (in fact, it currently returns some error message, as it can't find any reauired compiled classes, which stem from some custom Scala DSL).
Currently, my use of Callback is to output any compilation related messages inside finished.
Probably I'm missing something obvious, yet, I don't know how to use the Callback to solve this.

Cheers,

Phil

0
Comment actions Permalink

It's true that the callback will be called after your actionPerformed() method has completed. You need to invoke the compilation as the last step of your actionPerformed, and do whatever things you need to do after the compilation has finished from inside your callback.

1
Comment actions Permalink

D'oh, quite obvious to put it there...thanks for the help!
It's working now smoothly.


Cheers,

Phil

0

Please sign in to leave a comment.