Search in sources :

Example 56 with LibraryTable

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

the class MavenModuleImporter method configSurefirePlugin.

private void configSurefirePlugin() {
    // Remove "maven-surefire-plugin urls" library created by previous version of IDEA.
    // todo remove this code after 01.06.2013
    LibraryTable moduleLibraryTable = myRootModelAdapter.getRootModel().getModuleLibraryTable();
    Library library = moduleLibraryTable.getLibraryByName(SUREFIRE_PLUGIN_LIBRARY_NAME);
    if (library != null) {
        moduleLibraryTable.removeLibrary(library);
    }
}
Also used : LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) Library(com.intellij.openapi.roots.libraries.Library)

Example 57 with LibraryTable

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

the class LibrariesUtil method getGlobalLibraries.

public static Library[] getGlobalLibraries(Condition<Library> condition) {
    LibraryTable table = LibraryTablesRegistrar.getInstance().getLibraryTable();
    List<Library> libs = ContainerUtil.findAll(table.getLibraries(), condition);
    return libs.toArray(new Library[libs.size()]);
}
Also used : LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) Library(com.intellij.openapi.roots.libraries.Library)

Example 58 with LibraryTable

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

the class EclipseUserLibrariesHelper method readProjectLibrariesContent.

public static void readProjectLibrariesContent(@NotNull VirtualFile exportedFile, Project project, Collection<String> unknownLibraries) throws IOException, JDOMException {
    if (!exportedFile.isValid()) {
        return;
    }
    LibraryTable libraryTable = ProjectLibraryTable.getInstance(project);
    Element element = JDOMUtil.load(exportedFile.getInputStream());
    WriteAction.run(() -> {
        for (Element libElement : element.getChildren("library")) {
            String libName = libElement.getAttributeValue("name");
            Library libraryByName = libraryTable.getLibraryByName(libName);
            if (libraryByName == null) {
                LibraryTable.ModifiableModel model = libraryTable.getModifiableModel();
                libraryByName = model.createLibrary(libName);
                model.commit();
            }
            if (libraryByName != null) {
                Library.ModifiableModel model = libraryByName.getModifiableModel();
                for (Element a : libElement.getChildren("archive")) {
                    String rootPath = a.getAttributeValue("path");
                    // IDEA-138039 Eclipse import: Unix file system: user library gets wrong paths
                    LocalFileSystem fileSystem = LocalFileSystem.getInstance();
                    VirtualFile localFile = fileSystem.findFileByPath(rootPath);
                    if (rootPath.startsWith("/") && (localFile == null || !localFile.isValid())) {
                        // relative to workspace root
                        rootPath = project.getBaseDir().getPath() + rootPath;
                        localFile = fileSystem.findFileByPath(rootPath);
                    }
                    String url = localFile == null ? VfsUtilCore.pathToUrl(rootPath) : localFile.getUrl();
                    if (localFile != null) {
                        VirtualFile jarFile = JarFileSystem.getInstance().getJarRootForLocalFile(localFile);
                        if (jarFile != null) {
                            url = jarFile.getUrl();
                        }
                    }
                    model.addRoot(url, OrderRootType.CLASSES);
                }
                model.commit();
            }
            //ignore finally found libraries
            unknownLibraries.remove(libName);
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectLibraryTable(com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) Element(org.jdom.Element) Library(com.intellij.openapi.roots.libraries.Library)

Example 59 with LibraryTable

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

the class AbstractConfigUtils method getProjectSDKLibraries.

public Library[] getProjectSDKLibraries(Project project) {
    if (project == null || project.isDisposed())
        return Library.EMPTY_ARRAY;
    final LibraryTable table = ProjectLibraryTable.getInstance(project);
    final List<Library> all = ContainerUtil.findAll(table.getLibraries(), LIB_SEARCH_CONDITION);
    return all.toArray(new Library[all.size()]);
}
Also used : ProjectLibraryTable(com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) Library(com.intellij.openapi.roots.libraries.Library)

Example 60 with LibraryTable

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

the class ProjectFromSourcesBuilderImpl method setupRootModel.

private static void setupRootModel(ProjectDescriptor projectDescriptor, final ModuleDescriptor descriptor, final ModifiableRootModel rootModel, final Map<LibraryDescriptor, Library> projectLibs) {
    final CompilerModuleExtension compilerModuleExtension = rootModel.getModuleExtension(CompilerModuleExtension.class);
    compilerModuleExtension.setExcludeOutput(true);
    rootModel.inheritSdk();
    final Set<File> contentRoots = descriptor.getContentRoots();
    for (File contentRoot : contentRoots) {
        final LocalFileSystem lfs = LocalFileSystem.getInstance();
        VirtualFile moduleContentRoot = lfs.refreshAndFindFileByPath(FileUtil.toSystemIndependentName(contentRoot.getPath()));
        if (moduleContentRoot != null) {
            final ContentEntry contentEntry = rootModel.addContentEntry(moduleContentRoot);
            final Collection<DetectedSourceRoot> sourceRoots = descriptor.getSourceRoots(contentRoot);
            for (DetectedSourceRoot srcRoot : sourceRoots) {
                final String srcpath = FileUtil.toSystemIndependentName(srcRoot.getDirectory().getPath());
                final VirtualFile sourceRoot = lfs.refreshAndFindFileByPath(srcpath);
                if (sourceRoot != null) {
                    contentEntry.addSourceFolder(sourceRoot, shouldBeTestRoot(srcRoot.getDirectory()), getPackagePrefix(srcRoot));
                }
            }
        }
    }
    compilerModuleExtension.inheritCompilerOutputPath(true);
    final LibraryTable moduleLibraryTable = rootModel.getModuleLibraryTable();
    for (LibraryDescriptor libDescriptor : ModuleInsight.getLibraryDependencies(descriptor, projectDescriptor.getLibraries())) {
        final Library projectLib = projectLibs.get(libDescriptor);
        if (projectLib != null) {
            rootModel.addLibraryEntry(projectLib);
        } else {
            // add as module library
            final Collection<File> jars = libDescriptor.getJars();
            for (File file : jars) {
                Library library = moduleLibraryTable.createLibrary();
                Library.ModifiableModel modifiableModel = library.getModifiableModel();
                modifiableModel.addRoot(VfsUtil.getUrlForLibraryRoot(file), OrderRootType.CLASSES);
                modifiableModel.commit();
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) Library(com.intellij.openapi.roots.libraries.Library) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) LibraryDescriptor(com.intellij.ide.util.importProject.LibraryDescriptor)

Aggregations

LibraryTable (com.intellij.openapi.roots.libraries.LibraryTable)65 Library (com.intellij.openapi.roots.libraries.Library)44 ProjectLibraryTable (com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable)18 VirtualFile (com.intellij.openapi.vfs.VirtualFile)16 Module (com.intellij.openapi.module.Module)10 NotNull (org.jetbrains.annotations.NotNull)7 Project (com.intellij.openapi.project.Project)5 LibraryEx (com.intellij.openapi.roots.impl.libraries.LibraryEx)5 LibraryTablesRegistrar (com.intellij.openapi.roots.libraries.LibraryTablesRegistrar)4 File (java.io.File)4 Element (org.jdom.Element)4 LibraryImpl (com.intellij.openapi.roots.impl.libraries.LibraryImpl)3 ArrayList (java.util.ArrayList)3 FlexLibraryProperties (com.intellij.lang.javascript.flex.library.FlexLibraryProperties)2 Application (com.intellij.openapi.application.Application)2 Result (com.intellij.openapi.application.Result)2 Sdk (com.intellij.openapi.projectRoots.Sdk)2 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)2 OrderEntry (com.intellij.openapi.roots.OrderEntry)2 ModuleLibraryTable (com.intellij.openapi.roots.impl.ModuleLibraryTable)2