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
143
144 new MyEclipseMetadataWriter().init( getLog(), config ).write();
145
146 if ( getStruts() != null )
147 {
148 new MyEclipseStrutsDataWriter( getStruts() ).init( getLog(), config ).write();
149 }
150 if ( getSpring() != null )
151 {
152 new MyEclipseSpringBeansWriter( getSpring() ).init( getLog(), config ).write();
153 }
154 if ( getHibernate() != null )
155 {
156
157 String hbmCfgFile = (String) getHibernate().get( "config-file" );
158
159 if ( "".equals( hbmCfgFile ) )
160 {
161 hbmCfgFile = MYECLIPSE_DEFAULT_HIBERNATE_CFG_XML;
162 }
163
164 new MyEclipseHibernateWriter( getHibernate() ).init( getLog(), config ).write();
165 }
166 }
167
168
169
170
171
172
173 protected void fillDefaultBuilders( String packaging )
174 {
175 List commands = new ArrayList();
176
177 super.fillDefaultBuilders( packaging );
178
179 if ( Constants.PROJECT_PACKAGING_EAR.equals( packaging ) )
180 {
181 if ( getLog().isDebugEnabled() )
182 {
183 getLog().debug( "EAR packaging does not need specific builders" );
184 }
185 }
186 else if ( Constants.PROJECT_PACKAGING_WAR.equals( packaging ) )
187 {
188 commands.add( MYECLIPSE_DEPLOYMENT_DESCRIPTOR_VALIDATOR_BUILDER );
189 commands.add( MYECLIPSE_J2EE_PROJECT_VALIDATOR_BUILDER );
190 commands.add( MYECLIPSE_WEB_CLASSPATH_BUILDER );
191
192
193 if ( !getBuildcommands().contains( new BuildCommand( BUILDER_WST_VALIDATION ) ) )
194 {
195 commands.add( BUILDER_WST_VALIDATION );
196 }
197 }
198 else if ( Constants.PROJECT_PACKAGING_EJB.equals( packaging ) )
199 {
200 if ( getLog().isInfoEnabled() )
201 {
202 getLog().info( "EJB packaging is not implemented yet" );
203 }
204 }
205 else if ( isJavaProject() )
206 {
207 if ( getLog().isDebugEnabled() )
208 {
209 getLog().debug( "JAR packaging does not need specific builders" );
210 }
211 }
212
213 if ( getSpring() != null )
214 {
215 commands.add( MYECLIPSE_SPRING_BUILDER );
216 }
217 if ( getHibernate() != null )
218 {
219 commands.add( MYECLIPSE_HIBERNATE_BUILDER );
220 }
221
222 convertBuildCommandList( commands );
223 getBuildcommands().addAll( commands );
224 }
225
226
227
228
229
230
231 protected void fillDefaultNatures( String packaging )
232 {
233 List natures = new ArrayList();
234
235 super.fillDefaultNatures( packaging );
236
237 if ( Constants.PROJECT_PACKAGING_EAR.equals( packaging ) )
238 {
239 natures.add( MYECLIPSE_EAR_NATURE );
240 }
241 else if ( Constants.PROJECT_PACKAGING_WAR.equals( packaging ) )
242 {
243 natures.add( MYECLIPSE_WEB_NATURE );
244 }
245 else if ( Constants.PROJECT_PACKAGING_EJB.equals( packaging ) )
246 {
247 if ( getLog().isInfoEnabled() )
248 {
249 getLog().info( "EJB packaging is not implemented yet" );
250 }
251 }
252 else if ( isJavaProject() )
253 {
254 if ( getLog().isDebugEnabled() )
255 {
256 getLog().debug( "JAR projects does not need specific natures" );
257 }
258 }
259
260
261 if ( getSpring() != null )
262 {
263 natures.add( MYECLISPE_SPRING_NATURE );
264 }
265
266 if ( getStruts() != null )
267 {
268 natures.add( MYECLIPSE_STRUTS_NATURE );
269 }
270
271
272 if ( getHibernate() != null )
273 {
274 natures.add( MYECLIPSE_HIBERNATE_NATURE );
275 }
276
277 getProjectnatures().addAll( natures );
278 }
279
280 protected void fillDefaultClasspathContainers( String packaging )
281 {
282 super.fillDefaultClasspathContainers( packaging );
283
284 if ( Constants.PROJECT_PACKAGING_WAR.equals( packaging ) )
285 {
286 String jeeVersion =
287 JeeUtils.getJeeDescriptorFromServletVersion( JeeUtils.resolveServletVersion( project ) ).getJeeVersion();
288
289 if ( "1.3".equals( jeeVersion ) )
290 {
291 getClasspathContainers().add( MYECLIPSE_J2EE_13_CLASSPATH_CONTAINER );
292 }
293 else if ( "1.4".equals( jeeVersion ) )
294 {
295 getClasspathContainers().add( MYECLIPSE_J2EE_14_CLASSPATH_CONTAINER );
296 }
297 }
298 }
299
300 public Map getSpring()
301 {
302 return spring;
303 }
304
305 public void setSpring( Map spring )
306 {
307 this.spring = spring;
308 }
309
310 public Map getHibernate()
311 {
312 return hibernate;
313 }
314
315 public void setHibernate( Map hibernate )
316 {
317 this.hibernate = hibernate;
318 }
319
320 public Map getStruts()
321 {
322 return struts;
323 }
324
325 public void setStruts( Map struts )
326 {
327 this.struts = struts;
328 }
329
330 }