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