Search in sources :

Example 31 with Library

use of com.intellij.openapi.roots.libraries.Library 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 32 with Library

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

the class EclipseClasspathReader method addNamedLibrary.

@Override
protected void addNamedLibrary(final ModifiableRootModel rootModel, final Collection<String> unknownLibraries, final boolean exported, final String name, final boolean applicationLevel) {
    Library lib = findLibraryByName(myProject, name);
    if (lib != null) {
        rootModel.addLibraryEntry(lib).setExported(exported);
    } else {
        unknownLibraries.add(name);
        rootModel.addInvalidLibrary(name, applicationLevel ? LibraryTablesRegistrar.APPLICATION_LEVEL : LibraryTablesRegistrar.PROJECT_LEVEL).setExported(exported);
    }
}
Also used : Library(com.intellij.openapi.roots.libraries.Library)

Example 33 with Library

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

Example 34 with Library

use of com.intellij.openapi.roots.libraries.Library 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 35 with Library

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

the class LibraryCompositionSettings method addLibraries.

@Nullable
public Library addLibraries(@NotNull final ModifiableRootModel rootModel, @NotNull final List<Library> addedLibraries, @Nullable final LibrariesContainer librariesContainer) {
    Library newLibrary = createLibrary(rootModel, librariesContainer);
    if (newLibrary != null) {
        addedLibraries.add(newLibrary);
        DependencyScope scope = LibraryDependencyScopeSuggester.getDefaultScope(newLibrary);
        if (getLibraryLevel() != LibrariesContainer.LibraryLevel.MODULE) {
            rootModel.addLibraryEntry(newLibrary).setScope(scope);
        } else {
            LibraryOrderEntry orderEntry = rootModel.findLibraryOrderEntry(newLibrary);
            assert orderEntry != null;
            orderEntry.setScope(scope);
        }
    }
    if (mySelectedLibrary != null) {
        addedLibraries.add(mySelectedLibrary);
        rootModel.addLibraryEntry(mySelectedLibrary).setScope(LibraryDependencyScopeSuggester.getDefaultScope(mySelectedLibrary));
    }
    if (myLibraryProvider != null) {
        Library library = myLibraryProvider.createLibrary(myLibraryDescription.getSuitableLibraryKinds());
        addedLibraries.add(library);
        rootModel.addLibraryEntry(library).setScope(LibraryDependencyScopeSuggester.getDefaultScope(library));
    }
    return newLibrary;
}
Also used : DependencyScope(com.intellij.openapi.roots.DependencyScope) Library(com.intellij.openapi.roots.libraries.Library) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Library (com.intellij.openapi.roots.libraries.Library)266 LibraryTable (com.intellij.openapi.roots.libraries.LibraryTable)69 VirtualFile (com.intellij.openapi.vfs.VirtualFile)65 Module (com.intellij.openapi.module.Module)43 NotNull (org.jetbrains.annotations.NotNull)32 File (java.io.File)31 LibraryOrderEntry (com.intellij.openapi.roots.LibraryOrderEntry)28 LibraryEx (com.intellij.openapi.roots.impl.libraries.LibraryEx)27 Project (com.intellij.openapi.project.Project)25 ProjectLibraryTable (com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable)25 Nullable (org.jetbrains.annotations.Nullable)25 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)19 ArrayList (java.util.ArrayList)15 Sdk (com.intellij.openapi.projectRoots.Sdk)13 OrderEntry (com.intellij.openapi.roots.OrderEntry)12 THashSet (gnu.trove.THashSet)9 Element (org.jdom.Element)9 OrderRoot (com.intellij.openapi.roots.libraries.ui.OrderRoot)8 Result (com.intellij.openapi.application.Result)7 Logger (com.intellij.openapi.diagnostic.Logger)7