1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.internal.impl.resolver.relocation;
20
21 import org.apache.maven.api.di.Named;
22 import org.apache.maven.api.di.Priority;
23 import org.apache.maven.api.di.Singleton;
24 import org.apache.maven.api.model.DistributionManagement;
25 import org.apache.maven.api.model.Model;
26 import org.apache.maven.api.model.Relocation;
27 import org.apache.maven.internal.impl.resolver.MavenArtifactRelocationSource;
28 import org.apache.maven.internal.impl.resolver.RelocatedArtifact;
29 import org.eclipse.aether.RepositorySystemSession;
30 import org.eclipse.aether.artifact.Artifact;
31 import org.eclipse.aether.resolution.ArtifactDescriptorResult;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34
35
36
37
38
39
40
41
42
43 @Singleton
44 @Named(DistributionManagementArtifactRelocationSource.NAME)
45 @Priority(5)
46 public final class DistributionManagementArtifactRelocationSource implements MavenArtifactRelocationSource {
47 public static final String NAME = "distributionManagement";
48 private static final Logger LOGGER = LoggerFactory.getLogger(DistributionManagementArtifactRelocationSource.class);
49
50 @Override
51 public Artifact relocatedTarget(
52 RepositorySystemSession session, ArtifactDescriptorResult artifactDescriptorResult, Model model) {
53 DistributionManagement distMgmt = model.getDistributionManagement();
54 if (distMgmt != null) {
55 Relocation relocation = distMgmt.getRelocation();
56 if (relocation != null) {
57 Artifact result = new RelocatedArtifact(
58 artifactDescriptorResult.getRequest().getArtifact(),
59 relocation.getGroupId(),
60 relocation.getArtifactId(),
61 null,
62 null,
63 relocation.getVersion(),
64 relocation.getMessage());
65 LOGGER.debug(
66 "The artifact {} has been relocated to {}: {}",
67 artifactDescriptorResult.getRequest().getArtifact(),
68 result,
69 relocation.getMessage());
70 return result;
71 }
72 }
73 return null;
74 }
75 }