1 package org.apache.maven.artifact.installer;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23
24 import org.apache.maven.RepositoryUtils;
25 import org.apache.maven.artifact.Artifact;
26 import org.apache.maven.artifact.metadata.ArtifactMetadata;
27 import org.apache.maven.artifact.repository.ArtifactRepository;
28 import org.apache.maven.artifact.repository.LegacyLocalRepositoryManager;
29 import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
30 import org.apache.maven.artifact.repository.metadata.MetadataBridge;
31 import org.apache.maven.artifact.repository.metadata.Snapshot;
32 import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata;
33 import org.apache.maven.artifact.repository.metadata.Versioning;
34 import org.apache.maven.plugin.LegacySupport;
35 import org.apache.maven.project.artifact.ProjectArtifactMetadata;
36 import org.codehaus.plexus.component.annotations.Component;
37 import org.codehaus.plexus.component.annotations.Requirement;
38 import org.codehaus.plexus.logging.AbstractLogEnabled;
39 import org.sonatype.aether.RepositorySystem;
40 import org.sonatype.aether.installation.InstallRequest;
41 import org.sonatype.aether.installation.InstallationException;
42 import org.sonatype.aether.repository.LocalRepository;
43 import org.sonatype.aether.util.DefaultRepositorySystemSession;
44 import org.sonatype.aether.util.artifact.SubArtifact;
45
46
47
48
49 @Component( role = ArtifactInstaller.class )
50 public class DefaultArtifactInstaller
51 extends AbstractLogEnabled
52 implements ArtifactInstaller
53 {
54
55 @Requirement
56 private RepositorySystem repoSystem;
57
58 @Requirement
59 private LegacySupport legacySupport;
60
61
62 @Deprecated
63 public void install( String basedir, String finalName, Artifact artifact, ArtifactRepository localRepository )
64 throws ArtifactInstallationException
65 {
66 String extension = artifact.getArtifactHandler().getExtension();
67 File source = new File( basedir, finalName + "." + extension );
68
69 install( source, artifact, localRepository );
70 }
71
72 public void install( File source, Artifact artifact, ArtifactRepository localRepository )
73 throws ArtifactInstallationException
74 {
75 DefaultRepositorySystemSession session =
76 new DefaultRepositorySystemSession( legacySupport.getRepositorySession() );
77 session.setLocalRepositoryManager( LegacyLocalRepositoryManager.wrap( localRepository, repoSystem ) );
78
79 InstallRequest request = new InstallRequest();
80
81 org.sonatype.aether.artifact.Artifact mainArtifact = RepositoryUtils.toArtifact( artifact );
82 mainArtifact = mainArtifact.setFile( source );
83 request.addArtifact( mainArtifact );
84
85 for ( ArtifactMetadata metadata : artifact.getMetadataList() )
86 {
87 if ( metadata instanceof ProjectArtifactMetadata )
88 {
89 org.sonatype.aether.artifact.Artifact pomArtifact = new SubArtifact( mainArtifact, "", "pom" );
90 pomArtifact = pomArtifact.setFile( ( (ProjectArtifactMetadata) metadata ).getFile() );
91 request.addArtifact( pomArtifact );
92 }
93 else if ( metadata instanceof SnapshotArtifactRepositoryMetadata
94 || metadata instanceof ArtifactRepositoryMetadata )
95 {
96
97 }
98 else
99 {
100 request.addMetadata( new MetadataBridge( metadata ) );
101 }
102 }
103
104 try
105 {
106 repoSystem.install( session, request );
107 }
108 catch ( InstallationException e )
109 {
110 throw new ArtifactInstallationException( e.getMessage(), e );
111 }
112
113
114
115
116
117 if ( artifact.isSnapshot() )
118 {
119 Snapshot snapshot = new Snapshot();
120 snapshot.setLocalCopy( true );
121 artifact.addMetadata( new SnapshotArtifactRepositoryMetadata( artifact, snapshot ) );
122 }
123
124 Versioning versioning = new Versioning();
125 versioning.updateTimestamp();
126 versioning.addVersion( artifact.getBaseVersion() );
127 if ( artifact.isRelease() )
128 {
129 versioning.setRelease( artifact.getBaseVersion() );
130 }
131 artifact.addMetadata( new ArtifactRepositoryMetadata( artifact, versioning ) );
132 }
133
134 }