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