Skip to content
Merged
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
11 changes: 10 additions & 1 deletion maven-core/src/main/java/org/apache/maven/RepositoryUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,16 @@ private static String nullify(String string) {
return (string == null || string.length() <= 0) ? null : string;
}

private static org.apache.maven.artifact.Artifact toArtifact(Dependency dependency) {
/**
* Converts a {@link Dependency} object to a Maven {@link org.apache.maven.artifact.Artifact} object.
*
* @param dependency the dependency to be converted; may be null. If null, the method returns null.
* @return the equivalent {@link org.apache.maven.artifact.Artifact} object with the same attributes as the
* provided dependency, or null if the input dependency is null.
*
* @since 3.10.0
*/
public static org.apache.maven.artifact.Artifact toArtifact(Dependency dependency) {
if (dependency == null) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.graph.DependencyFilter;
import org.eclipse.aether.repository.RemoteRepository;
import org.eclipse.aether.resolution.ArtifactResult;
import org.eclipse.aether.resolution.DependencyResult;
import org.eclipse.aether.util.filter.AndDependencyFilter;

Expand Down Expand Up @@ -394,10 +393,7 @@ private void createPluginRealm(
project.getRemotePluginRepositories(),
repositorySession);

pluginArtifacts = result.getArtifactResults().stream()
.filter(ArtifactResult::isResolved)
.map(r -> RepositoryUtils.toArtifact(r.getArtifact()))
.collect(Collectors.toList());
pluginArtifacts = toMavenArtifacts(result);

pluginRealm = classRealmManager.createPluginRealm(
plugin, parent, null, foreignImports, toAetherArtifacts(pluginArtifacts));
Expand Down Expand Up @@ -435,6 +431,13 @@ private List<org.eclipse.aether.artifact.Artifact> toAetherArtifacts(final List<
return new ArrayList<>(RepositoryUtils.toArtifacts(pluginArtifacts));
}

private List<Artifact> toMavenArtifacts(DependencyResult dependencyResult) {
return dependencyResult.getDependencyNodeResults().stream()
.filter(n -> n.getArtifact().getPath() != null)
.map(n -> RepositoryUtils.toArtifact(n.getDependency()))
.collect(Collectors.toList());
}

private Map<String, ClassLoader> calcImports(MavenProject project, ClassLoader parent, List<String> imports) {
Map<String, ClassLoader> foreignImports = new HashMap<>();

Expand Down Expand Up @@ -829,9 +832,6 @@ private List<Artifact> resolveExtensionArtifacts(
throws PluginResolutionException {
DependencyResult result =
pluginDependenciesResolver.resolvePluginAndFlatten(extensionPlugin, null, null, repositories, session);
return result.getArtifactResults().stream()
.filter(ArtifactResult::isResolved)
.map(r -> RepositoryUtils.toArtifact(r.getArtifact()))
.collect(Collectors.toList());
return toMavenArtifacts(result);
}
}
Loading