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
36 import org.apache.maven.artifact.Artifact;
37 import org.apache.maven.artifact.handler.ArtifactHandler;
38 import org.apache.maven.model.Build;
39 import org.apache.maven.model.Plugin;
40 import org.apache.maven.model.Resource;
41 import org.apache.maven.plugin.MojoExecutionException;
42 import org.apache.maven.plugin.eclipse.reader.ReadWorkspaceLocations;
43 import org.apache.maven.plugin.eclipse.writers.EclipseAjdtWriter;
44 import org.apache.maven.plugin.eclipse.writers.EclipseClasspathWriter;
45 import org.apache.maven.plugin.eclipse.writers.EclipseManifestWriter;
46 import org.apache.maven.plugin.eclipse.writers.EclipseOSGiManifestWriter;
47 import org.apache.maven.plugin.eclipse.writers.EclipseProjectWriter;
48 import org.apache.maven.plugin.eclipse.writers.EclipseSettingsWriter;
49 import org.apache.maven.plugin.eclipse.writers.EclipseWriterConfig;
50 import org.apache.maven.plugin.eclipse.writers.wtp.EclipseWtpApplicationXMLWriter;
51 import org.apache.maven.plugin.eclipse.writers.wtp.EclipseWtpComponent15Writer;
52 import org.apache.maven.plugin.eclipse.writers.wtp.EclipseWtpComponentWriter;
53 import org.apache.maven.plugin.eclipse.writers.wtp.EclipseWtpFacetsWriter;
54 import org.apache.maven.plugin.eclipse.writers.wtp.EclipseWtpmodulesWriter;
55 import org.apache.maven.plugin.ide.AbstractIdeSupportMojo;
56 import org.apache.maven.plugin.ide.IdeDependency;
57 import org.apache.maven.plugin.ide.IdeUtils;
58 import org.apache.maven.plugin.ide.JeeUtils;
59 import org.apache.maven.project.MavenProject;
60 import org.codehaus.plexus.resource.ResourceManager;
61 import org.codehaus.plexus.resource.loader.FileResourceLoader;
62 import org.codehaus.plexus.resource.loader.ResourceNotFoundException;
63 import org.codehaus.plexus.util.FileUtils;
64 import org.codehaus.plexus.util.IOUtil;
65 import org.codehaus.plexus.util.StringUtils;
66 import org.codehaus.plexus.util.xml.Xpp3Dom;
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85 public class EclipsePlugin
86 extends AbstractIdeSupportMojo
87 {
88 private static final String WEAVE_DEPENDENCY = "weaveDependency";
89
90 private static final String WEAVE_DEPENDENCIES = "weaveDependencies";
91
92 private static final String ASPECT_LIBRARY = "aspectLibrary";
93
94 private static final String ASPECT_LIBRARIES = "aspectLibraries";
95
96 private static final String ASPECT_DIRECTORY = "aspectDirectory";
97
98 private static final String TEST_ASPECT_DIRECTORY = "testAspectDirectory";
99
100 private static final String ASPECTJ_MAVEN_PLUGIN = "aspectj-maven-plugin";
101
102 private static final String ORG_CODEHAUS_MOJO = "org.codehaus.mojo";
103
104 private static final String DEFAULT_TEST_ASPECT_DIRECTORY = "src/test/aspect";
105
106 private static final String DEFAULT_ASPECT_DIRECTORY = "src/main/aspect";
107
108 private static final String NATURE_WST_FACET_CORE_NATURE = "org.eclipse.wst.common.project.facet.core.nature";
109
110 private static final String BUILDER_WST_COMPONENT_STRUCTURAL_DEPENDENCY_RESOLVER =
111 "org.eclipse.wst.common.modulecore.ComponentStructuralBuilderDependencyResolver";
112
113 protected static final String BUILDER_WST_VALIDATION = "org.eclipse.wst.validation.validationbuilder";
114
115 private static final String BUILDER_JDT_CORE_JAVA = "org.eclipse.jdt.core.javabuilder";
116
117 private static final String BUILDER_WST_COMPONENT_STRUCTURAL =
118 "org.eclipse.wst.common.modulecore.ComponentStructuralBuilder";
119
120 private static final String BUILDER_WST_FACET = "org.eclipse.wst.common.project.facet.core.builder";
121
122 private static final String BUILDER_PDE_MANIFEST = "org.eclipse.pde.ManifestBuilder";
123
124 private static final String BUILDER_PDE_SCHEMA = "org.eclipse.pde.SchemaBuilder";
125
126 private static final String BUILDER_AJDT_CORE_JAVA = "org.eclipse.ajdt.core.ajbuilder";
127
128 private static final String NATURE_WST_MODULE_CORE_NATURE = "org.eclipse.wst.common.modulecore.ModuleCoreNature";
129
130 private static final String NATURE_JDT_CORE_JAVA = "org.eclipse.jdt.core.javanature";
131
132 private static final String NATURE_JEM_WORKBENCH_JAVA_EMF = "org.eclipse.jem.workbench.JavaEMFNature";
133
134 private static final String NATURE_PDE_PLUGIN = "org.eclipse.pde.PluginNature";
135
136 private static final String NATURE_AJDT_CORE_JAVA = "org.eclipse.ajdt.ui.ajnature";
137
138 protected static final String COMMON_PATH_JDT_LAUNCHING_JRE_CONTAINER = "org.eclipse.jdt.launching.JRE_CONTAINER";
139
140 protected static final String ASPECTJ_RT_CONTAINER = "org.eclipse.ajdt.core.ASPECTJRT_CONTAINER";
141
142 protected static final String REQUIRED_PLUGINS_CONTAINER = "org.eclipse.pde.core.requiredPlugins";
143
144
145 public static final String[] WTP_SUPPORTED_VERSIONS = new String[] { "1.0", "1.5", "2.0", "R7", "none" };
146
147 public static final String ASPECTJ_FILE_PATTERN = "**/*.aj";
148
149 public static final String JAVA_FILE_PATTERN = "**/*.java";
150
151
152
153
154 private static final String POM_ELT_ARTIFACT_ID = "artifactId";
155
156
157
158
159 private static final String POM_ELT_GROUP_ID = "groupId";
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174 private List projectnatures;
175
176
177
178
179
180
181
182
183 private List excludes;
184
185
186
187
188
189
190
191
192
193
194
195
196 private List additionalProjectnatures;
197
198
199
200
201
202
203
204
205
206
207
208
209 private Map additionalProjectFacets;
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229 private List buildcommands;
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259 private List additionalBuildcommands;
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275 private List classpathContainers;
276
277
278
279
280
281
282
283 private boolean eclipseDownloadSources;
284
285
286
287
288
289
290 private File eclipseProjectDir;
291
292
293
294
295
296
297
298
299 private boolean useProjectReferences;
300
301
302
303
304
305
306
307
308 private File buildOutputDirectory;
309
310
311
312
313
314
315
316 private String wtpversion;
317
318
319
320
321
322
323 private String wtpContextName;
324
325
326
327
328
329
330
331
332
333 private boolean pde;
334
335
336
337
338 private boolean ajdt;
339
340
341
342
343
344
345 private File manifest;
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
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416 private EclipseConfigFile[] additionalConfig;
417
418
419
420
421
422
423
424 private boolean addVersionToProjectName;
425
426
427
428
429
430
431
432 private boolean addGroupIdToProjectName;
433
434
435
436
437
438
439
440
441 private String projectNameTemplate;
442
443
444
445
446 private float wtpVersionFloat;
447
448
449
450
451 private boolean isJavaProject;
452
453
454
455
456
457
458 private boolean wtpmanifest;
459
460
461
462
463
464
465 private boolean wtpapplicationxml;
466
467
468
469
470
471
472 private String wtpdefaultserver;
473
474 private WorkspaceConfiguration workspaceConfiguration;
475
476
477
478
479
480
481
482
483 private ResourceManager locator;
484
485
486
487
488
489
490
491
492
493
494
495 protected File workspace;
496
497
498
499
500
501
502
503 protected boolean limitProjectReferencesToWorkspace;
504
505
506
507
508
509
510
511 private String ajdtVersion;
512
513
514
515
516
517
518
519
520 private List sourceExcludes;
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535 private List sourceIncludes;
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551 private List linkedResources;
552
553 protected final boolean isJavaProject()
554 {
555 return isJavaProject;
556 }
557
558 protected final boolean isPdeProject()
559 {
560 return pde;
561 }
562
563
564
565
566
567
568 public final List getBuildcommands()
569 {
570 return buildcommands;
571 }
572
573
574
575
576
577
578 public final void setBuildcommands( List buildcommands )
579 {
580 this.buildcommands = buildcommands;
581 }
582
583
584
585
586
587
588 public final File getBuildOutputDirectory()
589 {
590 return buildOutputDirectory;
591 }
592
593
594
595
596
597
598 public final void setBuildOutputDirectory( File buildOutputDirectory )
599 {
600 this.buildOutputDirectory = buildOutputDirectory;
601 }
602
603
604
605
606
607
608 public final List getClasspathContainers()
609 {
610 return classpathContainers;
611 }
612
613
614
615
616
617
618 public final void setClasspathContainers( List classpathContainers )
619 {
620 this.classpathContainers = classpathContainers;
621 }
622
623
624
625
626
627
628 public final File getEclipseProjectDir()
629 {
630 return eclipseProjectDir;
631 }
632
633
634
635
636
637
638 public final void setEclipseProjectDir( File eclipseProjectDir )
639 {
640 this.eclipseProjectDir = eclipseProjectDir;
641 }
642
643
644
645
646
647
648 public final List getProjectnatures()
649 {
650 return projectnatures;
651 }
652
653
654
655
656
657
658 public final void setProjectnatures( List projectnatures )
659 {
660 this.projectnatures = projectnatures;
661 }
662
663
664
665
666
667
668 public final boolean getUseProjectReferences()
669 {
670 return useProjectReferences;
671 }
672
673
674
675
676
677
678 public final void setUseProjectReferences( boolean useProjectReferences )
679 {
680 this.useProjectReferences = useProjectReferences;
681 }
682
683
684
685
686
687
688 public final String getWtpversion()
689 {
690 return wtpversion;
691 }
692
693
694
695
696
697
698 public final void setWtpversion( String wtpversion )
699 {
700 this.wtpversion = wtpversion;
701 }
702
703
704
705
706
707
708 public final List getAdditionalBuildcommands()
709 {
710 return additionalBuildcommands;
711 }
712
713
714
715
716
717
718 public final void setAdditionalBuildcommands( List additionalBuildcommands )
719 {
720 this.additionalBuildcommands = additionalBuildcommands;
721 }
722
723
724
725
726
727
728 public final List getAdditionalProjectnatures()
729 {
730 return additionalProjectnatures;
731 }
732
733
734
735
736
737
738 public final void setAdditionalProjectnatures( List additionalProjectnatures )
739 {
740 this.additionalProjectnatures = additionalProjectnatures;
741 }
742
743
744
745
746 public final boolean isAddVersionToProjectName()
747 {
748 return addVersionToProjectName;
749 }
750
751
752
753
754 public final void setAddVersionToProjectName( boolean addVersionToProjectName )
755 {
756 this.addVersionToProjectName = addVersionToProjectName;
757 }
758
759
760
761
762 public final boolean isAddGroupIdToProjectName()
763 {
764 return addGroupIdToProjectName;
765 }
766
767
768
769
770 public final void setAddGroupIdToProjectName( boolean addGroupIdToProjectName )
771 {
772 this.addGroupIdToProjectName = addGroupIdToProjectName;
773 }
774
775
776
777
778
779
780 public final String getProjectNameTemplate()
781 {
782 return projectNameTemplate;
783 }
784
785
786
787
788
789
790 public final void setProjectNameTemplate( String projectNameTemplate )
791 {
792 this.projectNameTemplate = projectNameTemplate;
793 }
794
795
796
797
798 public List getLinkedResources()
799 {
800 return linkedResources;
801 }
802
803
804
805
806 public void setLinkedResources( List linkedResources )
807 {
808 this.linkedResources = linkedResources;
809 }
810
811
812
813
814 public final boolean setup()
815 throws MojoExecutionException
816 {
817 boolean ready = true;
818
819 checkDeprecations();
820 setProjectNameTemplate( IdeUtils.calculateProjectNameTemplate( getProjectNameTemplate(),
821 isAddVersionToProjectName(),
822 isAddGroupIdToProjectName(), getLog() ) );
823 ajdt = enableAjdt( executedProject ) && !ajdtVersion.equals( "none" );
824 ready = validate();
825
826
827 ArtifactHandler artifactHandler = project.getArtifact().getArtifactHandler();
828
829
830
831 isJavaProject =
832 pde
833 || ( Constants.LANGUAGE_JAVA.equals( artifactHandler.getLanguage() ) && !Constants.PROJECT_PACKAGING_EAR.equals( packaging ) );
834
835 if ( sourceIncludes == null )
836 {
837 sourceIncludes = new ArrayList();
838 }
839 if ( isJavaProject )
840 {
841 sourceIncludes.add( JAVA_FILE_PATTERN );
842 }
843 if ( ajdt )
844 {
845 sourceIncludes.add( ASPECTJ_FILE_PATTERN );
846 }
847
848 if ( sourceExcludes == null )
849 {
850 sourceExcludes = new ArrayList();
851 }
852
853 setupExtras();
854
855 parseConfigurationOptions();
856
857
858 if ( projectnatures == null )
859 {
860 fillDefaultNatures( packaging );
861 }
862
863 if ( additionalProjectnatures != null )
864 {
865 projectnatures.addAll( additionalProjectnatures );
866 }
867
868 if ( buildcommands == null )
869 {
870 fillDefaultBuilders( packaging );
871 }
872 else
873 {
874 convertBuildCommandList( buildcommands );
875 }
876
877 if ( additionalBuildcommands != null )
878 {
879 convertBuildCommandList( additionalBuildcommands );
880 buildcommands.addAll( additionalBuildcommands );
881 }
882
883 if ( classpathContainers == null )
884 {
885 fillDefaultClasspathContainers( packaging );
886 }
887 else
888 {
889 verifyClasspathContainerListIsComplete();
890 }
891
892 if ( linkedResources == null )
893 {
894 linkedResources = new ArrayList();
895 }
896
897 locator.addSearchPath( FileResourceLoader.ID, project.getFile().getParentFile().getAbsolutePath() );
898 locator.setOutputDirectory( new File( project.getBuild().getDirectory() ) );
899
900
901 return ready;
902 }
903
904
905
906
907
908
909
910 protected final void convertBuildCommandList( List commands )
911 {
912 if ( commands != null )
913 {
914 for ( ListIterator i = commands.listIterator(); i.hasNext(); )
915 {
916 Object command = i.next();
917
918 if ( command instanceof String )
919 {
920 command = new BuildCommand( (String) command );
921 i.set( command );
922 }
923 }
924 }
925 }
926
927 private void parseConfigurationOptions()
928 {
929 if ( "R7".equalsIgnoreCase( wtpversion ) )
930 {
931 wtpVersionFloat = 0.7f;
932 }
933 else if ( "1.0".equalsIgnoreCase( wtpversion ) )
934 {
935 wtpVersionFloat = 1.0f;
936 }
937 else if ( "1.5".equalsIgnoreCase( wtpversion ) )
938 {
939 wtpVersionFloat = 1.5f;
940 }
941 else if ( "2.0".equalsIgnoreCase( wtpversion ) )
942 {
943 wtpVersionFloat = 2.0f;
944 }
945 if ( !"none".equalsIgnoreCase( wtpversion ) )
946 {
947 getLog().info( Messages.getString( "EclipsePlugin.wtpversion", wtpversion ) );
948 }
949 }
950
951
952
953
954
955
956
957
958 protected void setupExtras()
959 throws MojoExecutionException
960 {
961
962 }
963
964 private void verifyClasspathContainerListIsComplete()
965 {
966 boolean containsJREContainer = false;
967
968
969 for ( Iterator iter = classpathContainers.iterator(); iter.hasNext(); )
970 {
971 Object classPathContainer = iter.next();
972 if ( classPathContainer != null
973 && classPathContainer.toString().startsWith( COMMON_PATH_JDT_LAUNCHING_JRE_CONTAINER ) )
974 {
975 containsJREContainer = true;
976 break;
977 }
978 }
979 if ( !containsJREContainer )
980 {
981 getLog().warn( Messages.getString( "EclipsePlugin.missingjrecontainer" ) );
982 classpathContainers.add( 0, COMMON_PATH_JDT_LAUNCHING_JRE_CONTAINER );
983 }
984 }
985
986 private boolean validate()
987 throws MojoExecutionException
988 {
989
990 if ( Arrays.binarySearch( WTP_SUPPORTED_VERSIONS, wtpversion ) < 0 )
991 {
992 throw new MojoExecutionException(
993 Messages.getString( "EclipsePlugin.unsupportedwtp", new Object[] {
994 wtpversion,
995 StringUtils.join( WTP_SUPPORTED_VERSIONS, " " ) } ) );
996 }
997
998 assertNotEmpty( executedProject.getGroupId(), POM_ELT_GROUP_ID );
999 assertNotEmpty( executedProject.getArtifactId(), POM_ELT_ARTIFACT_ID );
1000
1001 if ( executedProject.getFile() == null || !executedProject.getFile().exists() )
1002 {
1003 throw new MojoExecutionException( Messages.getString( "EclipsePlugin.missingpom" ) );
1004 }
1005
1006 if ( "pom".equals( packaging ) && eclipseProjectDir == null )
1007 {
1008 getLog().info( Messages.getString( "EclipsePlugin.pompackaging" ) );
1009 return false;
1010 }
1011
1012 if ( "eclipse-plugin".equals( packaging ) )
1013 {
1014 pde = true;
1015 }
1016
1017 if ( eclipseProjectDir == null )
1018 {
1019 eclipseProjectDir = executedProject.getFile().getParentFile();
1020 }
1021
1022 if ( !eclipseProjectDir.exists() && !eclipseProjectDir.mkdirs() )
1023 {
1024 throw new MojoExecutionException( Messages.getString( "EclipsePlugin.cantcreatedir", eclipseProjectDir ) );
1025 }
1026
1027 if ( !eclipseProjectDir.equals( executedProject.getFile().getParentFile() ) )
1028 {
1029 if ( !eclipseProjectDir.isDirectory() )
1030 {
1031 throw new MojoExecutionException( Messages.getString( "EclipsePlugin.notadir", eclipseProjectDir ) );
1032 }
1033 eclipseProjectDir = new File( eclipseProjectDir, executedProject.getArtifactId() );
1034 if ( !eclipseProjectDir.isDirectory() && !eclipseProjectDir.mkdirs() )
1035 {
1036 throw new MojoExecutionException( Messages.getString( "EclipsePlugin.cantcreatedir", eclipseProjectDir ) );
1037 }
1038 }
1039
1040 validateExtras();
1041
1042 return true;
1043 }
1044
1045
1046
1047
1048
1049
1050
1051
1052 protected void validateExtras()
1053 throws MojoExecutionException
1054 {
1055
1056 }
1057
1058 private void checkDeprecations()
1059 {
1060 if ( eclipseDownloadSources )
1061 {
1062
1063 getLog().warn( Messages.getString( "EclipsePlugin.deprecatedpar", new Object[] {
1064 "eclipse.downloadSources",
1065 "downloadSources" } ) );
1066 downloadSources = true;
1067 }
1068
1069 checkDeprecationsExtras();
1070 }
1071
1072
1073
1074
1075
1076
1077 protected void checkDeprecationsExtras()
1078 {
1079
1080 }
1081
1082 public final void writeConfiguration( IdeDependency[] deps )
1083 throws MojoExecutionException
1084 {
1085 EclipseWriterConfig config = createEclipseWriterConfig( deps );
1086
1087 if ( wtpmanifest && isJavaProject() )
1088 {
1089
1090 EclipseManifestWriter.addManifestResource( getLog(), config );
1091 }
1092
1093 writeConfigurationExtras( config );
1094
1095 if ( wtpVersionFloat == 0.7f )
1096 {
1097 new EclipseWtpmodulesWriter().init( getLog(), config ).write();
1098 }
1099
1100 if ( wtpVersionFloat >= 1.0f )
1101 {
1102 new EclipseWtpFacetsWriter().init( getLog(), config ).write();
1103 }
1104 if ( wtpVersionFloat == 1.0f )
1105 {
1106 new EclipseWtpComponentWriter().init( getLog(), config ).write();
1107 }
1108 if ( wtpVersionFloat >= 1.5 )
1109 {
1110 new EclipseWtpComponent15Writer().init( getLog(), config ).write();
1111 }
1112
1113 new EclipseSettingsWriter().init( getLog(), config ).write();
1114
1115 if ( isJavaProject )
1116 {
1117 new EclipseClasspathWriter().init( getLog(), config ).write();
1118 if ( ajdt && ajdtVersion.equals( "1.4" ) )
1119 {
1120 new EclipseAjdtWriter().init( getLog(), config ).write();
1121 }
1122 }
1123
1124 if ( wtpapplicationxml )
1125 {
1126 new EclipseWtpApplicationXMLWriter().init( getLog(), config ).write();
1127 }
1128
1129 if ( pde )
1130 {
1131 this.getLog().info( "The Maven Eclipse plugin runs in 'pde'-mode." );
1132 new EclipseOSGiManifestWriter().init( getLog(), config ).write();
1133 }
1134
1135
1136
1137
1138
1139 new EclipseProjectWriter().init( getLog(), config ).write();
1140
1141 writeAdditionalConfig();
1142
1143 getLog().info( Messages.getString( "EclipsePlugin.wrote", new Object[] {
1144 config.getEclipseProjectName(), eclipseProjectDir.getAbsolutePath() } ) );
1145 }
1146
1147 private void writeAdditionalConfig()
1148 throws MojoExecutionException
1149 {
1150 if ( additionalConfig != null )
1151 {
1152 for ( int j = 0; j < additionalConfig.length; j++ )
1153 {
1154 EclipseConfigFile file = additionalConfig[j];
1155 File projectRelativeFile = new File( eclipseProjectDir, file.getName() );
1156 if ( projectRelativeFile.isDirectory() )
1157 {
1158
1159 getLog().warn( Messages.getString( "EclipsePlugin.foundadir",
1160 projectRelativeFile.getAbsolutePath() ) );
1161 }
1162
1163 try
1164 {
1165 projectRelativeFile.getParentFile().mkdirs();
1166 if ( file.getContent() == null )
1167 {
1168 InputStream inStream;
1169 if ( file.getLocation() != null )
1170 {
1171 inStream = locator.getResourceAsInputStream( file.getLocation() );
1172 }
1173 else
1174 {
1175 inStream = file.getURL().openConnection().getInputStream();
1176 }
1177 OutputStream outStream = new FileOutputStream( projectRelativeFile );
1178 try
1179 {
1180 IOUtil.copy( inStream, outStream );
1181 }
1182 finally
1183 {
1184 inStream.close();
1185 outStream.close();
1186 }
1187 }
1188 else
1189 {
1190 FileUtils.fileWrite( projectRelativeFile.getAbsolutePath(), file.getContent() );
1191 }
1192 }
1193 catch ( IOException e )
1194 {
1195 throw new MojoExecutionException( Messages.getString( "EclipsePlugin.cantwritetofile",
1196 projectRelativeFile.getAbsolutePath() ) );
1197 }
1198 catch ( ResourceNotFoundException e )
1199 {
1200 throw new MojoExecutionException( Messages.getString( "EclipsePlugin.cantfindresource",
1201 file.getLocation() ) );
1202 }
1203
1204 }
1205 }
1206 }
1207
1208
1209
1210
1211
1212
1213
1214
1215 protected final EclipseWriterConfig createEclipseWriterConfig( IdeDependency[] deps )
1216 throws MojoExecutionException
1217 {
1218 File projectBaseDir = executedProject.getFile().getParentFile();
1219
1220
1221
1222 EclipseSourceDir[] sourceDirs = buildDirectoryList( executedProject, eclipseProjectDir, buildOutputDirectory );
1223
1224 EclipseWriterConfig config = new EclipseWriterConfig();
1225
1226 config.setWorkspaceConfiguration( getWorkspaceConfiguration() );
1227
1228 config.setProjectNameTemplate( getProjectNameTemplate() );
1229
1230 String projectName = IdeUtils.getProjectName( config.getProjectNameTemplate(), project );
1231
1232 config.setEclipseProjectName( projectName );
1233
1234 config.setWtpapplicationxml( wtpapplicationxml );
1235
1236 config.setWtpVersion( wtpVersionFloat );
1237
1238 float ajdtVersionFloat;
1239 try
1240 {
1241 ajdtVersionFloat = Float.parseFloat( ajdtVersion );
1242 }
1243 catch ( NumberFormatException e )
1244 {
1245 ajdtVersionFloat = 0.0f;
1246 }
1247
1248 config.setAjdtVersion( ajdtVersionFloat );
1249
1250 Set convertedBuildCommands = new LinkedHashSet();
1251
1252 if ( buildcommands != null )
1253 {
1254 for ( Iterator it = buildcommands.iterator(); it.hasNext(); )
1255 {
1256 Object cmd = it.next();
1257
1258 if ( cmd instanceof BuildCommand )
1259 {
1260 convertedBuildCommands.add( cmd );
1261 }
1262 else
1263 {
1264 convertedBuildCommands.add( new BuildCommand( (String) cmd ) );
1265 }
1266 }
1267 }
1268
1269 if ( ajdt )
1270 {
1271 buildAjdtWeaveDeps( deps );
1272 buildAspectjDeps( deps );
1273 }
1274
1275 config.setBuildCommands( new LinkedList( convertedBuildCommands ) );
1276
1277 config.setBuildOutputDirectory( buildOutputDirectory );
1278 config.setClasspathContainers( classpathContainers );
1279 config.setDeps( deps );
1280 config.setEclipseProjectDirectory( eclipseProjectDir );
1281 config.setLocalRepository( localRepository );
1282 config.setOSGIManifestFile( manifest );
1283 config.setPde( pde );
1284 config.setProject( project );
1285 config.setProjectBaseDir( projectBaseDir );
1286 config.setProjectnatures( projectnatures );
1287 config.setProjectFacets( additionalProjectFacets );
1288 config.setSourceDirs( sourceDirs );
1289 config.setAddVersionToProjectName( isAddVersionToProjectName() );
1290 config.setPackaging( packaging );
1291 config.setLinkedResources( linkedResources );
1292
1293 collectWarContextRootsFromReactorEarConfiguration( config );
1294
1295 return config;
1296 }
1297
1298
1299
1300
1301
1302
1303
1304 private void collectWarContextRootsFromReactorEarConfiguration( EclipseWriterConfig config )
1305 {
1306 if ( reactorProjects != null && wtpContextName == null
1307 && Constants.PROJECT_PACKAGING_WAR.equals( project.getPackaging() ) )
1308 {
1309 for ( Iterator iter = reactorProjects.iterator(); iter.hasNext(); )
1310 {
1311 MavenProject reactorProject = (MavenProject) iter.next();
1312
1313 if ( Constants.PROJECT_PACKAGING_EAR.equals( reactorProject.getPackaging() ) )
1314 {
1315 Xpp3Dom[] warDefinitions =
1316 IdeUtils.getPluginConfigurationDom( reactorProject, JeeUtils.ARTIFACT_MAVEN_EAR_PLUGIN,
1317 new String[] { "modules", "webModule" } );
1318 for ( int index = 0; index < warDefinitions.length; index++ )
1319 {
1320 Xpp3Dom groupId = warDefinitions[index].getChild( "groupId" );
1321 Xpp3Dom artifactId = warDefinitions[index].getChild( "artifactId" );
1322 Xpp3Dom contextRoot = warDefinitions[index].getChild( "contextRoot" );
1323 if ( groupId != null && artifactId != null && contextRoot != null && groupId.getValue() != null
1324 && artifactId.getValue() != null && contextRoot.getValue() != null )
1325 {
1326 getLog().info(
1327 "Found context root definition for " + groupId.getValue() + ":"
1328 + artifactId.getValue() + " " + contextRoot.getValue() );
1329 if ( project.getArtifactId().equals( artifactId.getValue() )
1330 && project.getGroupId().equals( groupId.getValue() ) )
1331 {
1332 config.setContextName( contextRoot.getValue() );
1333 }
1334 }
1335 else
1336 {
1337 getLog().info(
1338 "Found incomplete ear configuration in " + reactorProject.getGroupId() + ":"
1339 + reactorProject.getGroupId() + " found "
1340 + warDefinitions[index].toString() );
1341 }
1342 }
1343 }
1344 }
1345 }
1346 if ( config.getContextName() == null && Constants.PROJECT_PACKAGING_WAR.equals( project.getPackaging() ) )
1347 {
1348 if ( wtpContextName == null )
1349 {
1350 config.setContextName( project.getArtifactId() );
1351 }
1352 else
1353 {
1354 config.setContextName( wtpContextName );
1355 }
1356 }
1357 }
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367 protected void writeConfigurationExtras( EclipseWriterConfig config )
1368 throws MojoExecutionException
1369 {
1370
1371 }
1372
1373 private void assertNotEmpty( String string, String elementName )
1374 throws MojoExecutionException
1375 {
1376 if ( string == null )
1377 {
1378 throw new MojoExecutionException( Messages.getString( "EclipsePlugin.missingelement", elementName ) );
1379 }
1380 }
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390 protected void fillDefaultNatures( String packaging )
1391 {
1392 projectnatures = new ArrayList();
1393
1394 if ( wtpVersionFloat >= 1.0f )
1395 {
1396 projectnatures.add( NATURE_WST_FACET_CORE_NATURE );
1397 }
1398
1399 if ( isJavaProject )
1400 {
1401 if ( ajdt )
1402 {
1403 projectnatures.add( NATURE_AJDT_CORE_JAVA );
1404 }
1405
1406 projectnatures.add( NATURE_JDT_CORE_JAVA );
1407 }
1408
1409 if ( wtpVersionFloat >= 0.7f )
1410 {
1411 projectnatures.add( NATURE_WST_MODULE_CORE_NATURE );
1412
1413 if ( isJavaProject )
1414 {
1415 projectnatures.add( NATURE_JEM_WORKBENCH_JAVA_EMF );
1416 }
1417 }
1418
1419 if ( pde )
1420 {
1421 projectnatures.add( NATURE_PDE_PLUGIN );
1422 }
1423
1424 }
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434 protected void fillDefaultClasspathContainers( String packaging )
1435 {
1436 classpathContainers = new ArrayList();
1437
1438 if ( getWorkspaceConfiguration().getDefaultClasspathContainer() != null )
1439 {
1440 getLog().info(
1441 "Adding default classpath container: "
1442 + getWorkspaceConfiguration().getDefaultClasspathContainer() );
1443 classpathContainers.add( getWorkspaceConfiguration().getDefaultClasspathContainer() );
1444 }
1445 if ( pde )
1446 {
1447 classpathContainers.add( REQUIRED_PLUGINS_CONTAINER );
1448 }
1449
1450 if ( ajdt )
1451 {
1452 classpathContainers.add( ASPECTJ_RT_CONTAINER );
1453 }
1454 }
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464 protected void fillDefaultBuilders( String packaging )
1465 {
1466 buildcommands = new ArrayList();
1467
1468 if ( wtpVersionFloat == 0.7f )
1469 {
1470 buildcommands.add( new BuildCommand( BUILDER_WST_COMPONENT_STRUCTURAL ) );
1471 }
1472
1473 if ( isJavaProject )
1474 {
1475 if ( ajdt )
1476 {
1477 buildcommands.add( new BuildCommand( BUILDER_AJDT_CORE_JAVA ) );
1478 }
1479 else
1480 {
1481 buildcommands.add( new BuildCommand( BUILDER_JDT_CORE_JAVA ) );
1482 }
1483 }
1484
1485 if ( wtpVersionFloat >= 1.5f )
1486 {
1487 buildcommands.add( new BuildCommand( BUILDER_WST_FACET ) );
1488 }
1489
1490 if ( wtpVersionFloat >= 0.7f )
1491 {
1492 buildcommands.add( new BuildCommand( BUILDER_WST_VALIDATION ) );
1493 }
1494
1495 if ( wtpVersionFloat == 0.7f )
1496 {
1497
1498 buildcommands.add( new BuildCommand( BUILDER_WST_COMPONENT_STRUCTURAL_DEPENDENCY_RESOLVER ) );
1499 }
1500
1501 if ( pde )
1502 {
1503 buildcommands.add( new BuildCommand( BUILDER_PDE_MANIFEST ) );
1504 buildcommands.add( new BuildCommand( BUILDER_PDE_SCHEMA ) );
1505 }
1506 }
1507
1508 public final EclipseSourceDir[] buildDirectoryList( MavenProject project, File basedir, File buildOutputDirectory )
1509 throws MojoExecutionException
1510 {
1511 File projectBaseDir = project.getFile().getParentFile();
1512
1513 String mainOutput = IdeUtils.toRelativeAndFixSeparator( projectBaseDir, buildOutputDirectory, false );
1514
1515
1516 String testOutput = null;
1517 boolean useStandardOutputDir =
1518 buildOutputDirectory.equals( new File( project.getBuild().getOutputDirectory() ) );
1519 if ( useStandardOutputDir )
1520 {
1521 getLog().debug(
1522 "testOutput toRelativeAndFixSeparator " + projectBaseDir + " , "
1523 + project.getBuild().getTestOutputDirectory() );
1524 testOutput =
1525 IdeUtils.toRelativeAndFixSeparator( projectBaseDir,
1526 new File( project.getBuild().getTestOutputDirectory() ), false );
1527 getLog().debug( "testOutput after toRelative : " + testOutput );
1528 }
1529
1530 Set mainDirectories = new LinkedHashSet();
1531
1532 extractSourceDirs( mainDirectories, project.getCompileSourceRoots(), basedir, projectBaseDir, false, null );
1533
1534 extractResourceDirs( mainDirectories, project.getBuild().getResources(), basedir, projectBaseDir, false,
1535 mainOutput );
1536
1537 Set testDirectories = new LinkedHashSet();
1538
1539 extractSourceDirs( testDirectories, project.getTestCompileSourceRoots(), basedir, projectBaseDir, true,
1540 testOutput );
1541
1542 extractResourceDirs( testDirectories, project.getBuild().getTestResources(), basedir, projectBaseDir, true,
1543 testOutput );
1544
1545
1546 Set directories = new LinkedHashSet();
1547
1548
1549 boolean testBeforeMain = isMavenVersion( "[2.0.8,)" );
1550
1551 if ( testBeforeMain )
1552 {
1553 directories.addAll( testDirectories );
1554 directories.removeAll( mainDirectories );
1555 directories.addAll( mainDirectories );
1556 }
1557 else
1558 {
1559 directories.addAll( mainDirectories );
1560 directories.addAll( testDirectories );
1561 }
1562 if ( ajdt )
1563 extractAspectDirs( directories, project, basedir, projectBaseDir, testOutput );
1564 return (EclipseSourceDir[]) directories.toArray( new EclipseSourceDir[directories.size()] );
1565 }
1566
1567 private void extractSourceDirs( Set directories, List sourceRoots, File basedir, File projectBaseDir, boolean test,
1568 String output )
1569 throws MojoExecutionException
1570 {
1571 for ( Iterator it = sourceRoots.iterator(); it.hasNext(); )
1572 {
1573
1574 File sourceRootFile = new File( (String) it.next() );
1575
1576 if ( sourceRootFile.isDirectory() )
1577 {
1578 String sourceRoot =
1579 IdeUtils.toRelativeAndFixSeparator( projectBaseDir, sourceRootFile,
1580 !projectBaseDir.equals( basedir ) );
1581
1582 directories.add( new EclipseSourceDir( sourceRoot, output, false, test, sourceIncludes, sourceExcludes,
1583 false ) );
1584 }
1585 }
1586 }
1587
1588 final void extractResourceDirs( Set directories, List resources, File basedir, File workspaceProjectBaseDir,
1589 boolean test, final String output )
1590 throws MojoExecutionException
1591 {
1592 for ( Iterator it = resources.iterator(); it.hasNext(); )
1593 {
1594 Resource resource = (Resource) it.next();
1595
1596 getLog().debug( "Processing resource dir: " + resource.getDirectory() );
1597
1598 List excludes = new ArrayList( resource.getExcludes() );
1599
1600
1601 excludes.add( JAVA_FILE_PATTERN );
1602
1603
1604
1605
1606 File resourceDirectory = new File(
1607
1608 if ( !resourceDirectory.exists() || !resourceDirectory.isDirectory() )
1609 {
1610 getLog().debug( "Resource dir: " + resourceDirectory + " either missing or not a directory." );
1611 continue;
1612 }
1613
1614 String resourcePath =
1615 IdeUtils.toRelativeAndFixSeparator( workspaceProjectBaseDir, resourceDirectory,
1616 !workspaceProjectBaseDir.equals( basedir ) );
1617 String thisOutput = output;
1618 if ( thisOutput != null )
1619 {
1620
1621 File outputFile = new File( thisOutput );
1622 if ( !outputFile.isAbsolute() )
1623 {
1624 outputFile = new File( workspaceProjectBaseDir, thisOutput );
1625 }
1626
1627 outputFile.mkdirs();
1628
1629 if ( !StringUtils.isEmpty( resource.getTargetPath() ) )
1630 {
1631 outputFile = new File( outputFile, resource.getTargetPath() );
1632
1633 outputFile.mkdirs();
1634 }
1635
1636 getLog().debug(
1637 "Making relative and fixing separator: { " + workspaceProjectBaseDir + ", "
1638 + outputFile + ", false }." );
1639 thisOutput = IdeUtils.toRelativeAndFixSeparator( workspaceProjectBaseDir, outputFile, false );
1640 }
1641
1642 EclipseSourceDir resourceDir =
1643 new EclipseSourceDir( resourcePath, thisOutput, true, test, resource.getIncludes(), excludes,
1644 resource.isFiltering() );
1645
1646 if ( !directories.add( resourceDir ) )
1647 {
1648 EclipseSourceDir originalDir = (EclipseSourceDir) get( directories, resourceDir );
1649 getLog().info(
1650 "Resource directory's path matches an existing source directory. Resources will be merged with the source directory "
1651 + originalDir.getPath() );
1652 originalDir.merge( resourceDir );
1653 }
1654 }
1655 }
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665 private Object get( Set set, Object o )
1666 {
1667 Iterator iter = set.iterator();
1668 while ( iter.hasNext() )
1669 {
1670 Object item = iter.next();
1671 if ( o.equals( item ) )
1672 {
1673 return item;
1674 }
1675 }
1676 return null;
1677 }
1678
1679 private void extractAspectDirs( Set directories, MavenProject project, File basedir, File projectBaseDir,
1680 String testOutput )
1681 throws MojoExecutionException
1682 {
1683 Xpp3Dom configuration = getAspectjConfiguration( project );
1684 if ( configuration != null )
1685 {
1686 String aspectDirectory = DEFAULT_ASPECT_DIRECTORY;
1687 Xpp3Dom aspectDirectoryElement = configuration.getChild( ASPECT_DIRECTORY );
1688 if ( aspectDirectoryElement != null )
1689 {
1690 aspectDirectory = aspectDirectoryElement.getValue();
1691 }
1692
1693 File aspectDirectoryFile = new File( basedir, aspectDirectory );
1694 if ( aspectDirectoryFile.exists() && aspectDirectoryFile.isDirectory() )
1695 {
1696 String sourceRoot =
1697 IdeUtils.toRelativeAndFixSeparator( projectBaseDir, aspectDirectoryFile,
1698 !projectBaseDir.equals( basedir ) );
1699
1700 directories.add( new EclipseSourceDir( sourceRoot, null, false, false, sourceIncludes, sourceExcludes,
1701 false ) );
1702 }
1703
1704 String testAspectDirectory = DEFAULT_TEST_ASPECT_DIRECTORY;
1705 Xpp3Dom testAspectDirectoryElement = configuration.getChild( TEST_ASPECT_DIRECTORY );
1706 if ( testAspectDirectoryElement != null )
1707 {
1708 testAspectDirectory = testAspectDirectoryElement.getValue();
1709 }
1710
1711 File testAspectDirectoryFile = new File( basedir, testAspectDirectory );
1712 if ( testAspectDirectoryFile.exists() && testAspectDirectoryFile.isDirectory() )
1713 {
1714 String sourceRoot =
1715 IdeUtils.toRelativeAndFixSeparator( projectBaseDir, testAspectDirectoryFile,
1716 !projectBaseDir.equals( basedir ) );
1717
1718 directories.add( new EclipseSourceDir( sourceRoot, testOutput, false, true, sourceIncludes,
1719 sourceExcludes, false ) );
1720 }
1721 }
1722 }
1723
1724 private boolean enableAjdt( MavenProject project )
1725 {
1726 boolean enable = false;
1727 List buildPlugins = project.getBuildPlugins();
1728 for ( Iterator it = buildPlugins.iterator(); it.hasNext(); )
1729 {
1730 Plugin plugin = (Plugin) it.next();
1731 if ( plugin.getGroupId().equals( ORG_CODEHAUS_MOJO )
1732 && plugin.getArtifactId().equals( ASPECTJ_MAVEN_PLUGIN ) )
1733 {
1734 enable = true;
1735 break;
1736 }
1737 }
1738
1739 return enable;
1740 }
1741
1742 private Xpp3Dom getAspectjConfiguration( MavenProject project )
1743 {
1744 Xpp3Dom configuration = null;
1745 List buildPlugins = project.getBuildPlugins();
1746 for ( Iterator it = buildPlugins.iterator(); it.hasNext(); )
1747 {
1748 Plugin plugin = (Plugin) it.next();
1749 if ( plugin.getGroupId().equals( ORG_CODEHAUS_MOJO )
1750 && plugin.getArtifactId().equals( ASPECTJ_MAVEN_PLUGIN ) )
1751 {
1752 configuration = (Xpp3Dom) plugin.getConfiguration();
1753 break;
1754 }
1755 }
1756
1757 return configuration;
1758 }
1759
1760 private void buildAspectjDeps( IdeDependency[] deps )
1761 throws MojoExecutionException
1762 {
1763 Xpp3Dom configuration = getAspectjConfiguration( executedProject );
1764 if ( configuration != null )
1765 {
1766 Xpp3Dom aspectLibrariesParent = configuration.getChild( ASPECT_LIBRARIES );
1767 if ( aspectLibrariesParent != null )
1768 {
1769 Xpp3Dom[] aspectLibraries = aspectLibrariesParent.getChildren( ASPECT_LIBRARY );
1770 outerLoop: for ( int i = 0; i < aspectLibraries.length; i++ )
1771 {
1772 String artifactId = aspectLibraries[i].getChild( POM_ELT_ARTIFACT_ID ).getValue();
1773 String groupId = aspectLibraries[i].getChild( POM_ELT_GROUP_ID ).getValue();
1774 for ( int j = 0; j < deps.length; j++ )
1775 {
1776 if ( deps[j].getArtifactId().equals( artifactId ) && deps[j].getGroupId().equals( groupId ) )
1777 {
1778 deps[j].setAjdtDependency( true );
1779 continue outerLoop;
1780 }
1781 }
1782
1783 throw new MojoExecutionException( "AspectLibrary is not a dependency of project" );
1784 }
1785 }
1786 }
1787 }
1788
1789 private void buildAjdtWeaveDeps( IdeDependency[] deps )
1790 throws MojoExecutionException
1791 {
1792 Xpp3Dom configuration = getAspectjConfiguration( executedProject );
1793 if ( configuration != null )
1794 {
1795 Xpp3Dom weaveDependenciesParent = configuration.getChild( WEAVE_DEPENDENCIES );
1796 if ( weaveDependenciesParent != null )
1797 {
1798 Xpp3Dom[] weaveDependencies = weaveDependenciesParent.getChildren( WEAVE_DEPENDENCY );
1799 outerLoop: for ( int i = 0; i < weaveDependencies.length; i++ )
1800 {
1801 String artifactId = weaveDependencies[i].getChild( POM_ELT_ARTIFACT_ID ).getValue();
1802 String groupId = weaveDependencies[i].getChild( POM_ELT_GROUP_ID ).getValue();
1803 for ( int j = 0; j < deps.length; j++ )
1804 {
1805 if ( deps[j].getArtifactId().equals( artifactId ) && deps[j].getGroupId().equals( groupId ) )
1806 {
1807 deps[j].setAjdtWeaveDependency( true );
1808 continue outerLoop;
1809 }
1810 }
1811
1812 throw new MojoExecutionException( "WeaveDependency is not a dependency of project" );
1813 }
1814 }
1815 }
1816 }
1817
1818
1819
1820
1821 public String getProjectNameForArifact( Artifact artifact )
1822 {
1823 IdeDependency[] workspaceArtefacts = getWorkspaceArtefacts();
1824 for ( int index = 0; workspaceArtefacts != null && index < workspaceArtefacts.length; index++ )
1825 {
1826 IdeDependency workspaceArtefact = workspaceArtefacts[index];
1827 if ( workspaceArtefact.isAddedToClasspath()
1828 && workspaceArtefact.getGroupId().equals( artifact.getGroupId() )
1829 && workspaceArtefact.getArtifactId().equals( artifact.getArtifactId() ) )
1830 {
1831 if ( workspaceArtefact.getVersion().equals( artifact.getVersion() ) )
1832 {
1833 return workspaceArtefact.getEclipseProjectName();
1834 }
1835 }
1836 }
1837 MavenProject reactorProject = getReactorProject( artifact );
1838 if ( reactorProject != null )
1839 {
1840 return IdeUtils.getProjectName( getProjectNameTemplateForMavenProject( reactorProject ), artifact );
1841 }
1842 return IdeUtils.getProjectName( getProjectNameTemplate(), artifact );
1843 }
1844
1845
1846
1847
1848
1849 private String getProjectNameTemplateForMavenProject( MavenProject mavenProject )
1850 {
1851 String projectNameTemplate = null;
1852 boolean addVersionToProjectName = false;
1853 boolean addGroupIdToProjectName = false;
1854
1855 Build build = mavenProject.getBuild();
1856 if ( build != null )
1857 {
1858 String eclipsePlugin = "org.apache.maven.plugins:maven-eclipse-plugin";
1859 Plugin plugin = (Plugin) build.getPluginsAsMap().get( eclipsePlugin );
1860 if ( plugin == null && build.getPluginManagement() != null )
1861 {
1862 plugin = (Plugin) build.getPluginManagement().getPluginsAsMap().get( eclipsePlugin );
1863 }
1864 if ( plugin != null )
1865 {
1866 Xpp3Dom config = (Xpp3Dom) plugin.getConfiguration();
1867 if ( config != null )
1868 {
1869 Xpp3Dom projectNameTemplateNode = config.getChild( "projectNameTemplate" );
1870 if ( projectNameTemplateNode != null )
1871 {
1872 projectNameTemplate = projectNameTemplateNode.getValue();
1873 }
1874 Xpp3Dom addVersionToProjectNameNode = config.getChild( "addVersionToProjectName" );
1875 addVersionToProjectName = addVersionToProjectNameNode != null;
1876 Xpp3Dom addGroupIdToProjectNameNode = config.getChild( "addGroupIdToProjectName" );
1877 addGroupIdToProjectName = addGroupIdToProjectNameNode != null;
1878 }
1879 }
1880 }
1881 return IdeUtils.calculateProjectNameTemplate( projectNameTemplate, addVersionToProjectName,
1882 addGroupIdToProjectName, getLog() );
1883 }
1884
1885
1886
1887
1888 protected final IdeDependency[] getWorkspaceArtefacts()
1889 {
1890 return getWorkspaceConfiguration().getWorkspaceArtefacts();
1891 }
1892
1893 public final WorkspaceConfiguration getWorkspaceConfiguration()
1894 {
1895 if ( workspaceConfiguration == null )
1896 {
1897 workspaceConfiguration = new WorkspaceConfiguration();
1898 locateWorkspace();
1899 getLog().info( Messages.getString( "EclipsePlugin.workspace", workspace ) );
1900 workspaceConfiguration.setWorkspaceDirectory( workspace );
1901
1902 new ReadWorkspaceLocations().init( getLog(), workspaceConfiguration, project, wtpdefaultserver );
1903 }
1904 return workspaceConfiguration;
1905 }
1906
1907
1908
1909
1910 private void locateWorkspace()
1911 {
1912 if ( workspace == null )
1913 {
1914 File currentWorkingDirectory = new File( "." ).getAbsoluteFile();
1915 while ( currentWorkingDirectory != null )
1916 {
1917 File metadataDirectory = new File( currentWorkingDirectory, ".metadata" );
1918 logger.debug( "Checking for eclipse workspace at " + currentWorkingDirectory );
1919 if ( metadataDirectory.exists() && metadataDirectory.isDirectory() )
1920 {
1921 logger.debug( " Found workspace at " + currentWorkingDirectory );
1922 workspace = currentWorkingDirectory;
1923 return;
1924 }
1925 currentWorkingDirectory = currentWorkingDirectory.getParentFile();
1926 }
1927 }
1928 }
1929
1930 public final List getExcludes()
1931 {
1932 return excludes;
1933 }
1934
1935
1936
1937
1938
1939
1940
1941 private boolean isAvailableAsAWorkspaceProject( Artifact artifact )
1942 {
1943 IdeDependency[] workspaceArtefacts = getWorkspaceArtefacts();
1944 for ( int index = 0; workspaceArtefacts != null && index < workspaceArtefacts.length; index++ )
1945 {
1946 IdeDependency workspaceArtefact = workspaceArtefacts[index];
1947 if ( workspaceArtefact.getGroupId().equals( artifact.getGroupId() )
1948 && workspaceArtefact.getArtifactId().equals( artifact.getArtifactId() ) )
1949 {
1950 if ( workspaceArtefact.getVersion().equals( artifact.getVersion() ) )
1951 {
1952 workspaceArtefact.setAddedToClasspath( true );
1953 getLog().debug( "Using workspace project: " + workspaceArtefact.getEclipseProjectName() );
1954 return true;
1955 }
1956 else
1957 {
1958 getLog().info(
1959 "Artifact "
1960 + artifact.getId()
1961 + " already available as a workspace project, but with different version. Expected: "
1962 + artifact.getVersion() + ", found: " + workspaceArtefact.getVersion() );
1963 }
1964 }
1965 }
1966 return false;
1967 }
1968
1969
1970
1971
1972
1973
1974
1975 protected final boolean hasToResolveJar( Artifact art )
1976 {
1977 return !( getUseProjectReferences() && isAvailableAsAReactorProject( art ) )
1978 || ( limitProjectReferencesToWorkspace && !( getUseProjectReferences() && isAvailableAsAWorkspaceProject( art ) ) );
1979 }
1980
1981
1982
1983
1984
1985
1986
1987 protected final boolean useProjectReference( Artifact art )
1988 {
1989 boolean isReactorProject = getUseProjectReferences() && isAvailableAsAReactorProject( art );
1990 boolean isWorkspaceProject = getUseProjectReferences() && isAvailableAsAWorkspaceProject( art );
1991 return ( isReactorProject && !limitProjectReferencesToWorkspace ) ||
1992 ( limitProjectReferencesToWorkspace && isWorkspaceProject ) ||
1993 ( !isReactorProject && isWorkspaceProject );
1994 }
1995 }