View Javadoc
1   package org.eclipse.aether.internal.test.util;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   * 
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   * 
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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 }