Coverage Report - org.owasp.dependencycheck.data.nexus.MavenArtifact
 
Classes in this File Line Coverage Branch Coverage Complexity
MavenArtifact
53%
22/41
50%
3/6
1.2
 
 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 = "//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  
      * @param secureDownload if the jar and pom files should be downloaded using HTTPS.
 84  
      */
 85  3
     public MavenArtifact(String groupId, String artifactId, String version, boolean jarAvailable, boolean pomAvailable, boolean secureDownload) {
 86  3
         this.groupId = groupId;
 87  3
         this.artifactId = artifactId;
 88  3
         this.version = version;
 89  
         String base;
 90  3
         if (secureDownload) {
 91  0
             base = "https:" + CENTRAL_CONTENT_URL;
 92  
         } else {
 93  3
             base = "http:" + CENTRAL_CONTENT_URL;
 94  
         }
 95  3
         if (jarAvailable) {
 96  
             //org/springframework/spring-core/3.2.0.RELEASE/spring-core-3.2.0.RELEASE.pom
 97  3
             this.artifactUrl = base + groupId.replace('.', '/') + '/' + artifactId + '/'
 98  
                     + version + '/' + artifactId + '-' + version + ".jar";
 99  
         }
 100  3
         if (pomAvailable) {
 101  
             //org/springframework/spring-core/3.2.0.RELEASE/spring-core-3.2.0.RELEASE.pom
 102  3
             this.pomUrl = base + groupId.replace('.', '/') + '/' + artifactId + '/'
 103  
                     + version + '/' + artifactId + '-' + version + ".pom";
 104  
         }
 105  3
     }
 106  
 
 107  
     /**
 108  
      * Creates a MavenArtifact with the given attributes.
 109  
      *
 110  
      * @param groupId the groupId
 111  
      * @param artifactId the artifactId
 112  
      * @param version the version
 113  
      * @param url the artifactLink url
 114  
      */
 115  2
     public MavenArtifact(String groupId, String artifactId, String version, String url) {
 116  2
         this.groupId = groupId;
 117  2
         this.artifactId = artifactId;
 118  2
         this.version = version;
 119  2
         this.artifactUrl = url;
 120  2
     }
 121  
 
 122  
     /**
 123  
      * Returns the Artifact coordinates as a String.
 124  
      *
 125  
      * @return the String representation of the artifact coordinates
 126  
      */
 127  
     @Override
 128  
     public String toString() {
 129  1
         return String.format("%s:%s:%s", groupId, artifactId, version);
 130  
     }
 131  
 
 132  
     /**
 133  
      * Sets the groupId.
 134  
      *
 135  
      * @param groupId the groupId
 136  
      */
 137  
     public void setGroupId(String groupId) {
 138  0
         this.groupId = groupId;
 139  0
     }
 140  
 
 141  
     /**
 142  
      * Gets the groupId.
 143  
      *
 144  
      * @return the groupId
 145  
      */
 146  
     public String getGroupId() {
 147  5
         return groupId;
 148  
     }
 149  
 
 150  
     /**
 151  
      * Sets the artifactId.
 152  
      *
 153  
      * @param artifactId the artifactId
 154  
      */
 155  
     public void setArtifactId(String artifactId) {
 156  0
         this.artifactId = artifactId;
 157  0
     }
 158  
 
 159  
     /**
 160  
      * Gets the artifactId.
 161  
      *
 162  
      * @return the artifactId
 163  
      */
 164  
     public String getArtifactId() {
 165  5
         return artifactId;
 166  
     }
 167  
 
 168  
     /**
 169  
      * Sets the version.
 170  
      *
 171  
      * @param version the version
 172  
      */
 173  
     public void setVersion(String version) {
 174  0
         this.version = version;
 175  0
     }
 176  
 
 177  
     /**
 178  
      * Gets the version.
 179  
      *
 180  
      * @return the version
 181  
      */
 182  
     public String getVersion() {
 183  5
         return version;
 184  
     }
 185  
 
 186  
     /**
 187  
      * Sets the artifactUrl.
 188  
      *
 189  
      * @param artifactUrl the artifactUrl
 190  
      */
 191  
     public void setArtifactUrl(String artifactUrl) {
 192  0
         this.artifactUrl = artifactUrl;
 193  0
     }
 194  
 
 195  
     /**
 196  
      * Gets the artifactUrl.
 197  
      *
 198  
      * @return the artifactUrl
 199  
      */
 200  
     public String getArtifactUrl() {
 201  4
         return artifactUrl;
 202  
     }
 203  
 
 204  
     /**
 205  
      * Get the value of pomUrl.
 206  
      *
 207  
      * @return the value of pomUrl
 208  
      */
 209  
     public String getPomUrl() {
 210  0
         return pomUrl;
 211  
     }
 212  
 
 213  
     /**
 214  
      * Set the value of pomUrl.
 215  
      *
 216  
      * @param pomUrl new value of pomUrl
 217  
      */
 218  
     public void setPomUrl(String pomUrl) {
 219  0
         this.pomUrl = pomUrl;
 220  0
     }
 221  
 
 222  
 }
 223  
 
 224  
 // vim: cc=120:sw=4:ts=4:sts=4