Search in sources :

Example 1 with ModuleTypeManager

use of com.intellij.openapi.module.ModuleTypeManager in project intellij-community by JetBrains.

the class PlatformProjectConfigurator method configureProject.

@Override
public void configureProject(final Project project, @NotNull final VirtualFile baseDir, final Ref<Module> moduleRef) {
    final ModuleManager moduleManager = ModuleManager.getInstance(project);
    final Module[] modules = moduleManager.getModules();
    if (modules.length == 0) {
        ApplicationManager.getApplication().runWriteAction(() -> {
            // correct module name when opening root of drive as project (RUBY-5181)
            String moduleName = baseDir.getName().replace(":", "");
            String imlName = baseDir.getPath() + "/.idea/" + moduleName + ModuleFileType.DOT_DEFAULT_EXTENSION;
            ModuleTypeManager instance = ModuleTypeManager.getInstance();
            String id = instance == null ? "unknown" : instance.getDefaultModuleType().getId();
            final Module module = moduleManager.newModule(imlName, id);
            ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
            ModifiableRootModel rootModel = rootManager.getModifiableModel();
            if (rootModel.getContentRoots().length == 0) {
                rootModel.addContentEntry(baseDir);
            }
            rootModel.inheritSdk();
            rootModel.commit();
            moduleRef.set(module);
        });
    }
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) ModuleTypeManager(com.intellij.openapi.module.ModuleTypeManager) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) ModuleManager(com.intellij.openapi.module.ModuleManager) Module(com.intellij.openapi.module.Module)

Aggregations

Module (com.intellij.openapi.module.Module)1 ModuleManager (com.intellij.openapi.module.ModuleManager)1 ModuleTypeManager (com.intellij.openapi.module.ModuleTypeManager)1 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)1 ModuleRootManager (com.intellij.openapi.roots.ModuleRootManager)1