1 package org.apache.maven.shared.transfer.artifact.install.internal;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.Collection;
23
24 import org.apache.maven.RepositoryUtils;
25 import org.apache.maven.artifact.metadata.ArtifactMetadata;
26 import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
27 import org.apache.maven.project.artifact.ProjectArtifactMetadata;
28 import org.apache.maven.shared.transfer.artifact.install.ArtifactInstallerException;
29 import org.apache.maven.shared.transfer.metadata.internal.Maven31MetadataBridge;
30 import org.eclipse.aether.RepositorySystem;
31 import org.eclipse.aether.RepositorySystemSession;
32 import org.eclipse.aether.artifact.Artifact;
33 import org.eclipse.aether.installation.InstallRequest;
34 import org.eclipse.aether.installation.InstallationException;
35 import org.eclipse.aether.util.artifact.SubArtifact;
36
37
38
39
40 class Maven31ArtifactInstaller
41 implements MavenArtifactInstaller
42 {
43 private final RepositorySystem repositorySystem;
44
45 private final RepositorySystemSession session;
46
47 Maven31ArtifactInstaller( RepositorySystem repositorySystem,
48 RepositorySystemSession session )
49 {
50 this.repositorySystem = repositorySystem;
51 this.session = session;
52 }
53
54 @Override
55 public void install( Collection<org.apache.maven.artifact.Artifact> mavenArtifacts )
56 throws ArtifactInstallerException
57 {
58
59 InstallRequest request = new InstallRequest();
60
61
62 for ( org.apache.maven.artifact.Artifact mavenArtifact : mavenArtifacts )
63 {
64 Artifact mainArtifact = Invoker.invoke( RepositoryUtils.class, "toArtifact",
65 org.apache.maven.artifact.Artifact.class, mavenArtifact );
66 request.addArtifact( mainArtifact );
67
68 for ( ArtifactMetadata metadata : mavenArtifact.getMetadataList() )
69 {
70 if ( metadata instanceof ProjectArtifactMetadata )
71 {
72 Artifact pomArtifact = new SubArtifact( mainArtifact, "", "pom" );
73 pomArtifact = pomArtifact.setFile( ( (ProjectArtifactMetadata) metadata ).getFile() );
74 request.addArtifact( pomArtifact );
75 }
76 else if (
77 metadata instanceof ArtifactRepositoryMetadata )
78 {
79
80 }
81 else if ( metadata instanceof org.apache.maven.shared.transfer.metadata.ArtifactMetadata )
82 {
83 org.apache.maven.shared.transfer.metadata.ArtifactMetadata transferMetadata =
84 (org.apache.maven.shared.transfer.metadata.ArtifactMetadata) metadata;
85
86 request.addMetadata( new Maven31MetadataBridge( metadata ).setFile( transferMetadata.getFile() ) );
87 }
88 }
89 }
90
91
92 try
93 {
94 repositorySystem.install( session, request );
95 }
96 catch ( InstallationException e )
97 {
98 throw new ArtifactInstallerException( e.getMessage(), e );
99 }
100 }
101 }