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