From 35ca8cd1b0e2821230cb52866bfd050957cc2e7b Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Thu, 21 Mar 2024 12:44:07 +0100 Subject: [PATCH] WIP --- .../maven/toolbox/cli/Resolve.java | 18 ++++- .../maven/toolbox/shared/DirectorySink.java | 6 +- .../maven/toolbox/shared/ToolboxCommando.java | 2 +- .../shared/internal/ArtifactMatcher.java | 9 ++- .../shared/internal/ToolboxCommandoImpl.java | 68 ++++++++++--------- 5 files changed, 62 insertions(+), 41 deletions(-) diff --git a/cli/src/main/java/eu/maveniverse/maven/toolbox/cli/Resolve.java b/cli/src/main/java/eu/maveniverse/maven/toolbox/cli/Resolve.java index 69d16fae..898e3f19 100644 --- a/cli/src/main/java/eu/maveniverse/maven/toolbox/cli/Resolve.java +++ b/cli/src/main/java/eu/maveniverse/maven/toolbox/cli/Resolve.java @@ -10,6 +10,9 @@ import eu.maveniverse.maven.mima.context.Context; import eu.maveniverse.maven.toolbox.shared.ResolutionScope; import eu.maveniverse.maven.toolbox.shared.ToolboxCommando; +import eu.maveniverse.maven.toolbox.shared.ToolboxResolver; +import java.util.stream.Collectors; +import org.eclipse.aether.resolution.ArtifactDescriptorException; import picocli.CommandLine; /** @@ -18,8 +21,8 @@ @CommandLine.Command(name = "resolve", description = "Resolves Maven Artifacts") public final class Resolve extends ResolverCommandSupport { - @CommandLine.Parameters(index = "0", description = "The GAV to graph") - private String gav; + @CommandLine.Parameters(index = "0..*", description = "The GAV to graph", arity = "1") + private java.util.List gav; @CommandLine.Option( names = {"--resolutionScope"}, @@ -52,9 +55,18 @@ public final class Resolve extends ResolverCommandSupport { @Override protected boolean doCall(Context context) throws Exception { ToolboxCommando toolboxCommando = getToolboxCommando(context); + ToolboxResolver toolboxResolver = toolboxCommando.toolboxResolver(); return toolboxCommando.resolve( ResolutionScope.parse(resolutionScope), - toolboxCommando.toolboxResolver().loadGav(gav, boms), + gav.stream() + .map(g -> { + try { + return toolboxResolver.loadGav(g, boms); + } catch (ArtifactDescriptorException e) { + throw new RuntimeException(e); + } + }) + .collect(Collectors.toList()), sources, javadoc, signature, diff --git a/shared/src/main/java/eu/maveniverse/maven/toolbox/shared/DirectorySink.java b/shared/src/main/java/eu/maveniverse/maven/toolbox/shared/DirectorySink.java index 71c0f66e..d3dced54 100644 --- a/shared/src/main/java/eu/maveniverse/maven/toolbox/shared/DirectorySink.java +++ b/shared/src/main/java/eu/maveniverse/maven/toolbox/shared/DirectorySink.java @@ -35,7 +35,7 @@ public final class DirectorySink implements Consumer> { */ public static DirectorySink flat(Output output, Path path) throws IOException { return new DirectorySink( - output, path, ArtifactMatcher.any(), ArtifactMapper.identity(), ArtifactNameMapper.ACVE(), false); + output, path, ArtifactMatcher.unique(), ArtifactMapper.identity(), ArtifactNameMapper.ACVE(), false); } private final Output output; @@ -96,7 +96,7 @@ public void accept(Collection artifacts) { } private void accept(Artifact artifact) throws IOException { - output.verbose("Artifact {} processed", artifact); + output.verbose("Accept artifact {}", artifact); if (artifactMatcher.test(artifact)) { output.verbose(" matched"); String name = artifactNameMapper.map(artifactMapper.map(artifact)); @@ -111,6 +111,8 @@ private void accept(Artifact artifact) throws IOException { target, StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.COPY_ATTRIBUTES); + } else { + output.verbose(" not matched"); } } diff --git a/shared/src/main/java/eu/maveniverse/maven/toolbox/shared/ToolboxCommando.java b/shared/src/main/java/eu/maveniverse/maven/toolbox/shared/ToolboxCommando.java index 0540f89d..6c8ec151 100644 --- a/shared/src/main/java/eu/maveniverse/maven/toolbox/shared/ToolboxCommando.java +++ b/shared/src/main/java/eu/maveniverse/maven/toolbox/shared/ToolboxCommando.java @@ -99,7 +99,7 @@ boolean copyAll( boolean resolve( ResolutionScope resolutionScope, - ResolutionRoot resolutionRoot, + Collection resolutionRoots, boolean sources, boolean javadoc, boolean signatures, diff --git a/shared/src/main/java/eu/maveniverse/maven/toolbox/shared/internal/ArtifactMatcher.java b/shared/src/main/java/eu/maveniverse/maven/toolbox/shared/internal/ArtifactMatcher.java index ab6a3df9..3a936b19 100644 --- a/shared/src/main/java/eu/maveniverse/maven/toolbox/shared/internal/ArtifactMatcher.java +++ b/shared/src/main/java/eu/maveniverse/maven/toolbox/shared/internal/ArtifactMatcher.java @@ -81,12 +81,17 @@ && matches(prototype.getExtension(), a.getExtension()) } static ArtifactMatcher any() { - return a -> true; + return artifact("*"); } static ArtifactMatcher unique() { HashSet artifacts = new HashSet<>(); - return artifacts::add; + return new ArtifactMatcher() { + @Override + public boolean test(Artifact artifact) { + return artifacts.add(artifact); + } + }; } private static boolean isAny(String str) { diff --git a/shared/src/main/java/eu/maveniverse/maven/toolbox/shared/internal/ToolboxCommandoImpl.java b/shared/src/main/java/eu/maveniverse/maven/toolbox/shared/internal/ToolboxCommandoImpl.java index ca49c687..1f5b9b1f 100644 --- a/shared/src/main/java/eu/maveniverse/maven/toolbox/shared/internal/ToolboxCommandoImpl.java +++ b/shared/src/main/java/eu/maveniverse/maven/toolbox/shared/internal/ToolboxCommandoImpl.java @@ -353,48 +353,50 @@ public boolean recordStop(Output output) { @Override public boolean resolve( ResolutionScope resolutionScope, - ResolutionRoot resolutionRoot, + Collection resolutionRoots, boolean sources, boolean javadoc, boolean signatures, Output output) { try { - DependencyResult dependencyResult = toolboxResolver.resolve( - resolutionScope, - resolutionRoot.getArtifact(), - resolutionRoot.getDependencies(), - resolutionRoot.getManagedDependencies()); + for (ResolutionRoot resolutionRoot : resolutionRoots) { + DependencyResult dependencyResult = toolboxResolver.resolve( + resolutionScope, + resolutionRoot.getArtifact(), + resolutionRoot.getDependencies(), + resolutionRoot.getManagedDependencies()); - output.normal(""); - if (output.isVerbose()) { - for (ArtifactResult artifactResult : dependencyResult.getArtifactResults()) { + output.normal(""); + if (output.isVerbose()) { + for (ArtifactResult artifactResult : dependencyResult.getArtifactResults()) { + output.verbose( + "{} -> {}", + artifactResult.getArtifact(), + artifactResult.getArtifact().getFile()); + } + } + output.normal("Resolved: {}", resolutionRoot.getArtifact()); + if (output.isVerbose()) { output.verbose( - "{} -> {}", - artifactResult.getArtifact(), - artifactResult.getArtifact().getFile()); + " Transitive hull count: {}", + dependencyResult.getArtifactResults().size()); + output.verbose( + " Transitive hull size: {}", + humanReadableByteCountBin(dependencyResult.getArtifactResults().stream() + .map(ArtifactResult::getArtifact) + .map(Artifact::getFile) + .filter(Objects::nonNull) + .map(f -> { + try { + return Files.size(f.toPath()); + } catch (IOException e) { + throw new RuntimeException(e); + } + }) + .collect(Collectors.summarizingLong(Long::longValue)) + .getSum())); } } - output.normal("Resolved: {}", resolutionRoot.getArtifact()); - if (output.isVerbose()) { - output.verbose( - " Transitive hull count: {}", - dependencyResult.getArtifactResults().size()); - output.verbose( - " Transitive hull size: {}", - humanReadableByteCountBin(dependencyResult.getArtifactResults().stream() - .map(ArtifactResult::getArtifact) - .map(Artifact::getFile) - .filter(Objects::nonNull) - .map(f -> { - try { - return Files.size(f.toPath()); - } catch (IOException e) { - throw new RuntimeException(e); - } - }) - .collect(Collectors.summarizingLong(Long::longValue)) - .getSum())); - } return true; } catch (Exception e) { throw new RuntimeException(e);