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 public String getProperty(String key, String defaultValue) {
131 return delegate.getProperty(key, defaultValue);
132 }
133
134 public Map<String, String> getProperties() {
135 return delegate.getProperties();
136 }
137
138 public Artifact setProperties(Map<String, String> properties) {
139 Artifact artifact = delegate.setProperties(properties);
140 if (artifact != delegate) {
141 return newInstance(artifact);
142 }
143 return this;
144 }
145
146 @Override
147 public boolean equals(Object obj) {
148 if (obj == this) {
149 return true;
150 }
151
152 if (obj instanceof DelegatingArtifact) {
153 return delegate.equals(((DelegatingArtifact) obj).delegate);
154 }
155
156 return delegate.equals(obj);
157 }
158
159 @Override
160 public int hashCode() {
161 return delegate.hashCode();
162 }
163
164 @Override
165 public String toString() {
166 return delegate.toString();
167 }
168 }