Search in sources :

Example 71 with Library

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

the class RenameLibraryHandler method invoke.

@Override
public void invoke(@NotNull final Project project, @NotNull PsiElement[] elements, @NotNull DataContext dataContext) {
    final Library library = LangDataKeys.LIBRARY.getData(dataContext);
    LOG.assertTrue(library != null);
    Messages.showInputDialog(project, IdeBundle.message("prompt.enter.new.library.name"), IdeBundle.message("title.rename.library"), Messages.getQuestionIcon(), library.getName(), new MyInputValidator(project, library));
}
Also used : Library(com.intellij.openapi.roots.libraries.Library)

Example 72 with Library

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

the class OrderEntryUtil method addLibraryToRoots.

public static void addLibraryToRoots(@NotNull Module module, @NotNull Library library) {
    final ModuleRootManager manager = ModuleRootManager.getInstance(module);
    final ModifiableRootModel rootModel = manager.getModifiableModel();
    if (library.getTable() == null) {
        final Library jarLibrary = rootModel.getModuleLibraryTable().createLibrary();
        final Library.ModifiableModel libraryModel = jarLibrary.getModifiableModel();
        for (OrderRootType orderRootType : OrderRootType.getAllTypes()) {
            VirtualFile[] files = library.getFiles(orderRootType);
            for (VirtualFile jarFile : files) {
                libraryModel.addRoot(jarFile, orderRootType);
            }
        }
        libraryModel.commit();
    } else {
        rootModel.addLibraryEntry(library);
    }
    rootModel.commit();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Library(com.intellij.openapi.roots.libraries.Library)

Example 73 with Library

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

the class OrderEntryUtil method addLibraryToRoots.

public static void addLibraryToRoots(final LibraryOrderEntry libraryOrderEntry, final Module module) {
    Library library = libraryOrderEntry.getLibrary();
    if (library == null)
        return;
    addLibraryToRoots(module, library);
}
Also used : Library(com.intellij.openapi.roots.libraries.Library)

Example 74 with Library

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

the class RootsChangedTest method verifyLibraryTableEditing.

private void verifyLibraryTableEditing(final LibraryTable libraryTable) {
    final Module moduleA = createModule("a.iml");
    final Module moduleB = createModule("b.iml");
    assertEventsCount(2);
    ApplicationManager.getApplication().runWriteAction(() -> {
        final Library libraryA = libraryTable.createLibrary("A");
        final Library.ModifiableModel libraryModifiableModel = libraryA.getModifiableModel();
        libraryModifiableModel.addRoot("file:///a", OrderRootType.CLASSES);
        libraryModifiableModel.commit();
        assertEventsCount(0);
        final ModifiableRootModel rootModelA = ModuleRootManager.getInstance(moduleA).getModifiableModel();
        final ModifiableRootModel rootModelB = ModuleRootManager.getInstance(moduleB).getModifiableModel();
        rootModelA.addLibraryEntry(libraryA);
        rootModelB.addLibraryEntry(libraryA);
        rootModelA.addInvalidLibrary("Q", libraryTable.getTableLevel());
        rootModelB.addInvalidLibrary("Q", libraryTable.getTableLevel());
        ModifiableRootModel[] rootModels = new ModifiableRootModel[] { rootModelA, rootModelB };
        if (rootModels.length > 0) {
            ModifiableModelCommitter.multiCommit(rootModels, ModuleManager.getInstance(rootModels[0].getProject()).getModifiableModel());
        }
        assertEventsCount(1);
        final Library.ModifiableModel libraryModifiableModel2 = libraryA.getModifiableModel();
        final File tmpDir;
        try {
            tmpDir = FileUtil.createTempDirectory(getTestName(true), "");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        try {
            final VirtualFile file = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tmpDir);
            assertNotNull(file);
            libraryModifiableModel2.addRoot(file.getUrl(), OrderRootType.CLASSES);
            libraryModifiableModel2.commit();
            assertEventsCount(1);
        } finally {
            FileUtil.delete(tmpDir);
        }
        libraryTable.removeLibrary(libraryA);
        assertEventsCount(1);
        final Library libraryQ = libraryTable.createLibrary("Q");
        assertEventsCount(1);
        libraryTable.removeLibrary(libraryQ);
        assertEventsCount(1);
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Library(com.intellij.openapi.roots.libraries.Library) IOException(java.io.IOException) Module(com.intellij.openapi.module.Module) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 75 with Library

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

the class RootsChangedTest method verifyLibraryTableEditingInUncommittedModel.

private void verifyLibraryTableEditingInUncommittedModel(final LibraryTable libraryTable) {
    ApplicationManager.getApplication().runWriteAction(() -> {
        final Module moduleA = createModule("a.iml");
        final Module moduleB = createModule("b.iml");
        assertEventsCount(2);
        final Library libraryA = libraryTable.createLibrary("A");
        final Library.ModifiableModel libraryModifiableModel = libraryA.getModifiableModel();
        libraryModifiableModel.addRoot("file:///a", OrderRootType.CLASSES);
        libraryModifiableModel.commit();
        assertEventsCount(0);
        final ModifiableRootModel rootModelA = ModuleRootManager.getInstance(moduleA).getModifiableModel();
        final ModifiableRootModel rootModelB = ModuleRootManager.getInstance(moduleB).getModifiableModel();
        rootModelA.addLibraryEntry(libraryA);
        rootModelB.addLibraryEntry(libraryA);
        final Library.ModifiableModel libraryModifiableModel2 = libraryA.getModifiableModel();
        libraryModifiableModel2.addRoot("file:///b", OrderRootType.CLASSES);
        libraryModifiableModel2.commit();
        assertEventsCount(0);
        libraryTable.removeLibrary(libraryA);
        assertEventsCount(0);
        rootModelA.addInvalidLibrary("Q", libraryTable.getTableLevel());
        rootModelB.addInvalidLibrary("Q", libraryTable.getTableLevel());
        assertEventsCount(0);
        final Library libraryQ = libraryTable.createLibrary("Q");
        assertEventsCount(0);
        ModifiableRootModel[] rootModels = new ModifiableRootModel[] { rootModelA, rootModelB };
        if (rootModels.length > 0) {
            ModifiableModelCommitter.multiCommit(rootModels, ModuleManager.getInstance(rootModels[0].getProject()).getModifiableModel());
        }
        assertEventsCount(1);
        libraryTable.removeLibrary(libraryQ);
        assertEventsCount(1);
    });
}
Also used : Library(com.intellij.openapi.roots.libraries.Library) Module(com.intellij.openapi.module.Module)

Aggregations

Library (com.intellij.openapi.roots.libraries.Library)240 LibraryTable (com.intellij.openapi.roots.libraries.LibraryTable)58 VirtualFile (com.intellij.openapi.vfs.VirtualFile)58 Module (com.intellij.openapi.module.Module)41 NotNull (org.jetbrains.annotations.NotNull)31 File (java.io.File)29 LibraryEx (com.intellij.openapi.roots.impl.libraries.LibraryEx)25 Nullable (org.jetbrains.annotations.Nullable)25 LibraryOrderEntry (com.intellij.openapi.roots.LibraryOrderEntry)23 Project (com.intellij.openapi.project.Project)22 ProjectLibraryTable (com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable)20 ArrayList (java.util.ArrayList)15 Sdk (com.intellij.openapi.projectRoots.Sdk)13 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)13 OrderEntry (com.intellij.openapi.roots.OrderEntry)10 THashSet (gnu.trove.THashSet)9 IOException (java.io.IOException)9 Element (org.jdom.Element)9 OrderRoot (com.intellij.openapi.roots.libraries.ui.OrderRoot)8 LibrariesContainer (com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainer)7