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