Search in sources :

Example 1 with ModuleRootManagerComponent

use of com.intellij.openapi.roots.impl.ModuleRootManagerComponent 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 2 with ModuleRootManagerComponent

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

the class LibraryTest method testLibrarySerialization.

public void testLibrarySerialization() {
    final long moduleModificationCount = ((ModuleRootManagerComponent) ModuleRootManager.getInstance(myModule)).getStateModificationCount();
    Library library = PsiTestUtil.addProjectLibrary(myModule, "junit", Collections.singletonList(getJDomJar()), Collections.singletonList(getJDomSources()));
    assertThat(((ModuleRootManagerComponent) ModuleRootManager.getInstance(myModule)).getStateModificationCount()).isGreaterThan(moduleModificationCount);
    Element element = serialize(library);
    String classesUrl = getJDomJar().getUrl();
    String sourcesUrl = getJDomSources().getUrl();
    PlatformTestUtil.assertElementEquals("<root><library name=\"junit\"><CLASSES><root url=\"" + classesUrl + "\" /></CLASSES>" + "<JAVADOC /><SOURCES><root url=\"" + sourcesUrl + "\" /></SOURCES></library></root>", element);
}
Also used : ModuleRootManagerComponent(com.intellij.openapi.roots.impl.ModuleRootManagerComponent) Element(org.jdom.Element) Library(com.intellij.openapi.roots.libraries.Library)

Aggregations

ModuleRootManagerComponent (com.intellij.openapi.roots.impl.ModuleRootManagerComponent)2 Library (com.intellij.openapi.roots.libraries.Library)2 ProjectLibraryTable (com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable)1 LibraryTable (com.intellij.openapi.roots.libraries.LibraryTable)1 Element (org.jdom.Element)1