Search in sources :

Example 21 with ModuleRootManager

use of com.intellij.openapi.roots.ModuleRootManager in project android by JetBrains.

the class PostProjectBuildTasksExecutor method excludeOutputFolders.

private static void excludeOutputFolders(@NotNull AndroidFacet facet) {
    AndroidModuleModel androidModel = AndroidModuleModel.get(facet);
    if (androidModel == null) {
        return;
    }
    File buildFolderPath = androidModel.getAndroidProject().getBuildFolder();
    if (!buildFolderPath.isDirectory()) {
        return;
    }
    Module module = facet.getModule();
    if (module.getProject().isDisposed()) {
        return;
    }
    ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
    ModifiableRootModel rootModel = moduleRootManager.getModifiableModel();
    try {
        ContentEntry[] contentEntries = rootModel.getContentEntries();
        ContentEntry parent = findParentContentEntry(buildFolderPath, contentEntries);
        if (parent == null) {
            rootModel.dispose();
            return;
        }
        List<File> excludedFolderPaths = androidModel.getExcludedFolderPaths();
        for (File folderPath : excludedFolderPaths) {
            parent.addExcludeFolder(pathToIdeaUrl(folderPath));
        }
    } finally {
        if (!rootModel.isDisposed()) {
            rootModel.commit();
        }
    }
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) ContentEntry(com.intellij.openapi.roots.ContentEntry) FilePaths.findParentContentEntry(com.android.tools.idea.gradle.util.FilePaths.findParentContentEntry) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) Module(com.intellij.openapi.module.Module) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 22 with ModuleRootManager

use of com.intellij.openapi.roots.ModuleRootManager in project android by JetBrains.

the class NonAndroidSourceTypeNode method getSourceFolders.

private List<VirtualFile> getSourceFolders() {
    ModuleRootManager rootManager = ModuleRootManager.getInstance(getValue());
    List<VirtualFile> folders = Lists.newArrayList();
    ContentEntry[] contentEntries = rootManager.getContentEntries();
    for (ContentEntry entry : contentEntries) {
        List<SourceFolder> sources = entry.getSourceFolders(mySourceType.rootType);
        for (SourceFolder folder : sources) {
            VirtualFile file = folder.getFile();
            if (file != null) {
                folders.add(file);
            }
        }
    }
    return folders;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SourceFolder(com.intellij.openapi.roots.SourceFolder) ContentEntry(com.intellij.openapi.roots.ContentEntry) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager)

Example 23 with ModuleRootManager

use of com.intellij.openapi.roots.ModuleRootManager in project android by JetBrains.

the class AddModuleDependencyTask method perform.

@Nullable
@Override
public Exception perform() {
    final Module module = myModuleProvider.getModule();
    final Module depModule = myDepModuleProvider.getModule();
    if (module == null || depModule == null) {
        return null;
    }
    final ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
    if (!rootManager.isDependsOn(depModule)) {
        ModuleRootModificationUtil.addDependency(module, depModule);
    }
    return null;
}
Also used : ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) Module(com.intellij.openapi.module.Module) Nullable(org.jetbrains.annotations.Nullable)

Example 24 with ModuleRootManager

use of com.intellij.openapi.roots.ModuleRootManager in project android by JetBrains.

the class ContentRootsModuleSetupStepTest method addContentRoots.

private void addContentRoots(@NotNull String... names) throws IOException {
    assertThat(names).isNotEmpty();
    VirtualFile projectFolder = getProject().getBaseDir();
    Module module = getModule();
    ModuleRootManager manager = ModuleRootManager.getInstance(module);
    ModifiableRootModel modifiableModel = manager.getModifiableModel();
    for (String name : names) {
        VirtualFile folder = findOrCreateChildFolder(projectFolder, name);
        modifiableModel.addContentEntry(folder);
    }
    ApplicationManager.getApplication().runWriteAction(modifiableModel::commit);
    ContentEntry[] entries = manager.getContentEntries();
    assertThat(entries).hasLength(names.length);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) ContentEntry(com.intellij.openapi.roots.ContentEntry) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) Module(com.intellij.openapi.module.Module)

Example 25 with ModuleRootManager

use of com.intellij.openapi.roots.ModuleRootManager in project intellij-plugins by JetBrains.

the class FlashUmlTest method doTestImpl.

