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 import java.io.File;
23 import java.util.ArrayList;
24
25 import org.apache.maven.artifact.Artifact;
26 import org.apache.maven.model.Resource;
27 import org.apache.maven.plugin.MojoExecutionException;
28 import org.apache.maven.plugin.eclipse.writers.EclipseWriterConfig;
29 import org.apache.maven.plugin.eclipse.writers.rad.RadApplicationXMLWriter;
30 import org.apache.maven.plugin.eclipse.writers.rad.RadEjbClasspathWriter;
31 import org.apache.maven.plugin.eclipse.writers.rad.RadJ2EEWriter;
32 import org.apache.maven.plugin.eclipse.writers.rad.RadLibCopier;
33 import org.apache.maven.plugin.eclipse.writers.rad.RadManifestWriter;
34 import org.apache.maven.plugin.eclipse.writers.rad.RadWebSettingsWriter;
35 import org.apache.maven.plugin.eclipse.writers.rad.RadWebsiteConfigWriter;
36 import org.apache.maven.plugin.ide.IdeDependency;
37 import org.apache.maven.plugin.ide.IdeUtils;
38 import org.apache.maven.plugin.ide.JeeUtils;
39 import org.apache.maven.plugins.annotations.Execute;
40 import org.apache.maven.plugins.annotations.LifecyclePhase;
41 import org.apache.maven.plugins.annotations.Mojo;
42 import org.apache.maven.plugins.annotations.Parameter;
43 import org.apache.maven.project.MavenProject;
44
45
46
47
48
49
50
51 @Mojo( name = "rad" )
52 @Execute( phase = LifecyclePhase.GENERATE_RESOURCES )
53 public class RadPlugin
54 extends EclipsePlugin
55 {
56
57 private static final String COM_IBM_ETOOLS_J2EE_UI_LIB_DIR_BUILDER = "com.ibm.etools.j2ee.ui.LibDirBuilder";
58
59 private static final String COM_IBM_ETOOLS_SITEEDIT_SITE_NAV_BUILDER = "com.ibm.etools.siteedit.SiteNavBuilder";
60
61 private static final String COM_IBM_ETOOLS_SITEEDIT_SITE_UPDATE_BUILDER =
62 "com.ibm.etools.siteedit.SiteUpdateBuilder";
63
64 private static final String COM_IBM_ETOOLS_SITEEDIT_WEB_SITE_NATURE = "com.ibm.etools.siteedit.WebSiteNature";
65
66 private static final String COM_IBM_ETOOLS_VALIDATION_VALIDATIONBUILDER =
67 "com.ibm.etools.validation.validationbuilder";
68
69 private static final String COM_IBM_ETOOLS_WEBPAGE_TEMPLATE_TEMPLATEBUILDER =
70 "com.ibm.etools.webpage.template.templatebuilder";
71
72 private static final String COM_IBM_ETOOLS_WEBPAGE_TEMPLATE_TEMPLATENATURE =
73 "com.ibm.etools.webpage.template.templatenature";
74
75 private static final String COM_IBM_ETOOLS_WEBTOOLS_ADDITIONS_JSPCOMPILATIONBUILDER =
76 "com.ibm.etools.webtools.additions.jspcompilationbuilder";
77
78 private static final String COM_IBM_ETOOLS_WEBTOOLS_ADDITIONS_LINKSBUILDER =
79 "com.ibm.etools.webtools.additions.linksbuilder";
80
81 private static final String COM_IBM_SSE_MODEL_STRUCTUREDBUILDER = "com.ibm.sse.model.structuredbuilder";
82
83 private static final String COM_IBM_WTP_EJB_EJBNATURE = "com.ibm.wtp.ejb.EJBNature";
84
85 private static final String COM_IBM_WTP_J2EE_EARNATURE = "com.ibm.wtp.j2ee.EARNature";
86
87 private static final String COM_IBM_WTP_J2EE_LIB_COPY_BUILDER = "com.ibm.wtp.j2ee.LibCopyBuilder";
88
89 private static final String COM_IBM_WTP_MIGRATION_MIGRATION_BUILDER = "com.ibm.wtp.migration.MigrationBuilder";
90
91 private static final String COM_IBM_WTP_WEB_WEB_NATURE = "com.ibm.wtp.web.WebNature";
92
93 private static final String NO_GENERATED_RESOURCE_DIRNAME = "none";
94
95 private static final String ORG_ECLIPSE_JDT_CORE_JAVABUILDER = "org.eclipse.jdt.core.javabuilder";
96
97 private static final String ORG_ECLIPSE_JDT_CORE_JAVANATURE = "org.eclipse.jdt.core.javanature";
98
99
100
101
102
103 @Parameter
104 private String warContextRoot;
105
106
107
108
109
110
111
112 @Parameter( property = "generatedResourceDirName", defaultValue = "target/generated-resources/rad6" )
113 private String generatedResourceDirName;
114
115
116
117
118 public String getWarContextRoot()
119 {
120 return warContextRoot;
121 }
122
123
124
125
126 public void setWarContextRoot( String warContextRoot )
127 {
128 this.warContextRoot = warContextRoot;
129 }
130
131
132
133
134
135
136
137
138
139 protected void writeConfigurationExtras( EclipseWriterConfig config )
140 throws MojoExecutionException
141 {
142 super.writeConfigurationExtras( config );
143
144 new RadJ2EEWriter().init( getLog(), config ).write();
145
146 new RadWebSettingsWriter( this.warContextRoot ).init( getLog(), config ).write();
147
148 new RadWebsiteConfigWriter().init( getLog(), config ).write();
149
150 new RadApplicationXMLWriter().init( getLog(), config ).write();
151
152 new RadLibCopier().init( getLog(), config ).write();
153
154 new RadEjbClasspathWriter().init( getLog(), config ).write();
155 }
156
157
158
159
160
161
162
163 private void addManifestResource( EclipseWriterConfig config )
164 throws MojoExecutionException
165 {
166 if ( isJavaProject() )
167 {
168
169
170 new RadManifestWriter().init( getLog(), config ).write();
171 }
172
173 if ( isJavaProject() && !Constants.PROJECT_PACKAGING_EAR.equals( packaging )
174 && !Constants.PROJECT_PACKAGING_WAR.equals( packaging )
175 && !Constants.PROJECT_PACKAGING_EJB.equals( packaging )
176 && !NO_GENERATED_RESOURCE_DIRNAME.equals( this.generatedResourceDirName ) )
177 {
178
179 String generatedResourceDir =
180 this.project.getBasedir().getAbsolutePath() + File.separatorChar + this.generatedResourceDirName;
181
182 String metainfDir = generatedResourceDir + File.separatorChar + "META-INF";
183
184 new File( metainfDir ).mkdirs();
185
186 final Resource resource = new Resource();
187
188 getLog().debug( "Adding " + this.generatedResourceDirName + " to resources" );
189
190 resource.setDirectory( generatedResourceDir );
191
192 this.executedProject.addResource( resource );
193 }
194
195 if ( Constants.PROJECT_PACKAGING_WAR.equals( packaging ) )
196 {
197 new File( getWebContentBaseDirectory( config ) + File.separatorChar + "META-INF" ).mkdirs();
198 }
199 }
200
201
202
203
204
205
206
207
208
209 private static String getWebContentBaseDirectory( EclipseWriterConfig config )
210 throws MojoExecutionException
211 {
212
213 File warSourceDirectory =
214 new File( IdeUtils.getPluginSetting( config.getProject(), JeeUtils.ARTIFACT_MAVEN_WAR_PLUGIN,
215 "warSourceDirectory", "src/main/webapp" ) );
216
217 String webContentDir =
218 IdeUtils.toRelativeAndFixSeparator( config.getEclipseProjectDirectory(), warSourceDirectory, false );
219
220
221 String result = config.getProject().getBasedir().getAbsolutePath() + File.separatorChar + webContentDir;
222
223 return result;
224 }
225
226
227
228
229
230
231 protected void fillDefaultBuilders( String packaging )
232 {
233 super.fillDefaultBuilders( packaging );
234
235 ArrayList buildcommands = new ArrayList();
236 if ( Constants.PROJECT_PACKAGING_EAR.equals( packaging ) )
237 {
238 buildcommands.add( COM_IBM_ETOOLS_VALIDATION_VALIDATIONBUILDER );
239 buildcommands.add( COM_IBM_SSE_MODEL_STRUCTUREDBUILDER );
240 }
241 else if ( Constants.PROJECT_PACKAGING_WAR.equals( packaging ) )
242 {
243 buildcommands.add( COM_IBM_WTP_MIGRATION_MIGRATION_BUILDER );
244 buildcommands.add( ORG_ECLIPSE_JDT_CORE_JAVABUILDER );
245 buildcommands.add( COM_IBM_ETOOLS_J2EE_UI_LIB_DIR_BUILDER );
246 buildcommands.add( COM_IBM_ETOOLS_WEBTOOLS_ADDITIONS_LINKSBUILDER );
247 buildcommands.add( COM_IBM_ETOOLS_WEBPAGE_TEMPLATE_TEMPLATEBUILDER );
248 buildcommands.add( COM_IBM_ETOOLS_SITEEDIT_SITE_NAV_BUILDER );
249 buildcommands.add( COM_IBM_ETOOLS_SITEEDIT_SITE_UPDATE_BUILDER );
250 buildcommands.add( COM_IBM_ETOOLS_VALIDATION_VALIDATIONBUILDER );
251 buildcommands.add( COM_IBM_WTP_J2EE_LIB_COPY_BUILDER );
252 buildcommands.add( COM_IBM_ETOOLS_WEBTOOLS_ADDITIONS_JSPCOMPILATIONBUILDER );
253 buildcommands.add( COM_IBM_SSE_MODEL_STRUCTUREDBUILDER );
254 }
255 else if ( Constants.PROJECT_PACKAGING_EJB.equals( packaging ) )
256 {
257 buildcommands.add( ORG_ECLIPSE_JDT_CORE_JAVABUILDER );
258 buildcommands.add( COM_IBM_ETOOLS_VALIDATION_VALIDATIONBUILDER );
259 buildcommands.add( COM_IBM_WTP_J2EE_LIB_COPY_BUILDER );
260 buildcommands.add( COM_IBM_SSE_MODEL_STRUCTUREDBUILDER );
261 }
262 else if ( isJavaProject() )
263 {
264 buildcommands.add( ORG_ECLIPSE_JDT_CORE_JAVABUILDER );
265 buildcommands.add( COM_IBM_SSE_MODEL_STRUCTUREDBUILDER );
266 }
267 setBuildcommands( buildcommands );
268 }
269
270
271
272
273
274
275 protected void fillDefaultNatures( String packaging )
276 {
277 super.fillDefaultNatures( packaging );
278
279 ArrayList projectnatures = new ArrayList();
280 if ( Constants.PROJECT_PACKAGING_EAR.equals( packaging ) )
281 {
282 projectnatures.add( COM_IBM_WTP_J2EE_EARNATURE );
283 }
284 else if ( Constants.PROJECT_PACKAGING_WAR.equals( packaging ) )
285 {
286 projectnatures.add( COM_IBM_WTP_WEB_WEB_NATURE );
287 projectnatures.add( ORG_ECLIPSE_JDT_CORE_JAVANATURE );
288 projectnatures.add( COM_IBM_ETOOLS_SITEEDIT_WEB_SITE_NATURE );
289 projectnatures.add( COM_IBM_ETOOLS_WEBPAGE_TEMPLATE_TEMPLATENATURE );
290 }
291 else if ( Constants.PROJECT_PACKAGING_EJB.equals( packaging ) )
292 {
293 projectnatures.add( COM_IBM_WTP_EJB_EJBNATURE );
294 projectnatures.add( ORG_ECLIPSE_JDT_CORE_JAVANATURE );
295 }
296 else if ( isJavaProject() )
297 {
298 projectnatures.add( ORG_ECLIPSE_JDT_CORE_JAVANATURE );
299 }
300 setProjectnatures( projectnatures );
301 }
302
303
304
305
306
307
308
309 protected boolean isAvailableAsAReactorProject( Artifact artifact )
310 {
311 if ( this.reactorProjects != null
312 && ( Constants.PROJECT_PACKAGING_JAR.equals( artifact.getType() )
313 || Constants.PROJECT_PACKAGING_EJB.equals( artifact.getType() )
314 || Constants.PROJECT_PACKAGING_WAR.equals( artifact.getType() ) ) )
315 {
316 for ( Object reactorProject1 : this.reactorProjects )
317 {
318 MavenProject reactorProject = (MavenProject) reactorProject1;
319
320 if ( reactorProject.getGroupId().equals( artifact.getGroupId() )
321 && reactorProject.getArtifactId().equals( artifact.getArtifactId() ) )
322 {
323 if ( reactorProject.getVersion().equals( artifact.getVersion() ) )
324 {
325 return true;
326 }
327 else
328 {
329 getLog().info( "Artifact "
330 + artifact.getId()
331 + " already available as a reactor project, but with different version. "
332 + "Expected: " + artifact.getVersion()
333 + ", found: " + reactorProject.getVersion() );
334 }
335 }
336 }
337 }
338 return false;
339 }
340
341
342
343
344
345 protected void setupExtras()
346 throws MojoExecutionException
347 {
348 super.setupExtras();
349
350 IdeDependency[] deps = doDependencyResolution();
351
352 EclipseWriterConfig config = createEclipseWriterConfig( deps );
353
354 addManifestResource( config );
355 }
356
357
358
359
360 public String getProjectNameForArifact( Artifact artifact )
361 {
362 return artifact.getArtifactId();
363 }
364 }