Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

robobario
Copy link

Closes #320

If we decide a root artefact is allowed by the include/exclude list we use the same logic to decide if we should process it as a node.

Note this changes the behaviour, an inclusion rule will beat an exclusion rule.

Context

We are using ProjectDependencyResolver to discover project dependencies and want to be able to configure it like:

excludePattern: "org.group:*:*"
includePattern: "org.group:specific:*"

However in this configuration org.group:specific:* is not resolved as the exclusion takes precedence. Then looking into the code we see some usages where inclusion beats exclusion and wonder what the intent of the inclusion/exclusion lists are.

This is more the start of a conversation as there are numerous places where the include/exclude list are consulted. For example when collecting projectBomConstraints it has different logic again:

if (includeSet.isEmpty()) {
                    collect = d.getGroupId().startsWith(config.getProjectBom().getGroupId()) && !isExclude(d);
                } else {
                    collect = !isExcluded(d) && isIncluded(d);
                }

where it applies this groupId restriction if there are no explicit inclusions else it requires it to be explicitly included.

There are other places in the resolver where we only check the exclusion list or inclusion list.

The javadoc on ProjectDependencyConfig is ambiguous around how getIncludePatterns and getExcludePatterns interact and how they relate to getIncludeArtifacts.

It feels like there should be some consistent way that the inclusion/exclusion rules are applied to dependencies.

This makes it consistent, if we decide a root artefact is allowed by
the include/exclude list we use the same logic to decide if we should
process it as a node.

Note this changes the behaviour, an inclusion rule will beat an
exclusion rule.

Signed-off-by: Robert Young <robeyoun@redhat.com>
} else {
collect = !isExcluded(d) && isIncluded(d);
collect = !isExplicitlyExcluded(d) && isExplicitlyIncluded(d);
Copy link
Author

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.

@@ -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())))) {
Copy link
Author

@robobario robobario Aug 27, 2024

Choose a reason for hiding this comment

The 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?

@@ -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)) {
Copy link
Author

Choose a reason for hiding this comment

The 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.

@robobario
Copy link
Author

Alternatively if exclusion should beat inclusion (hard to make everyone happy 😁), we should add that to the javadoc and put tests on it.

@@ -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)) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should the inclusion list be considered here too?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Artifacts excluded when present in included pattern set
1 participant