1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.internal.impl;
20
21 import java.util.Objects;
22
23 import org.apache.maven.api.Artifact;
24 import org.apache.maven.api.ArtifactCoordinates;
25 import org.apache.maven.api.Version;
26 import org.apache.maven.api.annotations.Nonnull;
27
28 import static org.apache.maven.internal.impl.Utils.nonNull;
29
30
31
32
33 public class DefaultArtifact implements Artifact {
34 protected final @Nonnull InternalSession session;
35 protected final @Nonnull org.eclipse.aether.artifact.Artifact artifact;
36 protected final String key;
37
38 public DefaultArtifact(@Nonnull InternalSession session, @Nonnull org.eclipse.aether.artifact.Artifact artifact) {
39 this.session = nonNull(session, "session");
40 this.artifact = nonNull(artifact, "artifact");
41 this.key = getGroupId()
42 + ':'
43 + getArtifactId()
44 + ':'
45 + getExtension()
46 + (getClassifier().isEmpty() ? "" : ":" + getClassifier())
47 + ':'
48 + getVersion();
49 }
50
51 public org.eclipse.aether.artifact.Artifact getArtifact() {
52 return artifact;
53 }
54
55 @Override
56 public String key() {
57 return key;
58 }
59
60 @Nonnull
61 @Override
62 public String getGroupId() {
63 return artifact.getGroupId();
64 }
65
66 @Nonnull
67 @Override
68 public String getArtifactId() {
69 return artifact.getArtifactId();
70 }
71
72 @Nonnull
73 @Override
74 public Version getVersion() {
75 return session.parseVersion(artifact.getVersion());
76 }
77
78 @Override
79 public Version getBaseVersion() {
80 return session.parseVersion(artifact.getBaseVersion());
81 }
82
83 @Nonnull
84 @Override
85 public String getExtension() {
86 return artifact.getExtension();
87 }
88
89 @Nonnull
90 @Override
91 public String getClassifier() {
92 return artifact.getClassifier();
93 }
94
95 @Override
96 public boolean isSnapshot() {
97 return DefaultModelVersionParser.checkSnapshot(artifact.getVersion());
98 }
99
100 @Nonnull
101 @Override
102 public ArtifactCoordinates toCoordinates() {
103 return session.createArtifactCoordinates(this);
104 }
105
106 @Override
107 public boolean equals(Object o) {
108 return o instanceof Artifact && Objects.equals(key(), ((Artifact) o).key());
109 }
110
111 @Override
112 public int hashCode() {
113 return key.hashCode();
114 }
115
116 @Override
117 public String toString() {
118 return artifact.toString();
119 }
120 }