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.ArtifactCoordinate;
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 private final @Nonnull InternalSession session;
35 private final @Nonnull org.eclipse.aether.artifact.Artifact artifact;
36 private 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 @Nonnull
79 @Override
80 public String getExtension() {
81 return artifact.getExtension();
82 }
83
84 @Nonnull
85 @Override
86 public String getClassifier() {
87 return artifact.getClassifier();
88 }
89
90 @Override
91 public boolean isSnapshot() {
92 return DefaultVersionParser.checkSnapshot(artifact.getVersion());
93 }
94
95 @Nonnull
96 @Override
97 public ArtifactCoordinate toCoordinate() {
98 return session.createArtifactCoordinate(this);
99 }
100
101 @Override
102 public boolean equals(Object o) {
103 return o instanceof Artifact && Objects.equals(key(), ((Artifact) o).key());
104 }
105
106 @Override
107 public int hashCode() {
108 return key.hashCode();
109 }
110
111 @Override
112 public String toString() {
113 return artifact.toString();
114 }
115 }