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