-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix inclusion/exclusion inconsistency #342
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -555,13 +555,13 @@ public void resolveDependencies() { | |
} | ||
|
||
for (ArtifactCoords coords : getProjectArtifacts()) { | ||
if (isIncluded(coords) || !isExcluded(coords)) { | ||
if (isIncluded(coords)) { | ||
processRootArtifact(coords); | ||
} | ||
} | ||
|
||
for (ArtifactCoords coords : toSortedCoords(config.getIncludeArtifacts())) { | ||
if (isIncluded(coords) || !isExcluded(coords)) { | ||
if (isIncluded(coords)) { | ||
processRootArtifact(coords); | ||
} | ||
} | ||
|
@@ -575,6 +575,17 @@ public void resolveDependencies() { | |
} | ||
} | ||
|
||
/** | ||
* An artefact is included if it is in the inclusion list or it is not in the | ||
* exclusion list. Inclusion beats exclusion. | ||
* | ||
* @param coords coords | ||
* @return included | ||
*/ | ||
private boolean isIncluded(ArtifactCoords coords) { | ||
return isExplicitlyIncluded(coords) || !isExplicitlyExcluded(coords); | ||
} | ||
|
||
private static List<ArtifactCoords> toSortedCoords(Collection<ArtifactCoords> col) { | ||
if (col.isEmpty()) { | ||
return List.of(); | ||
|
@@ -644,9 +655,9 @@ protected Iterable<ArtifactCoords> getProjectArtifacts() { | |
for (ArtifactCoords d : projectBomConstraints) { | ||
final boolean collect; | ||
if (includeSet.isEmpty()) { | ||
collect = d.getGroupId().startsWith(config.getProjectBom().getGroupId()) && !isExcluded(d); | ||
collect = d.getGroupId().startsWith(config.getProjectBom().getGroupId()) && !isExplicitlyExcluded(d); | ||
} else { | ||
collect = !isExcluded(d) && isIncluded(d); | ||
collect = !isExplicitlyExcluded(d) && isExplicitlyIncluded(d); | ||
} | ||
if (collect) { | ||
result.add(d); | ||
|
@@ -752,7 +763,7 @@ private void processRootArtifact(ArtifactCoords rootArtifact) { | |
} | ||
for (DependencyNode d : root.getChildren()) { | ||
if (d.getDependency().isOptional() | ||
&& !(config.isIncludeOptionalDeps() || isIncluded(toCoords(d.getArtifact())))) { | ||
&& !(config.isIncludeOptionalDeps() || isExplicitlyIncluded(toCoords(d.getArtifact())))) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we only consult the include list when deciding if we should recurse into optional deps? |
||
continue; | ||
} | ||
processNodes(d, 1, false); | ||
|
@@ -1238,7 +1249,7 @@ private void processNodes(DependencyNode node, int level, boolean remaining) { | |
if (winner != null) { | ||
final ArtifactCoords coords = toCoords(winner.getArtifact()); | ||
// linked dependencies should also be checked for exclusions | ||
if (!isExcluded(coords)) { | ||
if (!isExplicitlyExcluded(coords)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should the inclusion list be considered here too? |
||
for (DependencyTreeVisitor v : treeVisitors) { | ||
v.linkDependency(coords); | ||
} | ||
|
@@ -1247,7 +1258,7 @@ private void processNodes(DependencyNode node, int level, boolean remaining) { | |
} | ||
|
||
final ArtifactCoords coords = toCoords(node.getArtifact()); | ||
if (isExcluded(coords)) { | ||
if (!isIncluded(coords)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is the actual logic change, checking if the coords are in the inclusion list or not in the exclusion list. |
||
return; | ||
} | ||
ResolvedDependency visit = null; | ||
|
@@ -1297,7 +1308,7 @@ private ResolvedDependency addArtifactToBuild(ArtifactCoords coords, List<Remote | |
|
||
if (managed | ||
|| config.isIncludeNonManaged() | ||
|| isIncluded(coords) | ||
|| isExplicitlyIncluded(coords) | ||
|| coords.getType().equals(ArtifactCoords.TYPE_POM) | ||
&& (!config.isExcludeParentPoms() | ||
|| projectGavs.contains(toGav(coords)))) { | ||
|
@@ -1363,7 +1374,7 @@ private Map<String, String> addImportedBomsAndParentPomToBuild(ResolvedDependenc | |
if (parentVersion != null) { | ||
final ArtifactCoords parentPomCoords = ArtifactCoords.pom(parent.getGroupId(), parent.getArtifactId(), | ||
parentVersion); | ||
if (!isExcluded(parentPomCoords)) { | ||
if (!isExplicitlyExcluded(parentPomCoords)) { | ||
final ResolvedDependency resolvedParent = addArtifactToBuild(parentPomCoords, dependency.getRepositories()); | ||
artDep.setParentPom(getOrCreateArtifactDep(resolvedParent)); | ||
parentPomProps = addImportedBomsAndParentPomToBuild(resolvedParent); | ||
|
@@ -1416,7 +1427,7 @@ private void addImportedBomsToBuild(ArtifactDependency pomArtDep, Model model, M | |
continue; | ||
} | ||
final ArtifactCoords bomCoords = ArtifactCoords.pom(groupId, artifactId, version); | ||
if (!isExcluded(bomCoords)) { | ||
if (!isExplicitlyExcluded(bomCoords)) { | ||
final ResolvedDependency resolvedImport = addArtifactToBuild(bomCoords, | ||
pomArtDep.resolved.getRepositories()); | ||
if (resolvedImport != null) { | ||
|
@@ -1448,7 +1459,7 @@ private void addToRemaining(ArtifactCoords coords) { | |
} | ||
} | ||
|
||
private boolean isExcluded(ArtifactCoords coords) { | ||
private boolean isExplicitlyExcluded(ArtifactCoords coords) { | ||
for (ArtifactCoordsPattern pattern : excludeSet) { | ||
if (pattern.matches(coords)) { | ||
return true; | ||
|
@@ -1457,7 +1468,7 @@ private boolean isExcluded(ArtifactCoords coords) { | |
return false; | ||
} | ||
|
||
private boolean isIncluded(ArtifactCoords coords) { | ||
private boolean isExplicitlyIncluded(ArtifactCoords coords) { | ||
for (ArtifactCoordsPattern pattern : includeSet) { | ||
if (pattern.matches(coords)) { | ||
return true; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we check if the projectBomConstraint is explicitly included in this case? When discovering top level artefacts we check if they are included or not excluded.