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