| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| MavenArtifact |
|
| 1.1333333333333333;1.133 |
| 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 | /** | |
| 21 | * Simple bean representing a Maven Artifact. | |
| 22 | * | |
| 23 | * @author colezlaw | |
| 24 | */ | |
| 25 | public class MavenArtifact { | |
| 26 | ||
| 27 | /** | |
| 28 | * The base URL for download artifacts from Central. | |
| 29 | */ | |
| 30 | private static final String CENTRAL_CONTENT_URL = "http://search.maven.org/remotecontent?filepath="; | |
| 31 | ||
| 32 | /** | |
| 33 | * The groupId | |
| 34 | */ | |
| 35 | private String groupId; | |
| 36 | ||
| 37 | /** | |
| 38 | * The artifactId | |
| 39 | */ | |
| 40 | private String artifactId; | |
| 41 | ||
| 42 | /** | |
| 43 | * The version | |
| 44 | */ | |
| 45 | private String version; | |
| 46 | ||
| 47 | /** | |
| 48 | * The artifact url. This may change depending on which Nexus server the search took place. | |
| 49 | */ | |
| 50 | private String artifactUrl; | |
| 51 | /** | |
| 52 | * The url to download the POM from. | |
| 53 | */ | |
| 54 | private String pomUrl; | |
| 55 | ||
| 56 | /** | |
| 57 | * Creates an empty MavenArtifact. | |
| 58 | */ | |
| 59 | 0 | public MavenArtifact() { |
| 60 | 0 | } |
| 61 | ||
| 62 | /** | |
| 63 | * Creates a MavenArtifact with the given attributes. | |
| 64 | * | |
| 65 | * @param groupId the groupId | |
| 66 | * @param artifactId the artifactId | |
| 67 | * @param version the version | |
| 68 | */ | |
| 69 | 0 | public MavenArtifact(String groupId, String artifactId, String version) { |
| 70 | 0 | this.groupId = groupId; |
| 71 | 0 | this.artifactId = artifactId; |
| 72 | 0 | this.version = version; |
| 73 | 0 | } |
| 74 | ||
| 75 | /** | |
| 76 | * Creates a MavenArtifact with the given attributes. | |
| 77 | * | |
| 78 | * @param groupId the groupId | |
| 79 | * @param artifactId the artifactId | |
| 80 | * @param version the version | |
| 81 | * @param jarAvailable if the jar file is available from central | |
| 82 | * @param pomAvailable if the pom file is available from central | |
| 83 | */ | |
| 84 | 3 | public MavenArtifact(String groupId, String artifactId, String version, boolean jarAvailable, boolean pomAvailable) { |
| 85 | 3 | this.groupId = groupId; |
| 86 | 3 | this.artifactId = artifactId; |
| 87 | 3 | this.version = version; |
| 88 | 3 | if (jarAvailable) { |
| 89 | //org/springframework/spring-core/3.2.0.RELEASE/spring-core-3.2.0.RELEASE.pom | |
| 90 | 3 | this.artifactUrl = this.CENTRAL_CONTENT_URL + groupId.replace('.', '/') + "/" + artifactId.replace('.', '/') + "/" |
| 91 | + version + "/" + artifactId + "-" + version + ".jar"; | |
| 92 | } | |
| 93 | 3 | if (pomAvailable) { |
| 94 | //org/springframework/spring-core/3.2.0.RELEASE/spring-core-3.2.0.RELEASE.pom | |
| 95 | 3 | this.pomUrl = this.CENTRAL_CONTENT_URL + groupId.replace('.', '/') + "/" + artifactId.replace('.', '/') + "/" |
| 96 | + version + "/" + artifactId + "-" + version + ".pom"; | |
| 97 | } | |
| 98 | 3 | } |
| 99 | ||
| 100 | /** | |
| 101 | * Creates a MavenArtifact with the given attributes. | |
| 102 | * | |
| 103 | * @param groupId the groupId | |
| 104 | * @param artifactId the artifactId | |
| 105 | * @param version the version | |
| 106 | * @param url the artifactLink url | |
| 107 | */ | |
| 108 | 2 | public MavenArtifact(String groupId, String artifactId, String version, String url) { |
| 109 | 2 | this.groupId = groupId; |
| 110 | 2 | this.artifactId = artifactId; |
| 111 | 2 | this.version = version; |
| 112 | 2 | this.artifactUrl = url; |
| 113 | 2 | } |
| 114 | ||
| 115 | /** | |
| 116 | * Returns the Artifact coordinates as a String. | |
| 117 | * | |
| 118 | * @return the String representation of the artifact coordinates | |
| 119 | */ | |
| 120 | @Override | |
| 121 | public String toString() { | |
| 122 | 2 | return String.format("%s:%s:%s", groupId, artifactId, version); |
| 123 | } | |
| 124 | ||
| 125 | /** | |
| 126 | * Sets the groupId. | |
| 127 | * | |
| 128 | * @param groupId the groupId | |
| 129 | */ | |
| 130 | public void setGroupId(String groupId) { | |
| 131 | 0 | this.groupId = groupId; |
| 132 | 0 | } |
| 133 | ||
| 134 | /** | |
| 135 | * Gets the groupId. | |
| 136 | * | |
| 137 | * @return the groupId | |
| 138 | */ | |
| 139 | public String getGroupId() { | |
| 140 | 5 | return groupId; |
| 141 | } | |
| 142 | ||
| 143 | /** | |
| 144 | * Sets the artifactId. | |
| 145 | * | |
| 146 | * @param artifactId the artifactId | |
| 147 | */ | |
| 148 | public void setArtifactId(String artifactId) { | |
| 149 | 0 | this.artifactId = artifactId; |
| 150 | 0 | } |
| 151 | ||
| 152 | /** | |
| 153 | * Gets the artifactId. | |
| 154 | * | |
| 155 | * @return the artifactId | |
| 156 | */ | |
| 157 | public String getArtifactId() { | |
| 158 | 5 | return artifactId; |
| 159 | } | |
| 160 | ||
| 161 | /** | |
| 162 | * Sets the version. | |
| 163 | * | |
| 164 | * @param version the version | |
| 165 | */ | |
| 166 | public void setVersion(String version) { | |
| 167 | 0 | this.version = version; |
| 168 | 0 | } |
| 169 | ||
| 170 | /** | |
| 171 | * Gets the version. | |
| 172 | * | |
| 173 | * @return the version | |
| 174 | */ | |
| 175 | public String getVersion() { | |
| 176 | 5 | return version; |
| 177 | } | |
| 178 | ||
| 179 | /** | |
| 180 | * Sets the artifactUrl. | |
| 181 | * | |
| 182 | * @param artifactUrl the artifactUrl | |
| 183 | */ | |
| 184 | public void setArtifactUrl(String artifactUrl) { | |
| 185 | 0 | this.artifactUrl = artifactUrl; |
| 186 | 0 | } |
| 187 | ||
| 188 | /** | |
| 189 | * Gets the artifactUrl. | |
| 190 | * | |
| 191 | * @return the artifactUrl | |
| 192 | */ | |
| 193 | public String getArtifactUrl() { | |
| 194 | 4 | return artifactUrl; |
| 195 | } | |
| 196 | ||
| 197 | /** | |
| 198 | * Get the value of pomUrl. | |
| 199 | * | |
| 200 | * @return the value of pomUrl | |
| 201 | */ | |
| 202 | public String getPomUrl() { | |
| 203 | 0 | return pomUrl; |
| 204 | } | |
| 205 | ||
| 206 | /** | |
| 207 | * Set the value of pomUrl. | |
| 208 | * | |
| 209 | * @param pomUrl new value of pomUrl | |
| 210 | */ | |
| 211 | public void setPomUrl(String pomUrl) { | |
| 212 | 0 | this.pomUrl = pomUrl; |
| 213 | 0 | } |
| 214 | ||
| 215 | } | |
| 216 | ||
| 217 | // vim: cc=120:sw=4:ts=4:sts=4 |