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