Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
EarModuleFactory |
|
| 8.0;8 |
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 746754 2009-02-22 16:21:05Z snicoll $ | |
33 | */ | |
34 | 0 | public final class EarModuleFactory |
35 | { | |
36 | 1 | public final static List standardArtifactTypes = new ArrayList(); |
37 | ||
38 | static | |
39 | { | |
40 | 1 | standardArtifactTypes.add( "jar" ); |
41 | 1 | standardArtifactTypes.add( "ejb" ); |
42 | 1 | standardArtifactTypes.add( "ejb3" ); |
43 | 1 | standardArtifactTypes.add( "par" ); |
44 | 1 | standardArtifactTypes.add( "ejb-client" ); |
45 | 1 | standardArtifactTypes.add( "rar" ); |
46 | 1 | standardArtifactTypes.add( "war" ); |
47 | 1 | standardArtifactTypes.add( "sar" ); |
48 | 1 | standardArtifactTypes.add( "wsr" ); |
49 | 1 | standardArtifactTypes.add( "har" ); |
50 | 1 | } |
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 defaultLibBundleDir the default bundle dir for {@link JarModule} | |
59 | * @param includeInApplicationXml should {@link JarModule} be included in application Xml | |
60 | * @return an ear module for this artifact | |
61 | * @throws UnknownArtifactTypeException if the artifact is not handled | |
62 | */ | |
63 | public static EarModule newEarModule( Artifact artifact, String defaultLibBundleDir, | |
64 | Boolean includeInApplicationXml ) | |
65 | throws UnknownArtifactTypeException | |
66 | { | |
67 | // Get the standard artifact type based on default config and user-defined mapping(s) | |
68 | 0 | final String artifactType = ArtifactTypeMappingService.getInstance().getStandardType( artifact.getType() ); |
69 | ||
70 | 0 | if ( "jar".equals( artifactType ) ) |
71 | { | |
72 | 0 | return new JarModule( artifact, defaultLibBundleDir, includeInApplicationXml ); |
73 | } | |
74 | 0 | else if ( "ejb".equals( artifactType ) ) |
75 | { | |
76 | 0 | return new EjbModule( artifact ); |
77 | } | |
78 | 0 | else if ( "ejb3".equals( artifactType ) ) |
79 | { | |
80 | 0 | return new Ejb3Module( artifact ); |
81 | } | |
82 | 0 | else if ( "par".equals( artifactType ) ) |
83 | { | |
84 | 0 | return new ParModule( artifact ); |
85 | } | |
86 | 0 | else if ( "ejb-client".equals( artifactType ) ) |
87 | { | |
88 | 0 | return new EjbClientModule( artifact, null ); |
89 | } | |
90 | 0 | else if ( "rar".equals( artifactType ) ) |
91 | { | |
92 | 0 | return new RarModule( artifact ); |
93 | } | |
94 | 0 | else if ( "war".equals( artifactType ) ) |
95 | { | |
96 | 0 | return new WebModule( artifact ); |
97 | } | |
98 | 0 | else if ( "sar".equals( artifactType ) ) |
99 | { | |
100 | 0 | return new SarModule( artifact ); |
101 | } | |
102 | 0 | else if ( "wsr".equals( artifactType ) ) |
103 | { | |
104 | 0 | return new WsrModule( artifact ); |
105 | } | |
106 | 0 | else if ( "har".equals( artifactType ) ) |
107 | { | |
108 | 0 | return new HarModule( artifact ); |
109 | } | |
110 | else | |
111 | { | |
112 | 0 | throw new IllegalStateException( "Could not handle artifact type[" + artifactType + "]" ); |
113 | } | |
114 | } | |
115 | ||
116 | /** | |
117 | * Returns a list of standard artifact types. | |
118 | * | |
119 | * @return the standard artifact types | |
120 | */ | |
121 | public static List getStandardArtifactTypes() | |
122 | { | |
123 | 18 | return standardArtifactTypes; |
124 | } | |
125 | ||
126 | /** | |
127 | * Specify whether the specified type is standard artifact | |
128 | * type. | |
129 | * | |
130 | * @param type the type to check | |
131 | * @return true if the specified type is a standard artifact type | |
132 | */ | |
133 | public static boolean isStandardArtifactType( final String type ) | |
134 | { | |
135 | 51 | return standardArtifactTypes.contains( type ); |
136 | } | |
137 | ||
138 | } |