Search in sources :

Example 41 with LibraryTable

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

the class FlexProjectConfigTest method createModuleLibrary.

private String createModuleLibrary() {
    final ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(myModule).getModifiableModel();
    final LibraryTable.ModifiableModel libraryTable = modifiableModel.getModuleLibraryTable().getModifiableModel();
    LibraryEx library = (LibraryEx) libraryTable.createLibrary("test", FlexLibraryType.FLEX_LIBRARY);
    String libraryId = UUID.randomUUID().toString();
    ((FlexLibraryProperties) library.getProperties()).setId(libraryId);
    ApplicationManager.getApplication().runWriteAction(() -> {
        libraryTable.commit();
        modifiableModel.commit();
    });
    return libraryId;
}
Also used : LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) FlexLibraryProperties(com.intellij.lang.javascript.flex.library.FlexLibraryProperties) LibraryEx(com.intellij.openapi.roots.impl.libraries.LibraryEx)

Example 42 with LibraryTable

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

the class DartFileListener method updatePackagesLibraryRoots.

@NotNull
public static Library updatePackagesLibraryRoots(@NotNull final Project project, @NotNull final DartLibInfo libInfo) {
    final LibraryTable projectLibraryTable = ProjectLibraryTable.getInstance(project);
    final Library existingLibrary = projectLibraryTable.getLibraryByName(DartPackagesLibraryType.DART_PACKAGES_LIBRARY_NAME);
    final Library library = existingLibrary != null ? existingLibrary : WriteAction.compute(() -> {
        final LibraryTableBase.ModifiableModel libTableModel = ProjectLibraryTable.getInstance(project).getModifiableModel();
        final Library lib = libTableModel.createLibrary(DartPackagesLibraryType.DART_PACKAGES_LIBRARY_NAME, DartPackagesLibraryType.LIBRARY_KIND);
        libTableModel.commit();
        return lib;
    });
    final String[] existingUrls = library.getUrls(OrderRootType.CLASSES);
    final Collection<String> libRootUrls = libInfo.getLibRootUrls();
    if ((!libInfo.isProjectWithoutPubspec() && isBrokenPackageMap(((LibraryEx) library).getProperties())) || existingUrls.length != libRootUrls.size() || !libRootUrls.containsAll(Arrays.asList(existingUrls))) {
        ApplicationManager.getApplication().runWriteAction(() -> {
            final LibraryEx.ModifiableModelEx model = (LibraryEx.ModifiableModelEx) library.getModifiableModel();
            for (String url : existingUrls) {
                model.removeRoot(url, OrderRootType.CLASSES);
            }
            for (String url : libRootUrls) {
                model.addRoot(url, OrderRootType.CLASSES);
            }
            final DartPackagesLibraryProperties libraryProperties = new DartPackagesLibraryProperties();
            libraryProperties.setPackageNameToDirsMap(libInfo.getPackagesMap());
            model.setProperties(libraryProperties);
            model.commit();
        });
    }
    return library;
}
Also used : DartPackagesLibraryProperties(com.jetbrains.lang.dart.sdk.DartPackagesLibraryProperties) ProjectLibraryTable(com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) LibraryEx(com.intellij.openapi.roots.impl.libraries.LibraryEx) Library(com.intellij.openapi.roots.libraries.Library) NotNull(org.jetbrains.annotations.NotNull)

Example 43 with LibraryTable

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

the class PsiTestUtil method addProjectLibrary.

private static Library addProjectLibrary(Module module, ModifiableRootModel model, String libName, List<VirtualFile> classesRoots, List<VirtualFile> sourceRoots) {
    LibraryTable libraryTable = ProjectLibraryTable.getInstance(module.getProject());
    RunResult<Library> result = new WriteAction<Library>() {

        @Override
        protected void run(@NotNull Result<Library> result) throws Throwable {
            Library library = libraryTable.createLibrary(libName);
            Library.ModifiableModel libraryModel = library.getModifiableModel();
            try {
                for (VirtualFile root : classesRoots) {
                    libraryModel.addRoot(root, OrderRootType.CLASSES);
                }
                for (VirtualFile root : sourceRoots) {
                    libraryModel.addRoot(root, OrderRootType.SOURCES);
                }
                libraryModel.commit();
            } catch (Throwable t) {
                //noinspection SSBasedInspection
                libraryModel.dispose();
                throw t;
            }
            model.addLibraryEntry(library);
            OrderEntry[] orderEntries = model.getOrderEntries();
            OrderEntry last = orderEntries[orderEntries.length - 1];
            System.arraycopy(orderEntries, 0, orderEntries, 1, orderEntries.length - 1);
            orderEntries[0] = last;
            model.rearrangeOrderEntries(orderEntries);
            result.setResult(library);
        }
    }.execute();
    result.throwException();
    return result.getResultObject();
}
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 44 with LibraryTable

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

the class LibraryOrderEntryImpl method addListeners.

private void addListeners() {
    final String libraryLevel = getLibraryLevel();
    final LibraryTable libraryTable = LibraryTablesRegistrar.getInstance().getLibraryTableByLevel(libraryLevel, getRootModel().getModule().getProject());
    if (libraryTable != null) {
        myProjectRootManagerImpl.addListenerForTable(myLibraryListener, libraryTable);
    }
}
Also used : LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable)

Example 45 with LibraryTable

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

the class LibraryOrderEntryImpl method searchForLibrary.

private void searchForLibrary(@NotNull String name, @NotNull String level) {
    if (myLibrary != null)
        return;
    final LibraryTable libraryTable = LibraryTablesRegistrar.getInstance().getLibraryTableByLevel(level, getRootModel().getModule().getProject());
    final Library library = libraryTable != null ? libraryTable.getLibraryByName(name) : null;
    if (library == null) {
        myLibraryName = name;
        myLibraryLevel = level;
        myLibrary = null;
    } else {
        myLibraryName = null;
        myLibraryLevel = null;
        myLibrary = library;
    }
}
Also used : LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) Library(com.intellij.openapi.roots.libraries.Library)

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