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 * @version $Id$ 27 */ 28 // TODO Is this general enough to be in Plexus Archiver? 29 public class ManifestConfiguration 30 { 31 /** 32 * The simple layout. 33 */ 34 public static final String CLASSPATH_LAYOUT_TYPE_SIMPLE = "simple"; 35 36 /** 37 * The layout type 38 */ 39 public static final String CLASSPATH_LAYOUT_TYPE_REPOSITORY = "repository"; 40 41 /** 42 * custom layout type. 43 */ 44 public static final String CLASSPATH_LAYOUT_TYPE_CUSTOM = "custom"; 45 46 private String mainClass; 47 48 private String packageName; 49 50 private boolean addClasspath; 51 52 private boolean addExtensions; 53 54 /** 55 * This gets prefixed to all classpath entries. 56 */ 57 private String classpathPrefix = ""; 58 59 /** 60 * Add default, reproducible entries {@code Created-By} and {@code Build-Jdk-Spec}. 61 * 62 * @since 3.4.0 63 */ 64 private boolean addDefaultEntries = true; 65 66 67 /** 68 * Add build environment information about Maven, JDK, and OS. 69 * 70 * @since 3.4.0 71 */ 72 private boolean addBuildEnvironmentEntries; 73 74 /** 75 * Add default implementation entries if this is an extension specification. 76 * 77 * @since 2.1 78 */ 79 private boolean addDefaultSpecificationEntries; 80 81 /** 82 * Add default implementation entries if this is an extension. 83 * 84 * @since 2.1 85 */ 86 private boolean addDefaultImplementationEntries; 87 88 private String classpathLayoutType = CLASSPATH_LAYOUT_TYPE_SIMPLE; 89 90 private String customClasspathLayout; 91 92 private boolean useUniqueVersions = true; 93 94 /** 95 * @return mainClass 96 */ 97 public String getMainClass() 98 { 99 return mainClass; 100 } 101 102 /** 103 * @return the package name. 104 */ 105 public String getPackageName() 106 { 107 return packageName; 108 } 109 110 /** 111 * @return if addClasspath true or false. 112 */ 113 public boolean isAddClasspath() 114 { 115 return addClasspath; 116 } 117 118 /** 119 * @return {@link #addDefaultEntries} 120 */ 121 public boolean isAddDefaultEntries() 122 { 123 return addDefaultEntries; 124 } 125 126 /** 127 * @return {@link #addBuildEnvironmentEntries} 128 */ 129 public boolean isAddBuildEnvironmentEntries() 130 { 131 return addBuildEnvironmentEntries; 132 } 133 134 /** 135 * @return {@link #addDefaultImplementationEntries} 136 */ 137 public boolean isAddDefaultImplementationEntries() 138 { 139 return addDefaultImplementationEntries; 140 } 141 142 /** 143 * @return {@link #addDefaultSpecificationEntries} 144 */ 145 public boolean isAddDefaultSpecificationEntries() 146 { 147 return addDefaultSpecificationEntries; 148 } 149 150 /** 151 * @return {@link #addExtensions} 152 */ 153 public boolean isAddExtensions() 154 { 155 return addExtensions; 156 } 157 158 /** 159 * @param addClasspath turn on addClasspath or off. 160 */ 161 public void setAddClasspath( boolean addClasspath ) 162 { 163 this.addClasspath = addClasspath; 164 } 165 166 /** 167 * @param addDefaultEntries add default entries true/false. 168 */ 169 public void setAddDefaultEntries( boolean addDefaultEntries ) 170 { 171 this.addDefaultEntries = addDefaultEntries; 172 } 173 174 /** 175 * @param addBuildEnvironmentEntries add build environment information true/false. 176 */ 177 public void setAddBuildEnvironmentEntries( boolean addBuildEnvironmentEntries ) 178 { 179 this.addBuildEnvironmentEntries = addBuildEnvironmentEntries; 180 } 181 182 /** 183 * @param addDefaultImplementationEntries true to add default implementations false otherwise. 184 */ 185 public void setAddDefaultImplementationEntries( boolean addDefaultImplementationEntries ) 186 { 187 this.addDefaultImplementationEntries = addDefaultImplementationEntries; 188 } 189 190 /** 191 * @param addDefaultSpecificationEntries add default specifications true/false. 192 */ 193 public void setAddDefaultSpecificationEntries( boolean addDefaultSpecificationEntries ) 194 { 195 this.addDefaultSpecificationEntries = addDefaultSpecificationEntries; 196 } 197 198 /** 199 * @param addExtensions true to add extensions false otherwise. 200 */ 201 public void setAddExtensions( boolean addExtensions ) 202 { 203 this.addExtensions = addExtensions; 204 } 205 206 /** 207 * @param classpathPrefix The prefix. 208 */ 209 public void setClasspathPrefix( String classpathPrefix ) 210 { 211 this.classpathPrefix = classpathPrefix; 212 } 213 214 /** 215 * @param mainClass The main class. 216 */ 217 public void setMainClass( String mainClass ) 218 { 219 this.mainClass = mainClass; 220 } 221 222 /** 223 * @param packageName The package name. 224 */ 225 public void setPackageName( String packageName ) 226 { 227 this.packageName = packageName; 228 } 229 230 /** 231 * @return The classpath prefix. 232 */ 233 public String getClasspathPrefix() 234 { 235 String cpp = classpathPrefix.replaceAll( "\\\\", "/" ); 236 237 if ( cpp.length() != 0 && !cpp.endsWith( "/" ) ) 238 { 239 cpp += "/"; 240 } 241 242 return cpp; 243 } 244 245 /** 246 * Return the type of layout to use when formatting classpath entries. Default is taken from the constant 247 * CLASSPATH_LAYOUT_TYPE_SIMPLE, declared in this class, which has a value of 'simple'. Other values are: 248 * 'repository' (CLASSPATH_LAYOUT_TYPE_REPOSITORY, or the same as a maven classpath layout), and 'custom' 249 * (CLASSPATH_LAYOUT_TYPE_CUSTOM). <br> 250 * <b>NOTE:</b> If you specify a type of 'custom' you MUST set 251 * {@link ManifestConfiguration#setCustomClasspathLayout(String)}. 252 * @return The classpath layout type. 253 */ 254 public String getClasspathLayoutType() 255 { 256 return classpathLayoutType; 257 } 258 259 /** 260 * Set the type of layout to use when formatting classpath entries. Should be one of: 'simple' 261 * (CLASSPATH_LAYOUT_TYPE_SIMPLE), 'repository' (CLASSPATH_LAYOUT_TYPE_REPOSITORY, or the same as a maven classpath 262 * layout), and 'custom' (CLASSPATH_LAYOUT_TYPE_CUSTOM). The constant names noted here are defined in the 263 * {@link ManifestConfiguration} class. <br> 264 * <b>NOTE:</b> If you specify a type of 'custom' you MUST set 265 * {@link ManifestConfiguration#setCustomClasspathLayout(String)}. 266 * @param classpathLayoutType The classpath layout type. 267 */ 268 public void setClasspathLayoutType( String classpathLayoutType ) 269 { 270 this.classpathLayoutType = classpathLayoutType; 271 } 272 273 /** 274 * Retrieve the layout expression for use when the layout type set in 275 * {@link ManifestConfiguration#setClasspathLayoutType(String)} has the value 'custom'. <b>The default value is 276 * null.</b> Expressions will be evaluated against the following ordered list of classpath-related objects: 277 * <ol> 278 * <li>The current {@code Artifact} instance, if one exists.</li> 279 * <li>The current {@code ArtifactHandler} instance from the artifact above.</li> 280 * </ol> 281 * <br> 282 * <b>NOTE:</b> If you specify a layout type of 'custom' you MUST set this layout expression. 283 * @return The custom classpath layout. 284 */ 285 public String getCustomClasspathLayout() 286 { 287 return customClasspathLayout; 288 } 289 290 /** 291 * Set the layout expression for use when the layout type set in 292 * {@link ManifestConfiguration#setClasspathLayoutType(String)} has the value 'custom'. Expressions will be 293 * evaluated against the following ordered list of classpath-related objects: 294 * <ol> 295 * <li>The current {@code Artifact} instance, if one exists.</li> 296 * <li>The current {@code ArtifactHandler} instance from the artifact above.</li> 297 * </ol> 298 * <br> 299 * <b>NOTE:</b> If you specify a layout type of 'custom' you MUST set this layout expression. 300 * You can take a look at 301 * <ol> 302 * <li>{@link MavenArchiver#SIMPLE_LAYOUT}</li> 303 * <li>{@link MavenArchiver#SIMPLE_LAYOUT_NONUNIQUE}</li> 304 * <li>{@link MavenArchiver#REPOSITORY_LAYOUT}</li> 305 * <li>{@link MavenArchiver#REPOSITORY_LAYOUT_NONUNIQUE}</li> 306 * </ol> 307 * how such an expression looks like. 308 * @param customClasspathLayout The custom classpath layout. 309 */ 310 public void setCustomClasspathLayout( String customClasspathLayout ) 311 { 312 this.customClasspathLayout = customClasspathLayout; 313 } 314 315 /** 316 * Retrieve the flag for whether snapshot artifacts should be added to the classpath using the 317 * timestamp/buildnumber version (the default, when this flag is true), or using the generic 318 * -SNAPSHOT version (when the flag is false). <br> 319 * <b>NOTE:</b> If the snapshot was installed locally, this flag will not have an effect on 320 * that artifact's inclusion, since it will have the same version either way (i.e. -SNAPSHOT naming). 321 * 322 * @return The state of {@link #useUniqueVersions} 323 */ 324 public boolean isUseUniqueVersions() 325 { 326 return useUniqueVersions; 327 } 328 329 /** 330 * Set the flag for whether snapshot artifacts should be added to the classpath using the timestamp/buildnumber 331 * version (the default, when this flag is true), or using the generic -SNAPSHOT version (when the flag is false). 332 * <br> 333 * <b>NOTE:</b> If the snapshot was installed locally, this flag will not have an effect on that artifact's 334 * inclusion, since it will have the same version either way (i.e. -SNAPSHOT naming). 335 * @param useUniqueVersions true to use unique versions or not. 336 */ 337 public void setUseUniqueVersions( boolean useUniqueVersions ) 338 { 339 this.useUniqueVersions = useUniqueVersions; 340 } 341 }