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