View Javadoc
1   package org.apache.maven.plugin.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   * <p/>
31   * 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   * This class deprecates {@link org.apache.maven.plugin.ear.JavaModule}.
36   * 
37   * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
38   * @version $Id: JarModule.java 1648046 2014-12-27 11:07:02Z khmarbaise $
39   */
40  public class JarModule
41      extends AbstractEarModule
42  {
43      private Boolean includeInApplicationXml = Boolean.FALSE;
44  
45      /**
46       * Create an instance.
47       */
48      public JarModule()
49      {
50          super();
51      }
52  
53      /**
54       * @param a {@link Artifact}
55       * @param defaultLibBundleDir The default library bundle directory.
56       * @param includeInApplicationXml Include the application xml or not.
57       */
58      public JarModule( Artifact a, String defaultLibBundleDir, Boolean includeInApplicationXml )
59      {
60          super( a );
61          setLibBundleDir( defaultLibBundleDir );
62          this.includeInApplicationXml = includeInApplicationXml;
63  
64      }
65  
66      /**
67       * {@inheritDoc}
68       */
69      public void appendModule( XMLWriter writer, String version, Boolean generateId )
70      {
71          // Generates an entry in the application.xml only if
72          // includeInApplicationXml is set
73          if ( includeInApplicationXml )
74          {
75              startModuleElement( writer, generateId );
76              writer.startElement( JAVA_MODULE );
77              writer.writeText( getUri() );
78              writer.endElement();
79  
80              writeAltDeploymentDescriptor( writer, version );
81  
82              writer.endElement();
83          }
84      }
85  
86      /**
87       * {@inheritDoc}
88       */
89      public void resolveArtifact( Set<Artifact> artifacts )
90          throws EarPluginException, MojoFailureException
91      {
92          // Let's resolve the artifact
93          super.resolveArtifact( artifacts );
94  
95          // If the defaultLibBundleDir is set and no bundle dir is
96          // set, set the default as bundle dir
97          setLibBundleDir( earExecutionContext.getDefaultLibBundleDir() );
98      }
99  
100     /**
101      * {@inheritDoc}
102      */
103     public String getType()
104     {
105         return "jar";
106     }
107 
108     private void setLibBundleDir( String defaultLibBundleDir )
109     {
110         if ( defaultLibBundleDir != null && bundleDir == null )
111         {
112             this.bundleDir = defaultLibBundleDir;
113         }
114     }
115 
116     /**
117      * {@inheritDoc}
118      */
119     public boolean changeManifestClasspath()
120     {
121         return false;
122     }
123 }