Search in sources :

Example 1 with ProjectLibraryTable

use of com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable in project android by JetBrains.

the class SyncLibraryRegistryTest method simulateProjectLibraryTableHas.

private void simulateProjectLibraryTableHas(@NotNull Library[] libraries1) {
    Project project = getProject();
    myOriginalProjectLibraryTable = (ProjectLibraryTable) ProjectLibraryTable.getInstance(project);
    ProjectLibraryTable projectLibraryTable = IdeComponents.replaceServiceWithMock(project, ProjectLibraryTable.class);
    when(projectLibraryTable.getLibraries()).thenReturn(libraries1);
}
Also used : Project(com.intellij.openapi.project.Project) ProjectLibraryTable(com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable)

Example 2 with ProjectLibraryTable

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

the class LibraryTest method testFindLibraryByNameAfterRename.

public void testFindLibraryByNameAfterRename() {
    final long moduleModificationCount = ((ModuleRootManagerComponent) ModuleRootManager.getInstance(myModule)).getStateModificationCount();
    ProjectLibraryTable table = (ProjectLibraryTable) getLibraryTable();
    final long projectLibraryModificationCount = table.getStateModificationCount();
    Library a = createLibrary("a", null, null);
    LibraryTable.ModifiableModel model = table.getModifiableModel();
    assertSame(a, table.getLibraryByName("a"));
    assertSame(a, model.getLibraryByName("a"));
    Library.ModifiableModel libraryModel = a.getModifiableModel();
    libraryModel.setName("b");
    commit(libraryModel);
    // module not marked as to save if project library modified, but module is not affected
    assertThat(((ModuleRootManagerComponent) ModuleRootManager.getInstance(myModule)).getStateModificationCount()).isEqualTo(moduleModificationCount);
    assertThat(table.getStateModificationCount()).isGreaterThan(projectLibraryModificationCount);
    assertNull(table.getLibraryByName("a"));
    assertNull(model.getLibraryByName("a"));
    assertSame(a, table.getLibraryByName("b"));
    assertSame(a, model.getLibraryByName("b"));
    commit(model);
    assertSame(a, table.getLibraryByName("b"));
}
Also used : ProjectLibraryTable(com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) ProjectLibraryTable(com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable) ModuleRootManagerComponent(com.intellij.openapi.roots.impl.ModuleRootManagerComponent) Library(com.intellij.openapi.roots.libraries.Library)

Example 3 with ProjectLibraryTable

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

Aggregations

ProjectLibraryTable (com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable)3 Library (com.intellij.openapi.roots.libraries.Library)2 LibraryTable (com.intellij.openapi.roots.libraries.LibraryTable)2 Project (com.intellij.openapi.project.Project)1 ModuleRootManagerComponent (com.intellij.openapi.roots.impl.ModuleRootManagerComponent)1 LibraryEx (com.intellij.openapi.roots.impl.libraries.LibraryEx)1 DartPackagesLibraryProperties (com.jetbrains.lang.dart.sdk.DartPackagesLibraryProperties)1 NotNull (org.jetbrains.annotations.NotNull)1