Creating new Modules

Hi,

I want to create a new Module from my plugin, I am failing and surprisingly I could not find an answer in this forum. What I try:

ModuleManager moduleManager = ModuleManager.getInstance(project);
              moduleManager.newModule(
                        project.getBasePath() + "/" + "testcreate",
                        StdModuleTypes.JAVA.getId());


I get

INFO  13:05:14,934 [AWT-EventQueue-0 13.1.2#IC-135.690, eap:false] (ConnectServerAction.java:156) Connecting server: [dev1_alice_stf@localhost]
java.lang.IllegalArgumentException: Extension is missing for storage file: /home/holger/IdeaProjects/alice/testcreate
    at com.intellij.openapi.components.impl.stores.StateStorageManagerImpl.createFileStateStorage(StateStorageManagerImpl.java:242)
    at com.intellij.openapi.components.impl.stores.StateStorageManagerImpl.getFileStateStorage(StateStorageManagerImpl.java:133)
    at com.intellij.openapi.components.impl.stores.ModuleStoreImpl.getMainStorage(ModuleStoreImpl.java:60)
    at com.intellij.openapi.components.impl.stores.BaseFileConfigurableStoreImpl.getMainStorageData(BaseFileConfigurableStoreImpl.java:119)
    at com.intellij.openapi.components.impl.stores.ModuleStoreImpl.getMainStorageData(ModuleStoreImpl.java:98)
    at com.intellij.openapi.components.impl.stores.ModuleStoreImpl.setOption(ModuleStoreImpl.java:220)
    at com.intellij.openapi.module.impl.ModuleImpl.setOption(ModuleImpl.java:243)
    at com.intellij.openapi.module.impl.ModuleManagerImpl$ModuleModelImpl.newModule(ModuleManagerImpl.java:707)
    at com.intellij.openapi.module.impl.ModuleManagerImpl$ModuleModelImpl.newModule(ModuleManagerImpl.java:693)
    at com.intellij.openapi.module.impl.ModuleManagerImpl.newModule(ModuleManagerImpl.java:473)
    at de.fu_berlin.inf.dpp.intellij.ui.actions.ConnectServerAction$1.run(ConnectServerAction.java:120)
    [...]


so when I do

              moduleManager.newModule(
                        project.getBasePath() + "/" + "testcreate.iml",
                        StdModuleTypes.JAVA.getId());


I get a testcreate.iml file, but no module. How should I use the API?

Regards,
Holger

4 comments
Comment actions Permalink

Normally You need only to register your own com.intellij.openapi.module.ModuleType with com.intellij.ide.util.projectWizard.ModuleBuilder. When do You want to create Your module programmatically? On some action/project creation/something else?

0
Comment actions Permalink

Thanks! I just want to create a Java module, not a module type.

Exactly, I want to create it after an action (Sharing a module in another IDEA instance) that comes from outside.

0
Comment actions Permalink

You probably need to use this: com.intellij.ide.util.projectWizard.ModuleBuilder#createModule, but I never used this myself. Refer also com.intellij.openapi.roots.ui.configuration.ModulesConfigurator for clues how to use it.

0
Comment actions Permalink

Hi, I could not figure out how to use that API either. However, I noticed that creating the module with ModuleManager.newModule at least creates it in the project settings, though not on disk.

I realized that I do not have to create new modules, because I already have .iml files, so I could use ModuleManager.loadModule(pathToIMLFile). This works.

Thanks for the help!

0

Please sign in to leave a comment.