Search in sources :

Example 16 with ModuleManager

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

the class DirectoryIndexTest method testModuleInIgnoredDir.

public void testModuleInIgnoredDir() {
    final VirtualFile ignored = createChildDirectory(myRootVFile, ".git");
    assertTrue(FileTypeManager.getInstance().isFileIgnored(ignored));
    new WriteCommandAction.Simple(getProject()) {

        @Override
        protected void run() throws Throwable {
            ModuleManager moduleManager = ModuleManager.getInstance(myProject);
            ModifiableModuleModel model = moduleManager.getModifiableModel();
            model.disposeModule(myModule);
            model.disposeModule(myModule2);
            model.disposeModule(myModule3);
            model.commit();
            Module module = moduleManager.newModule(myRootVFile.getPath() + "/newModule.iml", StdModuleTypes.JAVA.getId());
            PsiTestUtil.addContentRoot(module, ignored);
            checkInfo(ignored, module, false, false, null, null);
        }
    }.execute().throwException();
}
Also used : ModifiableModuleModel(com.intellij.openapi.module.ModifiableModuleModel) ModuleManager(com.intellij.openapi.module.ModuleManager) Module(com.intellij.openapi.module.Module)

Example 17 with ModuleManager

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

the class DirectoryIndexTest method testAddModule.

public void testAddModule() {
    new WriteCommandAction.Simple(getProject()) {

        @Override
        protected void run() throws Throwable {
            VirtualFile newModuleContent = createChildDirectory(myRootVFile, "newModule");
            createChildDirectory(newModuleContent, "subDir");
            ModuleManager moduleManager = ModuleManager.getInstance(myProject);
            Module module = moduleManager.newModule(myRootVFile.getPath() + "/newModule.iml", StdModuleTypes.JAVA.getId());
            PsiTestUtil.addContentRoot(module, newModuleContent);
        }
    }.execute().throwException();
}
Also used : ModuleManager(com.intellij.openapi.module.ModuleManager) Module(com.intellij.openapi.module.Module)

Example 18 with ModuleManager

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

the class DirectoryIndexTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    final File root = createTempDirectory();
    ApplicationManager.getApplication().runWriteAction(() -> {
        /*
        root
            lib
                file.src
                file.cls
            module1
                src1
                    pack1
                    testSrc
                        pack2
                res
                testRes
                lib
                    src
                      exc
                    additional-src
                    cls
                      exc
                module2
                    src2
                        CVS
                        excluded
            module3
            out
                module1
      */
        myRootVFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(root);
        assertNotNull(myRootVFile);
        myFileLibDir = createChildDirectory(myRootVFile, "lib");
        myFileLibSrc = createChildData(myFileLibDir, "file.src");
        myFileLibCls = createChildData(myFileLibDir, "file.cls");
        myModule1Dir = createChildDirectory(myRootVFile, "module1");
        mySrcDir1 = createChildDirectory(myModule1Dir, "src1");
        myPack1Dir = createChildDirectory(mySrcDir1, "pack1");
        myTestSrc1 = createChildDirectory(mySrcDir1, "testSrc");
        myPack2Dir = createChildDirectory(myTestSrc1, "pack2");
        myResDir = createChildDirectory(myModule1Dir, "res");
        myTestResDir = createChildDirectory(myModule1Dir, "testRes");
        myLibDir = createChildDirectory(myModule1Dir, "lib");
        myLibSrcDir = createChildDirectory(myLibDir, "src");
        myExcludedLibSrcDir = createChildDirectory(myLibSrcDir, "exc");
        myLibAdditionalSrcDir = createChildDirectory(myLibDir, "additional-src");
        myLibClsDir = createChildDirectory(myLibDir, "cls");
        myExcludedLibClsDir = createChildDirectory(myLibClsDir, "exc");
        myModule2Dir = createChildDirectory(myModule1Dir, "module2");
        mySrcDir2 = createChildDirectory(myModule2Dir, "src2");
        myCvsDir = createChildDirectory(mySrcDir2, "CVS");
        myExcludeDir = createChildDirectory(mySrcDir2, "excluded");
        myModule3Dir = createChildDirectory(myRootVFile, "module3");
        myOutputDir = createChildDirectory(myRootVFile, "out");
        myModule1OutputDir = createChildDirectory(myOutputDir, "module1");
        getCompilerProjectExtension().setCompilerOutputUrl(myOutputDir.getUrl());
        ModuleManager moduleManager = ModuleManager.getInstance(myProject);
        // fill roots of module1
        {
            ModuleRootModificationUtil.setModuleSdk(myModule, null);
            PsiTestUtil.addContentRoot(myModule, myModule1Dir);
            PsiTestUtil.addSourceRoot(myModule, mySrcDir1);
            PsiTestUtil.addSourceRoot(myModule, myTestSrc1, true);
            PsiTestUtil.addSourceRoot(myModule, myResDir, JavaResourceRootType.RESOURCE);
            PsiTestUtil.addSourceRoot(myModule, myTestResDir, JavaResourceRootType.TEST_RESOURCE);
            ModuleRootModificationUtil.addModuleLibrary(myModule, "lib.js", Collections.singletonList(myFileLibCls.getUrl()), Collections.singletonList(myFileLibSrc.getUrl()));
            PsiTestUtil.addExcludedRoot(myModule, myExcludedLibClsDir);
            PsiTestUtil.addExcludedRoot(myModule, myExcludedLibSrcDir);
        }
        // fill roots of module2
        {
            VirtualFile moduleFile = createChildData(myModule2Dir, "module2.iml");
            myModule2 = moduleManager.newModule(moduleFile.getPath(), StdModuleTypes.JAVA.getId());
            PsiTestUtil.addContentRoot(myModule2, myModule2Dir);
            PsiTestUtil.addSourceRoot(myModule2, mySrcDir2);
            PsiTestUtil.addExcludedRoot(myModule2, myExcludeDir);
            ModuleRootModificationUtil.addModuleLibrary(myModule2, "lib", Collections.singletonList(myLibClsDir.getUrl()), Collections.singletonList(myLibSrcDir.getUrl()), Arrays.asList(myExcludedLibClsDir.getUrl(), myExcludedLibSrcDir.getUrl()), DependencyScope.COMPILE, true);
        }
        PlatformTestUtil.registerExtension(AdditionalLibraryRootsProvider.EP_NAME, new AdditionalLibraryRootsProvider() {

            @NotNull
            @Override
            public Collection<SyntheticLibrary> getAdditionalProjectLibraries(@NotNull Project project) {
                return myProject == project ? Collections.singletonList(SyntheticLibrary.newImmutableLibrary(Collections.singletonList(myLibAdditionalSrcDir))) : Collections.emptyList();
            }
        }, getTestRootDisposable());
        // fill roots of module3
        {
            VirtualFile moduleFile = createChildData(myModule3Dir, "module3.iml");
            myModule3 = moduleManager.newModule(moduleFile.getPath(), StdModuleTypes.JAVA.getId());
            PsiTestUtil.addContentRoot(myModule3, myModule3Dir);
            ModuleRootModificationUtil.addDependency(myModule3, myModule2);
        }
    });
    myIndex = (DirectoryIndexImpl) DirectoryIndex.getInstance(myProject);
    myFileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
    // to not interfere with previous test firing vfs events
    VirtualFileManager.getInstance().syncRefresh();
}
Also used : Project(com.intellij.openapi.project.Project) ModuleManager(com.intellij.openapi.module.ModuleManager) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 19 with ModuleManager

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

