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
31 public final class RelocatedArtifact extends AbstractArtifact {
32
33 private final Artifact artifact;
34
35 private final String groupId;
36
37 private final String artifactId;
38
39 private final String version;
40
41 private final String message;
42
43 RelocatedArtifact(Artifact artifact, String groupId, String artifactId, String version, String message) {
44 this.artifact = Objects.requireNonNull(artifact, "artifact cannot be null");
45
46 this.groupId = (groupId != null && groupId.length() > 0) ? groupId : null;
47 this.artifactId = (artifactId != null && artifactId.length() > 0) ? artifactId : null;
48 this.version = (version != null && version.length() > 0) ? version : null;
49 this.message = (message != null && message.length() > 0) ? message : null;
50 }
51
52 @Override
53 public String getGroupId() {
54 if (groupId != null) {
55 return groupId;
56 } else {
57 return artifact.getGroupId();
58 }
59 }
60
61 @Override
62 public String getArtifactId() {
63 if (artifactId != null) {
64 return artifactId;
65 } else {
66 return artifact.getArtifactId();
67 }
68 }
69
70 @Override
71 public String getVersion() {
72 if (version != null) {
73 return version;
74 } else {
75 return artifact.getVersion();
76 }
77 }
78
79
80 @Override
81 public Artifact setVersion(String version) {
82 String current = getVersion();
83 if (current.equals(version) || (version == null && current.length() <= 0)) {
84 return this;
85 }
86 return new RelocatedArtifact(artifact, groupId, artifactId, version, message);
87 }
88
89 @Override
90 public Artifact setFile(File file) {
91 File current = getFile();
92 if (Objects.equals(current, file)) {
93 return this;
94 }
95 return new RelocatedArtifact(artifact.setFile(file), groupId, artifactId, version, message);
96 }
97
98 @Override
99 public Artifact setProperties(Map<String, String> properties) {
100 Map<String, String> current = getProperties();
101 if (current.equals(properties) || (properties == null && current.isEmpty())) {
102 return this;
103 }
104 return new RelocatedArtifact(artifact.setProperties(properties), groupId, artifactId, version, message);
105 }
106
107 @Override
108 public String getClassifier() {
109 return artifact.getClassifier();
110 }
111
112 @Override
113 public String getExtension() {
114 return artifact.getExtension();
115 }
116
117 @Override
118 public File getFile() {
119 return artifact.getFile();
120 }
121
122 @Override
123 public String getProperty(String key, String defaultValue) {
124 return artifact.getProperty(key, defaultValue);
125 }
126
127 @Override
128 public Map<String, String> getProperties() {
129 return artifact.getProperties();
130 }
131
132 public String getMessage() {
133 return message;
134 }
135 }