1 package org.apache.maven.plugins.ear;
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 import org.apache.maven.artifact.Artifact;
23 import org.apache.maven.plugin.MojoFailureException;
24 import org.codehaus.plexus.util.xml.XMLWriter;
25
26 import java.util.Set;
27
28 /**
29 * The {@link EarModule} implementation for a non J2EE module such as third party libraries.
30 *
31 * <p>Such module is not incorporated in the generated {@code application.xml}
32 * but some application servers support it. To include it in the generated
33 * deployment descriptor anyway, set the {@code includeInApplicationXml} boolean flag.
34 * </p>
35 *
36 * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
37 */
38 public class JarModule
39 extends AbstractEarModule
40 {
41 /**
42 * Default type of the artifact of a non Java EE module such as third party library.
43 */
44 public static final String DEFAULT_ARTIFACT_TYPE = "jar";
45
46 private Boolean includeInApplicationXml = Boolean.FALSE;
47
48 /**
49 * Create an instance.
50 */
51 public JarModule()
52 {
53 this.type = DEFAULT_ARTIFACT_TYPE;
54 this.classPathItem = true;
55 }
56
57 /**
58 * @param a {@link Artifact}
59 * @param defaultLibBundleDir The default library bundle directory.
60 * @param includeInApplicationXml Include the application xml or not.
61 */
62 public JarModule( Artifact a, String defaultLibBundleDir, Boolean includeInApplicationXml )
63 {
64 super( a );
65 setLibBundleDir( defaultLibBundleDir );
66 this.includeInApplicationXml = includeInApplicationXml;
67 this.classPathItem = true;
68 }
69
70 /**
71 * {@inheritDoc}
72 */
73 public void appendModule( XMLWriter writer, String version, Boolean generateId )
74 {
75 // Generates an entry in the application.xml only if
76 // includeInApplicationXml is set
77 if ( includeInApplicationXml )
78 {
79 startModuleElement( writer, generateId );
80 writer.startElement( JAVA_MODULE );
81 writer.writeText( getUri() );
82 writer.endElement();
83
84 writeAltDeploymentDescriptor( writer, version );
85
86 writer.endElement();
87 }
88 }
89
90 /**
91 * {@inheritDoc}
92 */
93 public void resolveArtifact( Set<Artifact> artifacts )
94 throws EarPluginException, MojoFailureException
95 {
96 // Let's resolve the artifact
97 super.resolveArtifact( artifacts );
98
99 // If the defaultLibBundleDir is set and no bundle dir is
100 // set, set the default as bundle dir
101 setLibBundleDir( earExecutionContext.getDefaultLibBundleDir() );
102 }
103
104 private void setLibBundleDir( String defaultLibBundleDir )
105 {
106 if ( defaultLibBundleDir != null && bundleDir == null )
107 {
108 this.bundleDir = defaultLibBundleDir;
109 }
110 }
111
112 /**
113 * {@inheritDoc}
114 */
115 public boolean changeManifestClasspath()
116 {
117 return false;
118 }
119 }