Search in sources :

Example 1 with LibraryPathType

use of com.intellij.openapi.externalSystem.model.project.LibraryPathType in project intellij-community by JetBrains.

the class LibraryDataService method syncPaths.

private void syncPaths(@NotNull final LibraryData externalLibrary, @NotNull final Library ideLibrary, @NotNull final IdeModifiableModelsProvider modelsProvider) {
    if (externalLibrary.isUnresolved()) {
        return;
    }
    final Map<OrderRootType, Set<String>> toRemove = ContainerUtilRt.newHashMap();
    final Map<OrderRootType, Set<String>> toAdd = ContainerUtilRt.newHashMap();
    for (LibraryPathType pathType : LibraryPathType.values()) {
        OrderRootType ideType = myLibraryPathTypeMapper.map(pathType);
        HashSet<String> toAddPerType = ContainerUtilRt.newHashSet(externalLibrary.getPaths(pathType));
        toAdd.put(ideType, toAddPerType);
        HashSet<String> toRemovePerType = ContainerUtilRt.newHashSet();
        toRemove.put(ideType, toRemovePerType);
        for (VirtualFile ideFile : ideLibrary.getFiles(ideType)) {
            String idePath = ExternalSystemApiUtil.getLocalFileSystemPath(ideFile);
            if (!toAddPerType.remove(idePath)) {
                toRemovePerType.add(ideFile.getUrl());
            }
        }
    }
    if (toRemove.isEmpty() && toAdd.isEmpty()) {
        return;
    }
    final Library.ModifiableModel libraryModel = modelsProvider.getModifiableLibraryModel(ideLibrary);
    for (Map.Entry<OrderRootType, Set<String>> entry : toRemove.entrySet()) {
        for (String path : entry.getValue()) {
            libraryModel.removeRoot(path, entry.getKey());
        }
    }
    for (Map.Entry<OrderRootType, Set<String>> entry : toAdd.entrySet()) {
        Map<OrderRootType, Collection<File>> roots = ContainerUtilRt.newHashMap();
        roots.put(entry.getKey(), ContainerUtil.map(entry.getValue(), PATH_TO_FILE));
        registerPaths(externalLibrary.isUnresolved(), roots, libraryModel, externalLibrary.getInternalName());
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) OrderRootType(com.intellij.openapi.roots.OrderRootType) LibraryPathType(com.intellij.openapi.externalSystem.model.project.LibraryPathType) Library(com.intellij.openapi.roots.libraries.Library)

Example 2 with LibraryPathType

use of com.intellij.openapi.externalSystem.model.project.LibraryPathType in project intellij-community by JetBrains.

the class LibraryDataService method prepareLibraryFiles.

@NotNull
public Map<OrderRootType, Collection<File>> prepareLibraryFiles(@NotNull LibraryData data) {
    Map<OrderRootType, Collection<File>> result = ContainerUtilRt.newHashMap();
    for (LibraryPathType pathType : LibraryPathType.values()) {
        Set<String> paths = data.getPaths(pathType);
        if (paths.isEmpty()) {
            continue;
        }
        result.put(myLibraryPathTypeMapper.map(pathType), ContainerUtil.map(paths, PATH_TO_FILE));
    }
    return result;
}
Also used : OrderRootType(com.intellij.openapi.roots.OrderRootType) LibraryPathType(com.intellij.openapi.externalSystem.model.project.LibraryPathType) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

LibraryPathType (com.intellij.openapi.externalSystem.model.project.LibraryPathType)2 OrderRootType (com.intellij.openapi.roots.OrderRootType)2 Library (com.intellij.openapi.roots.libraries.Library)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 NotNull (org.jetbrains.annotations.NotNull)1