Search in sources :

Example 11 with ModuleManager

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

the class GradleBuildInvoker method cleanProject.

public void cleanProject() {
    setProjectBuildMode(CLEAN);
    ModuleManager moduleManager = ModuleManager.getInstance(myProject);
    // "Clean" also generates sources.
    List<String> tasks = findTasksToExecute(moduleManager.getModules(), SOURCE_GEN, TestCompileType.NONE);
    tasks.add(0, CLEAN_TASK_NAME);
    executeTasks(tasks, Collections.singletonList(createGenerateSourcesOnlyProperty()));
}
Also used : ModuleManager(com.intellij.openapi.module.ModuleManager)

Example 12 with ModuleManager

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

the class FmGetAppManifestDirMethod method findAppModuleIfAny.

@Nullable
private Module findAppModuleIfAny() {
    String modulePath = (String) myParamMap.get(TemplateMetadata.ATTR_PROJECT_OUT);
    if (modulePath != null) {
        VirtualFile file = LocalFileSystem.getInstance().findFileByIoFile(new File(modulePath.replace('/', File.separatorChar)));
        if (file != null) {
            Project project = ProjectLocator.getInstance().guessProjectForFile(file);
            if (project != null) {
                ModuleManager manager = ModuleManager.getInstance(project);
                Module module = manager.findModuleByName(APP_NAME);
                if (module != null) {
                    return module;
                }
                return manager.findModuleByName(MOBILE_NAME);
            }
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) ModuleManager(com.intellij.openapi.module.ModuleManager) Module(com.intellij.openapi.module.Module) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Example 13 with ModuleManager

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

the class ImportMavenRepositoriesTask method performTask.

private void performTask() {
    if (myProject.isDisposed())
        return;
    if (ApplicationManager.getApplication().isUnitTestMode())
        return;
    final LocalFileSystem localFileSystem = LocalFileSystem.getInstance();
    final List<PsiFile> psiFileList = ContainerUtil.newArrayList();
    final ModuleManager moduleManager = ModuleManager.getInstance(myProject);
    for (Module module : moduleManager.getModules()) {
        if (!ExternalSystemApiUtil.isExternalSystemAwareModule(GradleConstants.SYSTEM_ID, module))
            continue;
        final String modulePath = ExternalSystemApiUtil.getExternalProjectPath(module);
        if (modulePath == null)
            continue;
        String buildScript = FileUtil.findFileInProvidedPath(modulePath, GradleConstants.DEFAULT_SCRIPT_NAME);
        if (StringUtil.isEmpty(buildScript))
            continue;
        VirtualFile virtualFile = localFileSystem.refreshAndFindFileByPath(buildScript);
        if (virtualFile == null)
            continue;
        final PsiFile psiFile = PsiManager.getInstance(myProject).findFile(virtualFile);
        if (psiFile == null)
            continue;
        psiFileList.add(psiFile);
    }
    final PsiFile[] psiFiles = ArrayUtil.toObjectArray(psiFileList, PsiFile.class);
    final Set<MavenRemoteRepository> mavenRemoteRepositories = new ReadAction<Set<MavenRemoteRepository>>() {

        @Override
        protected void run(@NotNull Result<Set<MavenRemoteRepository>> result) throws Throwable {
            Set<MavenRemoteRepository> myRemoteRepositories = ContainerUtil.newHashSet();
            for (PsiFile psiFile : psiFiles) {
                List<GrClosableBlock> repositoriesBlocks = ContainerUtil.newArrayList();
                repositoriesBlocks.addAll(findClosableBlocks(psiFile, "repositories"));
                for (GrClosableBlock closableBlock : findClosableBlocks(psiFile, "buildscript", "subprojects", "allprojects", "project", "configure")) {
                    repositoriesBlocks.addAll(findClosableBlocks(closableBlock, "repositories"));
                }
                for (GrClosableBlock repositoriesBlock : repositoriesBlocks) {
                    myRemoteRepositories.addAll(findMavenRemoteRepositories(repositoriesBlock));
                }
            }
            result.setResult(myRemoteRepositories);
        }
    }.execute().getResultObject();
    if (mavenRemoteRepositories == null || mavenRemoteRepositories.isEmpty())
        return;
    // register imported maven repository URLs but do not force to download the index
    // the index can be downloaded and/or updated later using Maven Configuration UI (Settings -> Build, Execution, Deployment -> Build tools -> Maven -> Repositories)
    MavenRepositoriesHolder.getInstance(myProject).update(mavenRemoteRepositories);
    MavenProjectIndicesManager.getInstance(myProject).scheduleUpdateIndicesList(indexes -> {
        if (myProject.isDisposed())
            return;
        final List<String> repositoriesWithEmptyIndex = ContainerUtil.mapNotNull(indexes, index -> index.getUpdateTimestamp() == -1 && MavenRepositoriesHolder.getInstance(myProject).contains(index.getRepositoryPathOrUrl()) ? index.getRepositoryPathOrUrl() : null);
        if (!repositoriesWithEmptyIndex.isEmpty()) {
            final NotificationData notificationData = new NotificationData(GradleBundle.message("gradle.integrations.maven.notification.not_updated_repository.title"), "\n<br>" + GradleBundle.message("gradle.integrations.maven.notification.not_updated_repository.text", StringUtil.join(repositoriesWithEmptyIndex, "<br>")), NotificationCategory.WARNING, NotificationSource.PROJECT_SYNC);
            notificationData.setBalloonNotification(true);
            notificationData.setBalloonGroup(UNINDEXED_MAVEN_REPOSITORIES_NOTIFICATION_GROUP);
            notificationData.setListener("#open", new NotificationListener.Adapter() {

                @Override
                protected void hyperlinkActivated(@NotNull Notification notification, @NotNull HyperlinkEvent e) {
                    ShowSettingsUtil.getInstance().showSettingsDialog(myProject, MavenRepositoriesConfigurable.class);
                }
            });
            notificationData.setListener("#disable", new NotificationListener.Adapter() {

                @Override
                protected void hyperlinkActivated(@NotNull Notification notification, @NotNull HyperlinkEvent e) {
                    final int result = Messages.showYesNoDialog(myProject, "Notification will be disabled for all projects.\n\n" + "Settings | Appearance & Behavior | Notifications | " + UNINDEXED_MAVEN_REPOSITORIES_NOTIFICATION_GROUP + "\ncan be used to configure the notification.", "Unindexed Maven Repositories Gradle Detection", "Disable Notification", CommonBundle.getCancelButtonText(), Messages.getWarningIcon());
                    if (result == Messages.YES) {
                        NotificationsConfigurationImpl.getInstanceImpl().changeSettings(UNINDEXED_MAVEN_REPOSITORIES_NOTIFICATION_GROUP, NotificationDisplayType.NONE, false, false);
                        notification.hideBalloon();
                    }
                }
            });
            ExternalSystemNotificationManager.getInstance(myProject).showNotification(GradleConstants.SYSTEM_ID, notificationData);
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HyperlinkEvent(javax.swing.event.HyperlinkEvent) GrClosableBlock(org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock) ModuleManager(com.intellij.openapi.module.ModuleManager) NotNull(org.jetbrains.annotations.NotNull) Notification(com.intellij.notification.Notification) Result(com.intellij.openapi.application.Result) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) ReadAction(com.intellij.openapi.application.ReadAction) MavenRemoteRepository(org.jetbrains.idea.maven.model.MavenRemoteRepository) MavenRepositoriesConfigurable(org.jetbrains.idea.maven.indices.MavenRepositoriesConfigurable) Module(com.intellij.openapi.module.Module) NotificationData(com.intellij.openapi.externalSystem.service.notification.NotificationData) NotificationListener(com.intellij.notification.NotificationListener)

Example 14 with ModuleManager

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

the class ModuleDeleteProvider method deleteElement.

@Override
public void deleteElement(@NotNull DataContext dataContext) {
    final Module[] modules = LangDataKeys.MODULE_CONTEXT_ARRAY.getData(dataContext);
    assert modules != null;
    final Project project = CommonDataKeys.PROJECT.getData(dataContext);
    assert project != null;
    String names = StringUtil.join(Arrays.asList(modules), module -> "\'" + module.getName() + "\'", ", ");
    int ret = Messages.showOkCancelDialog(getConfirmationText(modules, names), getActionTitle(), Messages.getQuestionIcon());
    if (ret != Messages.OK)
        return;
    CommandProcessor.getInstance().executeCommand(project, () -> {
        final Runnable action = () -> {
            final ModuleManager moduleManager = ModuleManager.getInstance(project);
            final Module[] currentModules = moduleManager.getModules();
            final ModifiableModuleModel modifiableModuleModel = moduleManager.getModifiableModel();
            final Map<Module, ModifiableRootModel> otherModuleRootModels = new HashMap<>();
            for (final Module module : modules) {
                final ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(module).getModifiableModel();
                for (final Module otherModule : currentModules) {
                    if (otherModule == module || ArrayUtilRt.find(modules, otherModule) != -1)
                        continue;
                    if (!otherModuleRootModels.containsKey(otherModule)) {
                        otherModuleRootModels.put(otherModule, ModuleRootManager.getInstance(otherModule).getModifiableModel());
                    }
                }
                removeModule(module, modifiableModel, otherModuleRootModels.values(), modifiableModuleModel);
            }
            final ModifiableRootModel[] modifiableRootModels = otherModuleRootModels.values().toArray(new ModifiableRootModel[otherModuleRootModels.size()]);
            ModifiableModelCommitter.multiCommit(modifiableRootModels, modifiableModuleModel);
        };
        ApplicationManager.getApplication().runWriteAction(action);
    }, ProjectBundle.message("module.remove.command"), null);
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) Project(com.intellij.openapi.project.Project) ModifiableModuleModel(com.intellij.openapi.module.ModifiableModuleModel) Module(com.intellij.openapi.module.Module) ModuleManager(com.intellij.openapi.module.ModuleManager) HashMap(java.util.HashMap) Map(java.util.Map)

Example 15 with ModuleManager

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

the class DirectoryIndexTest method testModuleUnderIgnoredDir.

public void testModuleUnderIgnoredDir() {
    final VirtualFile ignored = createChildDirectory(myRootVFile, ".git");
    assertTrue(FileTypeManager.getInstance().isFileIgnored(ignored));
    assertTrue(myFileIndex.isExcluded(ignored));
    assertTrue(myFileIndex.isUnderIgnored(ignored));
    final VirtualFile module4 = createChildDirectory(ignored, "module4");
    assertFalse(FileTypeManager.getInstance().isFileIgnored(module4));
    assertTrue(myFileIndex.isExcluded(module4));
    assertTrue(myFileIndex.isUnderIgnored(module4));
    new WriteCommandAction.Simple(getProject()) {

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

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