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