View Javadoc
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 <tt>application.xml</tt>
32   * but some application servers support it. To include it in the generated
33   * deployment descriptor anyway, set the <tt>includeInApplicationXml</tt> 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      private Boolean includeInApplicationXml = Boolean.FALSE;
42  
43      /**
44       * Create an instance.
45       */
46      public JarModule()
47      {
48          super();
49      }
50  
51      /**
52       * @param a {@link Artifact}
53       * @param defaultLibBundleDir The default library bundle directory.
54       * @param includeInApplicationXml Include the application xml or not.
55       */
56      public JarModule( Artifact a, String defaultLibBundleDir, Boolean includeInApplicationXml )
57      {
58          super( a );
59          setLibBundleDir( defaultLibBundleDir );
60          this.includeInApplicationXml = includeInApplicationXml;
61  
62      }
63  
64      /**
65       * {@inheritDoc}
66       */
67      public void appendModule( XMLWriter writer, String version, Boolean generateId )
68      {
69          // Generates an entry in the application.xml only if
70          // includeInApplicationXml is set
71          if ( includeInApplicationXml )
72          {
73              startModuleElement( writer, generateId );
74              writer.startElement( JAVA_MODULE );
75              writer.writeText( getUri() );
76              writer.endElement();
77  
78              writeAltDeploymentDescriptor( writer, version );
79  
80              writer.endElement();
81          }
82      }
83  
84      /**
85       * {@inheritDoc}
86       */
87      public void resolveArtifact( Set<Artifact> artifacts )
88          throws EarPluginException, MojoFailureException
89      {
90          // Let's resolve the artifact
91          super.resolveArtifact( artifacts );
92  
93          // If the defaultLibBundleDir is set and no bundle dir is
94          // set, set the default as bundle dir
95          setLibBundleDir( earExecutionContext.getDefaultLibBundleDir() );
96      }
97  
98      /**
99       * {@inheritDoc}
100      */
101     public String getType()
102     {
103         return "jar";
104     }
105 
106     private void setLibBundleDir( String defaultLibBundleDir )
107     {
108         if ( defaultLibBundleDir != null && bundleDir == null )
109         {
110             this.bundleDir = defaultLibBundleDir;
111         }
112     }
113 
114     /**
115      * {@inheritDoc}
116      */
117     public boolean changeManifestClasspath()
118     {
119         return false;
120     }
121 }