1 package org.apache.maven.archiver; 2 3 /* 4 * Licensed to the Apache Software Foundation (ASF) under one 5 * or more contributor license agreements. See the NOTICE file 6 * distributed with this work for additional information 7 * regarding copyright ownership. The ASF licenses this file 8 * to you under the Apache License, Version 2.0 (the 9 * "License"); you may not use this file except in compliance 10 * with the License. You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, 15 * software distributed under the License is distributed on an 16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 * KIND, either express or implied. See the License for the 18 * specific language governing permissions and limitations 19 * under the License. 20 */ 21 22 /** 23 * Capture common manifest configuration. 24 * 25 * @author <a href="mailto:brett@apache.org">Brett Porter</a> 26 */ 27 // TODO Is this general enough to be in Plexus Archiver? 28 public class ManifestConfiguration 29 { 30 /** 31 * The simple layout. 32 */ 33 public static final String CLASSPATH_LAYOUT_TYPE_SIMPLE = "simple"; 34 35 /** 36 * The layout type 37 */ 38 public static final String CLASSPATH_LAYOUT_TYPE_REPOSITORY = "repository"; 39 40 /** 41 * custom layout type. 42 */ 43 public static final String CLASSPATH_LAYOUT_TYPE_CUSTOM = "custom"; 44 45 private String mainClass; 46 47 private String packageName; 48 49 private boolean addClasspath; 50 51 private boolean addExtensions; 52 53 /** 54 * This gets prefixed to all classpath entries. 55 */ 56 private String classpathPrefix = ""; 57 58 /** 59 * Add default, reproducible entries {@code Created-By} and {@code Build-Jdk-Spec}. 60 * 61 * @since 3.4.0 62 */ 63 private boolean addDefaultEntries = true; 64 65 66 /** 67 * Add build environment information about Maven, JDK, and OS. 68 * 69 * @since 3.4.0 70 */ 71 private boolean addBuildEnvironmentEntries; 72 73 /** 74 * Add default implementation entries if this is an extension specification. 75 * 76 * @since 2.1 77 */ 78 private boolean addDefaultSpecificationEntries; 79 80 /** 81 * Add default implementation entries if this is an extension. 82 * 83 * @since 2.1 84 */ 85 private boolean addDefaultImplementationEntries; 86 87 private String classpathLayoutType = CLASSPATH_LAYOUT_TYPE_SIMPLE; 88 89 private String customClasspathLayout; 90 91 private boolean useUniqueVersions = true; 92 93 /** 94 * <p>Getter for the field <code>mainClass</code>.</p> 95 * 96 * @return mainClass 97 */ 98 public String getMainClass() 99 { 100 return mainClass; 101 } 102 103 /** 104 * <p>Getter for the field <code>packageName</code>.</p> 105 * 106 * @return the package name. 107 */ 108 public String getPackageName() 109 { 110 return packageName; 111 } 112 113 /** 114 * <p>isAddClasspath.</p> 115 * 116 * @return if addClasspath true or false. 117 */ 118 public boolean isAddClasspath() 119 { 120 return addClasspath; 121 } 122 123 /** 124 * <p>isAddDefaultEntries.</p> 125 * 126 * @return {@link #addDefaultEntries} 127 */ 128 public boolean isAddDefaultEntries() 129 { 130 return addDefaultEntries; 131 } 132 133 /** 134 * <p>isAddBuildEnvironmentEntries.</p> 135 * 136 * @return {@link #addBuildEnvironmentEntries} 137 */ 138 public boolean isAddBuildEnvironmentEntries() 139 { 140 return addBuildEnvironmentEntries; 141 } 142 143 /** 144 * <p>isAddDefaultImplementationEntries.</p> 145 * 146 * @return {@link #addDefaultImplementationEntries} 147 */ 148 public boolean isAddDefaultImplementationEntries() 149 { 150 return addDefaultImplementationEntries; 151 } 152 153 /** 154 * <p>isAddDefaultSpecificationEntries.</p> 155 * 156 * @return {@link #addDefaultSpecificationEntries} 157 */ 158 public boolean isAddDefaultSpecificationEntries() 159 { 160 return addDefaultSpecificationEntries; 161 } 162 163 /** 164 * <p>isAddExtensions.</p> 165 * 166 * @return {@link #addExtensions} 167 */ 168 public boolean isAddExtensions() 169 { 170 return addExtensions; 171 } 172 173 /** 174 * <p>Setter for the field <code>addClasspath</code>.</p> 175 * 176 * @param addClasspath turn on addClasspath or off. 177 */ 178 public void setAddClasspath( boolean addClasspath ) 179 { 180 this.addClasspath = addClasspath; 181 } 182 183 /** 184 * <p>Setter for the field <code>addDefaultEntries</code>.</p> 185 * 186 * @param addDefaultEntries add default entries true/false. 187 */ 188 public void setAddDefaultEntries( boolean addDefaultEntries ) 189 { 190 this.addDefaultEntries = addDefaultEntries; 191 } 192 193 /** 194 * <p>Setter for the field <code>addBuildEnvironmentEntries</code>.</p> 195 * 196 * @param addBuildEnvironmentEntries add build environment information true/false. 197 */ 198 public void setAddBuildEnvironmentEntries( boolean addBuildEnvironmentEntries ) 199 { 200 this.addBuildEnvironmentEntries = addBuildEnvironmentEntries; 201 } 202 203 /** 204 * <p>Setter for the field <code>addDefaultImplementationEntries</code>.</p> 205 * 206 * @param addDefaultImplementationEntries true to add default implementations false otherwise. 207 */ 208 public void setAddDefaultImplementationEntries( boolean addDefaultImplementationEntries ) 209 { 210 this.addDefaultImplementationEntries = addDefaultImplementationEntries; 211 } 212 213 /** 214 * <p>Setter for the field <code>addDefaultSpecificationEntries</code>.</p> 215 * 216 * @param addDefaultSpecificationEntries add default specifications true/false. 217 */ 218 public void setAddDefaultSpecificationEntries( boolean addDefaultSpecificationEntries ) 219 { 220 this.addDefaultSpecificationEntries = addDefaultSpecificationEntries; 221 } 222 223 /** 224 * <p>Setter for the field <code>addExtensions</code>.</p> 225 * 226 * @param addExtensions true to add extensions false otherwise. 227 */ 228 public void setAddExtensions( boolean addExtensions ) 229 { 230 this.addExtensions = addExtensions; 231 } 232 233 /** 234 * <p>Setter for the field <code>classpathPrefix</code>.</p> 235 * 236 * @param classpathPrefix The prefix. 237 */ 238 public void setClasspathPrefix( String classpathPrefix ) 239 { 240 this.classpathPrefix = classpathPrefix; 241 } 242 243 /** 244 * <p>Setter for the field <code>mainClass</code>.</p> 245 * 246 * @param mainClass The main class. 247 */ 248 public void setMainClass( String mainClass ) 249 { 250 this.mainClass = mainClass; 251 } 252 253 /** 254 * <p>Setter for the field <code>packageName</code>.</p> 255 * 256 * @param packageName The package name. 257 */ 258 public void setPackageName( String packageName ) 259 { 260 this.packageName = packageName; 261 } 262 263 /** 264 * <p>Getter for the field <code>classpathPrefix</code>.</p> 265 * 266 * @return The classpath prefix. 267 */ 268 public String getClasspathPrefix() 269 { 270 String cpp = classpathPrefix.replaceAll( "\\\\", "/" ); 271 272 if ( cpp.length() != 0 && !cpp.endsWith( "/" ) ) 273 { 274 cpp += "/"; 275 } 276 277 return cpp; 278 } 279 280 /** 281 * Return the type of layout to use when formatting classpath entries. Default is taken from the constant 282 * CLASSPATH_LAYOUT_TYPE_SIMPLE, declared in this class, which has a value of 'simple'. Other values are: 283 * 'repository' (CLASSPATH_LAYOUT_TYPE_REPOSITORY, or the same as a maven classpath layout), and 'custom' 284 * (CLASSPATH_LAYOUT_TYPE_CUSTOM). <br> 285 * <b>NOTE:</b> If you specify a type of 'custom' you MUST set 286 * {@link org.apache.maven.archiver.ManifestConfiguration#setCustomClasspathLayout(String)}. 287 * 288 * @return The classpath layout type. 289 */ 290 public String getClasspathLayoutType() 291 { 292 return classpathLayoutType; 293 } 294 295 /** 296 * Set the type of layout to use when formatting classpath entries. Should be one of: 'simple' 297 * (CLASSPATH_LAYOUT_TYPE_SIMPLE), 'repository' (CLASSPATH_LAYOUT_TYPE_REPOSITORY, or the same as a maven classpath 298 * layout), and 'custom' (CLASSPATH_LAYOUT_TYPE_CUSTOM). The constant names noted here are defined in the 299 * {@link org.apache.maven.archiver.ManifestConfiguration} class. <br> 300 * <b>NOTE:</b> If you specify a type of 'custom' you MUST set 301 * {@link org.apache.maven.archiver.ManifestConfiguration#setCustomClasspathLayout(String)}. 302 * 303 * @param classpathLayoutType The classpath layout type. 304 */ 305 public void setClasspathLayoutType( String classpathLayoutType ) 306 { 307 this.classpathLayoutType = classpathLayoutType; 308 } 309 310 /** 311 * Retrieve the layout expression for use when the layout type set in 312 * {@link org.apache.maven.archiver.ManifestConfiguration#setClasspathLayoutType(String)} has the value 'custom'. 313 * <b>The default value is 314 * null.</b> Expressions will be evaluated against the following ordered list of classpath-related objects: 315 * <ol> 316 * <li>The current {@code Artifact} instance, if one exists.</li> 317 * <li>The current {@code ArtifactHandler} instance from the artifact above.</li> 318 * </ol> 319 * <br> 320 * <b>NOTE:</b> If you specify a layout type of 'custom' you MUST set this layout expression. 321 * 322 * @return The custom classpath layout. 323 */ 324 public String getCustomClasspathLayout() 325 { 326 return customClasspathLayout; 327 } 328 329 /** 330 * Set the layout expression for use when the layout type set in 331 * {@link org.apache.maven.archiver.ManifestConfiguration#setClasspathLayoutType(String)} has the value 'custom'. 332 * Expressions will be 333 * evaluated against the following ordered list of classpath-related objects: 334 * <ol> 335 * <li>The current {@code Artifact} instance, if one exists.</li> 336 * <li>The current {@code ArtifactHandler} instance from the artifact above.</li> 337 * </ol> 338 * <br> 339 * <b>NOTE:</b> If you specify a layout type of 'custom' you MUST set this layout expression. 340 * You can take a look at 341 * <ol> 342 * <li>{@link org.apache.maven.archiver.MavenArchiver#SIMPLE_LAYOUT}</li> 343 * <li>{@link org.apache.maven.archiver.MavenArchiver#SIMPLE_LAYOUT_NONUNIQUE}</li> 344 * <li>{@link org.apache.maven.archiver.MavenArchiver#REPOSITORY_LAYOUT}</li> 345 * <li>{@link org.apache.maven.archiver.MavenArchiver#REPOSITORY_LAYOUT_NONUNIQUE}</li> 346 * </ol> 347 * how such an expression looks like. 348 * 349 * @param customClasspathLayout The custom classpath layout. 350 */ 351 public void setCustomClasspathLayout( String customClasspathLayout ) 352 { 353 this.customClasspathLayout = customClasspathLayout; 354 } 355 356 /** 357 * Retrieve the flag for whether snapshot artifacts should be added to the classpath using the 358 * timestamp/buildnumber version (the default, when this flag is true), or using the generic 359 * -SNAPSHOT version (when the flag is false). <br> 360 * <b>NOTE:</b> If the snapshot was installed locally, this flag will not have an effect on 361 * that artifact's inclusion, since it will have the same version either way (i.e. -SNAPSHOT naming). 362 * 363 * @return The state of {@link #useUniqueVersions} 364 */ 365 public boolean isUseUniqueVersions() 366 { 367 return useUniqueVersions; 368 } 369 370 /** 371 * Set the flag for whether snapshot artifacts should be added to the classpath using the timestamp/buildnumber 372 * version (the default, when this flag is true), or using the generic -SNAPSHOT version (when the flag is false). 373 * <br> 374 * <b>NOTE:</b> If the snapshot was installed locally, this flag will not have an effect on that artifact's 375 * inclusion, since it will have the same version either way (i.e. -SNAPSHOT naming). 376 * 377 * @param useUniqueVersions true to use unique versions or not. 378 */ 379 public void setUseUniqueVersions( boolean useUniqueVersions ) 380 { 381 this.useUniqueVersions = useUniqueVersions; 382 } 383 }