[MNG-5600] Dependency management import should support exclusions. (#1155)

The original patch is made by: Christian Schulte <schulte@apache.org>
Co-authored-by: Alex Szakaly <alex.szakaly@gmail.com>
This commit is contained in:
Guillaume Nodet 2023-06-15 17:29:05 +02:00 committed by GitHub
parent a2d435b74a
commit 8b0bf378b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 0 deletions

View File

@ -40,7 +40,9 @@ import java.util.Objects;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import org.apache.maven.api.model.Exclusion;
import org.apache.maven.api.model.InputSource;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
@ -1680,9 +1682,29 @@ public class DefaultModelBuilder implements ModelBuilder {
}
}
// [MNG-5600] Dependency management import should support exclusions.
List<Exclusion> exclusions = dependency.getDelegate().getExclusions();
if (importMgmt != null && !exclusions.isEmpty()) {
// Dependency excluded from import.
List<org.apache.maven.api.model.Dependency> dependencies = importMgmt.getDependencies().stream()
.filter(candidate -> exclusions.stream().noneMatch(exclusion -> match(exclusion, candidate)))
.map(candidate -> candidate.withExclusions(exclusions))
.collect(Collectors.toList());
importMgmt = importMgmt.withDependencies(dependencies);
}
return importMgmt != null ? new DependencyManagement(importMgmt) : null;
}
private boolean match(Exclusion exclusion, org.apache.maven.api.model.Dependency candidate) {
return match(exclusion.getGroupId(), candidate.getGroupId())
&& match(exclusion.getArtifactId(), candidate.getArtifactId());
}
private boolean match(String match, String text) {
return match.equals("*") || match.equals(text);
}
@SuppressWarnings("checkstyle:parameternumber")
private DependencyManagement doLoadDependencyManagement(
Model model,