1 /* 2 * Copyright 2012 smartics, Kronseder & Reiner GmbH 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 package de.smartics.ci.config.maven; 17 18 import de.smartics.ci.config.hudson.ScmType; 19 import de.smartics.util.lang.Arguments; 20 import de.smartics.util.lang.BlankArgumentException; 21 22 /** 23 * Provides access to information of a Maven POM. 24 */ 25 public final class MavenPom 26 { 27 // ********************************* Fields ********************************* 28 29 // --- constants ------------------------------------------------------------ 30 31 // --- members -------------------------------------------------------------- 32 33 /** 34 * The project's group identifier. 35 */ 36 private String groupId; 37 38 /** 39 * The project's artifact identifier. 40 */ 41 private String artifactId; 42 43 /** 44 * The project's description. 45 */ 46 private String description; 47 48 /** 49 * The type of the SCM. 50 */ 51 private ScmType scmType; 52 53 /** 54 * The URL to the SCM server of the given {@link #getScmType() type}. 55 */ 56 private String scmUrl; 57 58 // ****************************** Initializer ******************************* 59 60 // ****************************** Constructors ****************************** 61 62 /** 63 * Default constructor. 64 */ 65 public MavenPom() 66 { 67 } 68 69 // ****************************** Inner Classes ***************************** 70 71 // ********************************* Methods ******************************** 72 73 // --- init ----------------------------------------------------------------- 74 75 // --- get&set -------------------------------------------------------------- 76 77 /** 78 * Returns the project's group identifier. 79 * 80 * @return the project's group identifier. 81 */ 82 public String getGroupId() 83 { 84 return groupId; 85 } 86 87 /** 88 * Sets the project's group identifier. 89 * 90 * @param groupId the project's group identifier. 91 */ 92 public void setGroupId(final String groupId) 93 { 94 this.groupId = groupId; 95 } 96 97 /** 98 * Returns the project's artifact identifier. 99 * 100 * @return the project's artifact identifier. 101 */ 102 public String getArtifactId() 103 { 104 return artifactId; 105 } 106 107 /** 108 * Sets the project's artifact identifier. 109 * 110 * @param artifactId the project's artifact identifier. 111 */ 112 public void setArtifactId(final String artifactId) 113 { 114 this.artifactId = artifactId; 115 } 116 117 /** 118 * Returns the project's description. 119 * 120 * @return the project's description. 121 */ 122 public String getDescription() 123 { 124 return description; 125 } 126 127 /** 128 * Sets the project's description. 129 * 130 * @param description the project's description. 131 */ 132 public void setDescription(final String description) 133 { 134 this.description = description; 135 } 136 137 /** 138 * Returns the type of the SCM. 139 * 140 * @return the type of the SCM. 141 */ 142 public ScmType getScmType() 143 { 144 return scmType; 145 } 146 147 /** 148 * Returns the URL to the SCM server of the given {@link #getScmType() type}. 149 * 150 * @return the URL to the SCM server of the given {@link #getScmType() type}. 151 */ 152 public String getScmUrl() 153 { 154 return scmUrl; 155 } 156 157 /** 158 * Checks if SCM information is provided. 159 * 160 * @return <code>true</code> if SCM info is provided, <code>false</code> if 161 * not. 162 */ 163 public boolean isScmInfoProvided() 164 { 165 return scmType != null; // && scmUrl != null; 166 } 167 168 /** 169 * Sets the SCM information to the Maven POM. 170 * 171 * @param connectionString the connection string of format 172 * <code>scm:SCM_TYPE:SCM_URL</code>. 173 * @throws BlankArgumentException if {@code connectionString} is 174 * <code>null</code>. 175 * @throws IllegalArgumentException if the {@code connectionString} does not 176 * meet the expected format <code>scm:SCM_TYPE:SCM_URL</code>. 177 */ 178 public void setScmConnectionString(final String connectionString) 179 throws BlankArgumentException, IllegalArgumentException 180 { 181 Arguments.checkNotBlank("connectionString", connectionString); 182 if (!connectionString.startsWith("scm:")) 183 { 184 throw new IllegalArgumentException( 185 "SCM connection string does not start with 'scm:': " 186 + connectionString); 187 } 188 final int endOfScmTypeString = connectionString.indexOf(':', 4); 189 if (endOfScmTypeString == -1) 190 { 191 throw new IllegalArgumentException( 192 "Cannot find SCM type" 193 + " (expected between first and second ':') in connection string: " 194 + connectionString); 195 } 196 final String scmTypeString = 197 connectionString.substring(4, endOfScmTypeString); 198 if ("http".equals(scmTypeString) || "https".equals(scmTypeString)) 199 { 200 throw new IllegalArgumentException( 201 "Cannot find valid SCM type" 202 + " (expected between first and second ':') in connection string: " 203 + connectionString); 204 } 205 final int startOfScmUrl = endOfScmTypeString + 1; 206 if (connectionString.length() <= startOfScmUrl) 207 { 208 throw new IllegalArgumentException( 209 "SCM connection string does not provide an URL: " + connectionString); 210 } 211 212 scmType = ScmType.getValueFor(scmTypeString); 213 scmUrl = connectionString.substring(endOfScmTypeString + 1); 214 } 215 216 // --- business ------------------------------------------------------------- 217 218 // --- object basics -------------------------------------------------------- 219 220 }