1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.internal.impl;
20
21 import static org.apache.maven.internal.impl.Utils.cast;
22 import static org.apache.maven.internal.impl.Utils.nonNull;
23
24 import java.util.Collection;
25 import javax.inject.Inject;
26 import javax.inject.Named;
27 import javax.inject.Singleton;
28 import org.apache.maven.api.Artifact;
29 import org.apache.maven.api.RemoteRepository;
30 import org.apache.maven.api.annotations.Nonnull;
31 import org.apache.maven.api.services.ArtifactDeployer;
32 import org.apache.maven.api.services.ArtifactDeployerException;
33 import org.apache.maven.api.services.ArtifactDeployerRequest;
34 import org.eclipse.aether.RepositorySystem;
35 import org.eclipse.aether.deployment.DeployRequest;
36 import org.eclipse.aether.deployment.DeployResult;
37 import org.eclipse.aether.deployment.DeploymentException;
38
39
40
41
42 @Named
43 @Singleton
44 public class DefaultArtifactDeployer implements ArtifactDeployer {
45 private final @Nonnull RepositorySystem repositorySystem;
46
47 @Inject
48 DefaultArtifactDeployer(@Nonnull RepositorySystem repositorySystem) {
49 this.repositorySystem = nonNull(repositorySystem, "repositorySystem can not be null");
50 }
51
52 @Override
53 public void deploy(@Nonnull ArtifactDeployerRequest request) {
54 nonNull(request, "request can not be null");
55 DefaultSession session =
56 cast(DefaultSession.class, request.getSession(), "request.session should be a " + DefaultSession.class);
57 Collection<Artifact> artifacts = nonNull(request.getArtifacts(), "request.artifacts can not be null");
58 RemoteRepository repository = nonNull(request.getRepository(), "request.repository can not be null");
59 try {
60 DeployRequest deployRequest = new DeployRequest()
61 .setRepository(session.toRepository(repository))
62 .setArtifacts(session.toArtifacts(artifacts));
63
64 DeployResult result = repositorySystem.deploy(session.getSession(), deployRequest);
65 } catch (DeploymentException e) {
66 throw new ArtifactDeployerException("Unable to deploy artifacts", e);
67 }
68 }
69 }