import com.intellij.testFramework.PsiTestUtil;
import com.intellij.util.PathsList;
import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
import java.io.IOException;
return output;
}
- protected Library createLibrary(final String name, final VirtualFile classesRoot, final VirtualFile sourceRoot) {
+ protected Library createLibrary(final String name, final @Nullable VirtualFile classesRoot, final @Nullable VirtualFile sourceRoot) {
final Library library = LibraryTablesRegistrar.getInstance().getLibraryTable(myProject).createLibrary(name);
final Library.ModifiableModel model = library.getModifiableModel();
- model.addRoot(classesRoot, OrderRootType.CLASSES);
+ if (classesRoot != null) {
+ model.addRoot(classesRoot, OrderRootType.CLASSES);
+ }
if (sourceRoot != null) {
model.addRoot(sourceRoot, OrderRootType.SOURCES);
}
import com.intellij.openapi.application.WriteAction;
import com.intellij.openapi.roots.*;
import com.intellij.openapi.roots.impl.libraries.LibraryEx;
+import com.intellij.openapi.roots.impl.libraries.LibraryTableBase;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.roots.libraries.LibraryTable;
import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar;
assertSameElements(getLibraries(), library);
}
+ public void testFindLibraryByNameAfterRename() {
+ Library a = createLibrary("a", null, null);
+ assertSame(a, getLibraryTable().getLibraryByName("a"));
+ Library.ModifiableModel libraryModel = a.getModifiableModel();
+ libraryModel.setName("b");
+ commit(libraryModel);
+ assertSame(a, getLibraryTable().getLibraryByName("b"));
+ }
+
+ public void testReloadLibraryTable() {
+ ((LibraryTableBase)getLibraryTable()).loadState(new Element("component"));
+ createLibrary("a", null, null);
+ ((LibraryTableBase)getLibraryTable()).loadState(new Element("component").addContent(new Element("library").setAttribute("name", "b")));
+ assertEquals("b", assertOneElement(getLibraryTable().getLibraries()).getName());
+ }
+
public void testResolveDependencyToRenamedLibrary() {
Library library = createLibrary("jdom2", getJDomJar(), null);
}
public void testNativePathSerialization() {
- LibraryTable table = LibraryTablesRegistrar.getInstance().getLibraryTable(myProject);
+ LibraryTable table = getLibraryTable();
Library library = table.createLibrary("native");
Library.ModifiableModel model = library.getModifiableModel();
model.addRoot("file://native-lib-root", NativeLibraryOrderRootType.getInstance());
element);
}
+ @NotNull
+ private LibraryTable getLibraryTable() {
+ return LibraryTablesRegistrar.getInstance().getLibraryTable(myProject);
+ }
+
public void testJarDirectoriesSerialization() {
- LibraryTable table = LibraryTablesRegistrar.getInstance().getLibraryTable(myProject);
+ LibraryTable table = getLibraryTable();
Library library = table.createLibrary("jarDirs");
Library.ModifiableModel model = library.getModifiableModel();
model.addJarDirectory("file://jar-dir", false, OrderRootType.CLASSES);