Search in sources :

Example 41 with ModuleManager

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

the class ConfigureAndroidModuleStepDynamicTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    ApplicationManager.getApplication().runWriteAction(() -> {
        final ModuleManager manager = ModuleManager.getInstance(getProject());
        File moduleRoot = new File(getProject().getBasePath(), "app");
        manager.newModule(moduleRoot.getPath(), ModuleTypeId.JAVA_MODULE);
        moduleRoot = new File(getProject().getBasePath(), "Lib");
        manager.newModule(moduleRoot.getPath(), ModuleTypeId.JAVA_MODULE);
        moduleRoot = new File(getProject().getBasePath(), "lib2");
        manager.newModule(moduleRoot.getPath(), ModuleTypeId.JAVA_MODULE);
    });
    ScopedStateStore wizardState = new ScopedStateStore(ScopedStateStore.Scope.WIZARD, null, null);
    ScopedStateStore pathState = new ScopedStateStore(ScopedStateStore.Scope.PATH, wizardState, null);
    myStep = new ConfigureAndroidModuleStepDynamic(getTestRootDisposable(), FormFactor.MOBILE);
    myStep.myState = new ScopedStateStore(ScopedStateStore.Scope.STEP, pathState, myStep);
}
Also used : ScopedStateStore(com.android.tools.idea.wizard.dynamic.ScopedStateStore) ConfigureAndroidModuleStepDynamic(com.android.tools.idea.npw.deprecated.ConfigureAndroidModuleStepDynamic) ModuleManager(com.intellij.openapi.module.ModuleManager) File(java.io.File)

Example 42 with ModuleManager

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

the class ConfigureAndroidModuleStepDynamicTest method testComputeModuleName_deduplication.

public void testComputeModuleName_deduplication() throws Exception {
    ModuleManager manager = ModuleManager.getInstance(getProject());
    Module module = manager.getModules()[0];
    assertEquals("app", module.getName());
    // "Lib" and "lib2" already exist
    assertEquals("lib3", WizardUtils.computeModuleName("Lib", getProject()));
    // "app" already exists
    assertEquals("app2", WizardUtils.computeModuleName("app", getProject()));
}
Also used : ModuleManager(com.intellij.openapi.module.ModuleManager) Module(com.intellij.openapi.module.Module)

Example 43 with ModuleManager

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

the class ProjectStructureUsageTrackerTest method trackGradleProject.

/**
   * Builds a set of mock objects representing an Android Studio project with a set of modules
   * and calls the tracking code to report metrics on this project.
   */
private void trackGradleProject(String project) throws Exception {
    loadProject(project);
    ProjectStructureUsageTracker psut = new ProjectStructureUsageTracker(getProject());
    ModuleManager moduleManager = ModuleManager.getInstance(getProject());
    psut.trackProjectStructure(moduleManager.getModules());
}
Also used : ModuleManager(com.intellij.openapi.module.ModuleManager)

Example 44 with ModuleManager

use of com.intellij.openapi.module.ModuleManager 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)

Example 45 with ModuleManager

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

the class GotoImplementationTest method test.

public void test() throws Exception {
    ModuleManager moduleManager = ModuleManager.getInstance(getProject());
    Module[] modules = moduleManager.getModules();
    assertEquals(3, modules.length);
    Module module1 = moduleManager.findModuleByName("test1");
    Module module2 = moduleManager.findModuleByName("test2");
    Module module3 = moduleManager.findModuleByName("test3");
    final GlobalSearchScope moduleScope = GlobalSearchScope.moduleScope(module1);
    PsiClass test1 = myJavaFacade.findClass("com.test.TestI", moduleScope);
    PsiClass test2 = myJavaFacade.findClass("com.test.TestI", GlobalSearchScope.moduleScope(module2));
    PsiClass test3 = myJavaFacade.findClass("com.test.TestI", GlobalSearchScope.moduleScope(module3));
    HashSet<PsiElement> expectedImpls1 = new HashSet<>(Arrays.asList(myJavaFacade.findClass("com.test.TestIImpl1", moduleScope), myJavaFacade.findClass("com.test.TestIImpl2", moduleScope)));
    assertEquals(expectedImpls1, new HashSet<>(getClassImplementations(test1)));
    PsiMethod psiMethod = test1.findMethodsByName("test", false)[0];
    Set<PsiElement> expectedMethodImpl1 = new HashSet<>(Arrays.asList(myJavaFacade.findClass("com.test.TestIImpl1", moduleScope).findMethodsByName("test", false)[0], myJavaFacade.findClass("com.test.TestIImpl2", moduleScope).findMethodsByName("test", false)[0]));
    CommonProcessors.CollectProcessor<PsiElement> processor = new CommonProcessors.CollectProcessor<>();
    MethodImplementationsSearch.processImplementations(psiMethod, processor, moduleScope);
    assertEquals(expectedMethodImpl1, new HashSet<>(processor.getResults()));
    HashSet<PsiElement> expectedImpls2 = new HashSet<>(Arrays.asList(myJavaFacade.findClass("com.test.TestIImpl1", GlobalSearchScope.moduleScope(module2)), myJavaFacade.findClass("com.test.TestIImpl3", GlobalSearchScope.moduleScope(module2))));
    assertEquals(expectedImpls2, new HashSet<>(getClassImplementations(test2)));
    HashSet<PsiElement> expectedImpls3 = new HashSet<>(Arrays.asList(myJavaFacade.findClass("com.test.TestIImpl1", GlobalSearchScope.moduleScope(module3))));
    assertEquals(expectedImpls3, new HashSet<>(getClassImplementations(test3)));
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass) ModuleManager(com.intellij.openapi.module.ModuleManager) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Module(com.intellij.openapi.module.Module) CommonProcessors(com.intellij.util.CommonProcessors) PsiElement(com.intellij.psi.PsiElement) HashSet(java.util.HashSet)

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