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.eclipse.aether.RepositorySystem;
40 import org.eclipse.aether.RepositorySystemSession;
41 import org.eclipse.aether.RequestTrace;
42 import org.eclipse.aether.installation.InstallRequest;
43 import org.eclipse.aether.installation.InstallationException;
44 import org.eclipse.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 RepositorySystemSession session =
76 LegacyLocalRepositoryManager.overlay( localRepository, legacySupport.getRepositorySession(), repoSystem );
77
78 InstallRequest request = new InstallRequest();
79
80 request.setTrace( RequestTrace.newChild( null, legacySupport.getSession().getCurrentProject() ) );
81
82 org.eclipse.aether.artifact.Artifact mainArtifact = RepositoryUtils.toArtifact( artifact );
83 mainArtifact = mainArtifact.setFile( source );
84 request.addArtifact( mainArtifact );
85
86 for ( ArtifactMetadata metadata : artifact.getMetadataList() )
87 {
88 if ( metadata instanceof ProjectArtifactMetadata )
89 {
90 org.eclipse.aether.artifact.Artifact pomArtifact = new SubArtifact( mainArtifact, "", "pom" );
91 pomArtifact = pomArtifact.setFile( ( (ProjectArtifactMetadata) metadata ).getFile() );
92 request.addArtifact( pomArtifact );
93 }
94 else if ( metadata instanceof SnapshotArtifactRepositoryMetadata
95 || metadata instanceof ArtifactRepositoryMetadata )
96 {
97
98 }
99 else
100 {
101 request.addMetadata( new MetadataBridge( metadata ) );
102 }
103 }
104
105 try
106 {
107 repoSystem.install( session, request );
108 }
109 catch ( InstallationException e )
110 {
111 throw new ArtifactInstallationException( e.getMessage(), e );
112 }
113
114
115
116
117
118 if ( artifact.isSnapshot() )
119 {
120 Snapshot snapshot = new Snapshot();
121 snapshot.setLocalCopy( true );
122 artifact.addMetadata( new SnapshotArtifactRepositoryMetadata( artifact, snapshot ) );
123 }
124
125 Versioning versioning = new Versioning();
126
127 versioning.updateTimestamp();
128 versioning.addVersion( artifact.getBaseVersion() );
129 if ( artifact.isRelease() )
130 {
131 versioning.setRelease( artifact.getBaseVersion() );
132 }
133 artifact.addMetadata( new ArtifactRepositoryMetadata( artifact, versioning ) );
134 }
135
136 }