1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.aether.internal.test.util;
20
21 class ArtifactDefinition {
22 private String groupId;
23
24 private String artifactId;
25
26 private String extension;
27
28 private String version;
29
30 private String scope = "";
31
32 private String definition;
33
34 private String id;
35
36 private String reference;
37
38 private Boolean optional;
39
40 ArtifactDefinition(String def) {
41 this.definition = def.trim();
42
43 if (definition.startsWith("(")) {
44 int idx = definition.indexOf(')');
45 this.id = definition.substring(1, idx);
46 this.definition = definition.substring(idx + 1);
47 } else if (definition.startsWith("^")) {
48 this.reference = definition.substring(1);
49 return;
50 }
51
52 String[] split = definition.split(":");
53 if (split.length < 4) {
54 throw new IllegalArgumentException(
55 "Need definition like 'gid:aid:ext:ver[:scope]', but was: " + definition);
56 }
57 groupId = split[0];
58 artifactId = split[1];
59 extension = split[2];
60 version = split[3];
61 if (split.length > 4) {
62 scope = split[4];
63 }
64 if (split.length > 5) {
65 if ("optional".equalsIgnoreCase(split[5])) {
66 optional = true;
67 } else if ("!optional".equalsIgnoreCase(split[5])) {
68 optional = false;
69 }
70 }
71 }
72
73 public String getGroupId() {
74 return groupId;
75 }
76
77 public String getArtifactId() {
78 return artifactId;
79 }
80
81 public String getExtension() {
82 return extension;
83 }
84
85 public String getVersion() {
86 return version;
87 }
88
89 public String getScope() {
90 return scope;
91 }
92
93 @Override
94 public String toString() {
95 return definition;
96 }
97
98 public String getId() {
99 return id;
100 }
101
102 public String getReference() {
103 return reference;
104 }
105
106 public boolean isReference() {
107 return reference != null;
108 }
109
110 public boolean hasId() {
111 return id != null;
112 }
113
114 public Boolean getOptional() {
115 return optional;
116 }
117 }