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