From 312983bc2d1f07f415d2542d64ad956958266ee1 Mon Sep 17 00:00:00 2001 From: Konrad Windszus Date: Mon, 4 Mar 2024 11:13:33 +0100 Subject: [PATCH] only emit warnings when urls differ --- .../validation/DefaultModelValidator.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java b/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java index 25838c5787e4..2c8f86b22ccc 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java @@ -799,6 +799,7 @@ public void validateExternalProfiles( for (Profile profile : activeExternalProfiles.stream() .map(org.apache.maven.model.Profile::getDelegate) .collect(Collectors.toList())) { +<<<<<<< Upstream, based on master for (Repository repository : profile.getRepositories()) { Optional clashingPomRepository = m.getRepositories().stream() .filter(r -> r.getId().equals(repository.getId())) @@ -814,6 +815,41 @@ public void validateExternalProfiles( + profile.getId(), clashingPomRepository.get()); } +======= + String externalRepositoriesSource = "external profile with id '" + profile.getId() + "' in settings.xml"; + validateUniqueRepositoryIds( + false, m.getRepositories(), profile.getRepositories(), externalRepositoriesSource, problems); + validateUniqueRepositoryIds( + true, + m.getPluginRepositories(), + profile.getPluginRepositories(), + externalRepositoriesSource, + problems); + } + } + + private void validateUniqueRepositoryIds( + boolean isPluginRepository, + Collection pomRepositories, + Collection externalRepositories, + String externalRepositoriesSource, + ModelProblemCollector problems) { + for (Repository externalRepository : externalRepositories) { + Optional clashingPomRepository = pomRepositories.stream() + .filter(r -> Objects.equals(r.getId(), externalRepository.getId())) + .filter(r -> !Objects.equals(r.getUrl(), externalRepository.getUrl())) + .findFirst(); + if (clashingPomRepository.isPresent()) { + addViolation( + problems, + Severity.WARNING, + Version.BASE, + isPluginRepository ? "pluginRepositories.repository" : "repositories.repository", + clashingPomRepository.get().getId(), + "is overwritten by the repository with same id but having a different url from " + + externalRepositoriesSource, + clashingPomRepository.get()); +>>>>>>> 885cee2 only emit warnings when urls differ } } }