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 1542508 2013-11-16 13:21:35Z rfscholte $
39   */
40  public class JarModule
41      extends AbstractEarModule
42  {
43      private Boolean includeInApplicationXml = Boolean.FALSE;
44  
45      public JarModule()
46      {
47          super();
48      }
49  
50      public JarModule( Artifact a, String defaultLibBundleDir, Boolean includeInApplicationXml )
51      {
52          super( a );
53          setLibBundleDir( defaultLibBundleDir );
54          this.includeInApplicationXml = includeInApplicationXml;
55  
56      }
57  
58      public void appendModule( XMLWriter writer, String version, Boolean generateId )
59      {
60          // Generates an entry in the application.xml only if
61          // includeInApplicationXml is set
62          if ( includeInApplicationXml )
63          {
64              startModuleElement( writer, generateId );
65              writer.startElement( JAVA_MODULE );
66              writer.writeText( getUri() );
67              writer.endElement();
68  
69              writeAltDeploymentDescriptor( writer, version );
70  
71              writer.endElement();
72          }
73      }
74  
75      public void resolveArtifact( Set<Artifact> artifacts )
76          throws EarPluginException, MojoFailureException
77      {
78          // Let's resolve the artifact
79          super.resolveArtifact( artifacts );
80  
81          // If the defaultLibBundleDir is set and no bundle dir is
82          // set, set the default as bundle dir
83          setLibBundleDir( earExecutionContext.getDefaultLibBundleDir() );
84      }
85  
86      public String getType()
87      {
88          return "jar";
89      }
90  
91      private void setLibBundleDir( String defaultLibBundleDir )
92      {
93          if ( defaultLibBundleDir != null && bundleDir == null )
94          {
95              this.bundleDir = defaultLibBundleDir;
96          }
97      }
98  
99      public boolean changeManifestClasspath()
100     {
101         return false;
102     }
103 }