Search in sources :

Example 26 with ModuleRootManager

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

the class ConflictSetTest method setUpModuleDependencies.

private void setUpModuleDependencies() {
    // Make module depend on myLibModule.
    ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(myModule);
    ModifiableRootModel rootModel = moduleRootManager.getModifiableModel();
    try {
        rootModel.addModuleOrderEntry(myLibModule);
    } finally {
        rootModel.commit();
    }
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager)

Example 27 with ModuleRootManager

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

the class CodeContext method createCodeContextFromLibraries.

private static CodeContext createCodeContextFromLibraries(final String namespace, final Module module, final FlexBuildConfiguration bc) {
    final Map<String, CodeContext> contextsOfModule = new THashMap<>();
    final ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
    // If fixed - then method usage at getStdCodeContext() must be changed to make sure that all namespaces handled at that point.
    for (DependencyEntry entry : bc.getDependencies().getEntries()) {
        if (entry.getDependencyType().getLinkageType() == LinkageType.LoadInRuntime)
            continue;
        if (entry instanceof BuildConfigurationEntry) {
            final FlexBuildConfiguration bcDependency = ((BuildConfigurationEntry) entry).findBuildConfiguration();
            if (bcDependency != null && bcDependency.getOutputType() == OutputType.Library) {
                addComponentsFromManifests(module, contextsOfModule, bcDependency, true);
            }
        } else if (entry instanceof ModuleLibraryEntry) {
            final LibraryOrderEntry orderEntry = FlexProjectRootsUtil.findOrderEntry((ModuleLibraryEntry) entry, rootManager);
            if (orderEntry != null) {
                for (VirtualFile file : orderEntry.getRootFiles(OrderRootType.CLASSES)) {
                    handleFileDependency(module, contextsOfModule, file);
                }
            }
        } else if (entry instanceof SharedLibraryEntry) {
            final Library library = FlexProjectRootsUtil.findOrderEntry(module.getProject(), (SharedLibraryEntry) entry);
            if (library != null) {
                for (VirtualFile file : library.getFiles(OrderRootType.CLASSES)) {
                    handleFileDependency(module, contextsOfModule, file);
                }
            }
        }
    }
    addComponentsFromManifests(module, contextsOfModule, bc, false);
    final CodeContextHolder contextHolder = CodeContextHolder.getInstance(module.getProject());
    for (Map.Entry<String, CodeContext> entry : contextsOfModule.entrySet()) {
        contextHolder.putCodeContext(entry.getKey(), module, entry.getValue());
    }
    CodeContext codeContext = contextsOfModule.get(namespace);
    if (codeContext == null) {
        codeContext = CodeContextHolder.EMPTY;
    }
    return codeContext;
}
Also used : ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) THashMap(gnu.trove.THashMap) Library(com.intellij.openapi.roots.libraries.Library) THashMap(gnu.trove.THashMap) Map(java.util.Map)

Example 28 with ModuleRootManager

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

the class FlexFileReferenceHelper method registerFixes.

@NotNull
public List<? extends LocalQuickFix> registerFixes(final FileReference reference) {
    final PsiElement element = reference.getElement();
    if (!(reference instanceof JSFlexFileReference) || !(element instanceof JSAttributeNameValuePair))
        return Collections.emptyList();
    final PsiElement parent = element.getParent();
    if (!(parent instanceof JSAttribute) || !FlexAnnotationNames.EMBED.equals(((JSAttribute) parent).getName())) {
        return Collections.emptyList();
    }
    final String value = ((JSAttributeNameValuePair) element).getSimpleValue();
    if (value.startsWith("/"))
        return Collections.emptyList();
    final Module module = ModuleUtil.findModuleForPsiElement(element);
    if (module == null)
        return Collections.emptyList();
    final ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
    final VirtualFile virtualFile = element.getContainingFile().getVirtualFile();
    final boolean testSourceRoot = virtualFile != null && rootManager.getFileIndex().isInTestSourceContent(virtualFile);
    for (VirtualFile sourceRoot : rootManager.getSourceRoots(testSourceRoot)) {
        if (sourceRoot.findFileByRelativePath(value) != null) {
            return Collections.singletonList(new AddLeadingSlashFix((JSAttributeNameValuePair) element));
        }
    }
    return Collections.emptyList();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) JSAttribute(com.intellij.lang.javascript.psi.ecmal4.JSAttribute) JSAttributeNameValuePair(com.intellij.lang.javascript.psi.ecmal4.JSAttributeNameValuePair) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) Module(com.intellij.openapi.module.Module) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 29 with ModuleRootManager

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

the class IdeFrameFixture method getSourceFolderRelativePaths.

@NotNull
public Collection<String> getSourceFolderRelativePaths(@NotNull String moduleName, @NotNull final JpsModuleSourceRootType<?> sourceType) {
    final Set<String> paths = new HashSet<>();
    Module module = getModule(moduleName);
    final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
    execute(new GuiTask() {

        @Override
        protected void executeInEDT() throws Throwable {
            ModifiableRootModel rootModel = moduleRootManager.getModifiableModel();
            try {
                for (ContentEntry contentEntry : rootModel.getContentEntries()) {
                    for (SourceFolder folder : contentEntry.getSourceFolders()) {
                        JpsModuleSourceRootType<?> rootType = folder.getRootType();
                        if (rootType.equals(sourceType)) {
                            String path = urlToPath(folder.getUrl());
                            String relativePath = getRelativePath(myProjectPath, new File(toSystemDependentName(path)));
                            paths.add(relativePath);
                        }
                    }
                }
            } finally {
                rootModel.dispose();
            }
        }
    });
    return paths;
}
Also used : ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) GuiTask(org.fest.swing.edt.GuiTask) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) SourceFolder(com.intellij.openapi.roots.SourceFolder) JpsModuleSourceRootType(org.jetbrains.jps.model.module.JpsModuleSourceRootType) ContentEntry(com.intellij.openapi.roots.ContentEntry) Module(com.intellij.openapi.module.Module) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Assert.assertNotNull(junit.framework.Assert.assertNotNull) NotNull(org.jetbrains.annotations.NotNull)

Example 30 with ModuleRootManager

use of com.intellij.openapi.roots.ModuleRootManager 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)

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