Search in sources :

Example 26 with ModifiableModuleModel

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

the class ModuleElementPresentation method render.

public void render(@NotNull PresentationData presentationData, SimpleTextAttributes mainAttributes, SimpleTextAttributes commentAttributes) {
    final Module module = findModule();
    if (myTestOutput) {
        presentationData.setIcon(PlatformIcons.TEST_SOURCE_FOLDER);
    } else if (module != null) {
        presentationData.setIcon(ModuleType.get(module).getIcon());
    }
    String moduleName;
    if (module != null) {
        moduleName = module.getName();
        final ModifiableModuleModel moduleModel = myContext.getModifiableModuleModel();
        if (moduleModel != null) {
            final String newName = moduleModel.getNewName(module);
            if (newName != null) {
                moduleName = newName;
            }
        }
    } else if (myModulePointer != null) {
        moduleName = myModulePointer.getModuleName();
    } else {
        moduleName = "<unknown>";
    }
    String text = myTestOutput ? CompilerBundle.message("node.text.0.test.compile.output", moduleName) : CompilerBundle.message("node.text.0.compile.output", moduleName);
    presentationData.addText(text, module != null ? mainAttributes : SimpleTextAttributes.ERROR_ATTRIBUTES);
}
Also used : ModifiableModuleModel(com.intellij.openapi.module.ModifiableModuleModel) Module(com.intellij.openapi.module.Module)

Example 27 with ModifiableModuleModel

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

the class ResolveClassTest method configureDependency.

