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
30   * third party libraries.
31   * <p/>
32   * Such module is not incorporated in the generated <tt>application.xml<tt>
33   * but some application servers support it. To include it in the generated
34   * deployment descriptor anyway, set the <tt>includeInApplicationXml</tt>
35   * boolean flag.
36   * <p/>
37   * This class deprecates {@link org.apache.maven.plugin.ear.JavaModule}.
38   *
39   * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
40   * @version $Id: JarModule.java 992817 2010-09-05 16:32:58Z snicoll $
41   */
42  public class JarModule
43      extends AbstractEarModule
44  {
45      private Boolean includeInApplicationXml = Boolean.FALSE;
46  
47      public JarModule()
48      {
49          super();
50      }
51  
52      public JarModule( Artifact a, String defaultLibBundleDir, Boolean includeInApplicationXml )
53      {
54          super( a );
55          setLibBundleDir( defaultLibBundleDir );
56          this.includeInApplicationXml = includeInApplicationXml;
57  
58      }
59  
60      public void appendModule( XMLWriter writer, String version, Boolean generateId )
61      {
62          // Generates an entry in the application.xml only if
63          // includeInApplicationXml is set
64          if ( includeInApplicationXml.booleanValue() )
65          {
66              startModuleElement( writer, generateId );
67              writer.startElement( JAVA_MODULE );
68              writer.writeText( getUri() );
69              writer.endElement();
70  
71              writeAltDeploymentDescriptor( writer, version );
72  
73              writer.endElement();
74          }
75      }
76  
77      public void resolveArtifact( Set artifacts )
78          throws EarPluginException, MojoFailureException
79      {
80          // Let's resolve the artifact
81          super.resolveArtifact( artifacts );
82  
83          // If the defaultLibBundleDir is set and no bundle dir is
84          // set, set the default as bundle dir
85          setLibBundleDir( earExecutionContext.getDefaultLibBundleDir() );
86      }
87  
88      public String getType()
89      {
90          return "jar";
91      }
92  
93      private void setLibBundleDir( String defaultLibBundleDir )
94      {
95          if ( defaultLibBundleDir != null && bundleDir == null )
96          {
97              this.bundleDir = defaultLibBundleDir;
98          }
99      }
100 }