1 package org.apache.maven.plugin.eclipse;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 import java.util.ArrayList;
24 import java.util.List;
25 import java.util.Map;
26
27 import org.apache.maven.plugin.MojoExecutionException;
28 import org.apache.maven.plugin.eclipse.writers.EclipseWriterConfig;
29 import org.apache.maven.plugin.eclipse.writers.myeclipse.MyEclipseHibernateWriter;
30 import org.apache.maven.plugin.eclipse.writers.myeclipse.MyEclipseMetadataWriter;
31 import org.apache.maven.plugin.eclipse.writers.myeclipse.MyEclipseSpringBeansWriter;
32 import org.apache.maven.plugin.eclipse.writers.myeclipse.MyEclipseStrutsDataWriter;
33 import org.apache.maven.plugin.ide.IdeUtils;
34 import org.apache.maven.plugin.ide.JeeUtils;
35 import org.apache.maven.plugins.annotations.Execute;
36 import org.apache.maven.plugins.annotations.LifecyclePhase;
37 import org.apache.maven.plugins.annotations.Mojo;
38 import org.apache.maven.plugins.annotations.Parameter;
39
40
41
42
43
44
45
46 @Mojo( name = "myeclipse" )
47 @Execute( phase = LifecyclePhase.GENERATE_RESOURCES )
48 public class MyEclipsePlugin
49 extends EclipsePlugin
50 {
51
52 private static final String MYECLIPSE_EAR_NATURE = "com.genuitec.eclipse.j2eedt.core.earnature";
53
54 private static final String MYECLIPSE_WEB_NATURE = "com.genuitec.eclipse.j2eedt.core.webnature";
55
56 private static final String MYECLISPE_SPRING_NATURE = "com.genuitec.eclipse.springframework.springnature";
57
58 private static final String MYECLIPSE_STRUTS_NATURE =
59 "com.genuitec.eclipse.cross.easystruts.eclipse.easystrutsnature";
60
61 private static final String MYECLIPSE_HIBERNATE_NATURE = "com.genuitec.eclipse.hibernate.hibernatenature";
62
63
64 private static final String MYECLIPSE_DEPLOYMENT_DESCRIPTOR_VALIDATOR_BUILDER =
65 "com.genuitec.eclipse.j2eedt.core.DeploymentDescriptorValidator";
66
67 private static final String MYECLIPSE_WEB_CLASSPATH_BUILDER =
68 "com.genuitec.eclipse.j2eedt.core.WebClasspathBuilder";
69
70 private static final String MYECLIPSE_J2EE_PROJECT_VALIDATOR_BUILDER =
71 "com.genuitec.eclipse.j2eedt.core.J2EEProjectValidator";
72
73 private static final String MYECLIPSE_SPRING_BUILDER = "com.genuitec.eclipse.springframework.springbuilder";
74
75 private static final String MYECLIPSE_HIBERNATE_BUILDER = "com.genuitec.eclipse.hibernate.HibernateBuilder";
76
77 private static final String MYECLIPSE_J2EE_14_CLASSPATH_CONTAINER =
78 "com.genuitec.eclipse.j2eedt.core.J2EE14_CONTAINER";
79
80 private static final String MYECLIPSE_J2EE_13_CLASSPATH_CONTAINER =
81 "com.genuitec.eclipse.j2eedt.core.J2EE13_CONTAINER";
82
83 private static final String MYECLIPSE_DEFAULT_HIBERNATE_CFG_XML = "src/main/resources/applicationContext.xml";
84
85
86
87
88
89
90
91
92
93
94
95
96
97 @Parameter
98 private Map spring;
99
100
101
102
103
104
105
106
107
108
109
110
111 @Parameter
112 private Map hibernate;
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127 @Parameter
128 private Map struts;
129
130
131
132
133 protected void writeConfigurationExtras( EclipseWriterConfig config )
134 throws MojoExecutionException
135 {
136 super.writeConfigurationExtras( config );
137 if ( isJavaProject() )
138 {
139
140 if ( Constants.PROJECT_PACKAGING_WAR.equals( project.getPackaging() ) )
141 {
142 String warSourceDirectory =
143 IdeUtils.getPluginSetting( config.getProject(), JeeUtils.ARTIFACT_MAVEN_WAR_PLUGIN,
144 "warSourceDirectory",
145 "/src/main/webapp" );
146
147 EclipseSourceDir[] sourceDirs = config.getSourceDirs();
148 for (EclipseSourceDir sourceDir : sourceDirs) {
149 if (!sourceDir.isTest()) {
150 sourceDir.setOutput(warSourceDirectory + "/WEB-INF/classes");
151 }
152 }
153 }
154 }
155
156
157
158 new MyEclipseMetadataWriter().init( getLog(), config ).write();
159
160 if ( getStruts() != null )
161 {
162 new MyEclipseStrutsDataWriter( getStruts() ).init( getLog(), config ).write();
163 }
164 if ( getSpring() != null )
165 {
166 new MyEclipseSpringBeansWriter( getSpring() ).init( getLog(), config ).write();
167 }
168 if ( getHibernate() != null )
169 {
170 new MyEclipseHibernateWriter( getHibernate() ).init( getLog(), config ).write();
171 }
172 }
173
174
175
176
177
178
179 protected void fillDefaultBuilders( String packaging )
180 {
181 List commands = new ArrayList();
182
183 super.fillDefaultBuilders( packaging );
184
185 if ( Constants.PROJECT_PACKAGING_EAR.equals( packaging ) )
186 {
187 if ( getLog().isDebugEnabled() )
188 {
189 getLog().debug( "EAR packaging does not need specific builders" );
190 }
191 }
192 else if ( Constants.PROJECT_PACKAGING_WAR.equals( packaging ) )
193 {
194 commands.add( MYECLIPSE_DEPLOYMENT_DESCRIPTOR_VALIDATOR_BUILDER );
195 commands.add( MYECLIPSE_J2EE_PROJECT_VALIDATOR_BUILDER );
196 commands.add( MYECLIPSE_WEB_CLASSPATH_BUILDER );
197
198
199 if ( !getBuildcommands().contains( new BuildCommand( BUILDER_WST_VALIDATION ) ) )
200 {
201 commands.add( BUILDER_WST_VALIDATION );
202 }
203 }
204 else if ( Constants.PROJECT_PACKAGING_EJB.equals( packaging ) )
205 {
206 if ( getLog().isInfoEnabled() )
207 {
208 getLog().info( "EJB packaging is not implemented yet" );
209 }
210 }
211 else if ( isJavaProject() )
212 {
213 if ( getLog().isDebugEnabled() )
214 {
215 getLog().debug( "JAR packaging does not need specific builders" );
216 }
217 }
218
219 if ( getSpring() != null )
220 {
221 commands.add( MYECLIPSE_SPRING_BUILDER );
222 }
223 if ( getHibernate() != null )
224 {
225 commands.add( MYECLIPSE_HIBERNATE_BUILDER );
226 }
227
228 convertBuildCommandList( commands );
229 getBuildcommands().addAll( commands );
230 }
231
232
233
234
235
236
237 protected void fillDefaultNatures( String packaging )
238 {
239 List natures = new ArrayList();
240
241 super.fillDefaultNatures( packaging );
242
243 if ( Constants.PROJECT_PACKAGING_EAR.equals( packaging ) )
244 {
245 natures.add( MYECLIPSE_EAR_NATURE );
246 }
247 else if ( Constants.PROJECT_PACKAGING_WAR.equals( packaging ) )
248 {
249 natures.add( MYECLIPSE_WEB_NATURE );
250 }
251 else if ( Constants.PROJECT_PACKAGING_EJB.equals( packaging ) )
252 {
253 if ( getLog().isInfoEnabled() )
254 {
255 getLog().info( "EJB packaging is not implemented yet" );
256 }
257 }
258 else if ( isJavaProject() )
259 {
260 if ( getLog().isDebugEnabled() )
261 {
262 getLog().debug( "JAR projects does not need specific natures" );
263 }
264 }
265
266
267 if ( getSpring() != null )
268 {
269 natures.add( MYECLISPE_SPRING_NATURE );
270 }
271
272 if ( getStruts() != null )
273 {
274 natures.add( MYECLIPSE_STRUTS_NATURE );
275 }
276
277
278 if ( getHibernate() != null )
279 {
280 natures.add( MYECLIPSE_HIBERNATE_NATURE );
281 }
282
283 getProjectnatures().addAll( natures );
284 }
285
286 protected void fillDefaultClasspathContainers( String packaging )
287 {
288 super.fillDefaultClasspathContainers( packaging );
289
290 if ( Constants.PROJECT_PACKAGING_WAR.equals( packaging ) )
291 {
292 String j2eeVersion;
293 if ( this.jeeversion != null )
294 {
295 j2eeVersion = JeeUtils.getJeeDescriptorFromJeeVersion( this.jeeversion ).getJeeVersion();
296 }
297 else
298 {
299 j2eeVersion =
300 JeeUtils.getJeeDescriptorFromServletVersion( JeeUtils.resolveServletVersion( project ) ).getJeeVersion();
301 }
302
303 if ( "1.3".equals( j2eeVersion ) )
304 {
305 getClasspathContainers().add( MYECLIPSE_J2EE_13_CLASSPATH_CONTAINER );
306 }
307 else if ( "1.4".equals( j2eeVersion ) )
308 {
309 getClasspathContainers().add( MYECLIPSE_J2EE_14_CLASSPATH_CONTAINER );
310 }
311 }
312 }
313
314 public Map getSpring()
315 {
316 return spring;
317 }
318
319 public void setSpring( Map spring )
320 {
321 this.spring = spring;
322 }
323
324 public Map getHibernate()
325 {
326 return hibernate;
327 }
328
329 public void setHibernate( Map hibernate )
330 {
331 this.hibernate = hibernate;
332 }
333
334 public Map getStruts()
335 {
336 return struts;
337 }
338
339 public void setStruts( Map struts )
340 {
341 this.struts = struts;
342 }
343
344 }