1 package org.apache.maven.archiver;
2
3 import org.apache.maven.artifact.Artifact;
4 import org.apache.maven.artifact.handler.ArtifactHandler;
5
6 /*
7 * Licensed to the Apache Software Foundation (ASF) under one
8 * or more contributor license agreements. See the NOTICE file
9 * distributed with this work for additional information
10 * regarding copyright ownership. The ASF licenses this file
11 * to you under the Apache License, Version 2.0 (the
12 * "License"); you may not use this file except in compliance
13 * with the License. You may obtain a copy of the License at
14 *
15 * http://www.apache.org/licenses/LICENSE-2.0
16 *
17 * Unless required by applicable law or agreed to in writing,
18 * software distributed under the License is distributed on an
19 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20 * KIND, either express or implied. See the License for the
21 * specific language governing permissions and limitations
22 * under the License.
23 */
24
25 /**
26 * Capture common manifest configuration.
27 *
28 * @author <a href="mailto:brett@apache.org">Brett Porter</a>
29 * @version $Id: ManifestConfiguration.java 697981 2008-09-22 20:44:40Z jdcasey $
30 * @todo is this general enough to be in Plexus Archiver?
31 */
32 public class ManifestConfiguration
33 {
34 public static final String CLASSPATH_LAYOUT_TYPE_SIMPLE = "simple";
35
36 public static final String CLASSPATH_LAYOUT_TYPE_REPOSITORY = "repository";
37
38 public static final String CLASSPATH_LAYOUT_TYPE_CUSTOM = "custom";
39
40 private String mainClass;
41
42 private String packageName;
43
44 private boolean addClasspath;
45
46 private boolean addExtensions;
47
48 /**
49 * This gets prefixed to all classpath entries.
50 */
51 private String classpathPrefix = "";
52
53 /**
54 * Add default implementation entries if this is an extension specification.
55 *
56 * @since 2.1
57 */
58 private boolean addDefaultSpecificationEntries;
59
60 /**
61 * Add default implementation entries if this is an extension.
62 *
63 * @since 2.1
64 */
65 private boolean addDefaultImplementationEntries;
66
67 /**
68 * The generated Class-Path entry will contains paths that follow the
69 * Maven 2 repository layout:
70 * $groupId[0]/../${groupId[n]/$artifactId/$version/{fileName}
71 * @since 2.3
72 * @deprecated Use {@link ManifestConfiguration#classpathLayoutType} instead.
73 */
74 private boolean classpathMavenRepositoryLayout = false;
75
76 private String classpathLayoutType = CLASSPATH_LAYOUT_TYPE_SIMPLE;
77
78 private String customClasspathLayout;
79
80 private boolean useUniqueVersions = true;
81
82 public String getMainClass()
83 {
84 return mainClass;
85 }
86
87 public String getPackageName()
88 {
89 return packageName;
90 }
91
92 public boolean isAddClasspath()
93 {
94 return addClasspath;
95 }
96
97 public boolean isAddDefaultImplementationEntries()
98 {
99 return addDefaultImplementationEntries;
100 }
101
102 public boolean isAddDefaultSpecificationEntries()
103 {
104 return addDefaultSpecificationEntries;
105 }
106
107 public boolean isAddExtensions()
108 {
109 return addExtensions;
110 }
111
112 /**
113 * @deprecated Use {@link ManifestConfiguration#getClasspathLayoutType()}, and compare to
114 * CLASSPATH_LAYOUT_TYPE_SIMPLE or CLASSPATH_LAYOUT_TYPE_REPOSITORY, also declared in {@link ManifestConfiguration}.
115 */
116 public boolean isClasspathMavenRepositoryLayout()
117 {
118 return classpathMavenRepositoryLayout;
119 }
120
121 public void setAddClasspath( boolean addClasspath )
122 {
123 this.addClasspath = addClasspath;
124 }
125
126 public void setAddDefaultImplementationEntries( boolean addDefaultImplementationEntries )
127 {
128 this.addDefaultImplementationEntries = addDefaultImplementationEntries;
129 }
130
131 public void setAddDefaultSpecificationEntries( boolean addDefaultSpecificationEntries )
132 {
133 this.addDefaultSpecificationEntries = addDefaultSpecificationEntries;
134 }
135
136 public void setAddExtensions( boolean addExtensions )
137 {
138 this.addExtensions = addExtensions;
139 }
140
141 /**
142 * @deprecated Use {@link ManifestConfiguration#setClasspathLayoutType(String)}, and use
143 * CLASSPATH_LAYOUT_TYPE_SIMPLE, CLASSPATH_LAYOUT_TYPE_CUSTOM, or CLASSPATH_LAYOUT_TYPE_REPOSITORY,
144 * also declared in {@link ManifestConfiguration}.
145 */
146 public void setClasspathMavenRepositoryLayout( boolean classpathMavenRepositoryLayout )
147 {
148 this.classpathMavenRepositoryLayout = classpathMavenRepositoryLayout;
149 }
150
151 public void setClasspathPrefix( String classpathPrefix )
152 {
153 this.classpathPrefix = classpathPrefix;
154 }
155
156 public void setMainClass( String mainClass )
157 {
158 this.mainClass = mainClass;
159 }
160
161 public void setPackageName( String packageName )
162 {
163 this.packageName = packageName;
164 }
165
166 public String getClasspathPrefix()
167 {
168 String cpp = classpathPrefix.replaceAll( "\\\\", "/" );
169
170 if ( cpp.length() != 0 && !cpp.endsWith( "/" ) )
171 {
172 cpp += "/";
173 }
174
175 return cpp;
176 }
177
178 /**
179 * Return the type of layout to use when formatting classpath entries.
180 * Default is taken from the constant CLASSPATH_LAYOUT_TYPE_SIMPLE, declared
181 * in this class, which has a value of 'simple'. Other values are: 'repository'
182 * (CLASSPATH_LAYOUT_TYPE_REPOSITORY, or the same as a maven classpath layout),
183 * and 'custom' (CLASSPATH_LAYOUT_TYPE_CUSTOM).
184 * <br/>
185 * <b>NOTE:</b> If you specify a type of 'custom' you MUST set {@link ManifestConfiguration#setCustomClasspathLayout(String)}.
186 */
187 public String getClasspathLayoutType()
188 {
189 return CLASSPATH_LAYOUT_TYPE_SIMPLE.equals( classpathLayoutType ) && classpathMavenRepositoryLayout ? CLASSPATH_LAYOUT_TYPE_REPOSITORY
190 : classpathLayoutType;
191 }
192
193 /**
194 * Set the type of layout to use when formatting classpath entries.
195 * Should be one of: 'simple' (CLASSPATH_LAYOUT_TYPE_SIMPLE), 'repository'
196 * (CLASSPATH_LAYOUT_TYPE_REPOSITORY, or the same as a maven classpath layout),
197 * and 'custom' (CLASSPATH_LAYOUT_TYPE_CUSTOM). The constant names noted here
198 * are defined in the {@link ManifestConfiguration} class.
199 * <br/>
200 * <b>NOTE:</b> If you specify a type of 'custom' you MUST set {@link ManifestConfiguration#setCustomClasspathLayout(String)}.
201 */
202 public void setClasspathLayoutType( String classpathLayoutType )
203 {
204 this.classpathLayoutType = classpathLayoutType;
205 }
206
207 /**
208 * Retrieve the layout expression for use when the layout type set in {@link ManifestConfiguration#setClasspathLayoutType(String)}
209 * has the value 'custom'. <b>The default value is null.</b>
210 * Expressions will be evaluated against the following ordered list of classpath-related objects:
211 * <ol>
212 * <li>The current {@link Artifact} instance, if one exists.</li>
213 * <li>The current {@link ArtifactHandler} instance from the artifact above.</li>
214 * </ol>
215 * <br/>
216 * <b>NOTE:</b> If you specify a layout type of 'custom' you MUST set this layout expression.
217 */
218 public String getCustomClasspathLayout()
219 {
220 return customClasspathLayout;
221 }
222
223 /**
224 * Set the layout expression for use when the layout type set in {@link ManifestConfiguration#setClasspathLayoutType(String)}
225 * has the value 'custom'. Expressions will be evaluated against the following ordered list of classpath-related objects:
226 * <ol>
227 * <li>The current {@link Artifact} instance, if one exists.</li>
228 * <li>The current {@link ArtifactHandler} instance from the artifact above.</li>
229 * </ol>
230 * <br/>
231 * <b>NOTE:</b> If you specify a layout type of 'custom' you MUST set this layout expression.
232 */
233 public void setCustomClasspathLayout( String customClasspathLayout )
234 {
235 this.customClasspathLayout = customClasspathLayout;
236 }
237
238 /**
239 * Retrieve the flag for whether snapshot artifacts should be added to the
240 * classpath using the timestamp/buildnumber version (the default, when this
241 * flag is true), or using the generic -SNAPSHOT version (when the flag is
242 * false).
243 * <br/>
244 * <b>NOTE:</b> If the snapshot was installed locally, this flag will not
245 * have an effect on that artifact's inclusion, since it will have the same
246 * version either way (i.e. -SNAPSHOT naming).
247 */
248 public boolean isUseUniqueVersions()
249 {
250 return useUniqueVersions;
251 }
252
253 /**
254 * Set the flag for whether snapshot artifacts should be added to the
255 * classpath using the timestamp/buildnumber version (the default, when this
256 * flag is true), or using the generic -SNAPSHOT version (when the flag is
257 * false).
258 * <br/>
259 * <b>NOTE:</b> If the snapshot was installed locally, this flag will not
260 * have an effect on that artifact's inclusion, since it will have the same
261 * version either way (i.e. -SNAPSHOT naming).
262 */
263 public void setUseUniqueVersions( boolean useUniqueVersions )
264 {
265 this.useUniqueVersions = useUniqueVersions;
266 }
267 }