Search in sources :

Example 31 with ModuleManager

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

the class AndroidGradleProjectComponent method trackLegacyIdeaAndroidProject.

private void trackLegacyIdeaAndroidProject() {
    if (!UsageTracker.getInstance().getAnalyticsSettings().hasOptedIn()) {
        return;
    }
    StartupManager.getInstance(myProject).runWhenProjectIsInitialized(() -> {
        String packageName = null;
        ModuleManager moduleManager = ModuleManager.getInstance(myProject);
        for (Module module : moduleManager.getModules()) {
            AndroidFacet facet = AndroidFacet.getInstance(module);
            if (facet != null && !facet.requiresAndroidModel()) {
                if (facet.isAppProject()) {
                    // Prefer the package name from an app module.
                    packageName = getPackageNameInLegacyIdeaAndroidModule(facet);
                    if (packageName != null) {
                        break;
                    }
                } else if (packageName == null) {
                    String modulePackageName = getPackageNameInLegacyIdeaAndroidModule(facet);
                    if (modulePackageName != null) {
                        packageName = modulePackageName;
                    }
                }
            }
            if (packageName != null) {
                AndroidStudioEvent.Builder event = AndroidStudioEvent.newBuilder().setCategory(EventCategory.GRADLE).setKind(EventKind.LEGACY_IDEA_ANDROID_PROJECT).setProjectId(anonymizeUtf8(packageName));
                UsageTracker.getInstance().log(event);
            }
        }
    });
}
Also used : ModuleManager(com.intellij.openapi.module.ModuleManager) Module(com.intellij.openapi.module.Module) AndroidStudioEvent(com.google.wireless.android.sdk.stats.AndroidStudioEvent) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 32 with ModuleManager

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

the class AndroidProjectStructureConfigurable method reset.

@Override
public void reset() {
    // Need this to ensure VFS operations will not block because of storage flushing and other maintenance IO tasks run in background.
    AccessToken token = HeavyProcessLatch.INSTANCE.processStarted("Resetting project structure");
    try {
        for (Configurable configurable : myConfigurables) {
            configurable.reset();
        }
        if (myUiInitialized) {
            validateState();
            // Prepare module entries but don't add them until after developer services
            ModuleManager moduleManager = ModuleManager.getInstance(myProject);
            Module[] modules = moduleManager.getModules();
            Arrays.sort(modules, ModuleTypeComparator.INSTANCE);
            List<AndroidModuleConfigurable> moduleConfigurables = Lists.newArrayList();
            for (Module module : modules) {
                AndroidModuleConfigurable configurable = addModule(module);
                if (configurable != null) {
                    moduleConfigurables.add(configurable);
                }
            }
            // Populate the "Developer Services" section
            removeServices();
            if (Projects.isBuildWithGradle(myProject)) {
                DefaultComboBoxModel moduleList = new DefaultComboBoxModel();
                for (AndroidModuleConfigurable moduleConfigurable : moduleConfigurables) {
                    // Collect only Android modules
                    if (AndroidFacet.getInstance(moduleConfigurable.getModule()) != null) {
                        moduleList.addElement(moduleConfigurable.getModule());
                    }
                }
                if (!myProject.isDefault() && moduleList.getSize() > 0) {
                    // into that event.
                    for (int i = 0; i < moduleList.getSize(); i++) {
                        Module module = (Module) moduleList.getElementAt(i);
                        for (DeveloperService service : DeveloperServices.getAll(module)) {
                            service.getContext().restore();
                        }
                    }
                    Module module = (Module) moduleList.getSelectedItem();
                    Set<ServiceCategory> categories = Sets.newHashSet();
                    for (DeveloperService s : DeveloperServices.getAll(module)) {
                        if (!s.getContext().hiddenFromStructureDialog().get()) {
                            categories.add(s.getCategory());
                        }
                    }
                    ArrayList<ServiceCategory> categoriesSorted = Lists.newArrayList(categories);
                    Collections.sort(categoriesSorted);
                    for (ServiceCategory category : categoriesSorted) {
                        myConfigurables.add(new ServiceCategoryConfigurable(moduleList, category));
                    }
                }
            }
            // Populate the "Modules" section.
            removeModules();
            Module toSelect = null;
            for (Module module : modules) {
                AndroidModuleConfigurable configurable = addModule(module);
                if (configurable != null) {
                    myConfigurables.add(configurable);
                    if (configurable.getDisplayName().equals(myUiState.lastSelectedConfigurable)) {
                        toSelect = module;
                    }
                }
            }
            if (myUiState.proportion > 0) {
                mySplitter.setProportion(myUiState.proportion);
            }
            mySidePanel.reset();
            if (toSelect != null) {
                mySidePanel.select(toSelect);
            } else {
                mySidePanel.selectSdk();
            }
        }
    } finally {
        token.finish();
    }
}
Also used : ServiceCategory(com.android.tools.idea.structure.services.ServiceCategory) ServiceCategoryConfigurable(com.android.tools.idea.structure.services.view.ServiceCategoryConfigurable) AndroidModuleConfigurable(com.android.tools.idea.gradle.structure.editors.AndroidModuleConfigurable) AndroidModuleConfigurable(com.android.tools.idea.gradle.structure.editors.AndroidModuleConfigurable) ServiceCategoryConfigurable(com.android.tools.idea.structure.services.view.ServiceCategoryConfigurable) AndroidProjectConfigurable(com.android.tools.idea.gradle.structure.editors.AndroidProjectConfigurable) ModuleManager(com.intellij.openapi.module.ModuleManager) DeveloperService(com.android.tools.idea.structure.services.DeveloperService) AccessToken(com.intellij.openapi.application.AccessToken) Module(com.intellij.openapi.module.Module)

