Skip to content

Commit

Permalink
[MNG-8329] ArtifactInstallerRequest and ArtifactDeployerRequest shoul…
Browse files Browse the repository at this point in the history
…d use Collection<ProducedArtifact> (#1836)
  • Loading branch information
gnodet authored Oct 25, 2024
1 parent 227b13a commit 2a6fc5a
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ Collection<DownloadedArtifact> resolveArtifacts(
*
* @see org.apache.maven.api.services.ArtifactInstaller#install(Session, Collection)
*/
void installArtifacts(@Nonnull Artifact... artifacts);
void installArtifacts(@Nonnull ProducedArtifact... artifacts);

/**
* Shortcut for {@code getService(ArtifactInstaller.class).install(...)}.
Expand All @@ -531,7 +531,7 @@ Collection<DownloadedArtifact> resolveArtifacts(
*
* @see org.apache.maven.api.services.ArtifactInstaller#install(Session, Collection)
*/
void installArtifacts(@Nonnull Collection<Artifact> artifacts);
void installArtifacts(@Nonnull Collection<ProducedArtifact> artifacts);

/**
* Shortcut for {@code getService(ArtifactDeployer.class).deploy(...)}.
Expand All @@ -542,7 +542,7 @@ Collection<DownloadedArtifact> resolveArtifacts(
*
* @see org.apache.maven.api.services.ArtifactDeployer#deploy(Session, RemoteRepository, Collection)
*/
void deployArtifact(@Nonnull RemoteRepository repository, @Nonnull Artifact... artifacts);
void deployArtifact(@Nonnull RemoteRepository repository, @Nonnull ProducedArtifact... artifacts);

/**
* Shortcut for {@code getService(ArtifactManager.class).setPath(...)}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@

import java.util.Collection;

import org.apache.maven.api.Artifact;
import org.apache.maven.api.ProducedArtifact;
import org.apache.maven.api.RemoteRepository;
import org.apache.maven.api.Service;
import org.apache.maven.api.Session;
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Nonnull;

/**
* Deploys {@link Artifact}s to a {@link RemoteRepository}.
* Deploys {@link ProducedArtifact}s to a {@link RemoteRepository}.
*
* @since 4.0.0
* @see Session#deployArtifact(RemoteRepository, Artifact...)
* @see Session#deployArtifact(RemoteRepository, ProducedArtifact...)
*/
@Experimental
public interface ArtifactDeployer extends Service {
Expand All @@ -50,7 +50,9 @@ public interface ArtifactDeployer extends Service {
* @throws IllegalArgumentException if an argument is {@code null} or invalid
*/
default void deploy(
@Nonnull Session session, @Nonnull RemoteRepository repository, @Nonnull Collection<Artifact> artifacts) {
@Nonnull Session session,
@Nonnull RemoteRepository repository,
@Nonnull Collection<ProducedArtifact> artifacts) {
deploy(ArtifactDeployerRequest.build(session, repository, artifacts));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import java.util.Collection;

import org.apache.maven.api.Artifact;
import org.apache.maven.api.ProducedArtifact;
import org.apache.maven.api.RemoteRepository;
import org.apache.maven.api.Session;
import org.apache.maven.api.annotations.Experimental;
Expand All @@ -45,7 +45,7 @@ public interface ArtifactDeployerRequest {
RemoteRepository getRepository();

@Nonnull
Collection<Artifact> getArtifacts();
Collection<ProducedArtifact> getArtifacts();

int getRetryFailedDeploymentCount();

Expand All @@ -56,7 +56,9 @@ static ArtifactDeployerRequestBuilder builder() {

@Nonnull
static ArtifactDeployerRequest build(
@Nonnull Session session, @Nonnull RemoteRepository repository, @Nonnull Collection<Artifact> artifacts) {
@Nonnull Session session,
@Nonnull RemoteRepository repository,
@Nonnull Collection<ProducedArtifact> artifacts) {
return builder()
.session(nonNull(session, "session cannot be null"))
.repository(nonNull(repository, "repository cannot be null"))
Expand All @@ -67,7 +69,7 @@ static ArtifactDeployerRequest build(
class ArtifactDeployerRequestBuilder {
Session session;
RemoteRepository repository;
Collection<Artifact> artifacts;
Collection<ProducedArtifact> artifacts;
int retryFailedDeploymentCount;

ArtifactDeployerRequestBuilder() {}
Expand All @@ -84,7 +86,7 @@ public ArtifactDeployerRequestBuilder repository(RemoteRepository repository) {
return this;
}

public ArtifactDeployerRequestBuilder artifacts(Collection<Artifact> artifacts) {
public ArtifactDeployerRequestBuilder artifacts(Collection<ProducedArtifact> artifacts) {
this.artifacts = artifacts;
return this;
}
Expand All @@ -102,13 +104,13 @@ public ArtifactDeployerRequest build() {
private static class DefaultArtifactDeployerRequest extends BaseRequest implements ArtifactDeployerRequest {

private final RemoteRepository repository;
private final Collection<Artifact> artifacts;
private final Collection<ProducedArtifact> artifacts;
private final int retryFailedDeploymentCount;

DefaultArtifactDeployerRequest(
@Nonnull Session session,
@Nonnull RemoteRepository repository,
@Nonnull Collection<Artifact> artifacts,
@Nonnull Collection<ProducedArtifact> artifacts,
int retryFailedDeploymentCount) {
super(session);
this.repository = nonNull(repository, "repository cannot be null");
Expand All @@ -124,7 +126,7 @@ public RemoteRepository getRepository() {

@Nonnull
@Override
public Collection<Artifact> getArtifacts() {
public Collection<ProducedArtifact> getArtifacts() {
return artifacts;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
import java.util.Collection;
import java.util.Collections;

import org.apache.maven.api.Artifact;
import org.apache.maven.api.ProducedArtifact;
import org.apache.maven.api.Service;
import org.apache.maven.api.Session;
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Nonnull;

/**
* Installs {@link Artifact}s to the local repository.
* Installs {@link ProducedArtifact}s to the local repository.
*
* @since 4.0.0
* @see Session#withLocalRepository(org.apache.maven.api.LocalRepository)
Expand All @@ -44,27 +44,27 @@ public interface ArtifactInstaller extends Service {

/**
* @param session the repository session
* @param artifact the {@link Artifact} to install
* @param artifact the {@link ProducedArtifact} to install
* @throws ArtifactInstallerException In case of an error which can be the a given artifact cannot be found or the
* installation has failed.
* @throws IllegalArgumentException in case of parameter {@code session} is {@code null} or
* {@code artifact} is {@code null}.
*/
default void install(Session session, Artifact artifact) {
default void install(Session session, ProducedArtifact artifact) {
install(session, Collections.singletonList(artifact));
}

/**
* @param session the repository session
* @param artifacts Collection of {@link Artifact MavenArtifacts}
* @param artifacts Collection of {@link ProducedArtifact MavenArtifacts}
* @throws ArtifactInstallerException In case of an error which can be the a given artifact cannot be found or the
* installation has failed.
* @throws IllegalArgumentException in case of parameter {@code request} is {@code null} or parameter
* {@code localRepository} is {@code null} or {@code localRepository} is not a directory
* or parameter {@code mavenArtifacts} is {@code null} or
* {@code mavenArtifacts.isEmpty()} is {@code true}.
*/
default void install(Session session, Collection<Artifact> artifacts) {
default void install(Session session, Collection<ProducedArtifact> artifacts) {
install(ArtifactInstallerRequest.build(session, artifacts));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import java.util.Collection;
import java.util.Collections;

import org.apache.maven.api.Artifact;
import org.apache.maven.api.ProducedArtifact;
import org.apache.maven.api.Session;
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Immutable;
Expand All @@ -44,15 +44,15 @@ public interface ArtifactInstallerRequest {
Session getSession();

@Nonnull
Collection<Artifact> getArtifacts();
Collection<ProducedArtifact> getArtifacts();

@Nonnull
static ArtifactInstallerRequestBuilder builder() {
return new ArtifactInstallerRequestBuilder();
}

@Nonnull
static ArtifactInstallerRequest build(Session session, Collection<Artifact> artifacts) {
static ArtifactInstallerRequest build(Session session, Collection<ProducedArtifact> artifacts) {
return builder()
.session(nonNull(session, "session cannot be null"))
.artifacts(nonNull(artifacts, "artifacts cannot be null"))
Expand All @@ -62,7 +62,7 @@ static ArtifactInstallerRequest build(Session session, Collection<Artifact> arti
@NotThreadSafe
class ArtifactInstallerRequestBuilder {
Session session;
Collection<Artifact> artifacts = Collections.emptyList();
Collection<ProducedArtifact> artifacts = Collections.emptyList();

ArtifactInstallerRequestBuilder() {}

Expand All @@ -73,7 +73,7 @@ public ArtifactInstallerRequestBuilder session(@Nonnull Session session) {
}

@Nonnull
public ArtifactInstallerRequestBuilder artifacts(@Nullable Collection<Artifact> artifacts) {
public ArtifactInstallerRequestBuilder artifacts(@Nullable Collection<ProducedArtifact> artifacts) {
this.artifacts = artifacts != null ? artifacts : Collections.emptyList();
return this;
}
Expand All @@ -85,16 +85,16 @@ public ArtifactInstallerRequest build() {

static class DefaultArtifactInstallerRequest extends BaseRequest implements ArtifactInstallerRequest {

private final Collection<Artifact> artifacts;
private final Collection<ProducedArtifact> artifacts;

DefaultArtifactInstallerRequest(@Nonnull Session session, @Nonnull Collection<Artifact> artifacts) {
DefaultArtifactInstallerRequest(@Nonnull Session session, @Nonnull Collection<ProducedArtifact> artifacts) {
super(session);
this.artifacts = unmodifiable(nonNull(artifacts, "artifacts cannot be null"));
}

@Nonnull
@Override
public Collection<Artifact> getArtifacts() {
public Collection<ProducedArtifact> getArtifacts() {
return artifacts;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ private org.eclipse.aether.graph.Exclusion toExclusion(Exclusion exclusion) {
}

@Override
public List<org.eclipse.aether.artifact.Artifact> toArtifacts(Collection<Artifact> artifacts) {
public List<org.eclipse.aether.artifact.Artifact> toArtifacts(Collection<? extends Artifact> artifacts) {
return artifacts == null ? null : map(artifacts, this::toArtifact);
}

Expand Down Expand Up @@ -637,7 +637,7 @@ public Collection<DownloadedArtifact> resolveArtifacts(Artifact... artifacts) {
* @see ArtifactInstaller#install(Session, Collection)
*/
@Override
public void installArtifacts(Artifact... artifacts) {
public void installArtifacts(ProducedArtifact... artifacts) {
installArtifacts(Arrays.asList(artifacts));
}

Expand All @@ -648,7 +648,7 @@ public void installArtifacts(Artifact... artifacts) {
* @see ArtifactInstaller#install(Session, Collection)
*/
@Override
public void installArtifacts(Collection<Artifact> artifacts) {
public void installArtifacts(Collection<ProducedArtifact> artifacts) {
getService(ArtifactInstaller.class).install(this, artifacts);
}

Expand All @@ -659,7 +659,7 @@ public void installArtifacts(Collection<Artifact> artifacts) {
* @see ArtifactDeployer#deploy(Session, RemoteRepository, Collection)
*/
@Override
public void deployArtifact(RemoteRepository repository, Artifact... artifacts) {
public void deployArtifact(RemoteRepository repository, ProducedArtifact... artifacts) {
getService(ArtifactDeployer.class).deploy(this, repository, Arrays.asList(artifacts));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import java.util.Collection;

import org.apache.maven.api.Artifact;
import org.apache.maven.api.ProducedArtifact;
import org.apache.maven.api.RemoteRepository;
import org.apache.maven.api.annotations.Nonnull;
import org.apache.maven.api.di.Named;
Expand All @@ -44,7 +44,7 @@ public class DefaultArtifactDeployer implements ArtifactDeployer {
public void deploy(@Nonnull ArtifactDeployerRequest request) {
nonNull(request, "request");
InternalSession session = InternalSession.from(request.getSession());
Collection<Artifact> artifacts = nonNull(request.getArtifacts(), "request.artifacts");
Collection<ProducedArtifact> artifacts = nonNull(request.getArtifacts(), "request.artifacts");
RemoteRepository repository = nonNull(request.getRepository(), "request.repository");
try {
DeployRequest deployRequest = new DeployRequest()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ List<org.eclipse.aether.graph.Dependency> toDependencies(

org.eclipse.aether.graph.Dependency toDependency(DependencyCoordinates dependency, boolean managed);

List<org.eclipse.aether.artifact.Artifact> toArtifacts(Collection<Artifact> artifacts);
List<org.eclipse.aether.artifact.Artifact> toArtifacts(Collection<? extends Artifact> artifacts);

org.eclipse.aether.artifact.Artifact toArtifact(Artifact artifact);

Expand Down

0 comments on commit 2a6fc5a

Please sign in to comment.