Search in sources :

Example 21 with LibraryTable

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

the class BytecodeAnalysisIntegrationTest method setUpExternalUpAnnotations.

private void setUpExternalUpAnnotations() {
    String annotationsPath = PathManagerEx.getTestDataPath() + "/codeInspection/bytecodeAnalysis/annotations";
    VirtualFile annotationsDir = LocalFileSystem.getInstance().refreshAndFindFileByPath(annotationsPath);
    assertNotNull(annotationsDir);
    ModuleRootModificationUtil.updateModel(myModule, new AsynchConsumer<ModifiableRootModel>() {

        @Override
        public void finished() {
        }

        @Override
        public void consume(ModifiableRootModel modifiableRootModel) {
            LibraryTable libraryTable = modifiableRootModel.getModuleLibraryTable();
            Library[] libs = libraryTable.getLibraries();
            for (Library library : libs) {
                Library.ModifiableModel libraryModel = library.getModifiableModel();
                libraryModel.addRoot(annotationsDir, AnnotationOrderRootType.getInstance());
                libraryModel.commit();
            }
            Sdk sdk = modifiableRootModel.getSdk();
            if (sdk != null) {
                Sdk clone;
                try {
                    clone = (Sdk) sdk.clone();
                } catch (CloneNotSupportedException e) {
                    throw new RuntimeException(e);
                }
                SdkModificator sdkModificator = clone.getSdkModificator();
                sdkModificator.addRoot(annotationsDir, AnnotationOrderRootType.getInstance());
                sdkModificator.commitChanges();
                modifiableRootModel.setSdk(clone);
            }
        }
    });
    VfsUtilCore.visitChildrenRecursively(annotationsDir, new VirtualFileVisitor() {
    });
    annotationsDir.refresh(false, true);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SdkModificator(com.intellij.openapi.projectRoots.SdkModificator) VirtualFileVisitor(com.intellij.openapi.vfs.VirtualFileVisitor) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) Library(com.intellij.openapi.roots.libraries.Library) Sdk(com.intellij.openapi.projectRoots.Sdk)

Example 22 with LibraryTable

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

the class ArtifactEditorContextImpl method selectLibrary.

@Override
public void selectLibrary(@NotNull Library library) {
    final LibraryTable table = library.getTable();
    if (table != null) {
        ProjectStructureConfigurable.getInstance(getProject()).selectProjectOrGlobalLibrary(library, true);
    } else {
        final Module module = ((LibraryImpl) library).getModule();
        if (module != null) {
            final ModuleRootModel rootModel = myParent.getModulesProvider().getRootModel(module);
            final String libraryName = library.getName();
            for (OrderEntry entry : rootModel.getOrderEntries()) {
                if (entry instanceof ModuleLibraryOrderEntryImpl) {
                    final ModuleLibraryOrderEntryImpl libraryEntry = (ModuleLibraryOrderEntryImpl) entry;
                    if (libraryName != null && libraryName.equals(libraryEntry.getLibraryName()) || libraryName == null && library.equals(libraryEntry.getLibrary())) {
                        ProjectStructureConfigurable.getInstance(getProject()).selectOrderEntry(module, libraryEntry);
                        return;
                    }
                }
            }
        }
    }
}
Also used : LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) OrderEntry(com.intellij.openapi.roots.OrderEntry) LibraryImpl(com.intellij.openapi.roots.impl.libraries.LibraryImpl) ModuleRootModel(com.intellij.openapi.roots.ModuleRootModel) ModuleLibraryOrderEntryImpl(com.intellij.openapi.roots.impl.ModuleLibraryOrderEntryImpl) Module(com.intellij.openapi.module.Module)

Example 23 with LibraryTable

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

the class ClsGenericsHighlightingTest method commitLibraryModel.

protected static void commitLibraryModel(ModifiableRootModel model, String testDataPath, @NotNull String... libraryPath) {
    LibraryTable libraryTable = model.getModuleLibraryTable();
    Library library = libraryTable.createLibrary("test");
    Library.ModifiableModel libraryModel = library.getModifiableModel();
    for (String annotationsDir : libraryPath) {
        String path = testDataPath + "/libs/" + annotationsDir;
        VirtualFile libJarLocal = LocalFileSystem.getInstance().findFileByPath(path);
        assertNotNull(libJarLocal);
        VirtualFile jarRoot = JarFileSystem.getInstance().getJarRootForLocalFile(libJarLocal);
        assertNotNull(jarRoot);
        libraryModel.addRoot(jarRoot, jarRoot.getName().contains("-sources") ? OrderRootType.SOURCES : OrderRootType.CLASSES);
    }
    libraryModel.commit();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) Library(com.intellij.openapi.roots.libraries.Library)

Example 24 with LibraryTable

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

the class EclipseImportBuilder method createEclipseLibrary.

private static void createEclipseLibrary(final Project project, final Collection<String> libraries, final String libraryName) {
    if (libraries.contains(libraryName)) {
        final FileChooserDescriptor fileChooserDescriptor = new FileChooserDescriptor(false, true, false, false, false, false) {

            @Override
            public Icon getIcon(final VirtualFile file) {
                return looksLikeEclipse(file) ? dressIcon(file, EclipseIcons.Eclipse) : super.getIcon(file);
            }

            private boolean looksLikeEclipse(final VirtualFile file) {
                return file.findChild(".eclipseproduct") != null;
            }
        };
        fileChooserDescriptor.setTitle(EclipseBundle.message("eclipse.create.library.title"));
        fileChooserDescriptor.setDescription(EclipseBundle.message("eclipse.create.library.description", libraryName));
        final VirtualFile file = FileChooser.chooseFile(fileChooserDescriptor, project, null);
        if (file != null) {
            final VirtualFile pluginsDir = file.findChild("plugins");
            if (pluginsDir != null) {
                ApplicationManager.getApplication().runWriteAction(() -> {
                    final LibraryTable table = LibraryTablesRegistrar.getInstance().getLibraryTableByLevel(LibraryTablesRegistrar.APPLICATION_LEVEL, project);
                    assert table != null;
                    final LibraryTable.ModifiableModel tableModel = table.getModifiableModel();
                    final Library library = tableModel.createLibrary(libraryName);
                    final Library.ModifiableModel libraryModel = library.getModifiableModel();
                    libraryModel.addJarDirectory(pluginsDir, true);
                    libraryModel.commit();
                    tableModel.commit();
                });
                libraries.remove(libraryName);
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) Library(com.intellij.openapi.roots.libraries.Library)

Example 25 with LibraryTable

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

the class EclipseClasspathReader method findLibraryByName.

public static Library findLibraryByName(Project project, String name) {
    final LibraryTablesRegistrar tablesRegistrar = LibraryTablesRegistrar.getInstance();
    Library lib = tablesRegistrar.getLibraryTable().getLibraryByName(name);
    if (lib == null) {
        lib = tablesRegistrar.getLibraryTable(project).getLibraryByName(name);
    }
    if (lib == null) {
        for (LibraryTable table : tablesRegistrar.getCustomLibraryTables()) {
            lib = table.getLibraryByName(name);
            if (lib != null) {
                break;
            }
        }
    }
    return lib;
}
Also used : LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) LibraryTablesRegistrar(com.intellij.openapi.roots.libraries.LibraryTablesRegistrar) Library(com.intellij.openapi.roots.libraries.Library)

Aggregations

LibraryTable (com.intellij.openapi.roots.libraries.LibraryTable)64 Library (com.intellij.openapi.roots.libraries.Library)43 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