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

Add a flattenDependencyNodes method accepting a DependencyFilter #388

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.eclipse.aether.deployment.DeployRequest;
import org.eclipse.aether.deployment.DeployResult;
import org.eclipse.aether.deployment.DeploymentException;
import org.eclipse.aether.graph.DependencyFilter;
import org.eclipse.aether.graph.DependencyNode;
import org.eclipse.aether.installation.InstallRequest;
import org.eclipse.aether.installation.InstallResult;
Expand Down Expand Up @@ -158,6 +159,19 @@ DependencyResult resolveDependencies(RepositorySystemSession session, Dependency
*/
List<DependencyNode> flattenDependencyNodes(RepositorySystemSession session, DependencyNode root);

/**
* Flattens the provided graph as {@link DependencyNode} into a {@link List}{@code <DependencyNode>} according to session
* configuration.
*
* @param session The repository session, must not be {@code null}.
* @param root The dependency node root of the graph, must not be {@code null}.
* @param filter The optional dependency filter, can be {@code null}.
* @return The flattened list of dependency nodes, never {@code null}.
* @since 2.0.0
*/
List<DependencyNode> flattenDependencyNodes(
RepositorySystemSession session, DependencyNode root, DependencyFilter filter);

/**
* Resolves the path for an artifact. The artifact will be downloaded to the local repository if necessary. An
* artifact that is already resolved will be skipped and is not re-resolved. In general, callers must not assume any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,9 @@ public DependencyResult resolveDependencies(RepositorySystemSession session, Dep
throw new NullPointerException("dependency node and collect request cannot be null");
}

final ArrayList<DependencyNode> dependencyNodes = new ArrayList<>();
DependencyVisitor builder = getDependencyVisitor(session, dependencyNodes::add);
DependencyFilter filter = request.getFilter();
DependencyVisitor visitor = (filter != null) ? new FilteringDependencyVisitor(builder, filter) : builder;
if (result.getRoot() != null) {
result.getRoot().accept(visitor);
}
final List<DependencyNode> dependencyNodes = result.getRoot() != null
? flattenDependencyNodes(session, request.getRoot(), request.getFilter())
: new ArrayList<>();

final List<ArtifactRequest> requests = dependencyNodes.stream()
.map(n -> {
Expand Down Expand Up @@ -303,11 +299,19 @@ public DependencyResult resolveDependencies(RepositorySystemSession session, Dep

@Override
public List<DependencyNode> flattenDependencyNodes(RepositorySystemSession session, DependencyNode root) {
return flattenDependencyNodes(session, root, null);
}

@Override
public List<DependencyNode> flattenDependencyNodes(
RepositorySystemSession session, DependencyNode root, DependencyFilter filter) {
validateSession(session);
requireNonNull(root, "root cannot be null");
Copy link
Member

Choose a reason for hiding this comment

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

this should happen only in public facing method (but maybe even there make it nullable?) As originally it CAN be null... See original code:

        if (result.getRoot() != null) {
            result.getRoot().accept(visitor);
        }


final ArrayList<DependencyNode> dependencyNodes = new ArrayList<>();
root.accept(getDependencyVisitor(session, dependencyNodes::add));
DependencyVisitor builder = getDependencyVisitor(session, dependencyNodes::add);
DependencyVisitor visitor = (filter != null) ? new FilteringDependencyVisitor(builder, filter) : builder;
root.accept(visitor);
return dependencyNodes;
}

Expand Down
Loading