-
Notifications
You must be signed in to change notification settings - Fork 334
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
Also exclude omitted dependencies #4563
base: main
Are you sure you want to change the base?
Changes from all commits
5277e49
7000b92
4bf2eca
9b7e294
a8b50a6
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 |
---|---|---|
|
@@ -52,6 +52,10 @@ public class ResolvedDependency implements Serializable { | |
@EqualsAndHashCode.Exclude | ||
List<ResolvedDependency> dependencies; | ||
|
||
@NonFinal | ||
@EqualsAndHashCode.Exclude | ||
List<GroupArtifactVersion> omitDependencies; | ||
|
||
List<License> licenses; | ||
|
||
@Nullable | ||
|
@@ -81,6 +85,10 @@ void unsafeSetDependencies(List<ResolvedDependency> dependencies) { | |
this.dependencies = dependencies; | ||
} | ||
|
||
void unsafeSetOmitDependencies(List<GroupArtifactVersion> omitDependencies) { | ||
this.omitDependencies = omitDependencies; | ||
} | ||
|
||
void unsafeSetEffectiveExclusions(List<GroupArtifact> effectiveExclusions) { | ||
this.effectiveExclusions = effectiveExclusions; | ||
} | ||
|
@@ -142,6 +150,40 @@ public boolean isTransitive() { | |
return null; | ||
} | ||
|
||
public @Nullable ResolvedDependency findDependencyWithOmit(String groupId, String artifactId) { | ||
return findDependencyWithOmit0(groupId, artifactId, Collections.newSetFromMap(new IdentityHashMap<>())); | ||
} | ||
|
||
private @Nullable ResolvedDependency findDependencyWithOmit0(String groupId, String artifactId, Set<ResolvedDependency> visited) { | ||
if (matchesGlob(getGroupId(), groupId) && matchesGlob(getArtifactId(), artifactId)) { | ||
return this; | ||
} else if (!visited.add(this)) { | ||
return null; | ||
} | ||
outer: | ||
for (ResolvedDependency dependency : dependencies) { | ||
ResolvedDependency found = dependency.findDependencyWithOmit0(groupId, artifactId, visited); | ||
if (found != null) { | ||
if (getRequested().getExclusions() != null) { | ||
for (GroupArtifact exclusion : getRequested().getExclusions()) { | ||
if (matchesGlob(found.getGroupId(), exclusion.getGroupId()) && | ||
matchesGlob(found.getArtifactId(), exclusion.getArtifactId())) { | ||
continue outer; | ||
} | ||
} | ||
} | ||
return found; | ||
} | ||
} | ||
|
||
for (GroupArtifactVersion omit : omitDependencies) { | ||
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 where we'd have to handle a possible |
||
if (matchesGlob(omit.getGroupId(), groupId) && matchesGlob(omit.getArtifactId(), artifactId)) { | ||
return this; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return (repository == null ? "" : repository.getUri() + "/") + | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -916,6 +916,13 @@ public List<ResolvedDependency> resolveDependencies(Scope scope, Map<GroupArtifa | |
} else if (contains(dependencies, ga, d.getClassifier())) { | ||
// we've already resolved this previously and the requirement didn't change, | ||
// so just skip and continue on | ||
ResolvedDependency includedBy = dd.getDependent(); | ||
if (includedBy != null) { | ||
if (includedBy.getOmitDependencies().isEmpty()) { | ||
includedBy.unsafeSetOmitDependencies(new ArrayList<>()); | ||
} | ||
includedBy.getOmitDependencies().add(new GroupArtifactVersion(d.getGroupId(), d.getArtifactId(), d.getVersion())); | ||
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. Also here the generated getter might return null; as an alternative we could create an explicit getter that always returns a collection. |
||
} | ||
continue; | ||
} | ||
} | ||
|
@@ -938,7 +945,7 @@ public List<ResolvedDependency> resolveDependencies(Scope scope, Map<GroupArtifa | |
} | ||
|
||
ResolvedDependency resolved = new ResolvedDependency(dPom.getRepository(), | ||
resolvedPom.getGav(), dd.getDependency(), emptyList(), | ||
resolvedPom.getGav(), dd.getDependency(), emptyList(), emptyList(), | ||
resolvedPom.getRequested().getLicenses(), | ||
resolvedPom.getValue(dd.getDependency().getType()), | ||
resolvedPom.getValue(dd.getDependency().getClassifier()), | ||
|
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.
One thing to note here is that
omitDependencies
is technically@Nullable
, since we serialize LSTs at Moderne, which mean folks might deserialize an olderResolvedDependency
class without anyomitDepedencies
field, which can then lead to a null pointer exception further down. Let's make that explicit by adding that annotation here to be safe, and then handle the usage site below to guard against a null value.