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.ear.util.ArtifactTypeMappingService;
24  
25  import java.util.ArrayList;
26  import java.util.List;
27  
28  /**
29   * Builds an {@link EarModule} based on an <tt>Artifact</tt>.
30   *
31   * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
32   * @version $Id: EarModuleFactory.java 905071 2010-01-31 16:50:13Z snicoll $
33   */
34  public final class EarModuleFactory
35  {
36      public final static List standardArtifactTypes = new ArrayList();
37  
38      static
39      {
40          standardArtifactTypes.add( "jar" );
41          standardArtifactTypes.add( "ejb" );
42          standardArtifactTypes.add( "ejb3" );
43          standardArtifactTypes.add( "par" );
44          standardArtifactTypes.add( "ejb-client" );
45          standardArtifactTypes.add( "rar" );
46          standardArtifactTypes.add( "war" );
47          standardArtifactTypes.add( "sar" );
48          standardArtifactTypes.add( "wsr" );
49          standardArtifactTypes.add( "har" );
50      }
51  
52      /**
53       * Creates a new {@link EarModule} based on the
54       * specified {@link Artifact} and the specified
55       * execution configuration.
56       *
57       * @param artifact                the artifact
58       * @param javaEEVersion           the javaEE version to use
59       * @param defaultLibBundleDir     the default bundle dir for {@link JarModule}
60       * @param includeInApplicationXml should {@link JarModule} be included in application Xml
61       * @return an ear module for this artifact
62       * @throws UnknownArtifactTypeException if the artifact is not handled
63       */
64      public static EarModule newEarModule( Artifact artifact, String javaEEVersion, String defaultLibBundleDir,
65                                            Boolean includeInApplicationXml )
66          throws UnknownArtifactTypeException
67      {
68          // Get the standard artifact type based on default config and user-defined mapping(s)
69          final String artifactType = ArtifactTypeMappingService.getInstance().getStandardType( artifact.getType() );
70  
71          if ( "jar".equals( artifactType ) )
72          {
73              return new JarModule( artifact, defaultLibBundleDir, includeInApplicationXml );
74          }
75          else if ( "ejb".equals( artifactType ) )
76          {
77              return new EjbModule( artifact );
78          }
79          else if ( "ejb3".equals( artifactType ) )
80          {
81              return new Ejb3Module( artifact );
82          }
83          else if ( "par".equals( artifactType ) )
84          {
85              return new ParModule( artifact );
86          }
87          else if ( "ejb-client".equals( artifactType ) )
88          {
89              // Somewhat weird way to tackle the problem described in MEAR-85
90              if ( AbstractEarMojo.VERSION_1_3.equals( javaEEVersion ) ||
91                  AbstractEarMojo.VERSION_1_4.equals( javaEEVersion ) )
92              {
93                  return new EjbClientModule( artifact, null );
94              }
95              else
96              {
97                  return new EjbClientModule( artifact, defaultLibBundleDir );
98              }
99          }
100         else if ( "rar".equals( artifactType ) )
101         {
102             return new RarModule( artifact );
103         }
104         else if ( "war".equals( artifactType ) )
105         {
106             return new WebModule( artifact );
107         }
108         else if ( "sar".equals( artifactType ) )
109         {
110             return new SarModule( artifact );
111         }
112         else if ( "wsr".equals( artifactType ) )
113         {
114             return new WsrModule( artifact );
115         }
116         else if ( "har".equals( artifactType ) )
117         {
118             return new HarModule( artifact );
119         }
120         else
121         {
122             throw new IllegalStateException( "Could not handle artifact type[" + artifactType + "]" );
123         }
124     }
125 
126     /**
127      * Returns a list of standard artifact types.
128      *
129      * @return the standard artifact types
130      */
131     public static List getStandardArtifactTypes()
132     {
133         return standardArtifactTypes;
134     }
135 
136     /**
137      * Specify whether the specified type is standard artifact
138      * type.
139      *
140      * @param type the type to check
141      * @return true if the specified type is a standard artifact type
142      */
143     public static boolean isStandardArtifactType( final String type )
144     {
145         return standardArtifactTypes.contains( type );
146     }
147 
148 }