1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.repository.internal;
20
21 import java.io.File;
22 import java.util.Map;
23 import java.util.Objects;
24
25 import org.eclipse.aether.artifact.AbstractArtifact;
26 import org.eclipse.aether.artifact.Artifact;
27
28
29
30 public final class RelocatedArtifact extends AbstractArtifact {
31
32 private final Artifact artifact;
33
34 private final String groupId;
35
36 private final String artifactId;
37
38 private final String version;
39
40 private final String message;
41
42 RelocatedArtifact(Artifact artifact, String groupId, String artifactId, String version, String message) {
43 this.artifact = Objects.requireNonNull(artifact, "artifact cannot be null");
44 this.groupId = (groupId != null && groupId.length() > 0) ? groupId : null;
45 this.artifactId = (artifactId != null && artifactId.length() > 0) ? artifactId : null;
46 this.version = (version != null && version.length() > 0) ? version : null;
47 this.message = (message != null && message.length() > 0) ? message : null;
48 }
49
50 @Override
51 public String getGroupId() {
52 if (groupId != null) {
53 return groupId;
54 } else {
55 return artifact.getGroupId();
56 }
57 }
58
59 @Override
60 public String getArtifactId() {
61 if (artifactId != null) {
62 return artifactId;
63 } else {
64 return artifact.getArtifactId();
65 }
66 }
67
68 @Override
69 public String getVersion() {
70 if (version != null) {
71 return version;
72 } else {
73 return artifact.getVersion();
74 }
75 }
76
77
78 @Override
79 public Artifact setVersion(String version) {
80 String current = getVersion();
81 if (current.equals(version) || (version == null && current.length() <= 0)) {
82 return this;
83 }
84 return new RelocatedArtifact(artifact, groupId, artifactId, version, message);
85 }
86
87 @Override
88 public Artifact setFile(File file) {
89 File current = getFile();
90 if (Objects.equals(current, file)) {
91 return this;
92 }
93 return new RelocatedArtifact(artifact.setFile(file), groupId, artifactId, version, message);
94 }
95
96 @Override
97 public Artifact setProperties(Map<String, String> properties) {
98 Map<String, String> current = getProperties();
99 if (current.equals(properties) || (properties == null && current.isEmpty())) {
100 return this;
101 }
102 return new RelocatedArtifact(artifact.setProperties(properties), groupId, artifactId, version, message);
103 }
104
105 @Override
106 public String getClassifier() {
107 return artifact.getClassifier();
108 }
109
110 @Override
111 public String getExtension() {
112 return artifact.getExtension();
113 }
114
115 @Override
116 public File getFile() {
117 return artifact.getFile();
118 }
119
120 @Override
121 public String getProperty(String key, String defaultValue) {
122 return artifact.getProperty(key, defaultValue);
123 }
124
125 @Override
126 public Map<String, String> getProperties() {
127 return artifact.getProperties();
128 }
129
130 public String getMessage() {
131 return message;
132 }
133 }