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