@SuppressWarnings({ "ConstantConditions" })
private void configureDependency() {
    ApplicationManager.getApplication().runWriteAction(() -> {
        ModifiableModuleModel modifiableModel = ModuleManager.getInstance(getProject()).getModifiableModel();
        Module module = modifiableModel.newModule("a.iml", StdModuleTypes.JAVA.getId());
        modifiableModel.commit();
        VirtualFile root = LocalFileSystem.getInstance().refreshAndFindFileByPath(getTestDataPath() + "/class/dependentModule");
        assert root != null;
        PsiTestUtil.addContentRoot(module, root);
        PsiTestUtil.addSourceRoot(module, root.findChild("src"));
        PsiTestUtil.addSourceRoot(module, root.findChild("test"), true);
        ModuleRootModificationUtil.addDependency(getModule(), module);
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ModifiableModuleModel(com.intellij.openapi.module.ModifiableModuleModel) Module(com.intellij.openapi.module.Module)

Example 28 with ModifiableModuleModel

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

the class MultiModuleEditingTest method testRootsEditing.

public void testRootsEditing() {
    final MessageBusConnection connection = myProject.getMessageBus().connect();
    final ModuleManager moduleManager = ModuleManager.getInstance(myProject);
    final MyModuleListener moduleListener = new MyModuleListener();
    connection.subscribe(ProjectTopics.MODULES, moduleListener);
    final Module moduleA;
    final Module moduleB;
    {
        final ModifiableModuleModel moduleModel = moduleManager.getModifiableModel();
        moduleA = moduleModel.newModule("a.iml", StdModuleTypes.JAVA.getId());
        moduleB = moduleModel.newModule("b.iml", StdModuleTypes.JAVA.getId());
        final ModifiableRootModel rootModelA = ModuleRootManager.getInstance(moduleA).getModifiableModel();
        final ModifiableRootModel rootModelB = ModuleRootManager.getInstance(moduleB).getModifiableModel();
        rootModelB.addModuleOrderEntry(moduleA);
        final ContentEntry contentEntryA = rootModelA.addContentEntry(getVirtualFileInTestData("a"));
        contentEntryA.addSourceFolder(getVirtualFileInTestData("a/src"), false);
        final ContentEntry contentEntryB = rootModelB.addContentEntry(getVirtualFileInTestData("b"));
        contentEntryB.addSourceFolder(getVirtualFileInTestData("b/src"), false);
        ApplicationManager.getApplication().runWriteAction(() -> ModifiableModelCommitter.multiCommit(new ModifiableRootModel[] { rootModelB, rootModelA }, moduleModel));
    }
    final JavaPsiFacade psiManager = getJavaFacade();
    assertNull(psiManager.findClass("j.B", GlobalSearchScope.moduleWithDependenciesScope(moduleA)));
    assertNull(psiManager.findClass("q.A", GlobalSearchScope.moduleScope(moduleB)));
    assertNotNull(psiManager.findClass("q.A", GlobalSearchScope.moduleScope(moduleA)));
    assertNotNull(psiManager.findClass("q.A", GlobalSearchScope.moduleWithDependenciesScope(moduleB)));
    assertNotNull(psiManager.findClass("j.B", GlobalSearchScope.moduleScope(moduleB)));
    assertNotNull(psiManager.findClass("j.B", GlobalSearchScope.moduleWithDependenciesScope(moduleB)));
    moduleManager.disposeModule(moduleB);
    moduleManager.disposeModule(moduleA);
    moduleListener.assertCorrectEvents(new String[][] { { "+b", "+a" }, { "-b" }, { "-a" } });
    connection.disconnect();
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) JavaPsiFacade(com.intellij.psi.JavaPsiFacade) MessageBusConnection(com.intellij.util.messages.MessageBusConnection) ModifiableModuleModel(com.intellij.openapi.module.ModifiableModuleModel) ContentEntry(com.intellij.openapi.roots.ContentEntry) ModuleManager(com.intellij.openapi.module.ModuleManager) Module(com.intellij.openapi.module.Module)

Example 29 with ModifiableModuleModel

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

the class MultiModuleEditingTest method testRenaming.

public void testRenaming() throws Exception {
    final ModuleManager moduleManager = ModuleManager.getInstance(myProject);
    final Module moduleA;
    final Module moduleB;
    {
        final ModifiableModuleModel moduleModel = moduleManager.getModifiableModel();
        moduleA = moduleModel.newModule("a.iml", StdModuleTypes.JAVA.getId());
        moduleB = moduleModel.newModule("b.iml", StdModuleTypes.JAVA.getId());
        final Module moduleC = moduleModel.newModule("c.iml", StdModuleTypes.JAVA.getId());
        final ModifiableRootModel rootModelB = ModuleRootManager.getInstance(moduleB).getModifiableModel();
        rootModelB.addModuleOrderEntry(moduleC);
        moduleModel.disposeModule(moduleC);
        ApplicationManager.getApplication().runWriteAction(() -> ModifiableModelCommitter.multiCommit(new ModifiableRootModel[] { rootModelB }, moduleModel));
    }
    final ModuleRootManager rootManagerB = ModuleRootManager.getInstance(moduleB);
    assertEquals(0, rootManagerB.getDependencies().length);
    final String[] dependencyModuleNames = rootManagerB.getDependencyModuleNames();
    assertEquals(1, dependencyModuleNames.length);
    assertEquals("c", dependencyModuleNames[0]);
    {
        final ModifiableModuleModel moduleModel = moduleManager.getModifiableModel();
        moduleModel.renameModule(moduleA, "c");
        assertSame(moduleA, moduleModel.findModuleByName("a"));
        assertSame(moduleA, moduleManager.findModuleByName("a"));
        assertEquals("c", moduleModel.getNewName(moduleA));
        assertSame(moduleA, moduleModel.getModuleToBeRenamed("c"));
        ApplicationManager.getApplication().runWriteAction(() -> moduleModel.commit());
    }
    assertEquals(1, rootManagerB.getDependencies().length);
    assertEquals(moduleA, rootManagerB.getDependencies()[0]);
    assertSame(moduleA, moduleManager.findModuleByName("c"));
    assertNull(moduleManager.findModuleByName("a"));
    assertEquals("c", moduleA.getName());
    moduleManager.disposeModule(moduleA);
    moduleManager.disposeModule(moduleB);
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) ModifiableModuleModel(com.intellij.openapi.module.ModifiableModuleModel) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) ModuleManager(com.intellij.openapi.module.ModuleManager) Module(com.intellij.openapi.module.Module)

Example 30 with ModifiableModuleModel

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

the class AbstractModuleDataService method importData.

@Override
public void importData(@NotNull final Collection<DataNode<E>> toImport, @Nullable ProjectData projectData, @NotNull final Project project, @NotNull IdeModifiableModelsProvider modelsProvider) {
    if (toImport.isEmpty()) {
        return;
    }
    final Collection<DataNode<E>> toCreate = filterExistingModules(toImport, modelsProvider, project);
    if (!toCreate.isEmpty()) {
        createModules(toCreate, modelsProvider, project);
    }
    for (DataNode<E> node : toImport) {
        Module module = node.getUserData(MODULE_KEY);
        if (module != null) {
            String productionModuleId = node.getData().getProductionModuleId();
            modelsProvider.setTestModuleProperties(module, productionModuleId);
            setModuleOptions(module, node);
            ModifiableRootModel modifiableRootModel = modelsProvider.getModifiableRootModel(module);
            syncPaths(module, modifiableRootModel, node.getData());
            setLanguageLevel(modifiableRootModel, node.getData());
        }
    }
    for (DataNode<E> node : toImport) {
        Module module = node.getUserData(MODULE_KEY);
        if (module != null) {
            final String[] groupPath;
            groupPath = node.getData().getIdeModuleGroup();
            final ModifiableModuleModel modifiableModel = modelsProvider.getModifiableModuleModel();
            modifiableModel.setModuleGroupPath(module, groupPath);
        }
    }
}
Also used : ModifiableModuleModel(com.intellij.openapi.module.ModifiableModuleModel) DataNode(com.intellij.openapi.externalSystem.model.DataNode) Module(com.intellij.openapi.module.Module)

Aggregations

ModifiableModuleModel (com.intellij.openapi.module.ModifiableModuleModel)44 Module (com.intellij.openapi.module.Module)29 VirtualFile (com.intellij.openapi.vfs.VirtualFile)13 ModuleManager (com.intellij.openapi.module.ModuleManager)10 Project (com.intellij.openapi.project.Project)9 NotNull (org.jetbrains.annotations.NotNull)8 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)5 File (java.io.File)5 Result (com.intellij.openapi.application.Result)4 LibraryTable (com.intellij.openapi.roots.libraries.LibraryTable)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 StdModuleTypes (com.intellij.openapi.module.StdModuleTypes)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)3 Task (com.intellij.openapi.progress.Task)3 ProjectLibraryTable (com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable)3 Nullable (org.jetbrains.annotations.Nullable)3 Project (aQute.bnd.build.Project)2 MoveModulesToSubGroupAction (com.intellij.ide.projectView.actions.MoveModulesToSubGroupAction)2 FlexProjectConfigurationEditor (com.intellij.lang.javascript.flex.projectStructure.model.impl.FlexProjectConfigurationEditor)2