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 javax.inject.Inject;
23 import javax.inject.Named;
24 import javax.inject.Singleton;
25
26 import org.apache.maven.api.annotations.Nonnull;
27 import org.apache.maven.api.services.ArtifactInstaller;
28 import org.apache.maven.api.services.ArtifactInstallerException;
29 import org.apache.maven.api.services.ArtifactInstallerRequest;
30 import org.eclipse.aether.RepositorySystem;
31 import org.eclipse.aether.installation.InstallRequest;
32 import org.eclipse.aether.installation.InstallResult;
33 import org.eclipse.aether.installation.InstallationException;
34
35 import static org.apache.maven.internal.impl.Utils.cast;
36 import static org.apache.maven.internal.impl.Utils.nonNull;
37
38 @Named
39 @Singleton
40 public class DefaultArtifactInstaller implements ArtifactInstaller
41 {
42
43 private final RepositorySystem repositorySystem;
44
45 @Inject
46 DefaultArtifactInstaller( @Nonnull RepositorySystem repositorySystem )
47 {
48 this.repositorySystem = nonNull( repositorySystem );
49 }
50
51 @Override
52 public void install( ArtifactInstallerRequest request ) throws ArtifactInstallerException, IllegalArgumentException
53 {
54 nonNull( request, "request can not be null" );
55 DefaultSession session = cast( DefaultSession.class, request.getSession(),
56 "request.session should be a " + DefaultSession.class );
57 try
58 {
59 InstallRequest installRequest = new InstallRequest()
60 .setArtifacts( session.toArtifacts( request.getArtifacts() ) );
61
62 InstallResult result = repositorySystem.install( session.getSession(), installRequest );
63 }
64 catch ( InstallationException e )
65 {
66 throw new ArtifactInstallerException( e.getMessage(), e );
67 }
68 }
69 }