Using ModuleManager.newNonPersistentModule

Answered

I want to use the above method in an IntelliJ-Plugin in order to add certain directories which are stored in a PersistenceComponent as a Module to the current project. The reason is that I want to edit files from different directories that might change during runtime by usage of the plugin without always having to confirm that I want to edit files "outside the project scope". My idea is to add all those directories as a Module to get rid of these alerts. However, I do not want to clutter each directory with the .iml-files. That is when I found the above mentioned method for creating a non-persistent module. I want to use this method to create the modules on startup of the plugin and manipulate them during runtime if necessary.

However I do not understand how to add a directory path to the newly created Module by newNonPersistentModule. The description of Module tells me to have a PersistentComponent which should contain the information (in particular the "setOption" is deprecated).

Could you give a minimal example on how to, given a directory path, create a non-persistent module at this location.

Thank you and best regards
Christian

0
2 comments

The created Module from newNonPersistentModule can be modified using ModifiableModel (com.intellij.openapi.roots.ModuleRootManager#getModifiableModel), see https://jetbrains.org/intellij/sdk/docs/reference_guide/project_model/module.html

 

Note that newNonPersistentModule() is experimental API and thus might be removed or altered without upfront notification.

0

Thanks a lot! In the meantime I have resolved my issue by adding the new directories as new content roots of the "root module" via ModifiableRootModel.addContentEntry.

0

Please sign in to leave a comment.