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