Example 33 with ModuleManager

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

the class AndroidApkFacet method getInstance.

@Nullable
public static AndroidApkFacet getInstance(@NotNull Project project) {
    ModuleManager moduleManager = ModuleManager.getInstance(project);
    // Only 1 module existed for Apk project
    Module[] modules = moduleManager.getModules();
    if (modules.length == 1) {
        return getInstance(modules[0]);
    }
    return null;
}
Also used : ModuleManager(com.intellij.openapi.module.ModuleManager) Module(com.intellij.openapi.module.Module) Nullable(org.jetbrains.annotations.Nullable)

Example 34 with ModuleManager

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

the class NewProjectImportGradleSyncListener method createTopLevelModule.

@VisibleForTesting
public static void createTopLevelModule(@NotNull Project project) {
    ModuleManager moduleManager = ModuleManager.getInstance(project);
    File projectRootDir = getBaseDirPath(project);
    VirtualFile contentRoot = findFileByIoFile(projectRootDir, true);
    if (contentRoot != null) {
        File moduleFile = new File(projectRootDir, projectRootDir.getName() + ".iml");
        Module module = moduleManager.newModule(moduleFile.getPath(), JAVA.getId());
        // This prevents the balloon "Unsupported Modules detected".
        ExternalSystemModulePropertyManager.getInstance(module).setExternalId(GRADLE_SYSTEM_ID);
        ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
        model.addContentEntry(contentRoot);
        if (IdeInfo.getInstance().isAndroidStudio()) {
            // If sync fails, make sure that the project has a JDK, otherwise Groovy indices won't work (a common scenario where
            // users will update build.gradle files to fix Gradle sync.)
            // See: https://code.google.com/p/android/issues/detail?id=194621
            Sdk jdk = IdeSdks.getInstance().getJdk();
            if (jdk != null) {
                model.setSdk(jdk);
            }
        }
        model.commit();
        FacetManager facetManager = FacetManager.getInstance(module);
        ModifiableFacetModel facetModel = facetManager.createModifiableModel();
        try {
            GradleFacet gradleFacet = GradleFacet.getInstance(module);
            if (gradleFacet == null) {
                // Add "gradle" facet, to avoid balloons about unsupported compilation of modules.
                gradleFacet = facetManager.createFacet(GradleFacet.getFacetType(), GradleFacet.getFacetName(), null);
                facetModel.addFacet(gradleFacet);
            }
            gradleFacet.getConfiguration().GRADLE_PROJECT_PATH = GRADLE_PATH_SEPARATOR;
            // Add "android" facet to avoid the balloon "Android Framework detected".
            AndroidFacet androidFacet = AndroidFacet.getInstance(module);
            if (androidFacet == null) {
                androidFacet = facetManager.createFacet(AndroidFacet.getFacetType(), AndroidFacet.NAME, null);
                facetModel.addFacet(androidFacet);
            }
            // This is what actually stops Studio from showing the balloon.
            androidFacet.getProperties().ALLOW_USER_CONFIGURATION = false;
        } finally {
            facetModel.commit();
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) ModifiableFacetModel(com.intellij.facet.ModifiableFacetModel) GradleFacet(com.android.tools.idea.gradle.project.facet.gradle.GradleFacet) Sdk(com.intellij.openapi.projectRoots.Sdk) ModuleManager(com.intellij.openapi.module.ModuleManager) Module(com.intellij.openapi.module.Module) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VfsUtil.findFileByIoFile(com.intellij.openapi.vfs.VfsUtil.findFileByIoFile) File(java.io.File) FacetManager(com.intellij.facet.FacetManager) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) VisibleForTesting(com.android.annotations.VisibleForTesting)

Example 35 with ModuleManager

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

the class GradleBuildInvoker method rebuild.

public void rebuild() {
    BuildMode buildMode = REBUILD;
    setProjectBuildMode(buildMode);
    ModuleManager moduleManager = ModuleManager.getInstance(myProject);
    List<String> tasks = findTasksToExecute(moduleManager.getModules(), buildMode, TestCompileType.NONE);
    executeTasks(tasks);
}
Also used : BuildMode(com.android.tools.idea.gradle.util.BuildMode) ModuleManager(com.intellij.openapi.module.ModuleManager)

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