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: ManifestConfiguration.java 1738433 2016-04-10 13:09:18Z khmarbaise $ 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 implementation entries if this is an extension specification. 61 * 62 * @since 2.1 63 */ 64 private boolean addDefaultSpecificationEntries; 65 66 /** 67 * Add default implementation entries if this is an extension. 68 * 69 * @since 2.1 70 */ 71 private boolean addDefaultImplementationEntries; 72 73 private String classpathLayoutType = CLASSPATH_LAYOUT_TYPE_SIMPLE; 74 75 private String customClasspathLayout; 76 77 private boolean useUniqueVersions = true; 78 79 /** 80 * @return mainClass 81 */ 82 public String getMainClass() 83 { 84 return mainClass; 85 } 86 87 /** 88 * @return the package name. 89 */ 90 public String getPackageName() 91 { 92 return packageName; 93 } 94 95 /** 96 * @return if addClasspath true or false. 97 */ 98 public boolean isAddClasspath() 99 { 100 return addClasspath; 101 } 102 103 /** 104 * @return {@link #addDefaultImplementationEntries} 105 */ 106 public boolean isAddDefaultImplementationEntries() 107 { 108 return addDefaultImplementationEntries; 109 } 110 111 /** 112 * @return {@link #addDefaultSpecificationEntries} 113 */ 114 public boolean isAddDefaultSpecificationEntries() 115 { 116 return addDefaultSpecificationEntries; 117 } 118 119 /** 120 * @return {@link #addExtensions} 121 */ 122 public boolean isAddExtensions() 123 { 124 return addExtensions; 125 } 126 127 /** 128 * @param addClasspath turn on addClasspath or off. 129 */ 130 public void setAddClasspath( boolean addClasspath ) 131 { 132 this.addClasspath = addClasspath; 133 } 134 135 /** 136 * @param addDefaultImplementationEntries true to add default implementations false otherwise. 137 */ 138 public void setAddDefaultImplementationEntries( boolean addDefaultImplementationEntries ) 139 { 140 this.addDefaultImplementationEntries = addDefaultImplementationEntries; 141 } 142 143 /** 144 * @param addDefaultSpecificationEntries add default specifications true/false. 145 */ 146 public void setAddDefaultSpecificationEntries( boolean addDefaultSpecificationEntries ) 147 { 148 this.addDefaultSpecificationEntries = addDefaultSpecificationEntries; 149 } 150 151 /** 152 * @param addExtensions true to add extensions false otherwise. 153 */ 154 public void setAddExtensions( boolean addExtensions ) 155 { 156 this.addExtensions = addExtensions; 157 } 158 159 /** 160 * @param classpathPrefix The prefix. 161 */ 162 public void setClasspathPrefix( String classpathPrefix ) 163 { 164 this.classpathPrefix = classpathPrefix; 165 } 166 167 /** 168 * @param mainClass The main class. 169 */ 170 public void setMainClass( String mainClass ) 171 { 172 this.mainClass = mainClass; 173 } 174 175 /** 176 * @param packageName The package name. 177 */ 178 public void setPackageName( String packageName ) 179 { 180 this.packageName = packageName; 181 } 182 183 /** 184 * @return The classpath prefix. 185 */ 186 public String getClasspathPrefix() 187 { 188 String cpp = classpathPrefix.replaceAll( "\\\\", "/" ); 189 190 if ( cpp.length() != 0 && !cpp.endsWith( "/" ) ) 191 { 192 cpp += "/"; 193 } 194 195 return cpp; 196 } 197 198 /** 199 * Return the type of layout to use when formatting classpath entries. Default is taken from the constant 200 * CLASSPATH_LAYOUT_TYPE_SIMPLE, declared in this class, which has a value of 'simple'. Other values are: 201 * 'repository' (CLASSPATH_LAYOUT_TYPE_REPOSITORY, or the same as a maven classpath layout), and 'custom' 202 * (CLASSPATH_LAYOUT_TYPE_CUSTOM). <br> 203 * <b>NOTE:</b> If you specify a type of 'custom' you MUST set 204 * {@link ManifestConfiguration#setCustomClasspathLayout(String)}. 205 * @return The classpath layout type. 206 */ 207 public String getClasspathLayoutType() 208 { 209 // CHECKSTYLE_OFF: LineLength 210 return CLASSPATH_LAYOUT_TYPE_SIMPLE.equals( classpathLayoutType ) ? CLASSPATH_LAYOUT_TYPE_REPOSITORY 211 : classpathLayoutType; 212 // CHECKSTYLE_ON: LineLength 213 } 214 215 /** 216 * Set the type of layout to use when formatting classpath entries. Should be one of: 'simple' 217 * (CLASSPATH_LAYOUT_TYPE_SIMPLE), 'repository' (CLASSPATH_LAYOUT_TYPE_REPOSITORY, or the same as a maven classpath 218 * layout), and 'custom' (CLASSPATH_LAYOUT_TYPE_CUSTOM). The constant names noted here are defined in the 219 * {@link ManifestConfiguration} class. <br> 220 * <b>NOTE:</b> If you specify a type of 'custom' you MUST set 221 * {@link ManifestConfiguration#setCustomClasspathLayout(String)}. 222 * @param classpathLayoutType The classpath layout type. 223 */ 224 public void setClasspathLayoutType( String classpathLayoutType ) 225 { 226 this.classpathLayoutType = classpathLayoutType; 227 } 228 229 /** 230 * Retrieve the layout expression for use when the layout type set in 231 * {@link ManifestConfiguration#setClasspathLayoutType(String)} has the value 'custom'. <b>The default value is 232 * null.</b> Expressions will be evaluated against the following ordered list of classpath-related objects: 233 * <ol> 234 * <li>The current {@code Artifact} instance, if one exists.</li> 235 * <li>The current {@code ArtifactHandler} instance from the artifact above.</li> 236 * </ol> 237 * <br> 238 * <b>NOTE:</b> If you specify a layout type of 'custom' you MUST set this layout expression. 239 * @return The custom classpath layout. 240 */ 241 public String getCustomClasspathLayout() 242 { 243 return customClasspathLayout; 244 } 245 246 /** 247 * Set the layout expression for use when the layout type set in 248 * {@link ManifestConfiguration#setClasspathLayoutType(String)} has the value 'custom'. Expressions will be 249 * evaluated against the following ordered list of classpath-related objects: 250 * <ol> 251 * <li>The current {@code Artifact} instance, if one exists.</li> 252 * <li>The current {@code ArtifactHandler} instance from the artifact above.</li> 253 * </ol> 254 * <br> 255 * <b>NOTE:</b> If you specify a layout type of 'custom' you MUST set this layout expression. 256 * You can take a look at 257 * <ol> 258 * <li>{@link MavenArchiver#SIMPLE_LAYOUT}</li> 259 * <li>{@link MavenArchiver#SIMPLE_LAYOUT_NONUNIQUE}</li> 260 * <li>{@link MavenArchiver#REPOSITORY_LAYOUT}</li> 261 * <li>{@link MavenArchiver#REPOSITORY_LAYOUT_NONUNIQUE}</li> 262 * </ol> 263 * how such an expression looks like. 264 * @param customClasspathLayout The custom classpath layout. 265 */ 266 public void setCustomClasspathLayout( String customClasspathLayout ) 267 { 268 this.customClasspathLayout = customClasspathLayout; 269 } 270 271 /** 272 * Retrieve the flag for whether snapshot artifacts should be added to the classpath using the 273 * timestamp/buildnumber version (the default, when this flag is true), or using the generic 274 * -SNAPSHOT version (when the flag is false). <br> 275 * <b>NOTE:</b> If the snapshot was installed locally, this flag will not have an effect on 276 * that artifact's inclusion, since it will have the same version either way (i.e. -SNAPSHOT naming). 277 * 278 * @return The state of {@link #useUniqueVersions} 279 */ 280 public boolean isUseUniqueVersions() 281 { 282 return useUniqueVersions; 283 } 284 285 /** 286 * Set the flag for whether snapshot artifacts should be added to the classpath using the timestamp/buildnumber 287 * version (the default, when this flag is true), or using the generic -SNAPSHOT version (when the flag is false). 288 * <br> 289 * <b>NOTE:</b> If the snapshot was installed locally, this flag will not have an effect on that artifact's 290 * inclusion, since it will have the same version either way (i.e. -SNAPSHOT naming). 291 * @param useUniqueVersions true to use unique versions or not. 292 */ 293 public void setUseUniqueVersions( boolean useUniqueVersions ) 294 { 295 this.useUniqueVersions = useUniqueVersions; 296 } 297 }