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