Search in sources :

Example 6 with ModuleManager

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

the class ModuleTestCase method loadModule.

protected Module loadModule(@NotNull String modulePath) {
    final ModuleManager moduleManager = ModuleManager.getInstance(myProject);
    Module module;
    try {
        module = ApplicationManager.getApplication().runWriteAction((ThrowableComputable<Module, Exception>) () -> moduleManager.loadModule(FileUtil.toSystemIndependentName(modulePath)));
    } catch (Exception e) {
        LOG.error(e);
        return null;
    }
    myModulesToDispose.add(module);
    return module;
}
Also used : ThrowableComputable(com.intellij.openapi.util.ThrowableComputable) ModuleManager(com.intellij.openapi.module.ModuleManager) Module(com.intellij.openapi.module.Module) CompoundRuntimeException(com.intellij.util.lang.CompoundRuntimeException) IOException(java.io.IOException)

Example 7 with ModuleManager

use of com.intellij.openapi.module.ModuleManager in project intellij-plugins by JetBrains.

the class AngularJSProjectConfigurator method configureProject.

@Override
public void configureProject(Project project, @NotNull VirtualFile baseDir, Ref<Module> moduleRef) {
    final ModuleManager moduleManager = ModuleManager.getInstance(project);
    final Module[] modules = moduleManager.getModules();
    if (modules.length == 1) {
        final VirtualFile cliJson = baseDir.findChild(ANGULAR_CLI_JSON);
        final ModifiableRootModel model = ModuleRootManager.getInstance(modules[0]).getModifiableModel();
        final ContentEntry entry = MarkRootActionBase.findContentEntry(model, baseDir);
        if (entry != null && cliJson != null) {
            excludeDefault(baseDir, entry);
            ApplicationManager.getApplication().runWriteAction(() -> {
                model.commit();
                project.save();
            });
        } else {
            model.dispose();
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) ContentEntry(com.intellij.openapi.roots.ContentEntry) ModuleManager(com.intellij.openapi.module.ModuleManager) Module(com.intellij.openapi.module.Module)

Example 8 with ModuleManager

use of com.intellij.openapi.module.ModuleManager in project android by JetBrains.

the class DataNodeCaches method isCacheMissingModels.

public boolean isCacheMissingModels(@NotNull DataNode<ProjectData> cache) {
    Collection<DataNode<ModuleData>> moduleDataNodes = findAll(cache, MODULE);
    if (!moduleDataNodes.isEmpty()) {
        Map<String, DataNode<ModuleData>> moduleDataNodesByName = indexByModuleName(moduleDataNodes);
        ModuleManager moduleManager = ModuleManager.getInstance(myProject);
        for (Module module : moduleManager.getModules()) {
            DataNode<ModuleData> moduleDataNode = moduleDataNodesByName.get(module.getName());
            if (moduleDataNode == null) {
                // When a Gradle facet is present, there should be a cache node for the module.
                GradleFacet gradleFacet = GradleFacet.getInstance(module);
                if (gradleFacet != null) {
                    return true;
                }
            } else if (isCacheMissingModels(moduleDataNode, module)) {
                return true;
            }
        }
        return false;
    }
    return true;
}
Also used : DataNode(com.intellij.openapi.externalSystem.model.DataNode) GradleFacet(com.android.tools.idea.gradle.project.facet.gradle.GradleFacet) ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData) ModuleManager(com.intellij.openapi.module.ModuleManager) Module(com.intellij.openapi.module.Module)

Example 9 with ModuleManager

use of com.intellij.openapi.module.ModuleManager in project android by JetBrains.

the class AndroidGradleTestCase method loadProject.

protected void loadProject(@NotNull String relativePath, @Nullable GradleSyncListener listener, @Nullable String chosenModuleName) throws Exception {
    prepareProjectForImport(relativePath);
    Project project = getProject();
    File projectRoot = virtualToIoFile(project.getBaseDir());
    importProject(project.getName(), projectRoot, listener);
    assertTrue(AndroidProjectInfo.getInstance(project).requiresAndroidModel());
    assertFalse(isLegacyIdeaAndroidProject(project));
    ModuleManager moduleManager = ModuleManager.getInstance(project);
    Module[] modules = moduleManager.getModules();
    // if module name is specified, find it
    if (chosenModuleName != null) {
        for (Module module : modules) {
            if (chosenModuleName.equals(module.getName())) {
                myAndroidFacet = AndroidFacet.getInstance(module);
                break;
            }
        }
    }
    if (myAndroidFacet == null) {
        // then try and find a non-lib facet
        for (Module module : modules) {
            AndroidFacet androidFacet = AndroidFacet.getInstance(module);
            if (androidFacet != null && androidFacet.isAppProject()) {
                myAndroidFacet = androidFacet;
                break;
            }
        }
    }
    // then try and find ANY android facet
    if (myAndroidFacet == null) {
        for (Module module : modules) {
            myAndroidFacet = AndroidFacet.getInstance(module);
            if (myAndroidFacet != null) {
                break;
            }
        }
    }
    refreshProjectFiles();
}
Also used : Projects.isLegacyIdeaAndroidProject(com.android.tools.idea.gradle.util.Projects.isLegacyIdeaAndroidProject) Project(com.intellij.openapi.project.Project) ModuleManager(com.intellij.openapi.module.ModuleManager) Module(com.intellij.openapi.module.Module) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) VfsUtilCore.virtualToIoFile(com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile) File(java.io.File) TestUtils.getWorkspaceFile(com.android.testutils.TestUtils.getWorkspaceFile) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 10 with ModuleManager

use of com.intellij.openapi.module.ModuleManager in project android by JetBrains.

the class MakeGradleProjectAction method doPerform.

@Override
protected void doPerform(@NotNull AnActionEvent e, @NotNull Project project) {
    StatusBar statusBar = WindowManager.getInstance().getStatusBar(project);
    if (statusBar != null) {
        // Reset info from the previous runs (if any).
        statusBar.setInfo(" ");
    }
    ModuleManager moduleManager = ModuleManager.getInstance(project);
    GradleBuildInvoker.getInstance(project).compileJava(moduleManager.getModules(), GradleBuildInvoker.TestCompileType.NONE);
}
Also used : ModuleManager(com.intellij.openapi.module.ModuleManager) StatusBar(com.intellij.openapi.wm.StatusBar)

Aggregations

ModuleManager (com.intellij.openapi.module.ModuleManager)51 Module (com.intellij.openapi.module.Module)40 VirtualFile (com.intellij.openapi.vfs.VirtualFile)11 Project (com.intellij.openapi.project.Project)10 NotNull (org.jetbrains.annotations.NotNull)8 ModifiableModuleModel (com.intellij.openapi.module.ModifiableModuleModel)7 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)7 File (java.io.File)7 GradleFacet (com.android.tools.idea.gradle.project.facet.gradle.GradleFacet)3 IOException (java.io.IOException)3 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)3 AndroidLibrary (com.android.builder.model.AndroidLibrary)2 Variant (com.android.builder.model.Variant)2 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)2 BuildMode (com.android.tools.idea.gradle.util.BuildMode)2 AccessToken (com.intellij.openapi.application.AccessToken)2 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 Sdk (com.intellij.openapi.projectRoots.Sdk)2 ContentEntry (com.intellij.openapi.roots.ContentEntry)2 ModuleRootManager (com.intellij.openapi.roots.ModuleRootManager)2