Should I use a SourceGeneratingCompiler?

Hi,

I would like to generate some Java files in the build process, just before the compilation part. The best way to do so is to use a SourceGeneratingCompiler, but I can't obtain what I want.
My generated source files have to be put inside the src folder, then be compiled. IIUC the "standard" way is to put generated files directly inside the output directory, but that's not what I want.

In fact, I cannot find a way to compute the relative path from my generated files to the compilation output directory (as required by org.intellij.plugins.kasper.compiler.KasperXmlItem#getPath).
In my case the output root directory (a random directory created by IDEA?) is in C:\ whereas my source folder is in D:\, and VfsUtil#getPath seems to be unable to compute the relative directory between two partitions...

Also, VfsUtil#getPath seems to return the wrong relative path if both "src" and "dst" parameters are directories (it misses one depth level).

First question: can I use SourceGeneratingCompiler to generate Java files in a source root, then compile them?
Second question:  what has changed regarding SourceGeneratingCompiler with the recent external build? (http://youtrack.jetbrains.com/issue/IDEA-94145)

Thanks a lot.

2 comments
Comment actions Permalink

1. No. If your generated files live in a source directory, you should use a different process to generate them. You can look at how the Android plugin generates R.java for an example,
2. The external make process does not use the IntelliJ plugin API at all, and has a completely different architecture. You can find an example at https://github.com/JetBrains/intellij-community/tree/master/plugins/android/jps-plugin
We plan to publish the documentation for the new external make soon.

0
Comment actions Permalink

Thanks Dmitry,

I looked at how R.java is generated, and I was actually quite close to how it's done. It's also a SourceGeneratingCompiler, which returns a fake path and forces a refresh of the generated files so that they are included in the compilation process, and shown/updated in the project view etc.

Regarding the external make process, I also found interesting answers in the Android plugin. I have something which is working quite well, except that I can't force IDEA to take generated files into account. I can mark those files as "dirty", so that the build process includes them, but when the compilation is done, the IDE does not reflect those new/modified files. I am not sure this is possible, I guess the communication between those two process is quite limited and does not includes actions such as "ask the IDE to refresh blah.java". Perhaps the documentation will soon enlighten me :).

Out of curiosity, what does "JPS" stand for?

0

Please sign in to leave a comment.