Skip to content

Commit

Permalink
DeploymentDependencySelector equals and hashCode impl
Browse files Browse the repository at this point in the history
(cherry picked from commit 25941ff)
  • Loading branch information
aloubyansky authored and gsmet committed Oct 19, 2021
1 parent 3d60256 commit cbafe97
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,28 +1,48 @@
package io.quarkus.bootstrap.resolver.maven;

import java.util.Objects;
import org.eclipse.aether.collection.DependencyCollectionContext;
import org.eclipse.aether.collection.DependencySelector;
import org.eclipse.aether.graph.Dependency;

class DeploymentDependencySelector implements DependencySelector {
final class DeploymentDependencySelector implements DependencySelector {

static DependencySelector ensureDeploymentDependencySelector(DependencySelector original) {
return original.getClass() == DeploymentDependencySelector.class ? original
: new DeploymentDependencySelector(original);
}

private final DependencySelector delegate;

public DeploymentDependencySelector(DependencySelector delegate) {
DeploymentDependencySelector(DependencySelector delegate) {
this.delegate = delegate;
}

@Override
public boolean selectDependency(Dependency dependency) {
if (dependency.isOptional()) {
return false;
}
return delegate.selectDependency(dependency);
return !dependency.isOptional() && delegate.selectDependency(dependency);
}

@Override
public DependencySelector deriveChildSelector(DependencyCollectionContext context) {
final DependencySelector newDelegate = delegate.deriveChildSelector(context);
return newDelegate == null ? null : new DeploymentDependencySelector(newDelegate);
return newDelegate == null ? null : ensureDeploymentDependencySelector(newDelegate);
}

@Override
public int hashCode() {
return Objects.hash(delegate);
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
DeploymentDependencySelector other = (DeploymentDependencySelector) obj;
return Objects.equals(delegate, other.delegate);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ public DeploymentInjectingDependencyVisitor(MavenArtifactResolver resolver, List
// we need to be able to take into account whether the deployment dependencies are on an optional dependency branch
// for that we are going to use a custom dependency selector and re-initialize the resolver to use it
final DefaultRepositorySystemSession session = new DefaultRepositorySystemSession(resolver.getSession());
final DeploymentDependencySelector depSelector = new DeploymentDependencySelector(session.getDependencySelector());
session.setDependencySelector(depSelector);
session.setDependencySelector(
DeploymentDependencySelector.ensureDeploymentDependencySelector(session.getDependencySelector()));
try {
this.resolver = new MavenArtifactResolver(new BootstrapMavenContext(BootstrapMavenContext.config()
.setRepositorySystem(resolver.getSystem())
Expand Down

0 comments on commit cbafe97

Please sign in to comment.