rfscholte commented on code in PR #1571: URL: https://github.com/apache/maven-dependency-plugin/pull/1571#discussion_r2675793542
########## src/main/java/org/apache/maven/plugins/dependency/fromDependencies/GraphRoot.java: ########## @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.maven.plugins.dependency.fromDependencies; + +/** + * All values are static, no expression, so matcher can use equals Review Comment: A small rewrite, you know must define the graphRoot's groupId and artifactId matching the targeted dependency. I've removed the type, because only the main artifact can have dependencies (classified like javadoc and sources don't have dependencies) and the pom can only point to 1 main artifact via packaging. I don't expect a request for support of type, but if so it should be solved separately. It is probably tricky if 2 main artifacts share the same pom. ########## src/main/java/org/apache/maven/plugins/dependency/fromDependencies/AbstractDependencyFilterMojo.java: ########## @@ -479,6 +502,38 @@ private Set<Artifact> resolve(Set<org.eclipse.aether.artifact.Artifact> artifact return resolvedArtifacts; } + private Set<Artifact> collectArtifacts(MavenProject project) throws DependencyResolutionException { + if (graphRoots == null || graphRoots.isEmpty()) { + return project.getArtifacts(); + } else { + List<DependencyMatcher> filterMatchers = + graphRoots.stream().map(GraphRootMatcher::new).collect(Collectors.toList()); + + DependencyMatcher subTreeMatcher = new OrDependencyMatcher(filterMatchers); + + Set<Artifact> artifacts = new HashSet<>(); + for (Dependency dep : project.getDependencies()) { + if (subTreeMatcher.matches(dep)) { + artifacts.addAll(resolveDependencyArtifacts(dep)); + } + } + return artifacts; + } + } + + private Set<Artifact> resolveDependencyArtifacts(Dependency root) throws DependencyResolutionException { + org.eclipse.aether.graph.Dependency dependency = RepositoryUtils.toDependency( + root, session.getRepositorySession().getArtifactTypeRegistry()); + + List<RemoteRepository> remoteRepositories = + RepositoryUtils.toRepos(session.getProjectBuildingRequest().getRemoteRepositories()); + + Collection<org.eclipse.aether.artifact.Artifact> depArtifacts = Review Comment: done -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
