Search in sources :

Example 16 with ModuleRootManager

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

the class ChooseScopeAndCreateLibraryDialog method createLibraryAndAssociate.

@Nullable
private ErrorMessage createLibraryAndAssociate() {
    String libraryName = myLibraryNameTextField.getText();
    ScriptingLibraryModel libraryModel = myLibraryHelper.getOrCreateJsLibraryModel(libraryName);
    try {
        ScriptingLibraryMappings libraryMappings = ServiceManager.getService(myProject, JSLibraryMappings.class);
        if (myModuleSelector.isAssociateWithProjectView()) {
            if (myModuleSelector.isAssociateWithProjectRequested()) {
                libraryMappings.associateWithProject(libraryModel.getName());
                LOG.info("Library '" + libraryModel.getName() + "' has been successfully associated with the project");
            } else {
                libraryMappings.disassociateWithProject(libraryModel.getName());
            }
        } else {
            for (Module module : myModuleSelector.getSelectedModules()) {
                ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
                VirtualFile[] roots = moduleRootManager.getContentRoots();
                for (VirtualFile root : roots) {
                    libraryMappings.associate(root, libraryModel.getName(), false);
                    LOG.info("Library '" + libraryModel.getName() + "' has been associated with " + root);
                }
            }
        }
        myLibraryHelper.commit();
        return null;
    } catch (Exception ex) {
        return new ErrorMessage("Unable to associate '" + libraryName + "' JavaScript library", ex);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ScriptingLibraryModel(com.intellij.webcore.libraries.ScriptingLibraryModel) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) Module(com.intellij.openapi.module.Module) ScriptingLibraryMappings(com.intellij.webcore.libraries.ScriptingLibraryMappings) Nullable(org.jetbrains.annotations.Nullable)

Example 17 with ModuleRootManager

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

the class IdeFrameFixture method getSourceFolderRelativePaths.

/**
   * Returns a list of system independent paths
   */
@NotNull
public Collection<String> getSourceFolderRelativePaths(@NotNull String moduleName, @NotNull JpsModuleSourceRootType<?> sourceType) {
    Set<String> paths = Sets.newHashSet();
    Module module = getModule(moduleName);
    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(PathUtil.toSystemIndependentName(relativePath));
                        }
                    }
                }
            } finally {
                rootModel.dispose();
            }
        }
    });
    return paths;
}
Also used : 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) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) Module(com.intellij.openapi.module.Module) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) GradleUtil.getGradleBuildFile(com.android.tools.idea.gradle.util.GradleUtil.getGradleBuildFile) Assert.assertNotNull(junit.framework.Assert.assertNotNull) NotNull(org.jetbrains.annotations.NotNull)

Example 18 with ModuleRootManager

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

the class VFSUtil method findFileInModule.

private static void findFileInModule(final Set<VirtualFile> found, Module module, VFile file) {
    ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
    findInRoots(found, rootManager.getSourceRoots(), file.getSourcePath());
    findInRoots(found, rootManager.getContentRoots(), file.getContentPath());
}
Also used : ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager)

Example 19 with ModuleRootManager

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

the class LibraryCollector method collect.

/**
   * We don't use BuildConfigurationEntry as source of libraries. If reference to component declared in such build configuration is resolved, so, we register such bc's module
   */
public void collect(Module module) {
    final FlexBuildConfiguration bc = FlexBuildConfigurationManager.getInstance(module).getActiveConfiguration();
    final Sdk sdk = bc.getSdk();
    assert sdk != null;
    final SdkType sdkType;
    try {
        sdkType = (SdkType) sdk.getClass().getMethod("getSdkType").invoke(sdk);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    final boolean isFlexmojosSdk = sdkType instanceof FlexmojosSdkType;
    if (!isFlexmojosSdk) {
        collectSdkLibraries(bc, sdk);
    } else {
        final String sdkHomePath = sdk.getHomePath();
        LogMessageUtil.LOG.assertTrue(sdkHomePath != null && sdkHomePath.contains("flex"), sdkHomePath + " must be path to maven repo and contains 'flex'");
        flexmojosSdkHomePath = sdkHomePath.substring(0, sdkHomePath.indexOf("flex"));
    }
    flexSdkVersion = sdk.getVersionString();
    assert flexSdkVersion != null;
    if (StringUtil.compareVersionNumbers(flexSdkVersion, "4.5.1") >= 0) {
        flexSdkVersion = "4.6";
    } else {
        flexSdkVersion = flexSdkVersion.substring(0, 3);
    }
    globalCatalogForTests(bc);
    final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
    for (DependencyEntry entry : bc.getDependencies().getEntries()) {
        if (entry instanceof ModuleLibraryEntry) {
            LibraryOrderEntry orderEntry = FlexProjectRootsUtil.findOrderEntry((ModuleLibraryEntry) entry, moduleRootManager);
            if (orderEntry != null) {
                collectFromLibraryOrderEntry(orderEntry.getRootFiles(OrderRootType.CLASSES));
            }
        } else if (entry instanceof SharedLibraryEntry) {
            com.intellij.openapi.roots.libraries.Library library = FlexProjectRootsUtil.findOrderEntry(module.getProject(), (SharedLibraryEntry) entry);
            if (library != null) {
                collectFromLibraryOrderEntry(library.getFiles(OrderRootType.CLASSES));
            }
        }
    }
    // IDEA-71055
    // todo css-based themes
    final List<String> themes = BCUtils.getThemes(module, bc);
    for (String theme : themes) {
        if (theme.endsWith(DOT_SWC)) {
            final VirtualFile file = LocalFileSystem.getInstance().findFileByPath(theme);
            if (file != null && uniqueGuard.add(file)) {
                final VirtualFile jarFile = JarFileSystem.getInstance().getJarRootForLocalFile(file);
                if (jarFile != null) {
                    addLibrary(jarFile, true);
                }
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FlexmojosSdkType(com.intellij.lang.javascript.flex.sdk.FlexmojosSdkType) SdkType(com.intellij.openapi.projectRoots.SdkType) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) Sdk(com.intellij.openapi.projectRoots.Sdk) FlexmojosSdkType(com.intellij.lang.javascript.flex.sdk.FlexmojosSdkType)

Example 20 with ModuleRootManager

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

the class CreateFlexUnitTestDialog method findExistingTestSourceRoot.

@Nullable
private static PsiDirectory findExistingTestSourceRoot(final Module module) {
    PsiDirectory testSourceRoot = null;
    final ModuleRootManager manager = ModuleRootManager.getInstance(module);
    for (VirtualFile srcRoot : manager.getSourceRoots(true)) {
        if (manager.getFileIndex().isInTestSourceContent(srcRoot)) {
            testSourceRoot = PsiManager.getInstance(module.getProject()).findDirectory(srcRoot);
            break;
        }
    }
    return testSourceRoot;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiDirectory(com.intellij.psi.PsiDirectory) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) Nullable(org.jetbrains.annotations.Nullable)

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