void (@NotNull IdeModifiableModelsProvider modelsProvider, @NotNull Map<Set<String>, LibraryDependencyData> moduleLibrariesToImport, @NotNull Map<String, LibraryDependencyData> projectLibrariesToImport, @NotNull Set<LibraryDependencyData> toImport, @NotNull Map<OrderEntry, OrderAware> orderEntryDataMap, @NotNull ModifiableRootModel moduleRootModel, boolean hasUnresolvedLibraries) { for (OrderEntry entry : moduleRootModel.getOrderEntries()) { if (OrderEntryUtil.isModuleLibraryOrderEntry(entry)) { LibraryOrderEntry moduleLibraryOrderEntry = (LibraryOrderEntry)entry; Library library = moduleLibraryOrderEntry.getLibrary(); final VirtualFile[] libraryFiles = library.getFiles(OrderRootType.CLASSES); final Set<String> moduleLibraryKey = new HashSet<>(libraryFiles.length); for (VirtualFile file : libraryFiles) { moduleLibraryKey.add(ExternalSystemApiUtil.getLocalFileSystemPath(file) + moduleLibraryOrderEntry.getScope().name()); } LibraryDependencyData existing = moduleLibrariesToImport.remove(moduleLibraryKey); if (existing == null || !StringUtil.equals(StringUtil.nullize(existing.getInternalName()), library.getName())) { moduleRootModel.removeOrderEntry(entry); } else { orderEntryDataMap.put(entry, existing); syncExistingLibraryDependency(modelsProvider, existing, library, moduleRootModel, moduleLibraryOrderEntry.getOwnerModule()); toImport.remove(existing); } } else if (entry instanceof LibraryOrderEntry libraryOrderEntry) { String libraryName = libraryOrderEntry.getLibraryName(); LibraryDependencyData existing = projectLibrariesToImport.remove(libraryName + libraryOrderEntry.getScope().name()); if (existing != null) { String module = modelsProvider.findModuleByPublication(existing.getTarget()); if(module == null) { toImport.remove(existing); orderEntryDataMap.put(entry, existing); libraryOrderEntry.setExported(existing.isExported()); libraryOrderEntry.setScope(existing.getScope()); } else { moduleRootModel.removeOrderEntry(entry); } } else if (!hasUnresolvedLibraries) { // There is a possible case that a project has been successfully imported from external model and after // that network/repo goes down. We don't want to drop existing binary mappings then. moduleRootModel.removeOrderEntry(entry); } } } }