Search in sources :

Example 1 with ModuleManager

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

the class MvcModuleStructureUtil method removeAuxiliaryModule.

public static void removeAuxiliaryModule(Module toRemove) {
    List<ModifiableRootModel> usingModels = new SmartList<>();
    Project project = toRemove.getProject();
    ModuleManager moduleManager = ModuleManager.getInstance(project);
    for (Module module : moduleManager.getModules()) {
        if (module == toRemove) {
            continue;
        }
        ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
        for (OrderEntry entry : moduleRootManager.getOrderEntries()) {
            if (entry instanceof ModuleOrderEntry && toRemove == ((ModuleOrderEntry) entry).getModule()) {
                usingModels.add(moduleRootManager.getModifiableModel());
                break;
            }
        }
    }
    final ModifiableModuleModel moduleModel = moduleManager.getModifiableModel();
    ModuleDeleteProvider.removeModule(toRemove, null, usingModels, moduleModel);
    ModifiableModelCommitter.multiCommit(usingModels, moduleModel);
}
Also used : Project(com.intellij.openapi.project.Project) ModifiableModuleModel(com.intellij.openapi.module.ModifiableModuleModel) SmartList(com.intellij.util.SmartList) ModuleManager(com.intellij.openapi.module.ModuleManager) Module(com.intellij.openapi.module.Module)

Example 2 with ModuleManager

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

the class MvcModuleStructureUtil method generateUniqueModuleName.

private static String generateUniqueModuleName(@NotNull Project project, String prefix) {
    ModuleManager manager = ModuleManager.getInstance(project);
    int i = 0;
    do {
        String res = i == 0 ? prefix : prefix + i;
        i++;
        if (manager.findModuleByName(res) == null)
            return res;
    } while (true);
}
Also used : ModuleManager(com.intellij.openapi.module.ModuleManager)

Example 3 with ModuleManager

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

the class ProjectImpl method distributeProgress.

private void distributeProgress() {
    ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
    if (indicator == null)
        return;
    ModuleManager moduleManager = ModuleManager.getInstance(this);
    if (!(moduleManager instanceof ModuleManagerImpl)) {
        return;
    }
    double toDistribute = 1 - indicator.getFraction();
    int modulesCount = ((ModuleManagerImpl) moduleManager).getModulePathsCount();
    EditorsSplitters splitters = ((FileEditorManagerImpl) FileEditorManager.getInstance(this)).getMainSplitters();
    int editors = splitters.getEditorsCount();
    double modulesPart = ourClassesAreLoaded || editors == 0 ? toDistribute : toDistribute * 0.5;
    if (modulesCount != 0) {
        double step = modulesPart / modulesCount;
        ((ModuleManagerImpl) moduleManager).setProgressStep(step);
    }
    if (editors != 0) {
        splitters.setProgressStep(toDistribute - modulesPart / editors);
    }
}
Also used : ModuleManagerImpl(com.intellij.openapi.module.impl.ModuleManagerImpl) EditorsSplitters(com.intellij.openapi.fileEditor.impl.EditorsSplitters) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) FileEditorManagerImpl(com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl) ModuleManager(com.intellij.openapi.module.ModuleManager)

Example 4 with ModuleManager

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

the class ModuleVcsDetector method autoDetectVcsMappings.

private void autoDetectVcsMappings(final boolean tryMapPieces) {
    Set<AbstractVcs> usedVcses = new HashSet<>();
    Map<VirtualFile, AbstractVcs> vcsMap = new HashMap<>();
    final ModuleManager moduleManager = ModuleManager.getInstance(myProject);
    for (Module module : moduleManager.getModules()) {
        final VirtualFile[] files = ModuleRootManager.getInstance(module).getContentRoots();
        for (VirtualFile file : files) {
            AbstractVcs contentRootVcs = myVcsManager.findVersioningVcs(file);
            if (contentRootVcs != null) {
                vcsMap.put(file, contentRootVcs);
            }
            usedVcses.add(contentRootVcs);
        }
    }
    if (usedVcses.size() == 1) {
        // todo I doubt this is correct, see IDEA-50527
        final AbstractVcs[] abstractVcses = usedVcses.toArray(new AbstractVcs[1]);
        final Module[] modules = moduleManager.getModules();
        final Set<String> contentRoots = new HashSet<>();
        for (Module module : modules) {
            final VirtualFile[] roots = ModuleRootManager.getInstance(module).getContentRoots();
            for (VirtualFile root : roots) {
                contentRoots.add(root.getPath());
            }
        }
        if (abstractVcses[0] != null) {
            final List<VcsDirectoryMapping> vcsDirectoryMappings = new ArrayList<>(myVcsManager.getDirectoryMappings());
            for (Iterator<VcsDirectoryMapping> iterator = vcsDirectoryMappings.iterator(); iterator.hasNext(); ) {
                final VcsDirectoryMapping mapping = iterator.next();
                if (!contentRoots.contains(mapping.getDirectory())) {
                    iterator.remove();
                }
            }
            myVcsManager.setAutoDirectoryMapping("", abstractVcses[0].getName());
            for (VcsDirectoryMapping mapping : vcsDirectoryMappings) {
                myVcsManager.removeDirectoryMapping(mapping);
            }
            myVcsManager.cleanupMappings();
        }
    } else if (tryMapPieces) {
        for (Map.Entry<VirtualFile, AbstractVcs> entry : vcsMap.entrySet()) {
            myVcsManager.setAutoDirectoryMapping(entry.getKey().getPath(), entry.getValue() == null ? "" : entry.getValue().getName());
        }
        myVcsManager.cleanupMappings();
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VcsDirectoryMapping(com.intellij.openapi.vcs.VcsDirectoryMapping) ModuleManager(com.intellij.openapi.module.ModuleManager) AbstractVcs(com.intellij.openapi.vcs.AbstractVcs) Module(com.intellij.openapi.module.Module)

Example 5 with ModuleManager

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

the class ModuleTestCase method tearDown.

@Override
protected void tearDown() throws Exception {
    try {
        if (!myModulesToDispose.isEmpty()) {
            List<Throwable> errors = new SmartList<>();
            WriteAction.run(() -> {
                ModuleManager moduleManager = ModuleManager.getInstance(myProject);
                for (Module module : myModulesToDispose) {
                    try {
                        String moduleName = module.getName();
                        if (moduleManager.findModuleByName(moduleName) != null) {
                            moduleManager.disposeModule(module);
                        }
                    } catch (Throwable e) {
                        errors.add(e);
                    }
                }
            });
            CompoundRuntimeException.throwIfNotEmpty(errors);
        }
    } finally {
        myModulesToDispose.clear();
        super.tearDown();
    }
}
Also used : SmartList(com.intellij.util.SmartList) ModuleManager(com.intellij.openapi.module.ModuleManager) Module(com.intellij.openapi.module.Module)

Aggregations

ModuleManager (com.intellij.openapi.module.ModuleManager)53 Module (com.intellij.openapi.module.Module)41 Project (com.intellij.openapi.project.Project)11 VirtualFile (com.intellij.openapi.vfs.VirtualFile)11 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