Skip to content

Commit

Permalink
improve message, validate pluginRepositories as well
Browse files Browse the repository at this point in the history
  • Loading branch information
kwin committed Feb 14, 2024
1 parent 8280b80 commit 35c9ac5
Showing 1 changed file with 32 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import java.io.File;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -589,21 +590,37 @@ public void validateExternalProfiles(
for (Profile profile : activeExternalProfiles.stream()
.map(org.apache.maven.model.Profile::getDelegate)
.collect(Collectors.toList())) {
for (Repository repository : profile.getRepositories()) {
Optional<Repository> clashingPomRepository = m.getRepositories().stream()
.filter(r -> r.getId().equals(repository.getId()))
.findFirst();
if (clashingPomRepository.isPresent()) {
addViolation(
problems,
Severity.WARNING,
Version.V40, // ?
"pom repository",
"?",
"is overwritten by the repository with same id from external profile with id "
+ 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<Repository> pomRepositories,
Collection<Repository> externalRepositories,
String externalRepositoriesSource,
ModelProblemCollector problems) {
for (Repository externalRepository : externalRepositories) {
Optional<Repository> clashingPomRepository = pomRepositories.stream()
.filter(r -> Objects.equals(r.getId(), externalRepository.getId()))
.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 from " + externalRepositoriesSource,
clashingPomRepository.get());
}
}
}
Expand Down

0 comments on commit 35c9ac5

Please sign in to comment.