View Javadoc
1   /*
2    * This file is part of dependency-check-core.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   *
16   * Copyright (c) 2014 Jeremy Long. All Rights Reserved.
17   */
18  package org.owasp.dependencycheck.data.nexus;
19  
20  import java.io.Serializable;
21  import javax.annotation.concurrent.ThreadSafe;
22  
23  /**
24   * Simple bean representing a Maven Artifact.
25   *
26   * @author colezlaw
27   * @author nhenneaux
28   */
29  @ThreadSafe
30  public class MavenArtifact implements Serializable {
31  
32      /**
33       * Generated UID.
34       */
35      private static final long serialVersionUID = -9112154330099159722L;
36  
37      /**
38       * The groupId
39       */
40      private String groupId;
41  
42      /**
43       * The artifactId
44       */
45      private String artifactId;
46  
47      /**
48       * The version
49       */
50      private String version;
51  
52      /**
53       * The artifact URL. This may change depending on which Nexus server the
54       * search took place.
55       */
56      private String artifactUrl;
57      /**
58       * The URL to download the POM from.
59       */
60      private String pomUrl;
61  
62      /**
63       * Creates an empty MavenArtifact.
64       */
65      public MavenArtifact() {
66      }
67  
68      /**
69       * Creates a MavenArtifact with the given attributes.
70       *
71       * @param groupId the groupId
72       * @param artifactId the artifactId
73       * @param version the version
74       */
75      public MavenArtifact(String groupId, String artifactId, String version) {
76          this.groupId = groupId;
77          this.artifactId = artifactId;
78          this.version = version;
79      }
80  
81      /**
82       * Creates a MavenArtifact with the given attributes.
83       *
84       * @param groupId the groupId
85       * @param artifactId the artifactId
86       * @param version the version
87       * @param url the artifactLink URL
88       */
89      public MavenArtifact(String groupId, String artifactId, String version, String url) {
90          this.groupId = groupId;
91          this.artifactId = artifactId;
92          this.version = version;
93          this.artifactUrl = url;
94      }
95  
96      /**
97       * Creates a MavenArtifact with the given attributes.
98       *
99       * @param groupId the groupId
100      * @param artifactId the artifactId
101      * @param version the version
102      * @param artifactUrl the artifactLink URL
103      * @param pomUrl the pomUrl
104      */
105     public MavenArtifact(String groupId, String artifactId, String version, String artifactUrl, String pomUrl) {
106         this.groupId = groupId;
107         this.artifactId = artifactId;
108         this.version = version;
109         this.artifactUrl = artifactUrl;
110         this.pomUrl = pomUrl;
111     }
112 
113     /**
114      * Tries to determine the URL to the pom.xml.
115      *
116      * @param artifactId the artifact id
117      * @param version the version
118      * @param artifactUrl the artifact URL
119      * @return the string representation of the URL
120      */
121     public static String derivePomUrl(String artifactId, String version, String artifactUrl) {
122         return artifactUrl.substring(0, artifactUrl.lastIndexOf('/')) + '/' + artifactId + '-' + version + ".pom";
123     }
124 
125     /**
126      * Returns the Artifact coordinates as a String.
127      *
128      * @return the String representation of the artifact coordinates
129      */
130     @Override
131     public String toString() {
132         return String.format("%s:%s:%s", groupId, artifactId, version);
133     }
134 
135     /**
136      * Gets the groupId.
137      *
138      * @return the groupId
139      */
140     public String getGroupId() {
141         return groupId;
142     }
143 
144     /**
145      * Sets the groupId.
146      *
147      * @param groupId the groupId
148      */
149     public void setGroupId(String groupId) {
150         this.groupId = groupId;
151     }
152 
153     /**
154      * Gets the artifactId.
155      *
156      * @return the artifactId
157      */
158     public String getArtifactId() {
159         return artifactId;
160     }
161 
162     /**
163      * Sets the artifactId.
164      *
165      * @param artifactId the artifactId
166      */
167     public void setArtifactId(String artifactId) {
168         this.artifactId = artifactId;
169     }
170 
171     /**
172      * Gets the version.
173      *
174      * @return the version
175      */
176     public String getVersion() {
177         return version;
178     }
179 
180     /**
181      * Sets the version.
182      *
183      * @param version the version
184      */
185     public void setVersion(String version) {
186         this.version = version;
187     }
188 
189     /**
190      * Gets the artifactUrl.
191      *
192      * @return the artifactUrl
193      */
194     public String getArtifactUrl() {
195         return artifactUrl;
196     }
197 
198     /**
199      * Sets the artifactUrl.
200      *
201      * @param artifactUrl the artifactUrl
202      */
203     public void setArtifactUrl(String artifactUrl) {
204         this.artifactUrl = artifactUrl;
205     }
206 
207     /**
208      * Get the value of pomUrl.
209      *
210      * @return the value of pomUrl
211      */
212     public String getPomUrl() {
213         return pomUrl;
214     }
215 
216     /**
217      * Set the value of pomUrl.
218      *
219      * @param pomUrl new value of pomUrl
220      */
221     public void setPomUrl(String pomUrl) {
222         this.pomUrl = pomUrl;
223     }
224 
225 }