blob: 490a92416617b51e4c0d5167bcc72af276e5c7d1 (
plain) (
blame)
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
|
package com.yahoo.container.plugin.util;
import org.apache.maven.artifact.Artifact;
import java.util.Objects;
import static com.yahoo.container.plugin.util.Artifacts.VESPA_GROUP_ID;
/**
* Helper class to work with artifacts. Vespa artifacts have their version set to '*'.
*
* @author gjoranv
*/
public class ArtifactInfo {
private final String groupId;
private final String artifactId;
private final String version;
private ArtifactInfo(String groupId, String artifactId, String version) {
this.groupId = groupId;
this.artifactId = artifactId;
this.version = VESPA_GROUP_ID.equals(groupId) ? "*" : version;
}
public static ArtifactInfo fromArtifact(Artifact artifact) {
return new ArtifactInfo(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion());
}
public static ArtifactInfo fromStringValue(String stringValue) {
var parts = stringValue.trim().split(":");
if (parts.length != 3) {
throw new IllegalArgumentException("Invalid artifact string: " + stringValue);
}
return new ArtifactInfo(parts[0], parts[1], parts[2]);
}
public String stringValue() {
return groupId + ":" + artifactId + ":" + version;
}
@Override
public String toString() {
return stringValue();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ArtifactInfo that = (ArtifactInfo) o;
return Objects.equals(groupId, that.groupId) && Objects.equals(artifactId, that.artifactId) && Objects.equals(version, that.version);
}
@Override
public int hashCode() {
return Objects.hash(groupId, artifactId, version);
}
}
|