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