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 import org.apache.maven.repository.internal.DefaultModelVersionParser;
28
29 import static org.apache.maven.internal.impl.Utils.nonNull;
30
31
32
33
34 public class DefaultArtifact implements Artifact {
35 private final @Nonnull InternalSession session;
36 private final @Nonnull org.eclipse.aether.artifact.Artifact artifact;
37 private final String key;
38
39 public DefaultArtifact(@Nonnull InternalSession session, @Nonnull org.eclipse.aether.artifact.Artifact artifact) {
40 this.session = nonNull(session, "session");
41 this.artifact = nonNull(artifact, "artifact");
42 this.key = getGroupId()
43 + ':'
44 + getArtifactId()
45 + ':'
46 + getExtension()
47 + (getClassifier().isEmpty() ? "" : ":" + getClassifier())
48 + ':'
49 + getVersion();
50 }
51
52 public org.eclipse.aether.artifact.Artifact getArtifact() {
53 return artifact;
54 }
55
56 @Override
57 public String key() {
58 return key;
59 }
60
61 @Nonnull
62 @Override
63 public String getGroupId() {
64 return artifact.getGroupId();
65 }
66
67 @Nonnull
68 @Override
69 public String getArtifactId() {
70 return artifact.getArtifactId();
71 }
72
73 @Nonnull
74 @Override
75 public Version getVersion() {
76 return session.parseVersion(artifact.getVersion());
77 }
78
79 @Override
80 public Version getBaseVersion() {
81 return session.parseVersion(artifact.getBaseVersion());
82 }
83
84 @Nonnull
85 @Override
86 public String getExtension() {
87 return artifact.getExtension();
88 }
89
90 @Nonnull
91 @Override
92 public String getClassifier() {
93 return artifact.getClassifier();
94 }
95
96 @Override
97 public boolean isSnapshot() {
98 return DefaultModelVersionParser.checkSnapshot(artifact.getVersion());
99 }
100
101 @Nonnull
102 @Override
103 public ArtifactCoordinate toCoordinate() {
104 return session.createArtifactCoordinate(this);
105 }
106
107 @Override
108 public boolean equals(Object o) {
109 return o instanceof Artifact && Objects.equals(key(), ((Artifact) o).key());
110 }
111
112 @Override
113 public int hashCode() {
114 return key.hashCode();
115 }
116
117 @Override
118 public String toString() {
119 return artifact.toString();
120 }
121 }