private DiagramBuilder doTestImpl(@Nullable File projectRoot, String[] files, String[] additionalClasses, Computable<GlobalSearchScope> scopeProvider, @Nullable EnumSet<FlashUmlDependenciesSettingsOption> dependencies, @Nullable String expectedFileNamePrefix) throws Exception {
    List<VirtualFile> vFiles = new ArrayList<>(files.length);
    for (String file : files) {
        vFiles.add(getVirtualFile(BASE_PATH + file));
    }
    ApplicationManager.getApplication().runWriteAction(() -> {
        final ModuleRootManager rootManager = ModuleRootManager.getInstance(myModule);
        final ModifiableRootModel rootModel = rootManager.getModifiableModel();
        ContentEntry[] contentEntries = rootModel.getContentEntries();
        for (ContentEntry contentEntry : contentEntries) {
            rootModel.removeContentEntry(contentEntry);
        }
        rootModel.commit();
    });
    configureByFiles(projectRoot, VfsUtilCore.toVirtualFileArray(vFiles));
    final LinkedHashMap<Integer, String> markers = JSTestUtils.extractPositionMarkers(getProject(), getEditor().getDocument());
    assertFalse(markers.isEmpty());
    DiagramBuilder builder = null;
    int i = 1;
    for (Map.Entry<Integer, String> marker : markers.entrySet()) {
        getEditor().getCaretModel().moveToOffset(marker.getKey());
        i++;
        String expectedPrefix = StringUtil.isNotEmpty(marker.getValue()) ? marker.getValue() : expectedFileNamePrefix;
        final DataContext dataContext = DataManager.getInstance().getDataContext();
        final DiagramProvider[] providers = DiagramProvider.findProviders(dataContext, "unknown");
        final FlashUmlProvider provider = ContainerUtil.findInstance(providers, FlashUmlProvider.class);
        assertNotNull("Flash UML provider not found", provider);
        final String actualOriginFqn = provider.getVfsResolver().getQualifiedName(provider.getElementManager().findInDataContext(dataContext));
        final Object actualOrigin = provider.getVfsResolver().resolveElementByFQN(actualOriginFqn, getProject());
        builder = UmlGraphBuilderFactory.create(myProject, provider, actualOrigin, null);
        Disposer.register(getTestRootDisposable(), builder);
        final DiagramDataModel<Object> model = builder.getDataModel();
        DiagramConfiguration configuration = DiagramConfiguration.getConfiguration();
        String originalCategories = configuration.categories.get(provider.getID());
        if (dependencies != null) {
            model.setShowDependencies(true);
            EnumSet<FlashUmlDependenciesSettingsOption> disabledOptions = EnumSet.complementOf(dependencies);
            configuration.categories.put(provider.getID(), StringUtil.join(disabledOptions, option -> option.getDisplayName(), ";"));
        } else {
            model.setShowDependencies(false);
        }
        try {
            model.refreshDataModel();
            // first limit elements by scope
            Collection<DiagramNode<Object>> nodesToRemove = new ArrayList<>();
            for (DiagramNode<Object> node : model.getNodes()) {
                if (node.getIdentifyingElement() instanceof JSClass && !scopeProvider.compute().contains(((JSClass) node.getIdentifyingElement()).getContainingFile().getVirtualFile())) {
                    nodesToRemove.add(node);
                }
            }
            for (DiagramNode<Object> node : nodesToRemove) {
                model.removeNode(node);
            }
            builder.updateGraph();
            // then add explicitly required classes
            for (String aClass : additionalClasses) {
                JSClass c = JSTestUtils.findClassByQName(aClass, GlobalSearchScope.allScope(myProject));
                final DiagramNode node = model.addElement(c);
                if (node != null) {
                    builder.createDraggedNode(node, node.getTooltip(), DiagramUtils.getBestPositionForNode(builder));
                    builder.updateGraph();
                }
            }
            assertModel(expectedPrefix, provider, actualOriginFqn, model);
        } finally {
            configuration.categories.put(provider.getID(), originalCategories);
        }
    }
    assert builder != null;
    return builder;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VfsRootAccess(com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ContentEntry(com.intellij.openapi.roots.ContentEntry) FlexStylesIndexableSetContributor(com.intellij.javascript.flex.css.FlexStylesIndexableSetContributor) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) Disposer(com.intellij.openapi.util.Disposer) CommonDataKeys(com.intellij.openapi.actionSystem.CommonDataKeys) LoadTextUtil(com.intellij.openapi.fileEditor.impl.LoadTextUtil) DiagramBuilder(com.intellij.diagram.DiagramBuilder) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) ModifiableFlexBuildConfiguration(com.intellij.lang.javascript.flex.projectStructure.model.ModifiableFlexBuildConfiguration) JDOMCompare(com.intellij.util.JDOMCompare) Nullable(org.jetbrains.annotations.Nullable) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) VfsUtilCore.convertFromUrl(com.intellij.openapi.vfs.VfsUtilCore.convertFromUrl) UmlDataModelDumper(com.intellij.diagram.util.UmlDataModelDumper) JdomKt(com.intellij.util.JdomKt) JSTestOptions(com.intellij.lang.javascript.JSTestOptions) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) ApplicationManager(com.intellij.openapi.application.ApplicationManager) DiagramProvider(com.intellij.diagram.DiagramProvider) VfsUtilCore.urlToPath(com.intellij.openapi.vfs.VfsUtilCore.urlToPath) java.util(java.util) CodeInsightTestCase(com.intellij.codeInsight.CodeInsightTestCase) ArrayUtil(com.intellij.util.ArrayUtil) DataContext(com.intellij.openapi.actionSystem.DataContext) JSTestOption(com.intellij.lang.javascript.JSTestOption) FlexModuleType(com.intellij.lang.javascript.flex.FlexModuleType) DiagramConfiguration(com.intellij.diagram.settings.DiagramConfiguration) FlashUmlDataModel(com.intellij.lang.javascript.uml.FlashUmlDataModel) Computable(com.intellij.openapi.util.Computable) ContainerUtil(com.intellij.util.containers.ContainerUtil) JDOMResult(org.jdom.transform.JDOMResult) UmlGraphBuilderFactory(com.intellij.uml.UmlGraphBuilderFactory) JDOMUtil(com.intellij.openapi.util.JDOMUtil) ModuleType(com.intellij.openapi.module.ModuleType) FlexTestUtils(com.intellij.flex.util.FlexTestUtils) DataManager(com.intellij.ide.DataManager) VfsUtilCore(com.intellij.openapi.vfs.VfsUtilCore) StringUtil(com.intellij.openapi.util.text.StringUtil) FlexSchemaHandler(com.intellij.javascript.flex.mxml.schema.FlexSchemaHandler) DiagramUtils(com.intellij.diagram.util.DiagramUtils) FlashUmlDependenciesSettingsOption(com.intellij.lang.javascript.uml.FlashUmlDependenciesSettingsOption) Sdk(com.intellij.openapi.projectRoots.Sdk) File(java.io.File) JSTestUtils(com.intellij.lang.javascript.JSTestUtils) SkipInHeadlessEnvironment(com.intellij.testFramework.SkipInHeadlessEnvironment) FlashUmlProvider(com.intellij.lang.javascript.uml.FlashUmlProvider) DiagramNode(com.intellij.diagram.DiagramNode) TargetElementUtil(com.intellij.codeInsight.TargetElementUtil) DiagramDataModel(com.intellij.diagram.DiagramDataModel) Element(org.jdom.Element) DiagramNode(com.intellij.diagram.DiagramNode) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) DiagramBuilder(com.intellij.diagram.DiagramBuilder) DataContext(com.intellij.openapi.actionSystem.DataContext) DiagramConfiguration(com.intellij.diagram.settings.DiagramConfiguration) FlashUmlProvider(com.intellij.lang.javascript.uml.FlashUmlProvider) FlashUmlDependenciesSettingsOption(com.intellij.lang.javascript.uml.FlashUmlDependenciesSettingsOption) DiagramProvider(com.intellij.diagram.DiagramProvider) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) ContentEntry(com.intellij.openapi.roots.ContentEntry) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass)

Aggregations

ModuleRootManager (com.intellij.openapi.roots.ModuleRootManager)47 VirtualFile (com.intellij.openapi.vfs.VirtualFile)26 Module (com.intellij.openapi.module.Module)19 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)13 ContentEntry (com.intellij.openapi.roots.ContentEntry)11 Sdk (com.intellij.openapi.projectRoots.Sdk)10 File (java.io.File)7 NotNull (org.jetbrains.annotations.NotNull)7 Nullable (org.jetbrains.annotations.Nullable)6 SourceFolder (com.intellij.openapi.roots.SourceFolder)5 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)2 ModuleManager (com.intellij.openapi.module.ModuleManager)2 OrderEntry (com.intellij.openapi.roots.OrderEntry)2 ProjectRootManager (com.intellij.openapi.roots.ProjectRootManager)2 ProjectRootManagerEx (com.intellij.openapi.roots.ex.ProjectRootManagerEx)2 FilePaths.findParentContentEntry (com.android.tools.idea.gradle.util.FilePaths.findParentContentEntry)1 GradleUtil.getGradleBuildFile (com.android.tools.idea.gradle.util.GradleUtil.getGradleBuildFile)1 CodeInsightTestCase (com.intellij.codeInsight.CodeInsightTestCase)1