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.io.IOException; |
23 | |
import java.util.ArrayList; |
24 | |
import java.util.Arrays; |
25 | |
import java.util.Iterator; |
26 | |
import java.util.LinkedHashSet; |
27 | |
import java.util.LinkedList; |
28 | |
import java.util.List; |
29 | |
import java.util.ListIterator; |
30 | |
import java.util.Map; |
31 | |
import java.util.Set; |
32 | |
import java.util.TreeSet; |
33 | |
|
34 | |
import org.apache.maven.artifact.Artifact; |
35 | |
import org.apache.maven.artifact.handler.ArtifactHandler; |
36 | |
import org.apache.maven.model.Resource; |
37 | |
import org.apache.maven.plugin.MojoExecutionException; |
38 | |
import org.apache.maven.plugin.eclipse.writers.EclipseClasspathWriter; |
39 | |
import org.apache.maven.plugin.eclipse.writers.EclipseManifestWriter; |
40 | |
import org.apache.maven.plugin.eclipse.writers.EclipseOSGiManifestWriter; |
41 | |
import org.apache.maven.plugin.eclipse.writers.EclipseProjectWriter; |
42 | |
import org.apache.maven.plugin.eclipse.writers.EclipseSettingsWriter; |
43 | |
import org.apache.maven.plugin.eclipse.writers.EclipseWriterConfig; |
44 | |
import org.apache.maven.plugin.eclipse.writers.wtp.EclipseWtpApplicationXMLWriter; |
45 | |
import org.apache.maven.plugin.eclipse.writers.wtp.EclipseWtpComponent15Writer; |
46 | |
import org.apache.maven.plugin.eclipse.writers.wtp.EclipseWtpComponentWriter; |
47 | |
import org.apache.maven.plugin.eclipse.writers.wtp.EclipseWtpFacetsWriter; |
48 | |
import org.apache.maven.plugin.eclipse.writers.wtp.EclipseWtpmodulesWriter; |
49 | |
import org.apache.maven.plugin.ide.AbstractIdeSupportMojo; |
50 | |
import org.apache.maven.plugin.ide.IdeDependency; |
51 | |
import org.apache.maven.plugin.ide.IdeUtils; |
52 | |
import org.apache.maven.plugin.ide.JeeUtils; |
53 | |
import org.apache.maven.project.MavenProject; |
54 | |
import org.codehaus.plexus.util.FileUtils; |
55 | |
import org.codehaus.plexus.util.StringUtils; |
56 | |
import org.codehaus.plexus.util.xml.Xpp3Dom; |
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | 5 | public class EclipsePlugin |
76 | |
extends AbstractIdeSupportMojo |
77 | |
{ |
78 | |
|
79 | |
private static final String NATURE_WST_FACET_CORE_NATURE = "org.eclipse.wst.common.project.facet.core.nature"; |
80 | |
|
81 | |
private static final String BUILDER_WST_COMPONENT_STRUCTURAL_DEPENDENCY_RESOLVER = |
82 | |
"org.eclipse.wst.common.modulecore.ComponentStructuralBuilderDependencyResolver"; |
83 | |
|
84 | |
protected static final String BUILDER_WST_VALIDATION = "org.eclipse.wst.validation.validationbuilder"; |
85 | |
|
86 | |
private static final String BUILDER_JDT_CORE_JAVA = "org.eclipse.jdt.core.javabuilder"; |
87 | |
|
88 | |
private static final String BUILDER_WST_COMPONENT_STRUCTURAL = |
89 | |
"org.eclipse.wst.common.modulecore.ComponentStructuralBuilder"; |
90 | |
|
91 | |
private static final String BUILDER_WST_FACET = "org.eclipse.wst.common.project.facet.core.builder"; |
92 | |
|
93 | |
private static final String BUILDER_PDE_MANIFEST = "org.eclipse.pde.ManifestBuilder"; |
94 | |
|
95 | |
private static final String BUILDER_PDE_SCHEMA = "org.eclipse.pde.SchemaBuilder"; |
96 | |
|
97 | |
private static final String NATURE_WST_MODULE_CORE_NATURE = "org.eclipse.wst.common.modulecore.ModuleCoreNature"; |
98 | |
|
99 | |
private static final String NATURE_JDT_CORE_JAVA = "org.eclipse.jdt.core.javanature"; |
100 | |
|
101 | |
private static final String NATURE_JEM_WORKBENCH_JAVA_EMF = "org.eclipse.jem.workbench.JavaEMFNature"; |
102 | |
|
103 | |
private static final String NATURE_PDE_PLUGIN = "org.eclipse.pde.PluginNature"; |
104 | |
|
105 | |
protected static final String COMMON_PATH_JDT_LAUNCHING_JRE_CONTAINER = "org.eclipse.jdt.launching.JRE_CONTAINER"; |
106 | |
|
107 | |
protected static final String REQUIRED_PLUGINS_CONTAINER = "org.eclipse.pde.core.requiredPlugins"; |
108 | |
|
109 | |
|
110 | 1 | public static final String[] WTP_SUPPORTED_VERSIONS = new String[] { "1.0", "1.5", "2.0", "R7", "none" }; |
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
private static final String POM_ELT_ARTIFACT_ID = "artifactId"; |
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
private static final String POM_ELT_GROUP_ID = "groupId"; |
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | |
|
134 | |
|
135 | |
private List projectnatures; |
136 | |
|
137 | |
|
138 | |
|
139 | |
|
140 | |
|
141 | |
|
142 | |
|
143 | |
|
144 | |
|
145 | |
|
146 | |
|
147 | |
|
148 | |
private List additionalProjectnatures; |
149 | |
|
150 | |
|
151 | |
|
152 | |
|
153 | |
|
154 | |
|
155 | |
|
156 | |
|
157 | |
|
158 | |
|
159 | |
|
160 | |
|
161 | |
private Map additionalProjectFacets; |
162 | |
|
163 | |
|
164 | |
|
165 | |
|
166 | |
|
167 | |
|
168 | |
|
169 | |
|
170 | |
|
171 | |
|
172 | |
|
173 | |
|
174 | |
|
175 | |
|
176 | |
|
177 | |
|
178 | |
|
179 | |
|
180 | |
|
181 | |
private List buildcommands; |
182 | |
|
183 | |
|
184 | |
|
185 | |
|
186 | |
|
187 | |
|
188 | |
|
189 | |
|
190 | |
|
191 | |
|
192 | |
|
193 | |
|
194 | |
|
195 | |
|
196 | |
|
197 | |
|
198 | |
|
199 | |
|
200 | |
|
201 | |
|
202 | |
|
203 | |
|
204 | |
|
205 | |
|
206 | |
|
207 | |
|
208 | |
|
209 | |
|
210 | |
|
211 | |
private List additionalBuildcommands; |
212 | |
|
213 | |
|
214 | |
|
215 | |
|
216 | |
|
217 | |
|
218 | |
|
219 | |
|
220 | |
|
221 | |
|
222 | |
|
223 | |
|
224 | |
|
225 | |
|
226 | |
|
227 | |
private List classpathContainers; |
228 | |
|
229 | |
|
230 | |
|
231 | |
|
232 | |
|
233 | |
|
234 | |
|
235 | |
private boolean eclipseDownloadSources; |
236 | |
|
237 | |
|
238 | |
|
239 | |
|
240 | |
|
241 | |
|
242 | |
private File eclipseProjectDir; |
243 | |
|
244 | |
|
245 | |
|
246 | |
|
247 | |
|
248 | |
|
249 | |
|
250 | |
|
251 | |
private boolean useProjectReferences; |
252 | |
|
253 | |
|
254 | |
|
255 | |
|
256 | |
|
257 | |
|
258 | |
|
259 | |
|
260 | |
private File buildOutputDirectory; |
261 | |
|
262 | |
|
263 | |
|
264 | |
|
265 | |
|
266 | |
|
267 | |
|
268 | |
private String wtpversion; |
269 | |
|
270 | |
|
271 | |
|
272 | |
|
273 | |
|
274 | |
|
275 | |
private String wtpContextName; |
276 | |
|
277 | |
|
278 | |
|
279 | |
|
280 | |
|
281 | |
|
282 | |
|
283 | |
|
284 | |
|
285 | |
private boolean pde; |
286 | |
|
287 | |
|
288 | |
|
289 | |
|
290 | |
|
291 | |
|
292 | |
private File manifest; |
293 | |
|
294 | |
|
295 | |
|
296 | |
|
297 | |
|
298 | |
|
299 | |
|
300 | |
|
301 | |
|
302 | |
|
303 | |
|
304 | |
|
305 | |
|
306 | |
|
307 | |
|
308 | |
|
309 | |
|
310 | |
|
311 | |
|
312 | |
|
313 | |
|
314 | |
|
315 | |
|
316 | |
private EclipseConfigFile[] additionalConfig; |
317 | |
|
318 | |
|
319 | |
|
320 | |
|
321 | |
|
322 | |
|
323 | |
|
324 | |
private boolean addVersionToProjectName; |
325 | |
|
326 | |
|
327 | |
|
328 | |
|
329 | |
|
330 | |
|
331 | |
|
332 | |
private boolean addGroupIdToProjectName; |
333 | |
|
334 | |
|
335 | |
|
336 | |
|
337 | |
|
338 | |
|
339 | |
|
340 | |
|
341 | |
private String projectNameTemplate; |
342 | |
|
343 | |
|
344 | |
|
345 | |
|
346 | |
private float wtpVersionFloat; |
347 | |
|
348 | |
|
349 | |
|
350 | |
|
351 | |
private boolean isJavaProject; |
352 | |
|
353 | |
|
354 | |
|
355 | |
|
356 | |
|
357 | |
|
358 | |
private boolean wtpmanifest; |
359 | |
|
360 | |
|
361 | |
|
362 | |
|
363 | |
|
364 | |
|
365 | |
private boolean wtpapplicationxml; |
366 | |
|
367 | |
protected boolean isJavaProject() |
368 | |
{ |
369 | |
return isJavaProject; |
370 | |
} |
371 | |
|
372 | |
protected boolean isPdeProject() |
373 | |
{ |
374 | |
return pde; |
375 | |
} |
376 | |
|
377 | |
|
378 | |
|
379 | |
|
380 | |
|
381 | |
|
382 | |
public List getBuildcommands() |
383 | |
{ |
384 | |
return this.buildcommands; |
385 | |
} |
386 | |
|
387 | |
|
388 | |
|
389 | |
|
390 | |
|
391 | |
|
392 | |
public void setBuildcommands( List buildcommands ) |
393 | |
{ |
394 | |
this.buildcommands = buildcommands; |
395 | |
} |
396 | |
|
397 | |
|
398 | |
|
399 | |
|
400 | |
|
401 | |
|
402 | |
public File getBuildOutputDirectory() |
403 | |
{ |
404 | |
return this.buildOutputDirectory; |
405 | |
} |
406 | |
|
407 | |
|
408 | |
|
409 | |
|
410 | |
|
411 | |
|
412 | |
public void setBuildOutputDirectory( File buildOutputDirectory ) |
413 | |
{ |
414 | |
this.buildOutputDirectory = buildOutputDirectory; |
415 | |
} |
416 | |
|
417 | |
|
418 | |
|
419 | |
|
420 | |
|
421 | |
|
422 | |
public List getClasspathContainers() |
423 | |
{ |
424 | |
return this.classpathContainers; |
425 | |
} |
426 | |
|
427 | |
|
428 | |
|
429 | |
|
430 | |
|
431 | |
|
432 | |
public void setClasspathContainers( List classpathContainers ) |
433 | |
{ |
434 | |
this.classpathContainers = classpathContainers; |
435 | |
} |
436 | |
|
437 | |
|
438 | |
|
439 | |
|
440 | |
|
441 | |
|
442 | |
public File getEclipseProjectDir() |
443 | |
{ |
444 | |
return this.eclipseProjectDir; |
445 | |
} |
446 | |
|
447 | |
|
448 | |
|
449 | |
|
450 | |
|
451 | |
|
452 | |
public void setEclipseProjectDir( File eclipseProjectDir ) |
453 | |
{ |
454 | |
this.eclipseProjectDir = eclipseProjectDir; |
455 | |
} |
456 | |
|
457 | |
|
458 | |
|
459 | |
|
460 | |
|
461 | |
|
462 | |
public List getProjectnatures() |
463 | |
{ |
464 | |
return this.projectnatures; |
465 | |
} |
466 | |
|
467 | |
|
468 | |
|
469 | |
|
470 | |
|
471 | |
|
472 | |
public void setProjectnatures( List projectnatures ) |
473 | |
{ |
474 | |
this.projectnatures = projectnatures; |
475 | |
} |
476 | |
|
477 | |
|
478 | |
|
479 | |
|
480 | |
|
481 | |
|
482 | |
public boolean getUseProjectReferences() |
483 | |
{ |
484 | |
return this.useProjectReferences; |
485 | |
} |
486 | |
|
487 | |
|
488 | |
|
489 | |
|
490 | |
|
491 | |
|
492 | |
public void setUseProjectReferences( boolean useProjectReferences ) |
493 | |
{ |
494 | |
this.useProjectReferences = useProjectReferences; |
495 | |
} |
496 | |
|
497 | |
|
498 | |
|
499 | |
|
500 | |
|
501 | |
|
502 | |
public String getWtpversion() |
503 | |
{ |
504 | |
return this.wtpversion; |
505 | |
} |
506 | |
|
507 | |
|
508 | |
|
509 | |
|
510 | |
|
511 | |
|
512 | |
public void setWtpversion( String wtpversion ) |
513 | |
{ |
514 | |
this.wtpversion = wtpversion; |
515 | |
} |
516 | |
|
517 | |
|
518 | |
|
519 | |
|
520 | |
|
521 | |
|
522 | |
public List getAdditionalBuildcommands() |
523 | |
{ |
524 | |
return this.additionalBuildcommands; |
525 | |
} |
526 | |
|
527 | |
|
528 | |
|
529 | |
|
530 | |
|
531 | |
|
532 | |
public void setAdditionalBuildcommands( List additionalBuildcommands ) |
533 | |
{ |
534 | |
this.additionalBuildcommands = additionalBuildcommands; |
535 | |
} |
536 | |
|
537 | |
|
538 | |
|
539 | |
|
540 | |
|
541 | |
|
542 | |
public List getAdditionalProjectnatures() |
543 | |
{ |
544 | |
return this.additionalProjectnatures; |
545 | |
} |
546 | |
|
547 | |
|
548 | |
|
549 | |
|
550 | |
|
551 | |
|
552 | |
public void setAdditionalProjectnatures( List additionalProjectnatures ) |
553 | |
{ |
554 | |
this.additionalProjectnatures = additionalProjectnatures; |
555 | |
} |
556 | |
|
557 | |
|
558 | |
|
559 | |
|
560 | |
public boolean isAddVersionToProjectName() |
561 | |
{ |
562 | |
return addVersionToProjectName; |
563 | |
} |
564 | |
|
565 | |
|
566 | |
|
567 | |
|
568 | |
public void setAddVersionToProjectName( boolean addVersionToProjectName ) |
569 | |
{ |
570 | |
this.addVersionToProjectName = addVersionToProjectName; |
571 | |
} |
572 | |
|
573 | |
|
574 | |
|
575 | |
|
576 | |
public boolean isAddGroupIdToProjectName() |
577 | |
{ |
578 | |
return addGroupIdToProjectName; |
579 | |
} |
580 | |
|
581 | |
|
582 | |
|
583 | |
|
584 | |
public void setAddGroupIdToProjectName( boolean addGroupIdToProjectName ) |
585 | |
{ |
586 | |
this.addGroupIdToProjectName = addGroupIdToProjectName; |
587 | |
} |
588 | |
|
589 | |
public String getProjectNameTemplate() |
590 | |
{ |
591 | |
return projectNameTemplate; |
592 | |
} |
593 | |
|
594 | |
public void setProjectNameTemplate( String projectNameTemplate ) |
595 | |
{ |
596 | |
this.projectNameTemplate = projectNameTemplate; |
597 | |
} |
598 | |
|
599 | |
|
600 | |
|
601 | |
|
602 | |
public boolean setup() |
603 | |
throws MojoExecutionException |
604 | |
{ |
605 | |
boolean ready = true; |
606 | |
|
607 | |
checkDeprecations(); |
608 | |
|
609 | |
ready = validate(); |
610 | |
|
611 | |
|
612 | |
ArtifactHandler artifactHandler = this.project.getArtifact().getArtifactHandler(); |
613 | |
|
614 | |
|
615 | |
|
616 | |
isJavaProject = |
617 | |
pde || |
618 | |
( Constants.LANGUAGE_JAVA.equals( artifactHandler.getLanguage() ) && !Constants.PROJECT_PACKAGING_EAR.equals( packaging ) ); |
619 | |
|
620 | |
setupExtras(); |
621 | |
|
622 | |
parseConfigurationOptions(); |
623 | |
|
624 | |
|
625 | |
if ( projectnatures == null ) |
626 | |
{ |
627 | |
fillDefaultNatures( packaging ); |
628 | |
} |
629 | |
|
630 | |
if ( additionalProjectnatures != null ) |
631 | |
{ |
632 | |
projectnatures.addAll( additionalProjectnatures ); |
633 | |
} |
634 | |
|
635 | |
if ( buildcommands == null ) |
636 | |
{ |
637 | |
fillDefaultBuilders( packaging ); |
638 | |
} |
639 | |
else |
640 | |
{ |
641 | |
convertBuildCommandList( buildcommands ); |
642 | |
} |
643 | |
|
644 | |
if ( additionalBuildcommands != null ) |
645 | |
{ |
646 | |
convertBuildCommandList( additionalBuildcommands ); |
647 | |
buildcommands.addAll( additionalBuildcommands ); |
648 | |
} |
649 | |
|
650 | |
if ( classpathContainers == null ) |
651 | |
{ |
652 | |
fillDefaultClasspathContainers( packaging ); |
653 | |
} |
654 | |
else |
655 | |
{ |
656 | |
verifyClasspathContainerListIsComplete(); |
657 | |
} |
658 | |
|
659 | |
|
660 | |
return ready; |
661 | |
} |
662 | |
|
663 | |
protected void convertBuildCommandList( List commands ) |
664 | |
{ |
665 | |
if ( commands != null ) |
666 | |
{ |
667 | |
for ( ListIterator i = commands.listIterator(); i.hasNext(); ) |
668 | |
{ |
669 | |
Object command = i.next(); |
670 | |
|
671 | |
if ( command instanceof String ) |
672 | |
{ |
673 | |
command = new BuildCommand( (String) command ); |
674 | |
i.set( command ); |
675 | |
} |
676 | |
} |
677 | |
} |
678 | |
} |
679 | |
|
680 | |
private void parseConfigurationOptions() |
681 | |
{ |
682 | |
if ( "R7".equalsIgnoreCase( wtpversion ) ) |
683 | |
{ |
684 | |
wtpVersionFloat = 0.7f; |
685 | |
} |
686 | |
else if ( "1.0".equalsIgnoreCase( wtpversion ) ) |
687 | |
{ |
688 | |
wtpVersionFloat = 1.0f; |
689 | |
} |
690 | |
else if ( "1.5".equalsIgnoreCase( wtpversion ) ) |
691 | |
{ |
692 | |
wtpVersionFloat = 1.5f; |
693 | |
} |
694 | |
else if ( "2.0".equalsIgnoreCase( wtpversion ) ) |
695 | |
{ |
696 | |
wtpVersionFloat = 2.0f; |
697 | |
} |
698 | |
if ( !"none".equalsIgnoreCase( wtpversion ) ) |
699 | |
{ |
700 | |
getLog().info( Messages.getString( "EclipsePlugin.wtpversion", wtpversion ) ); |
701 | |
} |
702 | |
} |
703 | |
|
704 | |
protected void setupExtras() |
705 | |
throws MojoExecutionException |
706 | |
{ |
707 | |
|
708 | |
} |
709 | |
|
710 | |
protected void verifyClasspathContainerListIsComplete() |
711 | |
{ |
712 | |
boolean containsJREContainer = false; |
713 | |
|
714 | |
for ( Iterator iter = classpathContainers.iterator(); iter.hasNext(); ) |
715 | |
{ |
716 | |
Object classPathContainer = iter.next(); |
717 | |
if ( classPathContainer != null && |
718 | |
classPathContainer.toString().startsWith( COMMON_PATH_JDT_LAUNCHING_JRE_CONTAINER ) ) |
719 | |
{ |
720 | |
containsJREContainer = true; |
721 | |
break; |
722 | |
} |
723 | |
} |
724 | |
if ( !containsJREContainer ) |
725 | |
{ |
726 | |
getLog().warn( Messages.getString( "EclipsePlugin.missingjrecontainer" ) ); |
727 | |
classpathContainers.add( 0, COMMON_PATH_JDT_LAUNCHING_JRE_CONTAINER ); |
728 | |
} |
729 | |
} |
730 | |
|
731 | |
private boolean validate() |
732 | |
throws MojoExecutionException |
733 | |
{ |
734 | |
|
735 | |
if ( Arrays.binarySearch( WTP_SUPPORTED_VERSIONS, wtpversion ) < 0 ) |
736 | |
{ |
737 | |
throw new MojoExecutionException( |
738 | |
Messages.getString( "EclipsePlugin.unsupportedwtp", new Object[] { |
739 | |
wtpversion, |
740 | |
StringUtils.join( WTP_SUPPORTED_VERSIONS, " " ) } ) ); |
741 | |
} |
742 | |
|
743 | |
assertNotEmpty( executedProject.getGroupId(), POM_ELT_GROUP_ID ); |
744 | |
assertNotEmpty( executedProject.getArtifactId(), POM_ELT_ARTIFACT_ID ); |
745 | |
|
746 | |
if ( executedProject.getFile() == null || !executedProject.getFile().exists() ) |
747 | |
{ |
748 | |
throw new MojoExecutionException( Messages.getString( "EclipsePlugin.missingpom" ) ); |
749 | |
} |
750 | |
|
751 | |
if ( "pom".equals( packaging ) && eclipseProjectDir == null ) |
752 | |
{ |
753 | |
getLog().info( Messages.getString( "EclipsePlugin.pompackaging" ) ); |
754 | |
return false; |
755 | |
} |
756 | |
|
757 | |
if ( "eclipse-plugin".equals( packaging ) ) |
758 | |
{ |
759 | |
pde = true; |
760 | |
} |
761 | |
|
762 | |
if ( eclipseProjectDir == null ) |
763 | |
{ |
764 | |
eclipseProjectDir = executedProject.getFile().getParentFile(); |
765 | |
} |
766 | |
|
767 | |
if ( !eclipseProjectDir.exists() && !eclipseProjectDir.mkdirs() ) |
768 | |
{ |
769 | |
throw new MojoExecutionException( Messages.getString( "EclipsePlugin.cantcreatedir", eclipseProjectDir ) ); |
770 | |
} |
771 | |
|
772 | |
if ( !eclipseProjectDir.equals( executedProject.getFile().getParentFile() ) ) |
773 | |
{ |
774 | |
if ( !eclipseProjectDir.isDirectory() ) |
775 | |
{ |
776 | |
throw new MojoExecutionException( Messages.getString( "EclipsePlugin.notadir", eclipseProjectDir ) ); |
777 | |
} |
778 | |
eclipseProjectDir = new File( eclipseProjectDir, executedProject.getArtifactId() ); |
779 | |
if ( !eclipseProjectDir.isDirectory() && !eclipseProjectDir.mkdirs() ) |
780 | |
{ |
781 | |
throw new MojoExecutionException( Messages.getString( "EclipsePlugin.cantcreatedir", eclipseProjectDir ) ); |
782 | |
} |
783 | |
} |
784 | |
|
785 | |
validateExtras(); |
786 | |
|
787 | |
return true; |
788 | |
} |
789 | |
|
790 | |
protected void validateExtras() |
791 | |
{ |
792 | |
|
793 | |
} |
794 | |
|
795 | |
private void checkDeprecations() |
796 | |
{ |
797 | |
if ( eclipseDownloadSources ) |
798 | |
{ |
799 | |
|
800 | |
getLog().warn( Messages.getString( "EclipsePlugin.deprecatedpar", new Object[] { |
801 | |
"eclipse.downloadSources", |
802 | |
"downloadSources" } ) ); |
803 | |
downloadSources = true; |
804 | |
} |
805 | |
|
806 | |
checkExtraDeprecations(); |
807 | |
} |
808 | |
|
809 | |
protected void checkExtraDeprecations() |
810 | |
{ |
811 | |
|
812 | |
} |
813 | |
|
814 | |
public void writeConfiguration( IdeDependency[] deps ) |
815 | |
throws MojoExecutionException |
816 | |
{ |
817 | |
EclipseWriterConfig config = createEclipseWriterConfig( deps ); |
818 | |
|
819 | |
if ( wtpmanifest && isJavaProject() ) |
820 | |
{ |
821 | |
EclipseManifestWriter.addManifestResource( getLog(), config ); |
822 | |
} |
823 | |
|
824 | |
writeExtraConfiguration( config ); |
825 | |
|
826 | |
if ( wtpVersionFloat == 0.7f ) |
827 | |
{ |
828 | |
new EclipseWtpmodulesWriter().init( getLog(), config ).write(); |
829 | |
} |
830 | |
|
831 | |
if ( wtpVersionFloat >= 1.0f ) |
832 | |
{ |
833 | |
new EclipseWtpFacetsWriter().init( getLog(), config ).write(); |
834 | |
} |
835 | |
if ( wtpVersionFloat == 1.0f ) |
836 | |
{ |
837 | |
new EclipseWtpComponentWriter().init( getLog(), config ).write(); |
838 | |
} |
839 | |
if ( wtpVersionFloat >= 1.5 ) |
840 | |
{ |
841 | |
new EclipseWtpComponent15Writer().init( getLog(), config ).write(); |
842 | |
} |
843 | |
|
844 | |
new EclipseSettingsWriter().init( getLog(), config ).write(); |
845 | |
|
846 | |
if ( isJavaProject ) |
847 | |
{ |
848 | |
new EclipseClasspathWriter().init( getLog(), config ).write(); |
849 | |
} |
850 | |
|
851 | |
if ( wtpapplicationxml ) |
852 | |
{ |
853 | |
new EclipseWtpApplicationXMLWriter().init( getLog(), config ).write(); |
854 | |
} |
855 | |
|
856 | |
if ( pde ) |
857 | |
{ |
858 | |
this.getLog().info( "The Maven Eclipse plugin runs in 'pde'-mode." ); |
859 | |
new EclipseOSGiManifestWriter().init( getLog(), config ).write(); |
860 | |
} |
861 | |
|
862 | |
|
863 | |
|
864 | |
|
865 | |
|
866 | |
new EclipseProjectWriter().init( getLog(), config ).write(); |
867 | |
|
868 | |
if ( additionalConfig != null ) |
869 | |
{ |
870 | |
for ( int j = 0; j < additionalConfig.length; j++ ) |
871 | |
{ |
872 | |
EclipseConfigFile file = additionalConfig[j]; |
873 | |
File projectRelativeFile = new File( this.eclipseProjectDir, file.getName() ); |
874 | |
if ( projectRelativeFile.isDirectory() ) |
875 | |
{ |
876 | |
|
877 | |
getLog().warn( Messages.getString( "EclipsePlugin.foundadir", |
878 | |
projectRelativeFile.getAbsolutePath() ) ); |
879 | |
} |
880 | |
|
881 | |
try |
882 | |
{ |
883 | |
projectRelativeFile.getParentFile().mkdirs(); |
884 | |
FileUtils.fileWrite( projectRelativeFile.getAbsolutePath(), file.getContent() ); |
885 | |
} |
886 | |
catch ( IOException e ) |
887 | |
{ |
888 | |
throw new MojoExecutionException( Messages.getString( "EclipsePlugin.cantwritetofile", |
889 | |
projectRelativeFile.getAbsolutePath() ) ); |
890 | |
} |
891 | |
} |
892 | |
} |
893 | |
|
894 | |
getLog().info( Messages.getString( "EclipsePlugin.wrote", new Object[] { |
895 | |
config.getEclipseProjectName(), eclipseProjectDir.getAbsolutePath() } ) ); |
896 | |
} |
897 | |
|
898 | |
protected EclipseWriterConfig createEclipseWriterConfig( IdeDependency[] deps ) |
899 | |
throws MojoExecutionException |
900 | |
{ |
901 | |
File projectBaseDir = executedProject.getFile().getParentFile(); |
902 | |
|
903 | |
|
904 | |
|
905 | |
EclipseSourceDir[] sourceDirs = buildDirectoryList( executedProject, eclipseProjectDir, buildOutputDirectory ); |
906 | |
|
907 | |
EclipseWriterConfig config = new EclipseWriterConfig(); |
908 | |
|
909 | |
config.setProjectNameTemplate( calculateProjectNameTemplate() ); |
910 | |
|
911 | |
String projectName = IdeUtils.getProjectName( config.getProjectNameTemplate(), project ); |
912 | |
|
913 | |
config.setEclipseProjectName( projectName ); |
914 | |
|
915 | |
config.setWtpapplicationxml( wtpapplicationxml ); |
916 | |
|
917 | |
config.setWtpVersion( this.wtpVersionFloat ); |
918 | |
|
919 | |
Set convertedBuildCommands = new LinkedHashSet(); |
920 | |
|
921 | |
if ( buildcommands != null ) |
922 | |
{ |
923 | |
for ( Iterator it = buildcommands.iterator(); it.hasNext(); ) |
924 | |
{ |
925 | |
Object cmd = it.next(); |
926 | |
|
927 | |
if ( cmd instanceof BuildCommand ) |
928 | |
{ |
929 | |
convertedBuildCommands.add( (BuildCommand) cmd ); |
930 | |
} |
931 | |
else |
932 | |
{ |
933 | |
convertedBuildCommands.add( new BuildCommand( (String) cmd ) ); |
934 | |
} |
935 | |
} |
936 | |
} |
937 | |
|
938 | |
config.setBuildCommands( new LinkedList( convertedBuildCommands ) ); |
939 | |
|
940 | |
config.setBuildOutputDirectory( buildOutputDirectory ); |
941 | |
config.setClasspathContainers( classpathContainers ); |
942 | |
config.setDeps( deps ); |
943 | |
config.setEclipseProjectDirectory( eclipseProjectDir ); |
944 | |
config.setLocalRepository( localRepository ); |
945 | |
config.setManifestFile( manifest ); |
946 | |
config.setPde( pde ); |
947 | |
config.setProject( project ); |
948 | |
config.setProjectBaseDir( projectBaseDir ); |
949 | |
config.setProjectnatures( projectnatures ); |
950 | |
config.setProjectFacets( additionalProjectFacets ); |
951 | |
config.setSourceDirs( sourceDirs ); |
952 | |
config.setAddVersionToProjectName( isAddVersionToProjectName() ); |
953 | |
config.setPackaging( this.packaging ); |
954 | |
|
955 | |
collectWarContextRootsFromReactorEarConfiguration( config ); |
956 | |
|
957 | |
return config; |
958 | |
} |
959 | |
|
960 | |
|
961 | |
|
962 | |
|
963 | |
|
964 | |
|
965 | |
|
966 | |
private void collectWarContextRootsFromReactorEarConfiguration( EclipseWriterConfig config ) |
967 | |
{ |
968 | |
if ( reactorProjects != null && this.wtpContextName == null && |
969 | |
Constants.PROJECT_PACKAGING_WAR.equals( this.project.getPackaging() ) ) |
970 | |
{ |
971 | |
for ( Iterator iter = reactorProjects.iterator(); iter.hasNext(); ) |
972 | |
{ |
973 | |
MavenProject reactorProject = (MavenProject) iter.next(); |
974 | |
|
975 | |
if ( Constants.PROJECT_PACKAGING_EAR.equals( reactorProject.getPackaging() ) ) |
976 | |
{ |
977 | |
Xpp3Dom[] warDefinitions = |
978 | |
IdeUtils.getPluginConfigurationDom( reactorProject, JeeUtils.ARTIFACT_MAVEN_EAR_PLUGIN, |
979 | |
new String[] { "modules", "webModule" } ); |
980 | |
for ( int index = 0; index < warDefinitions.length; index++ ) |
981 | |
{ |
982 | |
Xpp3Dom groupId = warDefinitions[index].getChild( "groupId" ); |
983 | |
Xpp3Dom artifactId = warDefinitions[index].getChild( "artifactId" ); |
984 | |
Xpp3Dom contextRoot = warDefinitions[index].getChild( "contextRoot" ); |
985 | |
if ( groupId != null && artifactId != null && contextRoot != null && |
986 | |
groupId.getValue() != null && artifactId.getValue() != null && |
987 | |
contextRoot.getValue() != null ) |
988 | |
{ |
989 | |
getLog().info( |
990 | |
"Found context root definition for " + groupId.getValue() + ":" + |
991 | |
artifactId.getValue() + " " + contextRoot.getValue() ); |
992 | |
if ( this.project.getArtifactId().equals( artifactId.getValue() ) && |
993 | |
this.project.getGroupId().equals( groupId.getValue() ) ) |
994 | |
{ |
995 | |
config.setContextName( contextRoot.getValue() ); |
996 | |
} |
997 | |
} |
998 | |
else |
999 | |
{ |
1000 | |
getLog().info( |
1001 | |
"Found incomplete ear configuration in " + reactorProject.getGroupId() + |
1002 | |
":" + reactorProject.getGroupId() + " found " + |
1003 | |
warDefinitions[index].toString() ); |
1004 | |
} |
1005 | |
} |
1006 | |
} |
1007 | |
} |
1008 | |
} |
1009 | |
if ( config.getContextName() == null && Constants.PROJECT_PACKAGING_WAR.equals( this.project.getPackaging() ) ) |
1010 | |
{ |
1011 | |
if ( this.wtpContextName == null ) |
1012 | |
{ |
1013 | |
config.setContextName( this.project.getArtifactId() ); |
1014 | |
} |
1015 | |
else |
1016 | |
{ |
1017 | |
config.setContextName( this.wtpContextName ); |
1018 | |
} |
1019 | |
} |
1020 | |
} |
1021 | |
|
1022 | |
|
1023 | |
|
1024 | |
|
1025 | |
|
1026 | |
|
1027 | |
|
1028 | |
|
1029 | |
protected void writeExtraConfiguration( EclipseWriterConfig config ) |
1030 | |
throws MojoExecutionException |
1031 | |
{ |
1032 | |
|
1033 | |
} |
1034 | |
|
1035 | |
private void assertNotEmpty( String string, String elementName ) |
1036 | |
throws MojoExecutionException |
1037 | |
{ |
1038 | |
if ( string == null ) |
1039 | |
{ |
1040 | |
throw new MojoExecutionException( Messages.getString( "EclipsePlugin.missingelement", elementName ) ); |
1041 | |
} |
1042 | |
} |
1043 | |
|
1044 | |
protected void fillDefaultNatures( String packaging ) |
1045 | |
{ |
1046 | |
projectnatures = new ArrayList(); |
1047 | |
|
1048 | |
if ( wtpVersionFloat >= 1.0f ) |
1049 | |
{ |
1050 | |
projectnatures.add( NATURE_WST_FACET_CORE_NATURE ); |
1051 | |
} |
1052 | |
|
1053 | |
if ( isJavaProject ) |
1054 | |
{ |
1055 | |
projectnatures.add( NATURE_JDT_CORE_JAVA ); |
1056 | |
} |
1057 | |
|
1058 | |
if ( wtpVersionFloat >= 0.7f ) |
1059 | |
{ |
1060 | |
projectnatures.add( NATURE_WST_MODULE_CORE_NATURE ); |
1061 | |
|
1062 | |
if ( isJavaProject ) |
1063 | |
{ |
1064 | |
projectnatures.add( NATURE_JEM_WORKBENCH_JAVA_EMF ); |
1065 | |
} |
1066 | |
} |
1067 | |
|
1068 | |
if ( pde ) |
1069 | |
{ |
1070 | |
projectnatures.add( NATURE_PDE_PLUGIN ); |
1071 | |
} |
1072 | |
|
1073 | |
} |
1074 | |
|
1075 | |
protected void fillDefaultClasspathContainers( String packaging ) |
1076 | |
{ |
1077 | |
classpathContainers = new ArrayList(); |
1078 | |
classpathContainers.add( COMMON_PATH_JDT_LAUNCHING_JRE_CONTAINER ); |
1079 | |
|
1080 | |
if ( pde ) |
1081 | |
{ |
1082 | |
classpathContainers.add( REQUIRED_PLUGINS_CONTAINER ); |
1083 | |
} |
1084 | |
} |
1085 | |
|
1086 | |
protected void fillDefaultBuilders( String packaging ) |
1087 | |
{ |
1088 | |
buildcommands = new ArrayList(); |
1089 | |
|
1090 | |
if ( wtpVersionFloat == 0.7f ) |
1091 | |
{ |
1092 | |
buildcommands.add( new BuildCommand( BUILDER_WST_COMPONENT_STRUCTURAL ) ); |
1093 | |
} |
1094 | |
|
1095 | |
if ( isJavaProject ) |
1096 | |
{ |
1097 | |
buildcommands.add( new BuildCommand( BUILDER_JDT_CORE_JAVA ) ); |
1098 | |
} |
1099 | |
|
1100 | |
if ( wtpVersionFloat >= 1.5f ) |
1101 | |
{ |
1102 | |
buildcommands.add( new BuildCommand( BUILDER_WST_FACET ) ); |
1103 | |
} |
1104 | |
|
1105 | |
if ( wtpVersionFloat >= 0.7f ) |
1106 | |
{ |
1107 | |
buildcommands.add( new BuildCommand( BUILDER_WST_VALIDATION ) ); |
1108 | |
} |
1109 | |
|
1110 | |
if ( wtpVersionFloat == 0.7f ) |
1111 | |
{ |
1112 | |
|
1113 | |
buildcommands.add( new BuildCommand( BUILDER_WST_COMPONENT_STRUCTURAL_DEPENDENCY_RESOLVER ) ); |
1114 | |
} |
1115 | |
|
1116 | |
if ( pde ) |
1117 | |
{ |
1118 | |
buildcommands.add( new BuildCommand( BUILDER_PDE_MANIFEST ) ); |
1119 | |
buildcommands.add( new BuildCommand( BUILDER_PDE_SCHEMA ) ); |
1120 | |
} |
1121 | |
} |
1122 | |
|
1123 | |
public EclipseSourceDir[] buildDirectoryList( MavenProject project, File basedir, File buildOutputDirectory ) |
1124 | |
throws MojoExecutionException |
1125 | |
{ |
1126 | 1 | File projectBaseDir = project.getFile().getParentFile(); |
1127 | |
|
1128 | |
|
1129 | 1 | Set directories = new TreeSet(); |
1130 | |
|
1131 | 1 | extractSourceDirs( directories, project.getCompileSourceRoots(), basedir, projectBaseDir, false, null ); |
1132 | |
|
1133 | 1 | String relativeOutput = IdeUtils.toRelativeAndFixSeparator( projectBaseDir, buildOutputDirectory, false ); |
1134 | |
|
1135 | 1 | extractResourceDirs( directories, project.getBuild().getResources(), project, basedir, projectBaseDir, false, |
1136 | |
relativeOutput ); |
1137 | |
|
1138 | |
|
1139 | 1 | String testOutput = null; |
1140 | 1 | boolean useStandardOutputDir = |
1141 | |
buildOutputDirectory.equals( new File( project.getBuild().getOutputDirectory() ) ); |
1142 | 1 | if ( useStandardOutputDir ) |
1143 | |
{ |
1144 | 1 | getLog().debug( |
1145 | |
"testOutput toRelativeAndFixSeparator " + projectBaseDir + " , " + |
1146 | |
project.getBuild().getTestOutputDirectory() ); |
1147 | 1 | testOutput = |
1148 | |
IdeUtils.toRelativeAndFixSeparator( projectBaseDir, |
1149 | |
new File( project.getBuild().getTestOutputDirectory() ), false ); |
1150 | 1 | getLog().debug( "testOutput after toRelative : " + testOutput ); |
1151 | |
} |
1152 | |
|
1153 | 1 | extractSourceDirs( directories, project.getTestCompileSourceRoots(), basedir, projectBaseDir, true, testOutput ); |
1154 | |
|
1155 | 1 | extractResourceDirs( directories, project.getBuild().getTestResources(), project, basedir, projectBaseDir, |
1156 | |
true, testOutput ); |
1157 | |
|
1158 | 1 | return (EclipseSourceDir[]) directories.toArray( new EclipseSourceDir[directories.size()] ); |
1159 | |
} |
1160 | |
|
1161 | |
private void extractSourceDirs( Set directories, List sourceRoots, File basedir, File projectBaseDir, boolean test, |
1162 | |
String output ) |
1163 | |
throws MojoExecutionException |
1164 | |
{ |
1165 | 2 | for ( Iterator it = sourceRoots.iterator(); it.hasNext(); ) |
1166 | |
{ |
1167 | |
|
1168 | |
File sourceRootFile = new File( (String) it.next() ); |
1169 | |
|
1170 | |
if ( sourceRootFile.isDirectory() ) |
1171 | |
{ |
1172 | |
String sourceRoot = |
1173 | |
IdeUtils.toRelativeAndFixSeparator( projectBaseDir, sourceRootFile, |
1174 | |
!projectBaseDir.equals( basedir ) ); |
1175 | |
|
1176 | |
directories.add( new EclipseSourceDir( sourceRoot, output, false, test, null, null, false ) ); |
1177 | |
} |
1178 | |
} |
1179 | 2 | } |
1180 | |
|
1181 | |
void extractResourceDirs( Set directories, List resources, MavenProject project, File basedir, |
1182 | |
File workspaceProjectBaseDir, boolean test, final String output ) |
1183 | |
throws MojoExecutionException |
1184 | |
{ |
1185 | 8 | for ( Iterator it = resources.iterator(); it.hasNext(); ) |
1186 | |
{ |
1187 | 7 | Resource resource = (Resource) it.next(); |
1188 | |
|
1189 | 7 | getLog().debug( "Processing resource dir: " + resource.getDirectory() ); |
1190 | |
|
1191 | 7 | String includePattern = null; |
1192 | 7 | String excludePattern = null; |
1193 | |
|
1194 | 7 | if ( resource.getIncludes().size() != 0 ) |
1195 | |
{ |
1196 | |
includePattern = StringUtils.join( resource.getIncludes().iterator(), "|" ); |
1197 | |
} |
1198 | |
|
1199 | 7 | if ( resource.getExcludes().size() != 0 ) |
1200 | |
{ |
1201 | |
excludePattern = StringUtils.join( resource.getExcludes().iterator(), "|" ); |
1202 | |
} |
1203 | |
|
1204 | |
|
1205 | |
|
1206 | |
|
1207 | 7 | File resourceDirectory = new File( resource.getDirectory() ); |
1208 | |
|
1209 | 7 | if ( !resourceDirectory.exists() || !resourceDirectory.isDirectory() ) |
1210 | |
{ |
1211 | |
getLog().debug( "Resource dir: " + resourceDirectory + " either missing or not a directory." ); |
1212 | |
continue; |
1213 | |
} |
1214 | |
|
1215 | 7 | String resourceDir = |
1216 | |
IdeUtils.toRelativeAndFixSeparator( workspaceProjectBaseDir, resourceDirectory, |
1217 | |
!workspaceProjectBaseDir.equals( basedir ) ); |
1218 | 7 | String thisOutput = output; |
1219 | 7 | if ( thisOutput != null ) |
1220 | |
{ |
1221 | |
|
1222 | 7 | File outputFile = new File( thisOutput ); |
1223 | 7 | if ( !outputFile.isAbsolute() ) |
1224 | |
{ |
1225 | 7 | outputFile = new File( workspaceProjectBaseDir, thisOutput ); |
1226 | |
} |
1227 | |
|
1228 | 7 | outputFile.mkdirs(); |
1229 | |
|
1230 | 7 | if ( !StringUtils.isEmpty( resource.getTargetPath() ) ) |
1231 | |
{ |
1232 | 1 | outputFile = new File( outputFile, resource.getTargetPath() ); |
1233 | |
|
1234 | 1 | outputFile.mkdirs(); |
1235 | |
} |
1236 | |
|
1237 | 7 | getLog().debug( |
1238 | |
"Making relative and fixing separator: { " + workspaceProjectBaseDir + ", " + |
1239 | |
outputFile + ", false }." ); |
1240 | 7 | thisOutput = IdeUtils.toRelativeAndFixSeparator( workspaceProjectBaseDir, outputFile, false ); |
1241 | |
} |
1242 | |
|
1243 | 7 | getLog().debug( |
1244 | |
"Adding eclipse source dir: { " + resourceDir + ", " + thisOutput + ", true, " + test + |
1245 | |
", " + includePattern + ", " + excludePattern + " }." ); |
1246 | |
|
1247 | 7 | directories.add( new EclipseSourceDir( resourceDir, thisOutput, true, test, includePattern, excludePattern, |
1248 | |
resource.isFiltering() ) ); |
1249 | 7 | } |
1250 | 8 | } |
1251 | |
|
1252 | |
|
1253 | |
|
1254 | |
|
1255 | |
|
1256 | |
|
1257 | |
|
1258 | |
private String calculateProjectNameTemplate() |
1259 | |
{ |
1260 | |
if ( getProjectNameTemplate() != null ) |
1261 | |
{ |
1262 | |
if ( isAddVersionToProjectName() || isAddGroupIdToProjectName() ) |
1263 | |
{ |
1264 | |
getLog().warn( |
1265 | |
"projectNameTemplate definition overrides " |
1266 | |
+ "addVersionToProjectName or addGroupIdToProjectName" ); |
1267 | |
} |
1268 | |
return getProjectNameTemplate(); |
1269 | |
} |
1270 | |
else if ( isAddVersionToProjectName() && isAddGroupIdToProjectName() ) |
1271 | |
{ |
1272 | |
return IdeUtils.PROJECT_NAME_WITH_GROUP_AND_VERSION_TEMPLATE; |
1273 | |
} |
1274 | |
else if ( isAddVersionToProjectName() ) |
1275 | |
{ |
1276 | |
return IdeUtils.PROJECT_NAME_WITH_VERSION_TEMPLATE; |
1277 | |
} |
1278 | |
else if ( isAddGroupIdToProjectName() ) |
1279 | |
{ |
1280 | |
return IdeUtils.PROJECT_NAME_WITH_GROUP_TEMPLATE; |
1281 | |
} |
1282 | |
return IdeUtils.PROJECT_NAME_DEFAULT_TEMPLATE; |
1283 | |
} |
1284 | |
|
1285 | |
|
1286 | |
|
1287 | |
|
1288 | |
public String getProjectNameForArifact( Artifact artifact ) |
1289 | |
{ |
1290 | |
return IdeUtils.getProjectName( calculateProjectNameTemplate(), artifact ); |
1291 | |
} |
1292 | |
} |