void (final @NotNull LibraryData externalLibrary, final @NotNull Library ideLibrary, final @NotNull IdeModifiableModelsProvider modelsProvider) { if (externalLibrary.isUnresolved()) { return; } final Map<OrderRootType, Set<String>> toRemove = new HashMap<>(); final Map<OrderRootType, Set<String>> toAdd = new HashMap<>(); ExternalLibraryPathTypeMapper externalLibraryPathTypeMapper = ExternalLibraryPathTypeMapper.getInstance(); for (LibraryPathType pathType: LibraryPathType.values()) { OrderRootType ideType = externalLibraryPathTypeMapper.map(pathType); if (ideType == null) continue; HashSet<String> toAddPerType = new HashSet<>(externalLibrary.getPaths(pathType)); toAdd.put(ideType, toAddPerType); // do not remove attached or manually added sources/javadocs if nothing to add if(pathType != LibraryPathType.BINARY && toAddPerType.isEmpty()) { continue; } HashSet<String> toRemovePerType = new HashSet<>(); toRemove.put(ideType, toRemovePerType); for (String url : ideLibrary.getUrls(ideType)) { String idePath = getLocalPath(url); if (!toAddPerType.remove(idePath)) { toRemovePerType.add(url); } } } 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()); } } Set<String> excludedPaths = externalLibrary.getPaths(LibraryPathType.EXCLUDED); for (Map.Entry<OrderRootType, Set<String>> entry: toAdd.entrySet()) { Map<OrderRootType, Collection<File>> roots = new HashMap<>(); roots.put(entry.getKey(), ContainerUtil.map(entry.getValue(), PATH_TO_FILE)); registerPaths(false, roots, excludedPaths, libraryModel, externalLibrary.getInternalName()); } }