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.nio.file.Path;
23 import java.util.Map;
24 import java.util.Objects;
25
26 import org.eclipse.aether.artifact.AbstractArtifact;
27 import org.eclipse.aether.artifact.Artifact;
28
29
30
31
32 @Deprecated(since = "4.0.0")
33 public final class RelocatedArtifact extends AbstractArtifact {
34
35 private final Artifact artifact;
36
37 private final String groupId;
38
39 private final String artifactId;
40
41 private final String classifier;
42
43 private final String extension;
44
45 private final String version;
46
47 private final String message;
48
49 public RelocatedArtifact(
50 Artifact artifact,
51 String groupId,
52 String artifactId,
53 String classifier,
54 String extension,
55 String version,
56 String message) {
57 this.artifact = Objects.requireNonNull(artifact, "artifact cannot be null");
58 this.groupId = (groupId != null && !groupId.isEmpty()) ? groupId : null;
59 this.artifactId = (artifactId != null && !artifactId.isEmpty()) ? artifactId : null;
60 this.classifier = (classifier != null && !classifier.isEmpty()) ? classifier : null;
61 this.extension = (extension != null && !extension.isEmpty()) ? extension : null;
62 this.version = (version != null && !version.isEmpty()) ? version : null;
63 this.message = (message != null && !message.isEmpty()) ? message : null;
64 }
65
66 @Override
67 public String getGroupId() {
68 if (groupId != null) {
69 return groupId;
70 } else {
71 return artifact.getGroupId();
72 }
73 }
74
75 @Override
76 public String getArtifactId() {
77 if (artifactId != null) {
78 return artifactId;
79 } else {
80 return artifact.getArtifactId();
81 }
82 }
83
84 @Override
85 public String getClassifier() {
86 if (classifier != null) {
87 return classifier;
88 } else {
89 return artifact.getClassifier();
90 }
91 }
92
93 @Override
94 public String getExtension() {
95 if (extension != null) {
96 return extension;
97 } else {
98 return artifact.getExtension();
99 }
100 }
101
102 @Override
103 public String getVersion() {
104 if (version != null) {
105 return version;
106 } else {
107 return artifact.getVersion();
108 }
109 }
110
111
112 @Override
113 public Artifact setVersion(String version) {
114 String current = getVersion();
115 if (current.equals(version) || (version == null && current.isEmpty())) {
116 return this;
117 }
118 return new RelocatedArtifact(artifact, groupId, artifactId, classifier, extension, version, message);
119 }
120
121 @Deprecated
122 @Override
123 public Artifact setFile(File file) {
124 File current = getFile();
125 if (Objects.equals(current, file)) {
126 return this;
127 }
128 return new RelocatedArtifact(
129 artifact.setFile(file), groupId, artifactId, classifier, extension, version, message);
130 }
131
132 @Override
133 public Artifact setPath(Path path) {
134 Path current = getPath();
135 if (Objects.equals(current, path)) {
136 return this;
137 }
138 return new RelocatedArtifact(
139 artifact.setPath(path), groupId, artifactId, classifier, extension, version, message);
140 }
141
142 @Override
143 public Artifact setProperties(Map<String, String> properties) {
144 Map<String, String> current = getProperties();
145 if (current.equals(properties) || (properties == null && current.isEmpty())) {
146 return this;
147 }
148 return new RelocatedArtifact(
149 artifact.setProperties(properties), groupId, artifactId, classifier, extension, version, message);
150 }
151
152 @Deprecated
153 @Override
154 public File getFile() {
155 return artifact.getFile();
156 }
157
158 @Override
159 public Path getPath() {
160 return artifact.getPath();
161 }
162
163 @Override
164 public String getProperty(String key, String defaultValue) {
165 return artifact.getProperty(key, defaultValue);
166 }
167
168 @Override
169 public Map<String, String> getProperties() {
170 return artifact.getProperties();
171 }
172
173 public String getMessage() {
174 return message;
175 }
176 }