1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.aether.util.artifact;
20
21 import java.io.File;
22 import java.nio.file.Path;
23 import java.util.Map;
24
25 import org.eclipse.aether.artifact.AbstractArtifact;
26 import org.eclipse.aether.artifact.Artifact;
27
28 import static java.util.Objects.requireNonNull;
29
30
31
32
33
34 public abstract class DelegatingArtifact extends AbstractArtifact {
35
36 private final Artifact delegate;
37
38
39
40
41
42
43 protected DelegatingArtifact(Artifact delegate) {
44 this.delegate = requireNonNull(delegate, "delegate artifact cannot be null");
45 }
46
47
48
49
50
51
52
53
54 protected abstract DelegatingArtifact newInstance(Artifact delegate);
55
56 @Override
57 public String getGroupId() {
58 return delegate.getGroupId();
59 }
60
61 @Override
62 public String getArtifactId() {
63 return delegate.getArtifactId();
64 }
65
66 @Override
67 public String getVersion() {
68 return delegate.getVersion();
69 }
70
71 @Override
72 public Artifact setVersion(String version) {
73 Artifact artifact = delegate.setVersion(version);
74 if (artifact != delegate) {
75 return newInstance(artifact);
76 }
77 return this;
78 }
79
80 @Override
81 public String getBaseVersion() {
82 return delegate.getBaseVersion();
83 }
84
85 @Override
86 public boolean isSnapshot() {
87 return delegate.isSnapshot();
88 }
89
90 @Override
91 public String getClassifier() {
92 return delegate.getClassifier();
93 }
94
95 @Override
96 public String getExtension() {
97 return delegate.getExtension();
98 }
99
100 @Deprecated
101 @Override
102 public File getFile() {
103 return delegate.getFile();
104 }
105
106 @Override
107 public Path getPath() {
108 return delegate.getPath();
109 }
110
111 @Deprecated
112 @Override
113 public Artifact setFile(File file) {
114 Artifact artifact = delegate.setFile(file);
115 if (artifact != delegate) {
116 return newInstance(artifact);
117 }
118 return this;
119 }
120
121 @Override
122 public Artifact setPath(Path path) {
123 Artifact artifact = delegate.setPath(path);
124 if (artifact != delegate) {
125 return newInstance(artifact);
126 }
127 return this;
128 }
129
130 @Override
131 public String getProperty(String key, String defaultValue) {
132 return delegate.getProperty(key, defaultValue);
133 }
134
135 @Override
136 public Map<String, String> getProperties() {
137 return delegate.getProperties();
138 }
139
140 @Override
141 public Artifact setProperties(Map<String, String> properties) {
142 Artifact artifact = delegate.setProperties(properties);
143 if (artifact != delegate) {
144 return newInstance(artifact);
145 }
146 return this;
147 }
148
149 @Override
150 public boolean equals(Object obj) {
151 if (obj == this) {
152 return true;
153 }
154
155 if (obj instanceof DelegatingArtifact) {
156 return delegate.equals(((DelegatingArtifact) obj).delegate);
157 }
158
159 return delegate.equals(obj);
160 }
161
162 @Override
163 public int hashCode() {
164 return delegate.hashCode();
165 }
166
167 @Override
168 public String toString() {
169 return delegate.toString();
170 }
171 }