-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
ArtifactCoords.java
139 lines (116 loc) · 4.47 KB
/
ArtifactCoords.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package io.quarkus.maven;
import io.quarkus.maven.dependency.GACT;
import java.io.Serializable;
import java.util.Objects;
public class ArtifactCoords implements io.quarkus.maven.dependency.ArtifactCoords, Serializable {
public static ArtifactCoords fromString(String str) {
return new ArtifactCoords(split(str, new String[5]));
}
public static ArtifactCoords pom(String groupId, String artifactId, String version) {
return new ArtifactCoords(groupId, artifactId, null, TYPE_POM, version);
}
protected static String[] split(String str, String[] parts) {
final int versionSep = str.lastIndexOf(':');
if (versionSep <= 0 || versionSep == str.length() - 1) {
throw new IllegalArgumentException("One of type, version or separating them ':' is missing from '" + str + "'");
}
parts[4] = str.substring(versionSep + 1);
return GACT.split(str, parts, versionSep);
}
protected final String groupId;
protected final String artifactId;
protected final String classifier;
protected final String type;
protected final String version;
protected transient ArtifactKey key;
protected ArtifactCoords(String[] parts) {
groupId = parts[0];
artifactId = parts[1];
classifier = parts[2] == null ? DEFAULT_CLASSIFIER : parts[2];
type = parts[3] == null ? TYPE_JAR : parts[3];
version = parts[4];
}
public ArtifactCoords(ArtifactKey key, String version) {
this.key = key;
this.groupId = key.getGroupId();
this.artifactId = key.getArtifactId();
this.classifier = key.getClassifier();
this.type = key.getType();
this.version = version;
}
public ArtifactCoords(String groupId, String artifactId, String version) {
this(groupId, artifactId, DEFAULT_CLASSIFIER, TYPE_JAR, version);
}
public ArtifactCoords(String groupId, String artifactId, String type, String version) {
this(groupId, artifactId, DEFAULT_CLASSIFIER, type, version);
}
public ArtifactCoords(String groupId, String artifactId, String classifier, String type, String version) {
this.groupId = groupId;
this.artifactId = artifactId;
this.classifier = classifier == null ? DEFAULT_CLASSIFIER : classifier;
this.type = type == null ? TYPE_JAR : type;
this.version = version;
}
public String getGroupId() {
return groupId;
}
public String getArtifactId() {
return artifactId;
}
public String getClassifier() {
return classifier;
}
public String getType() {
return type;
}
public String getVersion() {
return version;
}
public ArtifactKey getKey() {
return key == null ? key = new ArtifactKey(groupId, artifactId, classifier, type) : key;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof io.quarkus.maven.dependency.ArtifactCoords)) {
return false;
}
io.quarkus.maven.dependency.ArtifactCoords that = (io.quarkus.maven.dependency.ArtifactCoords) o;
return Objects.equals(groupId, that.getGroupId()) &&
Objects.equals(artifactId, that.getArtifactId()) &&
Objects.equals(classifier, that.getClassifier()) &&
Objects.equals(type, that.getType()) &&
Objects.equals(version, that.getVersion());
}
@Override
public int hashCode() {
return Objects.hash(groupId, artifactId, classifier, type, version);
}
@Override
public String toString() {
final StringBuilder buf = new StringBuilder();
append(buf);
return buf.toString();
}
protected StringBuilder append(final StringBuilder buf) {
buf.append(groupId).append(':').append(artifactId).append(':');
if (classifier != null && !classifier.isEmpty()) {
buf.append(classifier);
}
return buf.append(':').append(type).append(':').append(version);
}
public String toCompactCoords() {
final StringBuilder b = new StringBuilder();
b.append(getGroupId()).append(':').append(getArtifactId()).append(':');
if (!getClassifier().isEmpty()) {
b.append(getClassifier()).append(':');
}
if (!TYPE_JAR.equals(getType())) {
b.append(getType()).append(':');
}
b.append(getVersion());
return b.toString();
}
}