Refresh newly created folder and its content after source code generation

Hi there,

i want to refresh a folder in my intellij project after MyBuilder finished his work.

public class MyBuilder extends org.jetbrains.jps.incremental.ModuleLevelBuilder

    protected MyBuilder() {
        super(org.jetbrains.jps.incremental.SOURCE_GENERATOR);
    }

    // ...

}


MyBuilder creates a new folder in my Project and places a few Java files into it.

It would be great if the generated Java files would also be automatically compiled to Java Byte code.

How can i achieve that?

THX

4 comments

Has anyone an idea or hint for me?

0

Hi Sven,

> i want to refresh a folder in my intellij project after MyBuilder finished his work.

The easiest way to achieve this will be regestering CompilationStatusListener with CompileManager and then performing refresh on relevant directories after compilationFinished() notification.

A little bit harder, but more "precise" way to do this, is to send CustomBuilderMessage from the build process to IDEA via

CompileContext.processMessage().
On IDEA side your plugin should register CustomBuilderMessageHandler in the corresponding topic with the project's message bus:

CustomBuilderMessageHandler messageHandler = new MyMessageHandler();
project.getMessageBus().connect().subscribe(CustomBuilderMessageHandler.TOPIC, messageHandler);

in this approach your builder may send messages containing generated paths and your message handler on IDEA's side will analyse them and will call refresh exacly on those files that were generated. Also this allows you to perform refresh asynchronously after receiving the message from your builder, not waiting until the whole build finishes.

> would be great if the generated Java files would also be automatically compiled to Java Byte code.

In order for the generated sources to be visible to JavaBuilder that will be executed after the source generator, all such sources should be eplicitly martked as "dirty" by your builder via

FSOperations.markDirty(context, file)


Hope this helps,
Best regards,
  Eugene

0

Thanks Eugene, I also ran into this problem and your explanation really helps.
What I don't understand is why when a custom source generating compiler uses

  outputConsumer.registerOutputFile(moduleBuildTarget, generatedFile, sourcePaths);

the generatedFile is not marked dirty automatically? I built a helper always doing both.
Generally, I would have expected invalidation of files in IDEA created by a JPS source-generating compiler to come out of the box...
All in all, the transition to the JPS build system seems to still have some rough edges and looks a bit incomplete (e.g. JPS classes are not used in IDEA, so you have to implement de-serialization twice).
I hope it is continued and improved in IDEA 13.1 or at least 14?

Greetings
-Frank-

0

Okay, I implemented the "harder" solution to send invalidation messages as custom build messages,
so if anyone wants to reuse some code, here is the commit from which to start (Apache 2 license):
https://github.com/CoreMedia/jangaroo-idea/commit/00b7a1a3c4319311d611d59bb97a2a4c5aaf9355

Have fun,
-Frank-

0

Please sign in to leave a comment.