1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugin.ide;
20
21 import java.util.HashMap;
22 import java.util.Map;
23
24 import org.apache.maven.project.MavenProject;
25
26 public class JeeUtils
27 {
28 public static final String ARTIFACT_MAVEN_EAR_PLUGIN = "org.apache.maven.plugins:maven-ear-plugin";
29
30 public static final String ARTIFACT_MAVEN_WAR_PLUGIN = "org.apache.maven.plugins:maven-war-plugin";
31
32 private static final Map ejbMap = new HashMap();
33
34 private static final Map jeeMap = new HashMap();
35
36 private static final Map jspMap = new HashMap();
37
38 private static final Map servletMap = new HashMap();
39
40
41
42
43 static
44 {
45 addJEE( JeeDescriptor.JEE_6_0, JeeDescriptor.EJB_3_1, JeeDescriptor.SERVLET_3_0, JeeDescriptor.JSP_2_2 );
46 addJEE( JeeDescriptor.JEE_5_0, JeeDescriptor.EJB_3_0, JeeDescriptor.SERVLET_2_5, JeeDescriptor.JSP_2_1 );
47 addJEE( JeeDescriptor.JEE_1_4, JeeDescriptor.EJB_2_1, JeeDescriptor.SERVLET_2_4, JeeDescriptor.JSP_2_0 );
48 addJEE( JeeDescriptor.JEE_1_3, JeeDescriptor.EJB_2_0, JeeDescriptor.SERVLET_2_3, JeeDescriptor.JSP_1_2 );
49 addJEE( JeeDescriptor.JEE_1_2, JeeDescriptor.EJB_1_1, JeeDescriptor.SERVLET_2_2, JeeDescriptor.JSP_1_1 );
50
51 }
52
53
54
55
56
57
58
59 public final static JeeDescriptor getJeeDescriptorFromEjbVersion( String ejbVersion )
60 {
61 if ( ejbMap.containsKey( ejbVersion ) )
62 return (JeeDescriptor) ejbMap.get( ejbVersion );
63 else
64 return null;
65 }
66
67
68
69
70
71
72
73 public final static JeeDescriptor getJeeDescriptorFromJeeVersion( String jeeVersion )
74 {
75 if ( jeeMap.containsKey( jeeVersion ) )
76 return (JeeDescriptor) jeeMap.get( jeeVersion );
77 else
78 return null;
79 }
80
81
82
83
84
85
86
87 public final static JeeDescriptor getJeeDescriptorFromJspVersion( String jspVersion )
88 {
89 if ( jspMap.containsKey( jspVersion ) )
90 return (JeeDescriptor) jspMap.get( jspVersion );
91 else
92 return null;
93 }
94
95
96
97
98
99
100
101 public final static JeeDescriptor getJeeDescriptorFromServletVersion( String servletVersion )
102 {
103 if ( servletMap.containsKey( servletVersion ) )
104 return (JeeDescriptor) servletMap.get( servletVersion );
105 else
106 return null;
107 }
108
109
110
111
112
113
114
115
116 public static String resolveEjbVersion( MavenProject project )
117 {
118 String version = findEjbVersionInDependencies( project );
119
120 if ( version == null )
121 {
122
123
124 JeeDescriptor descriptor = getJeeDescriptorFromJeeVersion( findJeeVersionInDependencies( project ) );
125 if ( descriptor != null )
126 version = descriptor.getEjbVersion();
127 }
128 return version == null ? JeeDescriptor.EJB_2_1 : version;
129 }
130
131
132
133
134
135
136
137
138 public static String resolveJeeVersion( MavenProject project )
139 {
140
141 String version = findJeeVersionInDependencies( project );
142 if ( version == null )
143 {
144
145
146 JeeDescriptor descriptor = getJeeDescriptorFromEjbVersion( findEjbVersionInDependencies( project ) );
147 if ( descriptor != null )
148 version = descriptor.getJeeVersion();
149 }
150 if ( version == null )
151 {
152
153
154 JeeDescriptor descriptor = getJeeDescriptorFromServletVersion( findServletVersionInDependencies( project ) );
155 if ( descriptor != null )
156 version = descriptor.getJeeVersion();
157 }
158 if ( version == null )
159 {
160
161
162 JeeDescriptor descriptor = getJeeDescriptorFromJspVersion( findJspVersionInDependencies( project ) );
163 if ( descriptor != null )
164 version = descriptor.getJeeVersion();
165 }
166 return version == null ? JeeDescriptor.JEE_1_4 : version;
167 }
168
169
170
171
172
173
174
175
176
177 public static String resolveJspVersion( MavenProject project )
178 {
179 String version = findJspVersionInDependencies( project );
180
181 if ( version == null )
182 {
183
184
185 JeeDescriptor descriptor = getJeeDescriptorFromJeeVersion( findJeeVersionInDependencies( project ) );
186 if ( descriptor != null )
187 version = descriptor.getJspVersion();
188 }
189 if ( version == null )
190 {
191
192
193 JeeDescriptor descriptor = getJeeDescriptorFromServletVersion( findServletVersionInDependencies( project ) );
194 if ( descriptor != null )
195 version = descriptor.getJspVersion();
196 }
197 return version == null ? JeeDescriptor.JSP_2_0 : version;
198 }
199
200
201
202
203
204
205
206
207 public static String resolveServletVersion( MavenProject project )
208 {
209 String version = findServletVersionInDependencies( project );
210
211 if ( version == null )
212 {
213
214
215 JeeDescriptor descriptor = getJeeDescriptorFromJeeVersion( findJeeVersionInDependencies( project ) );
216 if ( descriptor != null )
217 version = descriptor.getServletVersion();
218 }
219 return version == null ? JeeDescriptor.SERVLET_2_4 : version;
220 }
221
222 private static void addJEE( String jeeVersion, String ejbVersion, String servletVersion, String jspVersion )
223 {
224 JeeDescriptor descriptor = new JeeDescriptor( jeeVersion, ejbVersion, servletVersion, jspVersion );
225 jeeMap.put( jeeVersion, descriptor );
226 ejbMap.put( ejbVersion, descriptor );
227 servletMap.put( servletVersion, descriptor );
228 jspMap.put( jspVersion, descriptor );
229 }
230
231 private static String findEjbVersionInDependencies( MavenProject project )
232 {
233
234 String version =
235 IdeUtils.getArtifactVersion( new String[] { "ejb", "ejb-api", "geronimo-spec-ejb" },
236 project.getDependencies(), 3 );
237
238 if ( version == null )
239 {
240 if ( IdeUtils.getArtifactVersion( new String[] { "geronimo-ejb_2.1_spec" }, project.getDependencies(), 3 ) != null )
241 return JeeDescriptor.EJB_2_1;
242 }
243 if ( version == null )
244 {
245 if ( IdeUtils.getArtifactVersion( new String[] { "geronimo-ejb_3.0_spec" }, project.getDependencies(), 3 ) != null )
246 return JeeDescriptor.EJB_3_0;
247 }
248
249
250 if ( version == null )
251 {
252 for (Object key : project.getProjectReferences().keySet()) {
253 MavenProject refProject = (MavenProject) project.getProjectReferences().get(key);
254 version = findEjbVersionInDependencies(refProject);
255 if (version != null)
256 {
257 break;
258 }
259 }
260 }
261 return version;
262 }
263
264 private static String findJeeVersionInDependencies( MavenProject project )
265 {
266 String version =
267 IdeUtils.getArtifactVersion( new String[] { "javaee-api", "j2ee", "geronimo-spec-j2ee" },
268 project.getDependencies(), 3 );
269
270
271 if ( version == null )
272 {
273 if ( IdeUtils.getArtifactVersion( new String[] { "geronimo-j2ee_1.4_spec" }, project.getDependencies(), 3 ) != null )
274 return JeeDescriptor.JEE_1_4;
275 }
276
277
278 if ( version == null )
279 {
280 for (Object key : project.getProjectReferences().keySet()) {
281 MavenProject refProject = (MavenProject) project.getProjectReferences().get(key);
282 version = findJeeVersionInDependencies(refProject);
283 if (version != null)
284 {
285 break;
286 }
287 }
288 }
289
290 return version;
291 }
292
293 private static String findJspVersionInDependencies( MavenProject project )
294 {
295 return null;
296 }
297
298 private static String findServletVersionInDependencies( MavenProject project )
299 {
300 String version =
301 IdeUtils.getArtifactVersion( new String[] { "servlet-api", "servletapi", "geronimo-spec-servlet" },
302 project.getDependencies(), 3 );
303
304
305 if ( version == null )
306 {
307 if ( IdeUtils.getArtifactVersion( new String[] { "geronimo-servlet_2.4_spec" }, project.getDependencies(),
308 3 ) != null )
309 return JeeDescriptor.SERVLET_2_4;
310 }
311 if ( version == null )
312 {
313 if ( IdeUtils.getArtifactVersion( new String[] { "geronimo-servlet_2.5_spec" }, project.getDependencies(),
314 3 ) != null )
315 return JeeDescriptor.SERVLET_2_5;
316 }
317
318
319 if ( version == null )
320 {
321 for (Object key : project.getProjectReferences().keySet()) {
322 MavenProject refProject = (MavenProject) project.getProjectReferences().get(key);
323 version = findServletVersionInDependencies(refProject);
324 if (version != null)
325 {
326 break;
327 }
328 }
329 }
330 return version;
331 }
332 }