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.apache.maven.shared.jar.identification;
20  
21  import java.util.ArrayList;
22  import java.util.List;
23  
24  /**
25   * Gathered Maven information about the JAR file. Stores both assumed/validated values and potential values.
26   *
27   * @see org.apache.maven.shared.jar.identification.JarIdentificationAnalysis#analyze(org.apache.maven.shared.jar.JarAnalyzer)
28   */
29  public class JarIdentification {
30      /**
31       * The group ID derived or guessed from the list of potentials of the JAR.
32       */
33      private String groupId;
34  
35      /**
36       * The artifact ID derived or guessed from the list of potentials of the JAR.
37       */
38      private String artifactId;
39  
40      /**
41       * The version derived or guessed from the list of potentials of the JAR.
42       */
43      private String version;
44  
45      /**
46       * The project name derived or guessed from the list of potentials of the JAR.
47       */
48      private String name;
49  
50      /**
51       * The vendor (organization name) derived or guessed from the list of potentials of the JAR.
52       */
53      private String vendor;
54  
55      /**
56       * The list of possible group IDs discovered.
57       */
58      private final List<String> potentialGroupIds = new ArrayList<>();
59  
60      /**
61       * The list of possible artifact IDs discovered.
62       */
63      private final List<String> potentialArtifactIds = new ArrayList<>();
64  
65      /**
66       * The list of possible versions discovered.
67       */
68      private final List<String> potentialVersions = new ArrayList<>();
69  
70      /**
71       * The list of possible artifact names discovered.
72       */
73      private final List<String> potentialNames = new ArrayList<>();
74  
75      /**
76       * The list of possible vendors discovered.
77       */
78      private final List<String> potentialVendors = new ArrayList<>();
79  
80      /**
81       * Add a validated group ID.
82       *
83       * @param groupId the group ID discovered
84       */
85      public void addAndSetGroupId(String groupId) {
86          if (groupId != null) {
87              this.groupId = groupId;
88          }
89  
90          addGroupId(groupId);
91      }
92  
93      /**
94       * Add a potential group ID.
95       *
96       * @param groupId the group ID discovered
97       */
98      public void addGroupId(String groupId) {
99          addUnique(potentialGroupIds, groupId);
100     }
101 
102     /**
103      * Add a validated artifact ID.
104      *
105      * @param artifactId the artifact ID discovered
106      */
107     public void addAndSetArtifactId(String artifactId) {
108         if (artifactId != null) {
109             this.artifactId = artifactId;
110         }
111 
112         addArtifactId(artifactId);
113     }
114 
115     /**
116      * Add a potential artifact ID.
117      *
118      * @param artifactId the artifact ID discovered
119      */
120     public void addArtifactId(String artifactId) {
121         addUnique(potentialArtifactIds, artifactId);
122     }
123 
124     /**
125      * Add a validated version.
126      *
127      * @param version the version discovered
128      */
129     public void addAndSetVersion(String version) {
130         if (version != null) {
131             this.version = version;
132         }
133 
134         addVersion(version);
135     }
136 
137     /**
138      * Add a potential version.
139      *
140      * @param version the version discovered
141      */
142     public void addVersion(String version) {
143         addUnique(potentialVersions, version);
144     }
145 
146     /**
147      * Add a validated vendor name.
148      *
149      * @param name the vendor name discovered
150      */
151     public void addAndSetVendor(String name) {
152         if (name != null) {
153             vendor = name;
154         }
155 
156         addVendor(name);
157     }
158 
159     /**
160      * Add a potential vendor name.
161      *
162      * @param name the vendor name discovered
163      */
164     public void addVendor(String name) {
165         addUnique(potentialVendors, name);
166     }
167 
168     /**
169      * Add a validated artifact name.
170      *
171      * @param name the artifact name discovered
172      */
173     public void addAndSetName(String name) {
174         if (name != null) {
175             this.name = name;
176         }
177 
178         addName(name);
179     }
180 
181     /**
182      * Add a potential artifact name.
183      *
184      * @param name the artifact name discovered
185      */
186     public void addName(String name) {
187         addUnique(potentialNames, name);
188     }
189 
190     private static void addUnique(List<String> list, String value) {
191         if (value != null) {
192             if (!list.contains(value)) {
193                 list.add(value);
194             }
195         }
196     }
197 
198     public String getArtifactId() {
199         return artifactId;
200     }
201 
202     public void setArtifactId(String artifactId) {
203         this.artifactId = artifactId;
204     }
205 
206     public String getGroupId() {
207         return groupId;
208     }
209 
210     public void setGroupId(String groupId) {
211         this.groupId = groupId;
212     }
213 
214     public String getName() {
215         return name;
216     }
217 
218     public void setName(String name) {
219         this.name = name;
220     }
221 
222     public String getVendor() {
223         return vendor;
224     }
225 
226     public void setVendor(String vendor) {
227         this.vendor = vendor;
228     }
229 
230     public String getVersion() {
231         return version;
232     }
233 
234     public void setVersion(String version) {
235         this.version = version;
236     }
237 
238     public List<String> getPotentialVersions() {
239         return potentialVersions;
240     }
241 
242     public List<String> getPotentialNames() {
243         return potentialNames;
244     }
245 
246     public List<String> getPotentialGroupIds() {
247         return potentialGroupIds;
248     }
249 
250     public List<String> getPotentialArtifactIds() {
251         return potentialArtifactIds;
252     }
253 
254     public List<String> getPotentialVendors() {
255         return potentialVendors;
256     }
257 }