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