the class MultiModuleEditingTest method testAddTwoModules.

public void testAddTwoModules() throws Exception {
    final MessageBusConnection connection = myProject.getMessageBus().connect();
    final MyModuleListener moduleListener = new MyModuleListener();
    connection.subscribe(ProjectTopics.MODULES, moduleListener);
    final ModuleManager moduleManager = ModuleManager.getInstance(myProject);
    final Module moduleA;
    final Module moduleB;
    {
        final ModifiableModuleModel modifiableModel = moduleManager.getModifiableModel();
        moduleA = modifiableModel.newModule("a.iml", StdModuleTypes.JAVA.getId());
        moduleB = modifiableModel.newModule("b.iml", StdModuleTypes.JAVA.getId());
        assertEquals("Changes are not applied until commit", 0, moduleManager.getModules().length);
        //noinspection SSBasedInspection
        moduleListener.assertCorrectEvents(new String[0][]);
        ApplicationManager.getApplication().runWriteAction(modifiableModel::commit);
    }
    assertEquals(2, moduleManager.getModules().length);
    assertTrue(moduleManager.findModuleByName("a").equals(moduleA));
    assertTrue(moduleManager.findModuleByName("b").equals(moduleB));
    moduleListener.assertCorrectEvents(new String[][] { { "+a", "+b" } });
    {
        final ModifiableModuleModel modifiableModel = moduleManager.getModifiableModel();
        modifiableModel.disposeModule(moduleA);
        modifiableModel.disposeModule(moduleB);
        assertEquals("Changes are not applied until commit", 2, moduleManager.getModules().length);
        moduleListener.assertCorrectEvents(new String[][] { { "+a", "+b" } });
        ApplicationManager.getApplication().runWriteAction(modifiableModel::commit);
    }
    assertEquals(0, moduleManager.getModules().length);
    moduleListener.assertCorrectEvents(new String[][] { { "+a", "+b" }, { "-a", "-b" } });
    connection.disconnect();
}
Also used : MessageBusConnection(com.intellij.util.messages.MessageBusConnection) ModifiableModuleModel(com.intellij.openapi.module.ModifiableModuleModel) ModuleManager(com.intellij.openapi.module.ModuleManager) Module(com.intellij.openapi.module.Module)

Example 20 with ModuleManager

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

the class AdvHighlightingTest method testMultiJDKConflict.

public void testMultiJDKConflict() throws Exception {
    String path = PathManagerEx.getTestDataPath() + BASE_PATH + "/" + getTestName(true);
    VirtualFile root = LocalFileSystem.getInstance().findFileByIoFile(new File(path));
    assert root != null : path;
    loadAllModulesUnder(root);
    ModuleManager moduleManager = ModuleManager.getInstance(getProject());
    Module java4 = moduleManager.findModuleByName("java4");
    Module java5 = moduleManager.findModuleByName("java5");
    ModuleRootModificationUtil.setModuleSdk(java4, IdeaTestUtil.getMockJdk17("java 1.4"));
    ModuleRootModificationUtil.setModuleSdk(java5, IdeaTestUtil.getMockJdk17("java 1.5"));
    ModuleRootModificationUtil.addDependency(java5, java4);
    configureByExistingFile(root.findFileByRelativePath("moduleJava5/com/Java5.java"));
    Collection<HighlightInfo> infos = highlightErrors();
    assertEmpty(infos);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo) ModuleManager(com.intellij.openapi.module.ModuleManager) Module(com.intellij.openapi.module.Module) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiJavaFile(com.intellij.psi.PsiJavaFile) File(java.io.File)

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