Search in sources :

Example 41 with Library

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

the class DartProjectComponent method removeGlobalDartSdkLib.

private void removeGlobalDartSdkLib() {
    for (final Library library : ApplicationLibraryTable.getApplicationTable().getLibraries()) {
        if (DartSdk.DART_SDK_LIB_NAME.equals(library.getName())) {
            final DartSdk oldGlobalSdk = DartSdk.getSdkByLibrary(library);
            if (oldGlobalSdk != null) {
                DartSdkUtil.updateKnownSdkPaths(myProject, oldGlobalSdk.getHomePath());
            }
            ApplicationManager.getApplication().runWriteAction(() -> ApplicationLibraryTable.getApplicationTable().removeLibrary(library));
            return;
        }
    }
}
Also used : DartSdk(com.jetbrains.lang.dart.sdk.DartSdk) Library(com.intellij.openapi.roots.libraries.Library)

Example 42 with Library

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

the class DartSdkLibUtil method createDartSdkLib.

private static void createDartSdkLib(@NotNull final Project project, @NotNull final LibraryTable.ModifiableModel libraryTableModel, @NotNull final String sdkHomePath) {
    final Library existingLib = libraryTableModel.getLibraryByName(DartSdk.DART_SDK_LIB_NAME);
    if (existingLib != null) {
        setupDartSdkRoots(project, existingLib, sdkHomePath);
    } else {
        final Library library = libraryTableModel.createLibrary(DartSdk.DART_SDK_LIB_NAME);
        setupDartSdkRoots(project, library, sdkHomePath);
    }
}
Also used : Library(com.intellij.openapi.roots.libraries.Library)

Example 43 with Library

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

the class DartSdkLibUtil method ensureDartSdkConfigured.

public static void ensureDartSdkConfigured(@NotNull final Project project, @NotNull final String sdkHomePath) {
    final LibraryTable libraryTable = ProjectLibraryTable.getInstance(project);
    final Library library = libraryTable.getLibraryByName(DartSdk.DART_SDK_LIB_NAME);
    if (library == null) {
        final LibraryTable.ModifiableModel model = libraryTable.getModifiableModel();
        createDartSdkLib(project, model, sdkHomePath);
        model.commit();
    } else {
        final DartSdk sdk = DartSdk.getSdkByLibrary(library);
        if (sdk == null || !sdkHomePath.equals(sdk.getHomePath())) {
            setupDartSdkRoots(project, library, sdkHomePath);
        }
    }
}
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 Library

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

the class CucumberConfigUtil method getCucumberCoreVersionImpl.

@Nullable
private static String getCucumberCoreVersionImpl(Module module) {
    for (OrderEntry orderEntry : ModuleRootManager.getInstance(module).getOrderEntries()) {
        if (orderEntry instanceof LibraryOrderEntry) {
            final String libraryName = ((LibraryOrderEntry) orderEntry).getLibraryName();
            final Library library = ((LibraryOrderEntry) orderEntry).getLibrary();
            //libraryName is null for simple jar entries
            if ((libraryName == null || libraryName.toLowerCase().contains("cucumber")) && library != null) {
                final VirtualFile[] files = library.getFiles(OrderRootType.CLASSES);
                for (VirtualFile file : files) {
                    final String version = getVersionByFile(file);
                    if (version != null)
                        return version;
                }
            }
        }
    }
    return getSimpleVersionFromMainClass(module);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Library(com.intellij.openapi.roots.libraries.Library) Nullable(org.jetbrains.annotations.Nullable)

Example 45 with Library

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

the class AndroidModuleDependenciesSetupTest method createLibrary.

@NotNull
private Library createLibrary(@NotNull File binaryPath, @NotNull File sourcePath) {
    LibraryTable libraryTable = ProjectLibraryTable.getInstance(getProject());
    LibraryTable.ModifiableModel libraryTableModel = libraryTable.getModifiableModel();
    Library library = libraryTableModel.createLibrary(binaryPath.getName());
    Application application = ApplicationManager.getApplication();
    application.runWriteAction(libraryTableModel::commit);
    Library.ModifiableModel libraryModel = library.getModifiableModel();
    libraryModel.addRoot(pathToIdeaUrl(binaryPath), CLASSES);
    libraryModel.addRoot(pathToIdeaUrl(sourcePath), SOURCES);
    application.runWriteAction(libraryModel::commit);
    return library;
}
Also used : ProjectLibraryTable(com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) Library(com.intellij.openapi.roots.libraries.Library) Application(com.intellij.openapi.application.Application) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Library (com.intellij.openapi.roots.libraries.Library)266 LibraryTable (com.intellij.openapi.roots.libraries.LibraryTable)69 VirtualFile (com.intellij.openapi.vfs.VirtualFile)65 Module (com.intellij.openapi.module.Module)43 NotNull (org.jetbrains.annotations.NotNull)32 File (java.io.File)31 LibraryOrderEntry (com.intellij.openapi.roots.LibraryOrderEntry)28 LibraryEx (com.intellij.openapi.roots.impl.libraries.LibraryEx)27 Project (com.intellij.openapi.project.Project)25 ProjectLibraryTable (com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable)25 Nullable (org.jetbrains.annotations.Nullable)25 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)19 ArrayList (java.util.ArrayList)15 Sdk (com.intellij.openapi.projectRoots.Sdk)13 OrderEntry (com.intellij.openapi.roots.OrderEntry)12 THashSet (gnu.trove.THashSet)9 Element (org.jdom.Element)9 OrderRoot (com.intellij.openapi.roots.libraries.ui.OrderRoot)8 Result (com.intellij.openapi.application.Result)7 Logger (com.intellij.openapi.diagnostic.Logger)7