Skip to content

Commit

Permalink
Improve sinks and parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
cstamas committed Mar 25, 2024
1 parent edfc501 commit f26c7ba
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<ArtifactMatcher, ArtifactSink> 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<ArtifactMatcher, ArtifactSink> sinks;
private final Map<ArtifactMatcher, ArtifactSink> sinks;

/**
* Creates a multi artifact sink.
*
* @param output The output.
*/
private MultiArtifactSink(Output output) {
private MultiArtifactSink(Output output, LinkedHashMap<ArtifactMatcher, ArtifactSink> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
}
Expand Down

0 comments on commit f26c7ba

Please sign in to comment.