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