[MNG-8329] ArtifactInstallerRequest and ArtifactDeployerRequest should use Collection<ProducedArtifact> (#1836)

This commit is contained in:
Guillaume Nodet 2024-10-25 18:43:07 +02:00 committed by GitHub
parent 227b13a900
commit 2a6fc5ab67
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 40 additions and 36 deletions

View File

@ -521,7 +521,7 @@ public interface Session {
* *
* @see org.apache.maven.api.services.ArtifactInstaller#install(Session, Collection) * @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(...)}. * Shortcut for {@code getService(ArtifactInstaller.class).install(...)}.
@ -531,7 +531,7 @@ public interface Session {
* *
* @see org.apache.maven.api.services.ArtifactInstaller#install(Session, Collection) * @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(...)}. * Shortcut for {@code getService(ArtifactDeployer.class).deploy(...)}.
@ -542,7 +542,7 @@ public interface Session {
* *
* @see org.apache.maven.api.services.ArtifactDeployer#deploy(Session, RemoteRepository, Collection) * @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(...)}. * Shortcut for {@code getService(ArtifactManager.class).setPath(...)}.

View File

@ -20,7 +20,7 @@ package org.apache.maven.api.services;
import java.util.Collection; 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.RemoteRepository;
import org.apache.maven.api.Service; import org.apache.maven.api.Service;
import org.apache.maven.api.Session; import org.apache.maven.api.Session;
@ -28,10 +28,10 @@ import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Nonnull; 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 * @since 4.0.0
* @see Session#deployArtifact(RemoteRepository, Artifact...) * @see Session#deployArtifact(RemoteRepository, ProducedArtifact...)
*/ */
@Experimental @Experimental
public interface ArtifactDeployer extends Service { public interface ArtifactDeployer extends Service {
@ -50,7 +50,9 @@ public interface ArtifactDeployer extends Service {
* @throws IllegalArgumentException if an argument is {@code null} or invalid * @throws IllegalArgumentException if an argument is {@code null} or invalid
*/ */
default void deploy( 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)); deploy(ArtifactDeployerRequest.build(session, repository, artifacts));
} }
} }

View File

@ -20,7 +20,7 @@ package org.apache.maven.api.services;
import java.util.Collection; 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.RemoteRepository;
import org.apache.maven.api.Session; import org.apache.maven.api.Session;
import org.apache.maven.api.annotations.Experimental; import org.apache.maven.api.annotations.Experimental;
@ -45,7 +45,7 @@ public interface ArtifactDeployerRequest {
RemoteRepository getRepository(); RemoteRepository getRepository();
@Nonnull @Nonnull
Collection<Artifact> getArtifacts(); Collection<ProducedArtifact> getArtifacts();
int getRetryFailedDeploymentCount(); int getRetryFailedDeploymentCount();
@ -56,7 +56,9 @@ public interface ArtifactDeployerRequest {
@Nonnull @Nonnull
static ArtifactDeployerRequest build( 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() return builder()
.session(nonNull(session, "session cannot be null")) .session(nonNull(session, "session cannot be null"))
.repository(nonNull(repository, "repository cannot be null")) .repository(nonNull(repository, "repository cannot be null"))
@ -67,7 +69,7 @@ public interface ArtifactDeployerRequest {
class ArtifactDeployerRequestBuilder { class ArtifactDeployerRequestBuilder {
Session session; Session session;
RemoteRepository repository; RemoteRepository repository;
Collection<Artifact> artifacts; Collection<ProducedArtifact> artifacts;
int retryFailedDeploymentCount; int retryFailedDeploymentCount;
ArtifactDeployerRequestBuilder() {} ArtifactDeployerRequestBuilder() {}
@ -84,7 +86,7 @@ public interface ArtifactDeployerRequest {
return this; return this;
} }
public ArtifactDeployerRequestBuilder artifacts(Collection<Artifact> artifacts) { public ArtifactDeployerRequestBuilder artifacts(Collection<ProducedArtifact> artifacts) {
this.artifacts = artifacts; this.artifacts = artifacts;
return this; return this;
} }
@ -102,13 +104,13 @@ public interface ArtifactDeployerRequest {
private static class DefaultArtifactDeployerRequest extends BaseRequest implements ArtifactDeployerRequest { private static class DefaultArtifactDeployerRequest extends BaseRequest implements ArtifactDeployerRequest {
private final RemoteRepository repository; private final RemoteRepository repository;
private final Collection<Artifact> artifacts; private final Collection<ProducedArtifact> artifacts;
private final int retryFailedDeploymentCount; private final int retryFailedDeploymentCount;
DefaultArtifactDeployerRequest( DefaultArtifactDeployerRequest(
@Nonnull Session session, @Nonnull Session session,
@Nonnull RemoteRepository repository, @Nonnull RemoteRepository repository,
@Nonnull Collection<Artifact> artifacts, @Nonnull Collection<ProducedArtifact> artifacts,
int retryFailedDeploymentCount) { int retryFailedDeploymentCount) {
super(session); super(session);
this.repository = nonNull(repository, "repository cannot be null"); this.repository = nonNull(repository, "repository cannot be null");
@ -124,7 +126,7 @@ public interface ArtifactDeployerRequest {
@Nonnull @Nonnull
@Override @Override
public Collection<Artifact> getArtifacts() { public Collection<ProducedArtifact> getArtifacts() {
return artifacts; return artifacts;
} }

View File

@ -21,14 +21,14 @@ package org.apache.maven.api.services;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; 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.Service;
import org.apache.maven.api.Session; import org.apache.maven.api.Session;
import org.apache.maven.api.annotations.Experimental; import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Nonnull; 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 * @since 4.0.0
* @see Session#withLocalRepository(org.apache.maven.api.LocalRepository) * @see Session#withLocalRepository(org.apache.maven.api.LocalRepository)
@ -44,19 +44,19 @@ public interface ArtifactInstaller extends Service {
/** /**
* @param session the repository session * @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 * @throws ArtifactInstallerException In case of an error which can be the a given artifact cannot be found or the
* installation has failed. * installation has failed.
* @throws IllegalArgumentException in case of parameter {@code session} is {@code null} or * @throws IllegalArgumentException in case of parameter {@code session} is {@code null} or
* {@code artifact} is {@code null}. * {@code artifact} is {@code null}.
*/ */
default void install(Session session, Artifact artifact) { default void install(Session session, ProducedArtifact artifact) {
install(session, Collections.singletonList(artifact)); install(session, Collections.singletonList(artifact));
} }
/** /**
* @param session the repository session * @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 * @throws ArtifactInstallerException In case of an error which can be the a given artifact cannot be found or the
* installation has failed. * installation has failed.
* @throws IllegalArgumentException in case of parameter {@code request} is {@code null} or parameter * @throws IllegalArgumentException in case of parameter {@code request} is {@code null} or parameter
@ -64,7 +64,7 @@ public interface ArtifactInstaller extends Service {
* or parameter {@code mavenArtifacts} is {@code null} or * or parameter {@code mavenArtifacts} is {@code null} or
* {@code mavenArtifacts.isEmpty()} is {@code true}. * {@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)); install(ArtifactInstallerRequest.build(session, artifacts));
} }
} }

View File

@ -21,7 +21,7 @@ package org.apache.maven.api.services;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; 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.Session;
import org.apache.maven.api.annotations.Experimental; import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Immutable; import org.apache.maven.api.annotations.Immutable;
@ -44,7 +44,7 @@ public interface ArtifactInstallerRequest {
Session getSession(); Session getSession();
@Nonnull @Nonnull
Collection<Artifact> getArtifacts(); Collection<ProducedArtifact> getArtifacts();
@Nonnull @Nonnull
static ArtifactInstallerRequestBuilder builder() { static ArtifactInstallerRequestBuilder builder() {
@ -52,7 +52,7 @@ public interface ArtifactInstallerRequest {
} }
@Nonnull @Nonnull
static ArtifactInstallerRequest build(Session session, Collection<Artifact> artifacts) { static ArtifactInstallerRequest build(Session session, Collection<ProducedArtifact> artifacts) {
return builder() return builder()
.session(nonNull(session, "session cannot be null")) .session(nonNull(session, "session cannot be null"))
.artifacts(nonNull(artifacts, "artifacts cannot be null")) .artifacts(nonNull(artifacts, "artifacts cannot be null"))
@ -62,7 +62,7 @@ public interface ArtifactInstallerRequest {
@NotThreadSafe @NotThreadSafe
class ArtifactInstallerRequestBuilder { class ArtifactInstallerRequestBuilder {
Session session; Session session;
Collection<Artifact> artifacts = Collections.emptyList(); Collection<ProducedArtifact> artifacts = Collections.emptyList();
ArtifactInstallerRequestBuilder() {} ArtifactInstallerRequestBuilder() {}
@ -73,7 +73,7 @@ public interface ArtifactInstallerRequest {
} }
@Nonnull @Nonnull
public ArtifactInstallerRequestBuilder artifacts(@Nullable Collection<Artifact> artifacts) { public ArtifactInstallerRequestBuilder artifacts(@Nullable Collection<ProducedArtifact> artifacts) {
this.artifacts = artifacts != null ? artifacts : Collections.emptyList(); this.artifacts = artifacts != null ? artifacts : Collections.emptyList();
return this; return this;
} }
@ -85,16 +85,16 @@ public interface ArtifactInstallerRequest {
static class DefaultArtifactInstallerRequest extends BaseRequest implements ArtifactInstallerRequest { 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); super(session);
this.artifacts = unmodifiable(nonNull(artifacts, "artifacts cannot be null")); this.artifacts = unmodifiable(nonNull(artifacts, "artifacts cannot be null"));
} }
@Nonnull @Nonnull
@Override @Override
public Collection<Artifact> getArtifacts() { public Collection<ProducedArtifact> getArtifacts() {
return artifacts; return artifacts;
} }
} }

View File

@ -344,7 +344,7 @@ public abstract class AbstractSession implements InternalSession {
} }
@Override @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); return artifacts == null ? null : map(artifacts, this::toArtifact);
} }
@ -637,7 +637,7 @@ public abstract class AbstractSession implements InternalSession {
* @see ArtifactInstaller#install(Session, Collection) * @see ArtifactInstaller#install(Session, Collection)
*/ */
@Override @Override
public void installArtifacts(Artifact... artifacts) { public void installArtifacts(ProducedArtifact... artifacts) {
installArtifacts(Arrays.asList(artifacts)); installArtifacts(Arrays.asList(artifacts));
} }
@ -648,7 +648,7 @@ public abstract class AbstractSession implements InternalSession {
* @see ArtifactInstaller#install(Session, Collection) * @see ArtifactInstaller#install(Session, Collection)
*/ */
@Override @Override
public void installArtifacts(Collection<Artifact> artifacts) { public void installArtifacts(Collection<ProducedArtifact> artifacts) {
getService(ArtifactInstaller.class).install(this, artifacts); getService(ArtifactInstaller.class).install(this, artifacts);
} }
@ -659,7 +659,7 @@ public abstract class AbstractSession implements InternalSession {
* @see ArtifactDeployer#deploy(Session, RemoteRepository, Collection) * @see ArtifactDeployer#deploy(Session, RemoteRepository, Collection)
*/ */
@Override @Override
public void deployArtifact(RemoteRepository repository, Artifact... artifacts) { public void deployArtifact(RemoteRepository repository, ProducedArtifact... artifacts) {
getService(ArtifactDeployer.class).deploy(this, repository, Arrays.asList(artifacts)); getService(ArtifactDeployer.class).deploy(this, repository, Arrays.asList(artifacts));
} }

View File

@ -20,7 +20,7 @@ package org.apache.maven.internal.impl;
import java.util.Collection; 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.RemoteRepository;
import org.apache.maven.api.annotations.Nonnull; import org.apache.maven.api.annotations.Nonnull;
import org.apache.maven.api.di.Named; import org.apache.maven.api.di.Named;
@ -44,7 +44,7 @@ public class DefaultArtifactDeployer implements ArtifactDeployer {
public void deploy(@Nonnull ArtifactDeployerRequest request) { public void deploy(@Nonnull ArtifactDeployerRequest request) {
nonNull(request, "request"); nonNull(request, "request");
InternalSession session = InternalSession.from(request.getSession()); 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"); RemoteRepository repository = nonNull(request.getRepository(), "request.repository");
try { try {
DeployRequest deployRequest = new DeployRequest() DeployRequest deployRequest = new DeployRequest()

View File

@ -77,7 +77,7 @@ public interface InternalSession extends Session {
org.eclipse.aether.graph.Dependency toDependency(DependencyCoordinates dependency, boolean managed); 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); org.eclipse.aether.artifact.Artifact toArtifact(Artifact artifact);