diff --git a/shared/src/main/java/eu/maveniverse/maven/toolbox/shared/MultiArtifactSink.java b/shared/src/main/java/eu/maveniverse/maven/toolbox/shared/MultiArtifactSink.java index 31c5aa7e..663a2f3e 100644 --- a/shared/src/main/java/eu/maveniverse/maven/toolbox/shared/MultiArtifactSink.java +++ b/shared/src/main/java/eu/maveniverse/maven/toolbox/shared/MultiArtifactSink.java @@ -11,6 +11,7 @@ import eu.maveniverse.maven.toolbox.shared.internal.ArtifactMatcher; import java.io.IOException; +import java.util.Collections; import java.util.LinkedHashMap; import java.util.Map; import org.eclipse.aether.artifact.Artifact; @@ -19,31 +20,40 @@ * Construction to accept collection of artifacts and differentiate the into separate "lanes", or sinks. */ public final class MultiArtifactSink implements ArtifactSink { + public static final class MultiArtifactSinkBuilder { + private final Output output; + private final LinkedHashMap sinks; + + private MultiArtifactSinkBuilder(Output output) { + this.output = requireNonNull(output); + this.sinks = new LinkedHashMap<>(); + } + + public MultiArtifactSinkBuilder addSink(ArtifactMatcher artifactMatcher, ArtifactSink sink) { + requireNonNull(artifactMatcher, "artifactMatcher"); + requireNonNull(sink, "sink"); + sinks.put(artifactMatcher, sink); + return this; + } + + public MultiArtifactSink build() { + return new MultiArtifactSink(output, sinks); + } + } + /** * Creates new empty instance. */ - public static MultiArtifactSink multi(Output output) { - return new MultiArtifactSink(output); + public static MultiArtifactSinkBuilder multiBuilder(Output output) { + return new MultiArtifactSinkBuilder(output); } private final Output output; - private final LinkedHashMap sinks; + private final Map sinks; - /** - * Creates a multi artifact sink. - * - * @param output The output. - */ - private MultiArtifactSink(Output output) { + private MultiArtifactSink(Output output, LinkedHashMap sinks) { this.output = requireNonNull(output, "output"); - this.sinks = new LinkedHashMap<>(); - } - - public MultiArtifactSink addSink(ArtifactMatcher artifactMatcher, ArtifactSink sink) { - requireNonNull(artifactMatcher, "artifactMatcher"); - requireNonNull(sink, "sink"); - sinks.put(artifactMatcher, sink); - return this; + this.sinks = Collections.unmodifiableMap(sinks); } @Override 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 ff38a1f5..6204b772 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 @@ -23,7 +23,9 @@ import eu.maveniverse.maven.toolbox.shared.ArtifactSink; import eu.maveniverse.maven.toolbox.shared.DeployingSink; import eu.maveniverse.maven.toolbox.shared.DirectorySink; +import eu.maveniverse.maven.toolbox.shared.InstallingSink; import eu.maveniverse.maven.toolbox.shared.Output; +import eu.maveniverse.maven.toolbox.shared.PurgingSink; import eu.maveniverse.maven.toolbox.shared.ResolutionRoot; import eu.maveniverse.maven.toolbox.shared.ResolutionScope; import eu.maveniverse.maven.toolbox.shared.ToolboxCommando; @@ -237,12 +239,22 @@ public ArtifactSink artifactSink(Output output, String spec) throws IOException case "repository": return DirectorySink.repository( output, context.basedir().resolve(spec.substring("repository:".length()))); + case "install": + return InstallingSink.installing( + output, + context.repositorySystem(), + context.repositorySystemSession()); case "deploy": return DeployingSink.deploying( output, context.repositorySystem(), context.repositorySystemSession(), toolboxResolver.parseRemoteRepository(spec.substring("deploy:".length()))); + case "purge": + return PurgingSink.purging(output, + context.repositorySystem(), + context.repositorySystemSession(), + context.remoteRepositories()); default: throw new IllegalArgumentException("unknown artifact sink spec"); }