How to add additional attribute to SourceRoot?

Hey,

first of all a little background: We develop a SDK to push Java code to many platforms (Android, iOS, JVM, Web)
from both a single-code base as well as allowing users to write dedicated applications.

I recently started developing a plugin for IntelliJ IDEA which is open-source at https://github.com/defrac/defrac-plugin-intellij/
Setting up the SdkType was simple, and I think that a Run/Debug configuration is also easily done. However I am not
quite sure how to represent our project structure in IDEA.

Our project structure, or the gist of it:

project
|_ src
    |_ java (generic source visible to all platforms
    |_ java.ios (visible only when building for ios)
    |_ java.web (visible only when building for web)
|_ macro
    |_ java (generic macro source, visible only to compiler)
    |_ java.ios (ios macros, visible only to compiler when building for ios)
    ...
|_ bin
    |_ java (generic java bytecode from src/java)
    |_ java.ios (bytecode from src/java.ios)
    ...
|_ target
    |_ ios (ipa etc)
    |_ web (generated js etc)
    ...
|_ resources
    |_ resource.png (visible to all platforms)
    |_ resource.ios.png (overwrites resource.png for ios)
    |_ asset.web.png (only visible to web, no generic file available
    |_ dir.ios
        |_ ... (contents available only to ios)
|_ lib
    |_ generic.jar (visible to all platforms)
    |_ server.jvm.jar (visible only when targeting jvm)


Now the way we create a project at the moment is by entering "defrac create" to create a plain
project and then "defrac ide-intellij" which generates .idea, modules.xml etc.

Right now, we create a distinct module for each target platform. We do this obviously because there is no plug-in.

Pro:

  • The web module does not see code from iOS module
  • The web module can be linked to the "Generic" module
  • Macro source code, which is executed at compile time, is not visible to runtime modules


Contra:

  • The project consists of (Platforms + Generic) x (Macro + Runtime) modules: For 4 Platforms, that makes 10 modules
  • Modules are shown with weird names which leads to a lot of confusion
  • Project does not feel like a single instance


Attached is a screenshot of the project structure at the moment.
As you can see, the names of the source folders are shown in the form "directory [module] (sources root)" and this is confusing.

This brings me to the main question.

We would like to create a single module using the plug-in. The IDE should handle the dependencies and visibilities. Ideally
we configure source folders with a scope, like "ANDROID". Then the source root will only see classes from libraries and other
sources scoped "ANDROID" or "GENERIC".

How do I add an attribute, scope, to a Java source root?

I saw that there is JavaSourceRootType (side question: is jps documented somewhere?) and it allows me to specify the
package prefix as well as the generated attribute. Can I extend JavaSourceRootType or do I have to create a new
SourceRootType? If so, how would I let IntelliJ know that it is actual Java source since I tried it without much success.

The SDK contains currently also a set of libraries that are not "scoped". In general, this question extends over the whole
plug-in since I would need to add this attribute also to the class path entries of the SDK.

Thank you!


Joa



Attachment(s):
structure.png
2 comments
Comment actions Permalink

Hello,

currently it isn't possible to extend Java source root properties; if you create your own implementation of JavaSourceRootType it won't be treated as
java source root indeed. However even if it could be possible, you would still need to hook into compilation process to provide different classpath
for different source roots inside the same module what also cannot be done in IntelliJ. So unfortunately I don't see a solution for your problem.

--
Nikolay Chashnikov
JetBrains
http://www.jetbrains.com
"Develop with pleasure!"

0
Comment actions Permalink

Nikolay,

thank you for the reply. Too bad that it is not possible. A different approach would be to use custom Facet and stay with
the module structure as-is. Do you think that it is feasable?

The Facet could at least provide the required libraries for each platform and we would need to hook into the build system
anyways since we'd like to leverage IntelliJ's knowledge about the Java source code for incremental building.


Best,
Joa

0

Please sign in to leave a comment.