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 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 return classpathLayoutType;
210 }
211
212 /**
213 * Set the type of layout to use when formatting classpath entries. Should be one of: 'simple'
214 * (CLASSPATH_LAYOUT_TYPE_SIMPLE), 'repository' (CLASSPATH_LAYOUT_TYPE_REPOSITORY, or the same as a maven classpath
215 * layout), and 'custom' (CLASSPATH_LAYOUT_TYPE_CUSTOM). The constant names noted here are defined in the
216 * {@link ManifestConfiguration} class. <br>
217 * <b>NOTE:</b> If you specify a type of 'custom' you MUST set
218 * {@link ManifestConfiguration#setCustomClasspathLayout(String)}.
219 * @param classpathLayoutType The classpath layout type.
220 */
221 public void setClasspathLayoutType( String classpathLayoutType )
222 {
223 this.classpathLayoutType = classpathLayoutType;
224 }
225
226 /**
227 * Retrieve the layout expression for use when the layout type set in
228 * {@link ManifestConfiguration#setClasspathLayoutType(String)} has the value 'custom'. <b>The default value is
229 * null.</b> Expressions will be evaluated against the following ordered list of classpath-related objects:
230 * <ol>
231 * <li>The current {@code Artifact} instance, if one exists.</li>
232 * <li>The current {@code ArtifactHandler} instance from the artifact above.</li>
233 * </ol>
234 * <br>
235 * <b>NOTE:</b> If you specify a layout type of 'custom' you MUST set this layout expression.
236 * @return The custom classpath layout.
237 */
238 public String getCustomClasspathLayout()
239 {
240 return customClasspathLayout;
241 }
242
243 /**
244 * Set the layout expression for use when the layout type set in
245 * {@link ManifestConfiguration#setClasspathLayoutType(String)} has the value 'custom'. Expressions will be
246 * evaluated against the following ordered list of classpath-related objects:
247 * <ol>
248 * <li>The current {@code Artifact} instance, if one exists.</li>
249 * <li>The current {@code ArtifactHandler} instance from the artifact above.</li>
250 * </ol>
251 * <br>
252 * <b>NOTE:</b> If you specify a layout type of 'custom' you MUST set this layout expression.
253 * You can take a look at
254 * <ol>
255 * <li>{@link MavenArchiver#SIMPLE_LAYOUT}</li>
256 * <li>{@link MavenArchiver#SIMPLE_LAYOUT_NONUNIQUE}</li>
257 * <li>{@link MavenArchiver#REPOSITORY_LAYOUT}</li>
258 * <li>{@link MavenArchiver#REPOSITORY_LAYOUT_NONUNIQUE}</li>
259 * </ol>
260 * how such an expression looks like.
261 * @param customClasspathLayout The custom classpath layout.
262 */
263 public void setCustomClasspathLayout( String customClasspathLayout )
264 {
265 this.customClasspathLayout = customClasspathLayout;
266 }
267
268 /**
269 * Retrieve the flag for whether snapshot artifacts should be added to the classpath using the
270 * timestamp/buildnumber version (the default, when this flag is true), or using the generic
271 * -SNAPSHOT version (when the flag is false). <br>
272 * <b>NOTE:</b> If the snapshot was installed locally, this flag will not have an effect on
273 * that artifact's inclusion, since it will have the same version either way (i.e. -SNAPSHOT naming).
274 *
275 * @return The state of {@link #useUniqueVersions}
276 */
277 public boolean isUseUniqueVersions()
278 {
279 return useUniqueVersions;
280 }
281
282 /**
283 * Set the flag for whether snapshot artifacts should be added to the classpath using the timestamp/buildnumber
284 * version (the default, when this flag is true), or using the generic -SNAPSHOT version (when the flag is false).
285 * <br>
286 * <b>NOTE:</b> If the snapshot was installed locally, this flag will not have an effect on that artifact's
287 * inclusion, since it will have the same version either way (i.e. -SNAPSHOT naming).
288 * @param useUniqueVersions true to use unique versions or not.
289 */
290 public void setUseUniqueVersions( boolean useUniqueVersions )
291 {
292 this.useUniqueVersions = useUniqueVersions;
293 }
294 }