From 5bb17a9ee7e9cd2ddb959da8a4699b7cd63bd5e6 Mon Sep 17 00:00:00 2001 From: "Jose M. Arnesto" Date: Sat, 23 Dec 2023 03:51:56 +0100 Subject: [PATCH] Mirror are now included in the returned list of known locations --- .../repository/DefaultRepositoryIdManager.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/p2-maven-plugin/src/main/java/org/eclipse/tycho/p2maven/repository/DefaultRepositoryIdManager.java b/p2-maven-plugin/src/main/java/org/eclipse/tycho/p2maven/repository/DefaultRepositoryIdManager.java index 94c9e0cee8..9c82e70a51 100644 --- a/p2-maven-plugin/src/main/java/org/eclipse/tycho/p2maven/repository/DefaultRepositoryIdManager.java +++ b/p2-maven-plugin/src/main/java/org/eclipse/tycho/p2maven/repository/DefaultRepositoryIdManager.java @@ -40,6 +40,11 @@ public class DefaultRepositoryIdManager implements IRepositoryIdManager { private Map knownMavenRepositoryIds = new ConcurrentHashMap<>(); + /** + * Map of known mirror identifiers, indexed by their URI. + */ + private Map knownMavenMirrorIds = new ConcurrentHashMap<>(); + @Override public void addMapping(String mavenRepositoryId, URI location) { if (mavenRepositoryId == null) @@ -52,6 +57,15 @@ public void addMapping(String mavenRepositoryId, URI location) { logger.warn("p2 repository with URL " + key + " is associated with multiple IDs; was '" + previousValue + "', now is '" + mavenRepositoryId + "'"); } + + // Checks if a mirror exists for the given location + MavenRepositoryLocation repositoryLocation = new MavenRepositoryLocation(mavenRepositoryId, key); + MavenRepositoryLocation mirrorLocation = settings.getMirror(repositoryLocation); + if (mirrorLocation != null) { + // A mirror exists. Adds its id to the map of known mirror ids. + URI mirrorKey = normalize(mirrorLocation.getURL()); + knownMavenMirrorIds.put(mirrorKey, mirrorLocation.getId()); + } } private static URI normalize(URI location) { @@ -118,8 +132,8 @@ private static boolean certainlyNoRemoteURL(URI location) { @Override public Stream getKnownMavenRepositoryLocations() { - return knownMavenRepositoryIds.entrySet().stream() - .map(e -> new MavenRepositoryLocation(e.getValue(), e.getKey())); + return Stream.concat(knownMavenRepositoryIds.entrySet().stream(), knownMavenMirrorIds.entrySet().stream()) + .map(e -> new MavenRepositoryLocation(e.getValue(), e.getKey())); } @Override