|
4 | 4 | import eu.maveniverse.maven.mima.context.ContextOverrides; |
5 | 5 | import eu.maveniverse.maven.mima.context.Runtime; |
6 | 6 | import eu.maveniverse.maven.mima.context.Runtimes; |
7 | | -import java.nio.file.Path; |
8 | | -import java.util.Arrays; |
9 | | -import java.util.List; |
10 | | -import java.util.stream.Collectors; |
11 | 7 | import org.eclipse.aether.artifact.Artifact; |
12 | 8 | import org.eclipse.aether.artifact.DefaultArtifact; |
13 | 9 | import org.eclipse.aether.collection.CollectRequest; |
|
18 | 14 | import org.eclipse.aether.resolution.DependencyResult; |
19 | 15 | import org.eclipse.aether.util.artifact.JavaScopes; |
20 | 16 |
|
21 | | -/** Utility class for resolving Maven artifacts. */ |
22 | | -public class ResolverUtils { |
23 | | - /** |
24 | | - * Resolves the paths of the given artifacts. Handles parsing and resolving of artifacts and |
25 | | - * extracts their paths. |
26 | | - * |
27 | | - * @param artifactNames the artifacts to resolve as an array of strings in the format |
28 | | - * "groupId:artifactId:version" |
29 | | - * @return the paths of the resolved artifacts |
30 | | - * @throws DependencyResolutionException if an error occurs while resolving the artifacts |
31 | | - */ |
32 | | - public static List<Path> resolveArtifactPaths(String[] artifactNames) |
33 | | - throws DependencyResolutionException { |
34 | | - List<Artifact> artifacts = parseArtifacts(artifactNames); |
35 | | - List<ArtifactResult> resolvedArtifacts = resolveArtifacts(artifacts); |
36 | | - return resolvedArtifacts.stream() |
| 17 | +import java.nio.file.Path; |
| 18 | +import java.util.Arrays; |
| 19 | +import java.util.List; |
| 20 | +import java.util.stream.Collectors; |
| 21 | + |
| 22 | +public class Resolver { |
| 23 | + private final List<Artifact> artifacts; |
| 24 | + |
| 25 | + private List<ArtifactResult> resolvedArtifacts; |
| 26 | + |
| 27 | + public static Resolver create(String[] artifactNames) { |
| 28 | + return new Resolver(artifactNames); |
| 29 | + } |
| 30 | + |
| 31 | + private Resolver(String[] artifactNames) { |
| 32 | + artifacts = parseArtifacts(artifactNames); |
| 33 | + } |
| 34 | + |
| 35 | + public List<ArtifactResult> resolve() throws DependencyResolutionException { |
| 36 | + if (resolvedArtifacts == null) { |
| 37 | + resolvedArtifacts = resolveArtifacts(artifacts); |
| 38 | + } |
| 39 | + return resolvedArtifacts; |
| 40 | + } |
| 41 | + |
| 42 | + public List<Path> resolvePaths() throws DependencyResolutionException { |
| 43 | + List<ArtifactResult> ras = resolve(); |
| 44 | + return ras.stream() |
37 | 45 | .map(ar -> ar.getArtifact().getFile().toPath()) |
38 | 46 | .collect(Collectors.toList()); |
39 | 47 | } |
|
0 commit comments