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