Skip to content

Commit

Permalink
Mirror are now included in the returned list of known locations
Browse files Browse the repository at this point in the history
  • Loading branch information
kevloral committed Dec 23, 2023
1 parent 3283144 commit 5bb17a9
Showing 1 changed file with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ public class DefaultRepositoryIdManager implements IRepositoryIdManager {

private Map<URI, String> knownMavenRepositoryIds = new ConcurrentHashMap<>();

/**
* Map of known mirror identifiers, indexed by their URI.
*/
private Map<URI, String> knownMavenMirrorIds = new ConcurrentHashMap<>();

@Override
public void addMapping(String mavenRepositoryId, URI location) {
if (mavenRepositoryId == null)
Expand All @@ -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) {
Expand Down Expand Up @@ -118,8 +132,8 @@ private static boolean certainlyNoRemoteURL(URI location) {

@Override
public Stream<MavenRepositoryLocation> 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
Expand Down

0 comments on commit 5bb17a9

Please sign in to comment.