summaryrefslogtreecommitdiffstats
path: root/maven-plugins/trunk/maven-bundle-plugin/src/main/java/org/apache/tuscany/maven/plugin/eclipse/EclipsePlugin.java
blob: 781bc130d952911f065fee12d8e2dfa8dad9e160 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
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
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
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package org.apache.tuscany.maven.plugin.eclipse;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Set;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.model.Build;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.Resource;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.eclipse.BuildCommand;
import org.apache.maven.plugin.eclipse.Constants;
import org.apache.maven.plugin.eclipse.EclipseConfigFile;
import org.apache.maven.plugin.eclipse.EclipseSourceDir;
import org.apache.maven.plugin.eclipse.WorkspaceConfiguration;
import org.apache.maven.plugin.eclipse.reader.ReadWorkspaceLocations;
import org.apache.maven.plugin.eclipse.writers.EclipseAjdtWriter;
import org.apache.maven.plugin.eclipse.writers.EclipseManifestWriter;
import org.apache.maven.plugin.eclipse.writers.EclipseSettingsWriter;
import org.apache.maven.plugin.eclipse.writers.EclipseWriterConfig;
import org.apache.maven.plugin.eclipse.writers.wtp.EclipseWtpApplicationXMLWriter;
import org.apache.maven.plugin.eclipse.writers.wtp.EclipseWtpComponent15Writer;
import org.apache.maven.plugin.eclipse.writers.wtp.EclipseWtpComponentWriter;
import org.apache.maven.plugin.eclipse.writers.wtp.EclipseWtpFacetsWriter;
import org.apache.maven.plugin.eclipse.writers.wtp.EclipseWtpmodulesWriter;
import org.apache.maven.plugin.ide.IdeDependency;
import org.apache.maven.plugin.ide.IdeUtils;
import org.apache.maven.plugin.ide.JeeUtils;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.resource.ResourceManager;
import org.codehaus.plexus.resource.loader.FileResourceLoader;
import org.codehaus.plexus.resource.loader.ResourceNotFoundException;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.xml.Xpp3Dom;

/**
 * Generates the following eclipse configuration files:
 * <ul>
 * <li><code>.project</code> and <code>.classpath</code> files</li>
 * <li><code>.setting/org.eclipse.jdt.core.prefs</code> with project specific compiler settings</li>
 * <li>various configuration files for WTP (Web Tools Project), if the parameter <code>wtpversion</code> is set to a
 * valid version (WTP configuration is not generated by default)</li>
 * </ul>
 * If this goal is run on a multiproject root, dependencies between modules will be configured as direct project
 * dependencies in Eclipse (unless <code>useProjectReferences</code> is set to <code>false</code>).
 *
 * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
 * @author <a href="mailto:fgiust@apache.org">Fabrizio Giustina</a>
 * @version $Id: EclipsePlugin.java 756392 2009-03-20 09:46:09Z baerrach $
 * @goal eclipse
 * @execute phase="generate-resources"
 */
public class EclipsePlugin
    extends AbstractIdeSupportMojo
{
    private static final String WEAVE_DEPENDENCY = "weaveDependency";

    private static final String WEAVE_DEPENDENCIES = "weaveDependencies";

    private static final String ASPECT_LIBRARY = "aspectLibrary";

    private static final String ASPECT_LIBRARIES = "aspectLibraries";

    private static final String ASPECT_DIRECTORY = "aspectDirectory";

    private static final String TEST_ASPECT_DIRECTORY = "testAspectDirectory";

    private static final String ASPECTJ_MAVEN_PLUGIN = "aspectj-maven-plugin";

    private static final String ORG_CODEHAUS_MOJO = "org.codehaus.mojo";

    private static final String DEFAULT_TEST_ASPECT_DIRECTORY = "src/test/aspect";

    private static final String DEFAULT_ASPECT_DIRECTORY = "src/main/aspect";

    private static final String NATURE_WST_FACET_CORE_NATURE = "org.eclipse.wst.common.project.facet.core.nature"; //$NON-NLS-1$

    private static final String BUILDER_WST_COMPONENT_STRUCTURAL_DEPENDENCY_RESOLVER =
        "org.eclipse.wst.common.modulecore.ComponentStructuralBuilderDependencyResolver"; //$NON-NLS-1$

    protected static final String BUILDER_WST_VALIDATION = "org.eclipse.wst.validation.validationbuilder"; //$NON-NLS-1$

    private static final String BUILDER_JDT_CORE_JAVA = "org.eclipse.jdt.core.javabuilder"; //$NON-NLS-1$

    private static final String BUILDER_WST_COMPONENT_STRUCTURAL =
        "org.eclipse.wst.common.modulecore.ComponentStructuralBuilder"; //$NON-NLS-1$

    private static final String BUILDER_WST_FACET = "org.eclipse.wst.common.project.facet.core.builder"; //$NON-NLS-1$

    private static final String BUILDER_PDE_MANIFEST = "org.eclipse.pde.ManifestBuilder"; //$NON-NLS-1$

    private static final String BUILDER_PDE_SCHEMA = "org.eclipse.pde.SchemaBuilder"; //$NON-NLS-1$

    private static final String BUILDER_AJDT_CORE_JAVA = "org.eclipse.ajdt.core.ajbuilder"; //$NON-NLS-1$

    private static final String NATURE_WST_MODULE_CORE_NATURE = "org.eclipse.wst.common.modulecore.ModuleCoreNature"; //$NON-NLS-1$

    private static final String NATURE_JDT_CORE_JAVA = "org.eclipse.jdt.core.javanature"; //$NON-NLS-1$

    private static final String NATURE_JEM_WORKBENCH_JAVA_EMF = "org.eclipse.jem.workbench.JavaEMFNature"; //$NON-NLS-1$

    private static final String NATURE_PDE_PLUGIN = "org.eclipse.pde.PluginNature"; //$NON-NLS-1$

    private static final String NATURE_AJDT_CORE_JAVA = "org.eclipse.ajdt.ui.ajnature"; //$NON-NLS-1$

    protected static final String COMMON_PATH_JDT_LAUNCHING_JRE_CONTAINER = "org.eclipse.jdt.launching.JRE_CONTAINER"; //$NON-NLS-1$

    protected static final String ASPECTJ_RT_CONTAINER = "org.eclipse.ajdt.core.ASPECTJRT_CONTAINER"; //$NON-NLS-1$

    protected static final String REQUIRED_PLUGINS_CONTAINER = "org.eclipse.pde.core.requiredPlugins"; //$NON-NLS-1$

    // warning, order is important for binary search
    public static final String[] WTP_SUPPORTED_VERSIONS = new String[] { "1.0", "1.5", "2.0", "R7", "none" }; //$NON-NLS-1$ //$NON-NLS-2$  //$NON-NLS-3$

    /**
     * Constant for 'artifactId' element in POM.xml.
     */
    private static final String POM_ELT_ARTIFACT_ID = "artifactId"; //$NON-NLS-1$

    /**
     * Constant for 'groupId' element in POM.xml.
     */
    private static final String POM_ELT_GROUP_ID = "groupId"; //$NON-NLS-1$

    /**
     * List of eclipse project natures. By default the <code>org.eclipse.jdt.core.javanature</code> nature plus the
     * needed WTP natures are added. Natures added using this property <strong>replace</strong> the default list.
     *
     * <pre>
     * &lt;projectnatures&gt;
     *    &lt;projectnature&gt;org.eclipse.jdt.core.javanature&lt;/projectnature&gt;
     *    &lt;projectnature&gt;org.eclipse.wst.common.modulecore.ModuleCoreNature&lt;/projectnature&gt;
     * &lt;/projectnatures&gt;
     * </pre>
     *
     * @parameter
     */
    private List projectnatures;

    /**
     * List of artifact to exclude from eclipse classpath, beeing provided by some eclipse classPathContainer
     * [MECLIPSE-79]
     *
     * @since 2.5
     * @parameter
     */
    private List excludes;

    /**
     * List of eclipse project natures to be added to the default ones.
     *
     * <pre>
     * &lt;additionalProjectnatures&gt;
     *    &lt;projectnature&gt;org.springframework.ide.eclipse.core.springnature&lt;/projectnature&gt;
     * &lt;/additionalProjectnatures&gt;
     * </pre>
     *
     * @parameter
     */
    private List additionalProjectnatures;

    /**
     * List of eclipse project facets to be added to the default ones.
     *
     * <pre>
     * &lt;additionalProjectFacets&gt;
     *    &lt;jst.jsf&gt;1.1&lt;jst.jsf/&gt;
     * &lt;/additionalProjectFacets&gt;
     * </pre>
     *
     * @parameter
     */
    private Map additionalProjectFacets;

    /**
     * List of eclipse build commands. By default the <code>org.eclipse.jdt.core.javabuilder</code> builder plus the
     * needed WTP builders are added. If you specify any configuration for this parameter, only those buildcommands
     * specified will be used; the defaults won't be added. Use the <code>additionalBuildCommands</code> parameter for
     * that. Configuration example: Old style:
     *
     * <pre>
     * &lt;buildcommands&gt;
     *    &lt;buildcommand&gt;org.eclipse.wst.common.modulecore.ComponentStructuralBuilder&lt;/buildcommand&gt;
     *    &lt;buildcommand&gt;org.eclipse.jdt.core.javabuilder&lt;/buildcommand&gt;
     *    &lt;buildcommand&gt;org.eclipse.wst.common.modulecore.ComponentStructuralBuilderDependencyResolver&lt;/buildcommand&gt;
     * &lt;/buildcommands&gt;
     * </pre>
     *
     * For new style, see <code>additionalBuildCommands</code>.
     *
     * @parameter
     */
    private List buildcommands;

    /**
     * List of eclipse build commands to be added to the default ones. Old style:
     *
     * <pre>
     * &lt;additionalBuildcommands&gt;
     *    &lt;buildcommand&gt;org.springframework.ide.eclipse.core.springbuilder&lt;/buildcommand&gt;
     * &lt;/additionalBuildcommands&gt;
     * </pre>
     *
     * New style:
     *
     * <pre>
     * &lt;additionalBuildcommands&gt;
     *    &lt;buildCommand&gt;
     *      &lt;name&gt;org.ui.externaltools.ExternalToolBuilder&lt;/name&gt;
     *      &lt;triggers&gt;auto,full,incremental,&lt;/triggers&gt;
     *      &lt;arguments&gt;
     *        &lt;LaunchConfigHandle&gt;&amp;lt;project&amp;gt;./externalToolBuilders/MavenBuilder.launch&lt;/LaunchConfighandle&gt;
     *      &lt;/arguments&gt;
     *    &lt;/buildCommand&gt;
     * &lt;/additionalBuildcommands&gt;
     * </pre>
     *
     * Note the difference between <code>build<strong>c</strong>ommand</code> and
     * <code>build<strong>C</strong>ommand</code>. You can mix and match old and new-style configuration entries.
     *
     * @parameter
     */
    private List additionalBuildcommands;

    /**
     * List of container classpath entries. By default the <code>org.eclipse.jdt.launching.JRE_CONTAINER</code>
     * classpath container is added. Configuration example:
     *
     * <pre>
     * &lt;classpathContainers&gt;
     *    &lt;classpathContainer&gt;org.eclipse.jdt.launching.JRE_CONTAINER&lt;/classpathContainer&gt;
     *    &lt;classpathContainer&gt;org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v5.5&lt;/classpathContainer&gt;
     *    &lt;classpathContainer&gt;org.eclipse.jst.j2ee.internal.web.container/artifact&lt;/classpathContainer&gt;
     * &lt;/classpathContainers&gt;
     * </pre>
     *
     * @parameter
     */
    private List classpathContainers;

    /**
     * Enables/disables the downloading of source attachments. Defaults to false. DEPRECATED - use downloadSources
     *
     * @parameter expression="${eclipse.downloadSources}"
     * @deprecated use downloadSources
     */
    private boolean eclipseDownloadSources;

    /**
     * Eclipse workspace directory.
     *
     * @parameter expression="${eclipse.projectDir}" alias="outputDir"
     */
    private File eclipseProjectDir;

    /**
     * When set to false, the plugin will not create sub-projects and instead reference those sub-projects using the
     * installed package in the local repository
     *
     * @parameter expression="${eclipse.useProjectReferences}" default-value="true"
     * @required
     */
    private boolean useProjectReferences;

    /**
     * The default output directory
     *
     * @parameter expression="${outputDirectory}" alias="outputDirectory"
     *            default-value="${project.build.outputDirectory}"
     * @required
     */
    private File buildOutputDirectory;

    /**
     * The version of WTP for which configuration files will be generated. The default value is "none" (don't generate
     * WTP configuration), supported versions are "R7", "1.0", and "1.5"
     *
     * @parameter expression="${wtpversion}" default-value="none"
     */
    private String wtpversion;

    /**
     * JEE context name of the WTP module. ( ex. WEB context name ).
     *
     * @parameter expression="${wtpContextName}"
     */
    private String wtpContextName;

    /**
     * Is it an AJDT project? If yes, the plugin adds the necessary natures and build commands to the .project file.
     */
    private boolean ajdt;

    /**
     * The relative path of the manifest file
     *
     * @parameter expression="${eclipse.manifest}" default-value="${basedir}/META-INF/MANIFEST.MF"
     */
    private File manifest;

    /**
     * Allow to configure additional generic configuration files for eclipse that will be written out to disk when
     * running eclipse:eclipse. FOr each file you can specify the name and the text content.
     *
     * <pre>
     * &lt;plugin&gt;
     *  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
     *  &lt;artifactId&gt;maven-eclipse-plugin&lt;/artifactId&gt;
     *  &lt;configuration&gt;
     *   &lt;additionalConfig&gt;
     *    &lt;file&gt;
     *      &lt;name&gt;.checkstyle&lt;/name&gt;
     *      &lt;content&gt;
     *        &lt;![CDATA[&lt;fileset-config file-format-version=&quot;1.2.0&quot; simple-config=&quot;true&quot;&gt;
     *          &lt;fileset name=&quot;all&quot; enabled=&quot;true&quot; check-config-name=&quot;acme corporate style&quot; local=&quot;false&quot;&gt;
     *              &lt;file-match-pattern match-pattern=&quot;.&quot; include-pattern=&quot;true&quot;/&gt;
     *          &lt;/fileset&gt;
     *          &lt;filter name=&quot;NonSrcDirs&quot; enabled=&quot;true&quot;/&gt;
     *        &lt;/fileset-config&gt;]]&gt;
     *      &lt;/content&gt;
     *    &lt;/file&gt;
     *   &lt;/additionalConfig&gt;
     *  &lt;/configuration&gt;
     * &lt;/plugin&gt;
     * </pre>
     *
     * Instead of the content you can also define (from version 2.5) an url to download the file :
     *
     * <pre>
     * &lt;plugin&gt;
     *  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
     *  &lt;artifactId&gt;maven-eclipse-plugin&lt;/artifactId&gt;
     *  &lt;configuration&gt;
     *   &lt;additionalConfig&gt;
     *    &lt;file&gt;
     *      &lt;name&gt;.checkstyle&lt;/name&gt;
     *      &lt;url&gt;http://some.place.org/path/to/file&lt;/url&gt;
     *    &lt;/file&gt;
     *   &lt;/additionalConfig&gt;
     *  &lt;/configuration&gt;
     * </pre>
     *
     * or a location :
     *
     * <pre>
     * &lt;plugin&gt;
     *  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
     *  &lt;artifactId&gt;maven-eclipse-plugin&lt;/artifactId&gt;
     *  &lt;configuration&gt;
     *   &lt;additionalConfig&gt;
     *    &lt;file&gt;
     *     &lt;name&gt;.checkstyle&lt;/name&gt;
     *     &lt;location&gt;/checkstyle-config.xml&lt;/location&gt;
     *    &lt;/file&gt;
     *   &lt;/additionalConfig&gt;
     *  &lt;/configuration&gt;
     *  &lt;dependencies&gt;
     *   &lt;!-- The file defined in the location is stored in this dependency --&gt;
     *   &lt;dependency&gt;
     *    &lt;groupId&gt;eclipsetest&lt;/groupId&gt;
     *    &lt;artifactId&gt;checkstyle-config&lt;/artifactId&gt;
     *    &lt;version&gt;1.0&lt;/version&gt;
     *   &lt;/dependency&gt;
     *  &lt;/dependencies&gt;
     * &lt;/plugin&gt;
     * </pre>
     *
     * @parameter
     */
    private EclipseConfigFile[] additionalConfig;

    /**
     * If set to <code>true</code>, the version number of the artifact is appended to the name of the generated Eclipse
     * project. See projectNameTemplate for other options.
     *
     * @parameter expression="${eclipse.addVersionToProjectName}" default-value="false"
     */
    private boolean addVersionToProjectName;

    /**
     * If set to <code>true</code>, the groupId of the artifact is appended to the name of the generated Eclipse
     * project. See projectNameTemplate for other options.
     *
     * @parameter expression="${eclipse.addGroupIdToProjectName}" default-value="false"
     */
    private boolean addGroupIdToProjectName;

    /**
     * Allows configuring the name of the eclipse projects. This property if set wins over addVersionToProjectName and
     * addGroupIdToProjectName You can use <code>[groupId]</code>, <code>[artifactId]</code> and <code>[version]</code>
     * variables. eg. <code>[groupId].[artifactId]-[version]</code>
     *
     * @parameter expression="${eclipse.projectNameTemplate}"
     */
    private String projectNameTemplate;

    /**
     * Parsed wtp version.
     */
    private float wtpVersionFloat;

    /**
     * Not a plugin parameter. Is this a java project?
     */
    private boolean isJavaProject;

    /**
     * Must the manifest files be written for java projects so that that the jee classpath for wtp is correct.
     *
     * @parameter expression="${eclipse.wtpmanifest}" default-value="false"
     */
    private boolean wtpmanifest;

    /**
     * Must the application files be written for ear projects in a separate directory.
     *
     * @parameter expression="${eclipse.wtpapplicationxml}" default-value="false"
     */
    private boolean wtpapplicationxml;

    /**
     * What WTP defined server to use for deployment informations.
     *
     * @parameter expression="${eclipse.wtpdefaultserver}"
     */
    private String wtpdefaultserver;

    private WorkspaceConfiguration workspaceConfiguration;

    /**
     * ResourceManager for getting additonalConfig files from resources
     *
     * @component
     * @required
     * @readonly
     */
    private ResourceManager locator;

    /**
     * This eclipse workspace is read and all artifacts detected there will be connected as eclipse projects and will
     * not be linked to the jars in the local repository. Requirement is that it was created with the similar wtp
     * settings as the reactor projects, but the project name template my differ. The pom's in the workspace projects
     * may not contain variables in the artefactId, groupId and version tags.
     *
     * If workspace is not defined, then an attempt to locate it by checking up the directory hierarchy will be made.
     *
     * @since 2.5
     * @parameter expression="${eclipse.workspace}"
     */
    protected File workspace;

    /**
     * Limit the use of project references to the current workspace. No project references will be created to projects
     * in the reactor when they are not available in the workspace.
     *
     * @parameter expression="${eclipse.limitProjectReferencesToWorkspace}" default-value="false"
     */
    protected boolean limitProjectReferencesToWorkspace;

    /**
     * The version of AJDT for which configuration files will be generated. The default value is "1.5", supported
     * versions are "none", "1.4", and "1.5".
     *
     * @parameter expression="${eclipse.ajdtVersion}" default-value="1.5"
     */
    private String ajdtVersion;

    protected final boolean isJavaProject()
    {
        return isJavaProject;
    }

    protected final boolean isPdeProject()
    {
        return pde;
    }

    /**
     * Getter for <code>buildcommands</code>.
     *
     * @return Returns the buildcommands.
     */
    public final List getBuildcommands()
    {
        return buildcommands;
    }

    /**
     * Setter for <code>buildcommands</code>.
     *
     * @param buildcommands The buildcommands to set.
     */
    public final void setBuildcommands( List buildcommands )
    {
        this.buildcommands = buildcommands;
    }

    /**
     * Getter for <code>buildOutputDirectory</code>.
     *
     * @return Returns the buildOutputDirectory.
     */
    public final File getBuildOutputDirectory()
    {
        return buildOutputDirectory;
    }

    /**
     * Setter for <code>buildOutputDirectory</code>.
     *
     * @param buildOutputDirectory The buildOutputDirectory to set.
     */
    public final void setBuildOutputDirectory( File buildOutputDirectory )
    {
        this.buildOutputDirectory = buildOutputDirectory;
    }

    /**
     * Getter for <code>classpathContainers</code>.
     *
     * @return Returns the classpathContainers.
     */
    public final List getClasspathContainers()
    {
        return classpathContainers;
    }

    /**
     * Setter for <code>classpathContainers</code>.
     *
     * @param classpathContainers The classpathContainers to set.
     */
    public final void setClasspathContainers( List classpathContainers )
    {
        this.classpathContainers = classpathContainers;
    }

    /**
     * Getter for <code>eclipseProjectDir</code>.
     *
     * @return Returns the eclipseProjectDir.
     */
    public final File getEclipseProjectDir()
    {
        return eclipseProjectDir;
    }

    /**
     * Setter for <code>eclipseProjectDir</code>.
     *
     * @param eclipseProjectDir The eclipseProjectDir to set.
     */
    public final void setEclipseProjectDir( File eclipseProjectDir )
    {
        this.eclipseProjectDir = eclipseProjectDir;
    }

    /**
     * Getter for <code>projectnatures</code>.
     *
     * @return Returns the projectnatures.
     */
    public final List getProjectnatures()
    {
        return projectnatures;
    }

    /**
     * Setter for <code>projectnatures</code>.
     *
     * @param projectnatures The projectnatures to set.
     */
    public final void setProjectnatures( List projectnatures )
    {
        this.projectnatures = projectnatures;
    }

    /**
     * Getter for <code>useProjectReferences</code>.
     *
     * @return Returns the useProjectReferences.
     */
    public final boolean getUseProjectReferences()
    {
        return useProjectReferences;
    }

    /**
     * Setter for <code>useProjectReferences</code>.
     *
     * @param useProjectReferences The useProjectReferences to set.
     */
    public final void setUseProjectReferences( boolean useProjectReferences )
    {
        this.useProjectReferences = useProjectReferences;
    }

    /**
     * Getter for <code>wtpversion</code>.
     *
     * @return Returns the wtpversion.
     */
    public final String getWtpversion()
    {
        return wtpversion;
    }

    /**
     * Setter for <code>wtpversion</code>.
     *
     * @param wtpversion The wtpversion to set.
     */
    public final void setWtpversion( String wtpversion )
    {
        this.wtpversion = wtpversion;
    }

    /**
     * Getter for <code>additionalBuildcommands</code>.
     *
     * @return Returns the additionalBuildcommands.
     */
    public final List getAdditionalBuildcommands()
    {
        return additionalBuildcommands;
    }

    /**
     * Setter for <code>additionalBuildcommands</code>.
     *
     * @param additionalBuildcommands The additionalBuildcommands to set.
     */
    public final void setAdditionalBuildcommands( List additionalBuildcommands )
    {
        this.additionalBuildcommands = additionalBuildcommands;
    }

    /**
     * Getter for <code>additionalProjectnatures</code>.
     *
     * @return Returns the additionalProjectnatures.
     */
    public final List getAdditionalProjectnatures()
    {
        return additionalProjectnatures;
    }

    /**
     * Setter for <code>additionalProjectnatures</code>.
     *
     * @param additionalProjectnatures The additionalProjectnatures to set.
     */
    public final void setAdditionalProjectnatures( List additionalProjectnatures )
    {
        this.additionalProjectnatures = additionalProjectnatures;
    }

    /**
     * Getter for <code>addVersionToProjectName</code>.
     */
    public final boolean isAddVersionToProjectName()
    {
        return addVersionToProjectName;
    }

    /**
     * Setter for <code>addVersionToProjectName</code>.
     */
    public final void setAddVersionToProjectName( boolean addVersionToProjectName )
    {
        this.addVersionToProjectName = addVersionToProjectName;
    }

    /**
     * Getter for <code>addGroupIdToProjectName</code>.
     */
    public final boolean isAddGroupIdToProjectName()
    {
        return addGroupIdToProjectName;
    }

    /**
     * Setter for <code>addGroupIdToProjectName</code>.
     */
    public final void setAddGroupIdToProjectName( boolean addGroupIdToProjectName )
    {
        this.addGroupIdToProjectName = addGroupIdToProjectName;
    }

    /**
     * Getter for <code>projectNameTemplate</code>
     *
     * @return projectNameTemplate
     */
    public final String getProjectNameTemplate()
    {
        return projectNameTemplate;
    }

    /**
     * Setter for <code>projectNameTemplate</code>.
     *
     * @param projectNameTemplate projectNameTemplate
     */
    public final void setProjectNameTemplate( String projectNameTemplate )
    {
        this.projectNameTemplate = projectNameTemplate;
    }

    /**
     * @see org.apache.maven.plugin.Mojo#execute()
     */
    public final boolean setup()
        throws MojoExecutionException
    {
        boolean ready = true;

        checkDeprecations();
        setProjectNameTemplate( IdeUtils.calculateProjectNameTemplate( getProjectNameTemplate(), isAddVersionToProjectName(),
                                                              isAddGroupIdToProjectName(), getLog() ) );
        ajdt = enableAjdt( executedProject ) && !ajdtVersion.equals( "none" );
        ready = validate();

        // TODO: Why are we using project in some places, and executedProject in others??
        ArtifactHandler artifactHandler = project.getArtifact().getArtifactHandler();

        // ear projects don't contain java sources
        // pde projects are always java projects
        isJavaProject =
            pde
                || ( Constants.LANGUAGE_JAVA.equals( artifactHandler.getLanguage() ) && !Constants.PROJECT_PACKAGING_EAR.equals( packaging ) );

        setupExtras();

        parseConfigurationOptions();

        // defaults
        if ( projectnatures == null )
        {
            fillDefaultNatures( packaging );
        }

        if ( additionalProjectnatures != null )
        {
            projectnatures.addAll( additionalProjectnatures );
        }

        if ( buildcommands == null )
        {
            fillDefaultBuilders( packaging );
        }
        else
        {
            convertBuildCommandList( buildcommands );
        }

        if ( additionalBuildcommands != null )
        {
            convertBuildCommandList( additionalBuildcommands );
            buildcommands.addAll( additionalBuildcommands );
        }

        if ( classpathContainers == null )
        {
            fillDefaultClasspathContainers( packaging );
        }
        else
        {
            verifyClasspathContainerListIsComplete();
        }
        locator.addSearchPath( FileResourceLoader.ID, project.getFile().getParentFile().getAbsolutePath() );
        locator.setOutputDirectory( new File( project.getBuild().getDirectory() ) );

        // ready to start
        return ready;
    }

    /**
     * Convert any Strings in the <code>commands</code> List to <code>BuildCommand</code>s. The conversion happens
     * in situ.
     *
     * @param commands a list of commands to convert into <code>BuildCommand</code>
     */
    protected final void convertBuildCommandList( List commands )
    {
        if ( commands != null )
        {
            for ( ListIterator i = commands.listIterator(); i.hasNext(); )
            {
                Object command = i.next();

                if ( command instanceof String )
                {
                    command = new BuildCommand( (String) command );
                    i.set( command );
                }
            }
        }
    }

    private void parseConfigurationOptions()
    {
        if ( "R7".equalsIgnoreCase( wtpversion ) ) //$NON-NLS-1$
        {
            wtpVersionFloat = 0.7f;
        }
        else if ( "1.0".equalsIgnoreCase( wtpversion ) ) //$NON-NLS-1$
        {
            wtpVersionFloat = 1.0f;
        }
        else if ( "1.5".equalsIgnoreCase( wtpversion ) ) //$NON-NLS-1$
        {
            wtpVersionFloat = 1.5f;
        }
        else if ( "2.0".equalsIgnoreCase( wtpversion ) ) //$NON-NLS-1$
        {
            wtpVersionFloat = 2.0f;
        }
        if ( !"none".equalsIgnoreCase( wtpversion ) )
        {
            getLog().info( Messages.getString( "EclipsePlugin.wtpversion", wtpversion ) );
        }
    }

    /**
     * Extension point for subclasses.
     * <p>
     * Called during <code>setup</code>.
     *
     * @throws MojoExecutionException mojo failures.
     */
    protected void setupExtras()
        throws MojoExecutionException
    {
        // extension point.
    }

    private void verifyClasspathContainerListIsComplete()
    {
        boolean containsJREContainer = false;
        // Check if classpathContainer contains a JRE (default, alternate or
        // Execution Environment)
        for ( Iterator iter = classpathContainers.iterator(); iter.hasNext(); )
        {
            Object classPathContainer = iter.next();
            if ( classPathContainer != null
                && classPathContainer.toString().startsWith( COMMON_PATH_JDT_LAUNCHING_JRE_CONTAINER ) )
            {
                containsJREContainer = true;
                break;
            }
        }
        if ( !containsJREContainer )
        {
            getLog().warn( Messages.getString( "EclipsePlugin.missingjrecontainer" ) ); //$NON-NLS-1$
            classpathContainers.add( 0, COMMON_PATH_JDT_LAUNCHING_JRE_CONTAINER );
        }
    }

    private boolean validate()
        throws MojoExecutionException
    {
        // validate sanity of the current m2 project
        if ( Arrays.binarySearch( WTP_SUPPORTED_VERSIONS, wtpversion ) < 0 )
        {
            throw new MojoExecutionException(
                                              Messages.getString( "EclipsePlugin.unsupportedwtp", new Object[] { //$NON-NLS-1$
                                                                  wtpversion,
                                                                      StringUtils.join( WTP_SUPPORTED_VERSIONS, " " ) } ) ); //$NON-NLS-1$
        }

        assertNotEmpty( executedProject.getGroupId(), POM_ELT_GROUP_ID );
        assertNotEmpty( executedProject.getArtifactId(), POM_ELT_ARTIFACT_ID );

        if ( executedProject.getFile() == null || !executedProject.getFile().exists() )
        {
            throw new MojoExecutionException( Messages.getString( "EclipsePlugin.missingpom" ) ); //$NON-NLS-1$
        }

        if ( "pom".equals( packaging ) && eclipseProjectDir == null ) //$NON-NLS-1$
        {
            getLog().info( Messages.getString( "EclipsePlugin.pompackaging" ) ); //$NON-NLS-1$
            return false;
        }

        if ( "eclipse-plugin".equals( packaging ) )
        {
            pde = true;
        }

        // [rfeng] Set PDE to false if the project is not a bundle
        if(!isOSGiBundle()) {
            pde = false;
        }

        if ( eclipseProjectDir == null )
        {
            eclipseProjectDir = executedProject.getFile().getParentFile();
        }

        if ( !eclipseProjectDir.exists() && !eclipseProjectDir.mkdirs() )
        {
            throw new MojoExecutionException( Messages.getString( "EclipsePlugin.cantcreatedir", eclipseProjectDir ) ); //$NON-NLS-1$
        }

        if ( !eclipseProjectDir.equals( executedProject.getFile().getParentFile() ) )
        {
            if ( !eclipseProjectDir.isDirectory() )
            {
                throw new MojoExecutionException( Messages.getString( "EclipsePlugin.notadir", eclipseProjectDir ) ); //$NON-NLS-1$
            }
            eclipseProjectDir = new File( eclipseProjectDir, executedProject.getArtifactId() );
            if ( !eclipseProjectDir.isDirectory() && !eclipseProjectDir.mkdirs() )
            {
                throw new MojoExecutionException( Messages.getString( "EclipsePlugin.cantcreatedir", eclipseProjectDir ) ); //$NON-NLS-1$
            }
        }

        validateExtras();

        return true;
    }

    /**
     * Extension point for subclasses.
     * <p>
     * Called during <code>setup</code> and used to validate that the configuration is sane.
     *
     * @throws MojoExecutionException mojo failures.
     */
    protected void validateExtras() throws MojoExecutionException
    {
        // provided for extension.
    }

    private void checkDeprecations()
    {
        if ( eclipseDownloadSources )
        {
            // deprecated warning
            getLog().warn( Messages.getString( "EclipsePlugin.deprecatedpar", new Object[] { //$NON-NLS-1$
                                               "eclipse.downloadSources", //$NON-NLS-1$
                                                   "downloadSources" } ) ); //$NON-NLS-1$
            downloadSources = true;
        }

        checkDeprecationsExtras();
    }

    /**
     * Extension point for subclasses.
     * <p>
     * Check for any extra deprecations and log warnings. Called during <code>setup</code>
     */
    protected void checkDeprecationsExtras()
    {
        // provided for extension.
    }

    public final void writeConfiguration( IdeDependency[] deps )
        throws MojoExecutionException
    {
        EclipseWriterConfig config = createEclipseWriterConfig( deps );

        if ( wtpmanifest && isJavaProject() )
        {
            EclipseManifestWriter.addManifestResource( getLog(), config );
        }
        // NOTE: This could change the config!
        writeConfigurationExtras( config );

        if ( wtpVersionFloat == 0.7f )
        {
            new EclipseWtpmodulesWriter().init( getLog(), config ).write();
        }

        if ( wtpVersionFloat >= 1.0f )
        {
            new EclipseWtpFacetsWriter().init( getLog(), config ).write();
        }
        if ( wtpVersionFloat == 1.0f )
        {
            new EclipseWtpComponentWriter().init( getLog(), config ).write();
        }
        if ( wtpVersionFloat >= 1.5 )
        {
            new EclipseWtpComponent15Writer().init( getLog(), config ).write();
        }

        new EclipseSettingsWriter().init( getLog(), config ).write();

        if ( isJavaProject )
        {
            new EclipseClasspathWriter().init( getLog(), config ).write();
            if ( ajdt && ajdtVersion.equals( "1.4" ) )
            {
                new EclipseAjdtWriter().init( getLog(), config ).write();
            }
        }

        if ( wtpapplicationxml )
        {
            new EclipseWtpApplicationXMLWriter().init( getLog(), config ).write();
        }

        // [rfeng]
        /*
        if ( pde )
        {
            this.getLog().info( "The Maven Eclipse plugin runs in 'pde'-mode." );
            new EclipseOSGiManifestWriter().init( getLog(), config ).write();
        }
        */
        // [rfeng]

        // NOTE: This one MUST be after EclipseClasspathwriter, and possibly others,
        // since currently EclipseClasspathWriter does some magic to detect nested
        // output folders and modifies the configuration by adding new (Ant) builders.
        // So the .project file must be written AFTER those have run!
        new EclipseProjectWriter().init( getLog(), config ).write();

        writeAdditionalConfig();

        getLog().info( Messages.getString( "EclipsePlugin.wrote", new Object[] { //$NON-NLS-1$
                                           config.getEclipseProjectName(), eclipseProjectDir.getAbsolutePath() } ) );
    }

    private void writeAdditionalConfig()
        throws MojoExecutionException
    {
        if ( additionalConfig != null )
        {
            for ( int j = 0; j < additionalConfig.length; j++ )
            {
                EclipseConfigFile file = additionalConfig[j];
                File projectRelativeFile = new File( eclipseProjectDir, file.getName() );
                if ( projectRelativeFile.isDirectory() )
                {
                    // just ignore?
                    getLog().warn( Messages.getString( "EclipsePlugin.foundadir", //$NON-NLS-1$
                                                       projectRelativeFile.getAbsolutePath() ) );
                }

                try
                {
                    projectRelativeFile.getParentFile().mkdirs();
                    if ( file.getContent() == null )
                    {
                        InputStream inStream;
                        if ( file.getLocation() != null )
                        {
                            inStream = locator.getResourceAsInputStream( file.getLocation() );
                        }
                        else
                        {
                            inStream = file.getURL().openConnection().getInputStream();
                        }
                        OutputStream outStream = new FileOutputStream( projectRelativeFile );
                        try
                        {
                            IOUtil.copy( inStream, outStream );
                        }
                        finally
                        {
                            inStream.close();
                            outStream.close();
                        }
                    }
                    else
                    {
                        FileUtils.fileWrite( projectRelativeFile.getAbsolutePath(), file.getContent() );
                    }
                }
                catch ( IOException e )
                {
                    throw new MojoExecutionException( Messages.getString( "EclipsePlugin.cantwritetofile", //$NON-NLS-1$
                                                                          projectRelativeFile.getAbsolutePath() ) );
                }
                catch ( ResourceNotFoundException e )
                {
                    throw new MojoExecutionException( Messages.getString( "EclipsePlugin.cantfindresource", //$NON-NLS-1$
                                                                          file.getLocation() ) );
                }

            }
        }
    }

    /**
     * Create the <code>EclipseWriterConfig</code> for the specified dependencies.
     *
     * @param deps the project dependencies
     * @return a configured <code>EclipseWriterConfig</code>
     * @throws MojoExecutionException mojo failures.
     */
    protected final EclipseWriterConfig createEclipseWriterConfig( IdeDependency[] deps )
        throws MojoExecutionException
    {
        File projectBaseDir = executedProject.getFile().getParentFile();

        // build a list of UNIQUE source dirs (both src and resources) to be
        // used in classpath and wtpmodules
        EclipseSourceDir[] sourceDirs = buildDirectoryList( executedProject, eclipseProjectDir, buildOutputDirectory );

        EclipseWriterConfig config = new EclipseWriterConfig();

        config.setWorkspaceConfiguration( getWorkspaceConfiguration() );

        config.setProjectNameTemplate( getProjectNameTemplate() );

        String projectName = IdeUtils.getProjectName( config.getProjectNameTemplate(), project );

        config.setEclipseProjectName( projectName );

        config.setWtpapplicationxml( wtpapplicationxml );

        config.setWtpVersion( wtpVersionFloat );

        float ajdtVersionFloat;
        try
        {
            ajdtVersionFloat = Float.parseFloat( ajdtVersion );
        }
        catch ( NumberFormatException e )
        {
            ajdtVersionFloat = 0.0f;
        }

        config.setAjdtVersion( ajdtVersionFloat );

        Set convertedBuildCommands = new LinkedHashSet();

        if ( buildcommands != null )
        {
            for ( Iterator it = buildcommands.iterator(); it.hasNext(); )
            {
                Object cmd = it.next();

                if ( cmd instanceof BuildCommand )
                {
                    convertedBuildCommands.add( cmd );
                }
                else
                {
                    convertedBuildCommands.add( new BuildCommand( (String) cmd ) );
                }
            }
        }

        if ( ajdt )
        {
            buildAjdtWeaveDeps( deps );
            buildAspectjDeps( deps );
        }

        config.setBuildCommands( new LinkedList( convertedBuildCommands ) );

        config.setBuildOutputDirectory( buildOutputDirectory );
        config.setClasspathContainers( classpathContainers );
        config.setDeps( deps );
        config.setEclipseProjectDirectory( eclipseProjectDir );
        config.setLocalRepository( localRepository );
        config.setOSGIManifestFile( manifest );
        config.setPde( pde );
        config.setProject( project );
        config.setProjectBaseDir( projectBaseDir );
        config.setProjectnatures( projectnatures );
        config.setProjectFacets( additionalProjectFacets );
        config.setSourceDirs( sourceDirs );
        config.setAddVersionToProjectName( isAddVersionToProjectName() );
        config.setPackaging( packaging );

        collectWarContextRootsFromReactorEarConfiguration( config );

        return config;
    }

    /**
     * If this is a war module peek into the reactor an search for an ear module that defines the context root of this
     * module.
     *
     * @param config config to save the context root.
     */
    private void collectWarContextRootsFromReactorEarConfiguration( EclipseWriterConfig config )
    {
        if ( reactorProjects != null && wtpContextName == null
            && Constants.PROJECT_PACKAGING_WAR.equals( project.getPackaging() ) )
        {
            for ( Iterator iter = reactorProjects.iterator(); iter.hasNext(); )
            {
                MavenProject reactorProject = (MavenProject) iter.next();

                if ( Constants.PROJECT_PACKAGING_EAR.equals( reactorProject.getPackaging() ) )
                {
                    Xpp3Dom[] warDefinitions =
                        IdeUtils.getPluginConfigurationDom( reactorProject, JeeUtils.ARTIFACT_MAVEN_EAR_PLUGIN,
                                                            new String[] { "modules", "webModule" } );
                    for ( int index = 0; index < warDefinitions.length; index++ )
                    {
                        Xpp3Dom groupId = warDefinitions[index].getChild( "groupId" );
                        Xpp3Dom artifactId = warDefinitions[index].getChild( "artifactId" );
                        Xpp3Dom contextRoot = warDefinitions[index].getChild( "contextRoot" );
                        if ( groupId != null && artifactId != null && contextRoot != null && groupId.getValue() != null
                            && artifactId.getValue() != null && contextRoot.getValue() != null )
                        {
                            getLog().info(
                                           "Found context root definition for " + groupId.getValue() + ":"
                                               + artifactId.getValue() + " " + contextRoot.getValue() );
                            if ( project.getArtifactId().equals( artifactId.getValue() )
                                && project.getGroupId().equals( groupId.getValue() ) )
                            {
                                config.setContextName( contextRoot.getValue() );
                            }
                        }
                        else
                        {
                            getLog().info(
                                           "Found incomplete ear configuration in " + reactorProject.getGroupId() + ":"
                                               + reactorProject.getGroupId() + " found "
                                               + warDefinitions[index].toString() );
                        }
                    }
                }
            }
        }
        if ( config.getContextName() == null && Constants.PROJECT_PACKAGING_WAR.equals( project.getPackaging() ) )
        {
            if ( wtpContextName == null )
            {
                config.setContextName( project.getArtifactId() );
            }
            else
            {
                config.setContextName( wtpContextName );
            }
        }
    }

    /**
     * Write any extra configuration information for the Eclipse project. This is an extension point, called before the
     * main configurations are written. <br/> <b> NOTE: This could change the config! </b>
     *
     * @param config
     * @throws MojoExecutionException
     */
    protected void writeConfigurationExtras( EclipseWriterConfig config )
        throws MojoExecutionException
    {
        // extension point.
    }

    private void assertNotEmpty( String string, String elementName )
        throws MojoExecutionException
    {
        if ( string == null )
        {
            throw new MojoExecutionException( Messages.getString( "EclipsePlugin.missingelement", elementName ) ); //$NON-NLS-1$
        }
    }

    /**
     * Fill getProjectnatures() with values.
     * <p>
     * Subclasses should call super and then calculate their own additions and insert them via
     * <code>getProjectnatures().addAll()</code>.
     *
     * @param packaging the pom's packaging
     */
    protected void fillDefaultNatures( String packaging )
    {
        projectnatures = new ArrayList();

        if ( wtpVersionFloat >= 1.0f )
        {
            projectnatures.add( NATURE_WST_FACET_CORE_NATURE ); // WTP 1.0 nature
        }

        if ( isJavaProject )
        {
            if ( ajdt )
            {
                projectnatures.add( NATURE_AJDT_CORE_JAVA );
            }

            projectnatures.add( NATURE_JDT_CORE_JAVA );
        }

        if ( wtpVersionFloat >= 0.7f )
        {
            projectnatures.add( NATURE_WST_MODULE_CORE_NATURE ); // WTP 0.7/1.0 nature

            if ( isJavaProject )
            {
                projectnatures.add( NATURE_JEM_WORKBENCH_JAVA_EMF ); // WTP 0.7/1.0 nature
            }
        }

        if ( pde )
        {
            projectnatures.add( NATURE_PDE_PLUGIN );
        }

    }

    /**
     * Fill getClasspathContainers() with values.
     * <p>
     * Subclasses should call super and then calculate their own additions and insert them via
     * <code>getClasspathContainers().addAll()</code>.
     *
     * @param packaging the pom's packaging
     */
    protected void fillDefaultClasspathContainers( String packaging )
    {
        classpathContainers = new ArrayList();

        if ( getWorkspaceConfiguration().getDefaultClasspathContainer() != null )
        {
            getLog().info(
                           "Adding default classpath container: "
                               + getWorkspaceConfiguration().getDefaultClasspathContainer() );
            classpathContainers.add( getWorkspaceConfiguration().getDefaultClasspathContainer() );
        }
        if ( pde )
        {
            classpathContainers.add( REQUIRED_PLUGINS_CONTAINER );
        }

        if ( ajdt )
        {
            classpathContainers.add( ASPECTJ_RT_CONTAINER );
        }
    }

    /**
     * Fill getBuildcommands() with values.
     * <p>
     * Subclasses should call super and then calculate their own additions and insert them via
     * <code>getBuildcommands().addAll()</code>.
     *
     * @param packaging the pom's packaging
     */
    protected void fillDefaultBuilders( String packaging )
    {
        buildcommands = new ArrayList();

        if ( wtpVersionFloat == 0.7f )
        {
            buildcommands.add( new BuildCommand( BUILDER_WST_COMPONENT_STRUCTURAL ) ); // WTP 0.7 builder
        }

        if ( isJavaProject )
        {
            if ( ajdt )
            {
                buildcommands.add( new BuildCommand( BUILDER_AJDT_CORE_JAVA ) );
            }
            else
            {
                buildcommands.add( new BuildCommand( BUILDER_JDT_CORE_JAVA ) );
            }
        }

        if ( wtpVersionFloat >= 1.5f )
        {
            buildcommands.add( new BuildCommand( BUILDER_WST_FACET ) ); // WTP 1.5 builder
        }

        if ( wtpVersionFloat >= 0.7f )
        {
            buildcommands.add( new BuildCommand( BUILDER_WST_VALIDATION ) ); // WTP 0.7/1.0 builder
        }

        if ( wtpVersionFloat == 0.7f )
        {
            // WTP 0.7 builder
            buildcommands.add( new BuildCommand( BUILDER_WST_COMPONENT_STRUCTURAL_DEPENDENCY_RESOLVER ) );
        }

        if ( pde )
        {
            buildcommands.add( new BuildCommand( BUILDER_PDE_MANIFEST ) );
            buildcommands.add( new BuildCommand( BUILDER_PDE_SCHEMA ) );
        }
    }

    public final EclipseSourceDir[] buildDirectoryList( MavenProject project, File basedir, File buildOutputDirectory )
        throws MojoExecutionException
    {
        File projectBaseDir = project.getFile().getParentFile();

        String mainOutput = IdeUtils.toRelativeAndFixSeparator( projectBaseDir, buildOutputDirectory, false );

        // If using the standard output location, don't mix the test output into it.
        String testOutput = null;
        boolean useStandardOutputDir =
            buildOutputDirectory.equals( new File( project.getBuild().getOutputDirectory() ) );
        if ( useStandardOutputDir )
        {
            getLog().debug(
                            "testOutput toRelativeAndFixSeparator " + projectBaseDir + " , "
                                + project.getBuild().getTestOutputDirectory() );
            testOutput =
                IdeUtils.toRelativeAndFixSeparator( projectBaseDir,
                                                    new File( project.getBuild().getTestOutputDirectory() ), false );
            getLog().debug( "testOutput after toRelative : " + testOutput );
        }

        Set mainDirectories = new LinkedHashSet();

        extractSourceDirs( mainDirectories, project.getCompileSourceRoots(), basedir, projectBaseDir, false, null );

        extractResourceDirs( mainDirectories, project.getBuild().getResources(), basedir, projectBaseDir, false,
                             mainOutput );

        Set testDirectories = new LinkedHashSet();

        extractSourceDirs( testDirectories, project.getTestCompileSourceRoots(), basedir, projectBaseDir, true,
                           testOutput );

        extractResourceDirs( testDirectories, project.getBuild().getTestResources(), basedir, projectBaseDir, true,
                             testOutput );

        // avoid duplicated entries
        Set directories = new LinkedHashSet();

        // NOTE: Since MNG-3118, test classes come before main classes
        boolean testBeforeMain = isMavenVersion( "[2.0.8,)" );

        if ( testBeforeMain )
        {
            directories.addAll( testDirectories );
            directories.removeAll( mainDirectories );
            directories.addAll( mainDirectories );
        }
        else
        {
            directories.addAll( mainDirectories );
            directories.addAll( testDirectories );
        }
        if ( ajdt )
            extractAspectDirs( directories, project, basedir, projectBaseDir, testOutput );
        return (EclipseSourceDir[]) directories.toArray( new EclipseSourceDir[directories.size()] );
    }

    private void extractSourceDirs( Set directories, List sourceRoots, File basedir, File projectBaseDir, boolean test,
                                    String output )
        throws MojoExecutionException
    {
        for ( Iterator it = sourceRoots.iterator(); it.hasNext(); )
        {

            File sourceRootFile = new File( (String) it.next() );

            if ( sourceRootFile.isDirectory() )
            {
                String sourceRoot =
                    IdeUtils.toRelativeAndFixSeparator( projectBaseDir, sourceRootFile,
                                                        !projectBaseDir.equals( basedir ) );

                directories.add( new EclipseSourceDir( sourceRoot, output, false, test, null, null, false ) );
            }
        }
    }

    final void extractResourceDirs( Set directories, List resources, File basedir, File workspaceProjectBaseDir,
                              boolean test, final String output )
        throws MojoExecutionException
    {
        for ( Iterator it = resources.iterator(); it.hasNext(); )
        {
            Resource resource = (Resource) it.next();

            getLog().debug( "Processing resource dir: " + resource.getDirectory() );

            String includePattern = null;
            String excludePattern = null;

            if ( resource.getIncludes().size() != 0 )
            {
                includePattern = StringUtils.join( resource.getIncludes().iterator(), "|" );
            }

            if ( resource.getExcludes().size() != 0 )
            {
                excludePattern = StringUtils.join( resource.getExcludes().iterator(), "|" );
            }

            // TODO: figure out how to merge if the same dir is specified twice
            // with different in/exclude patterns.

            File resourceDirectory = new File( /* basedir, */resource.getDirectory() );

            if ( !resourceDirectory.exists() || !resourceDirectory.isDirectory() )
            {
                getLog().debug( "Resource dir: " + resourceDirectory + " either missing or not a directory." );
                continue;
            }

            String resourceDir =
                IdeUtils.toRelativeAndFixSeparator( workspaceProjectBaseDir, resourceDirectory,
                                                    !workspaceProjectBaseDir.equals( basedir ) );
            String thisOutput = output;
            if ( thisOutput != null )
            {
                // sometimes thisOutput is already an absolute path
                File outputFile = new File( thisOutput );
                if ( !outputFile.isAbsolute() )
                {
                    outputFile = new File( workspaceProjectBaseDir, thisOutput );
                }
                // create output dir if it doesn't exist
                outputFile.mkdirs();

                if ( !StringUtils.isEmpty( resource.getTargetPath() ) )
                {
                    outputFile = new File( outputFile, resource.getTargetPath() );
                    // create output dir if it doesn't exist
                    outputFile.mkdirs();
                }

                getLog().debug(
                                "Making relative and fixing separator: { " + workspaceProjectBaseDir + ", "
                                    + outputFile + ", false }." );
                thisOutput = IdeUtils.toRelativeAndFixSeparator( workspaceProjectBaseDir, outputFile, false );
            }

            getLog().debug(
                            "Adding eclipse source dir: { " + resourceDir + ", " + thisOutput + ", true, " + test
                                + ", " + includePattern + ", " + excludePattern + " }." );

            directories.add( new EclipseSourceDir( resourceDir, thisOutput, true, test, includePattern, excludePattern,
                                                   resource.isFiltering() ) );
        }
    }

    private void extractAspectDirs( Set directories, MavenProject project, File basedir, File projectBaseDir,
                                    String testOutput )
        throws MojoExecutionException
    {
        Xpp3Dom configuration = getAspectjConfiguration( project );
        if ( configuration != null )
        {
            String aspectDirectory = DEFAULT_ASPECT_DIRECTORY;
            Xpp3Dom aspectDirectoryElement = configuration.getChild( ASPECT_DIRECTORY );
            if ( aspectDirectoryElement != null )
            {
                aspectDirectory = aspectDirectoryElement.getValue();
            }

            File aspectDirectoryFile = new File( basedir, aspectDirectory );
            if ( aspectDirectoryFile.exists() && aspectDirectoryFile.isDirectory() )
            {
                String sourceRoot =
                    IdeUtils.toRelativeAndFixSeparator( projectBaseDir, aspectDirectoryFile,
                                                        !projectBaseDir.equals( basedir ) );

                directories.add( new EclipseSourceDir( sourceRoot, null, false, false, null, null, false ) );
            }

            String testAspectDirectory = DEFAULT_TEST_ASPECT_DIRECTORY;
            Xpp3Dom testAspectDirectoryElement = configuration.getChild( TEST_ASPECT_DIRECTORY );
            if ( testAspectDirectoryElement != null )
            {
                testAspectDirectory = testAspectDirectoryElement.getValue();
            }

            File testAspectDirectoryFile = new File( basedir, testAspectDirectory );
            if ( testAspectDirectoryFile.exists() && testAspectDirectoryFile.isDirectory() )
            {
                String sourceRoot =
                    IdeUtils.toRelativeAndFixSeparator( projectBaseDir, testAspectDirectoryFile,
                                                        !projectBaseDir.equals( basedir ) );

                directories.add( new EclipseSourceDir( sourceRoot, testOutput, false, true, null, null, false ) );
            }
        }
    }

    private boolean enableAjdt( MavenProject project )
    {
        boolean enable = false;
        List buildPlugins = project.getBuildPlugins();
        for ( Iterator it = buildPlugins.iterator(); it.hasNext(); )
        {
            Plugin plugin = (Plugin) it.next();
            if ( plugin.getGroupId().equals( ORG_CODEHAUS_MOJO )
                && plugin.getArtifactId().equals( ASPECTJ_MAVEN_PLUGIN ) )
            {
                enable = true;
                break;
            }
        }

        return enable;
    }

    private Xpp3Dom getAspectjConfiguration( MavenProject project )
    {
        Xpp3Dom configuration = null;
        List buildPlugins = project.getBuildPlugins();
        for ( Iterator it = buildPlugins.iterator(); it.hasNext(); )
        {
            Plugin plugin = (Plugin) it.next();
            if ( plugin.getGroupId().equals( ORG_CODEHAUS_MOJO )
                && plugin.getArtifactId().equals( ASPECTJ_MAVEN_PLUGIN ) )
            {
                configuration = (Xpp3Dom) plugin.getConfiguration();
                break;
            }
        }

        return configuration;
    }

    private void buildAspectjDeps( IdeDependency[] deps )
        throws MojoExecutionException
    {
        Xpp3Dom configuration = getAspectjConfiguration( executedProject );
        if ( configuration != null )
        {
            Xpp3Dom aspectLibrariesParent = configuration.getChild( ASPECT_LIBRARIES );
            if ( aspectLibrariesParent != null )
            {
                Xpp3Dom[] aspectLibraries = aspectLibrariesParent.getChildren( ASPECT_LIBRARY );
                outerLoop: for ( int i = 0; i < aspectLibraries.length; i++ )
                {
                    String artifactId = aspectLibraries[i].getChild( POM_ELT_ARTIFACT_ID ).getValue();
                    String groupId = aspectLibraries[i].getChild( POM_ELT_GROUP_ID ).getValue();
                    for ( int j = 0; j < deps.length; j++ )
                    {
                        if ( deps[j].getArtifactId().equals( artifactId ) && deps[j].getGroupId().equals( groupId ) )
                        {
                            deps[j].setAjdtDependency( true );
                            continue outerLoop;
                        }
                    }

                    throw new MojoExecutionException( "AspectLibrary is not a dependency of project" );
                }
            }
        }
    }

    private void buildAjdtWeaveDeps( IdeDependency[] deps )
        throws MojoExecutionException
    {
        Xpp3Dom configuration = getAspectjConfiguration( executedProject );
        if ( configuration != null )
        {
            Xpp3Dom weaveDependenciesParent = configuration.getChild( WEAVE_DEPENDENCIES );
            if ( weaveDependenciesParent != null )
            {
                Xpp3Dom[] weaveDependencies = weaveDependenciesParent.getChildren( WEAVE_DEPENDENCY );
                outerLoop: for ( int i = 0; i < weaveDependencies.length; i++ )
                {
                    String artifactId = weaveDependencies[i].getChild( POM_ELT_ARTIFACT_ID ).getValue();
                    String groupId = weaveDependencies[i].getChild( POM_ELT_GROUP_ID ).getValue();
                    for ( int j = 0; j < deps.length; j++ )
                    {
                        if ( deps[j].getArtifactId().equals( artifactId ) && deps[j].getGroupId().equals( groupId ) )
                        {
                            deps[j].setAjdtWeaveDependency( true );
                            continue outerLoop;
                        }
                    }

                    throw new MojoExecutionException( "WeaveDependency is not a dependency of project" );
                }
            }
        }
    }

    /**
     * {@inheritDoc}
     */
    public String getProjectNameForArifact( Artifact artifact )
    {
        IdeDependency[] workspaceArtefacts = getWorkspaceArtefacts();
        for ( int index = 0; workspaceArtefacts != null && index < workspaceArtefacts.length; index++ )
        {
            IdeDependency workspaceArtefact = workspaceArtefacts[index];
            if ( workspaceArtefact.isAddedToClasspath()
                && workspaceArtefact.getGroupId().equals( artifact.getGroupId() )
                && workspaceArtefact.getArtifactId().equals( artifact.getArtifactId() ) )
            {
                if ( workspaceArtefact.getVersion().equals( artifact.getVersion() ) )
                {
                    return workspaceArtefact.getEclipseProjectName();
                }
            }
        }
        MavenProject reactorProject = getReactorProject( artifact );
        if ( reactorProject != null ) {
            return IdeUtils.getProjectName( getProjectNameTemplateForMavenProject( reactorProject ), artifact );
        }
        return IdeUtils.getProjectName( getProjectNameTemplate(), artifact );
    }

    /**
     * @param mavenProject the project to get the projectNameTemplate configuration from
     * @return the projectNameTemplate configuration from the specified MavenProject
     */
    private String getProjectNameTemplateForMavenProject( MavenProject mavenProject )
    {
        String projectNameTemplate = null;
        boolean addVersionToProjectName = false;
        boolean addGroupIdToProjectName = false;

        Build build = mavenProject.getBuild();
        if ( build != null )
        {
            Plugin plugin = (Plugin) build.getPluginsAsMap().get( "org.apache.maven.plugins:maven-eclipse-plugin" );
            if ( plugin != null )
            {
                Xpp3Dom config = (Xpp3Dom) plugin.getConfiguration();
                if ( config != null )
                {
                    Xpp3Dom projectNameTemplateNode = config.getChild( "projectNameTemplate" );
                    if ( projectNameTemplateNode != null )
                    {
                        projectNameTemplate = projectNameTemplateNode.getValue();
                    }
                    Xpp3Dom addVersionToProjectNameNode = config.getChild( "addVersionToProjectName" );
                    addVersionToProjectName = addVersionToProjectNameNode != null;
                    Xpp3Dom addGroupIdToProjectNameNode = config.getChild( "addGroupIdToProjectName" );
                    addGroupIdToProjectName = addGroupIdToProjectNameNode != null;
                }
            }
        }
        return IdeUtils.calculateProjectNameTemplate(projectNameTemplate, addVersionToProjectName, addGroupIdToProjectName, getLog());
    }

    /**
     * {@inheritDoc}
     */
    protected final IdeDependency[] getWorkspaceArtefacts()
    {
        return getWorkspaceConfiguration().getWorkspaceArtefacts();
    }

    public final WorkspaceConfiguration getWorkspaceConfiguration()
    {
        if ( workspaceConfiguration == null )
        {
            workspaceConfiguration = new WorkspaceConfiguration();
            locateWorkspace();
            getLog().info( Messages.getString( "EclipsePlugin.workspace", workspace ) );
            workspaceConfiguration.setWorkspaceDirectory( workspace );

            new ReadWorkspaceLocations().init( getLog(), workspaceConfiguration, project, wtpdefaultserver );
        }
        return workspaceConfiguration;
    }

    /**
     * If workspace is not defined, then attempt to locate it by checking up the directory hierarchy.
     */
    private void locateWorkspace()
    {
        if ( workspace == null )
        {
            File currentWorkingDirectory = new File( "." ).getAbsoluteFile();
            while ( currentWorkingDirectory != null )
            {
                File metadataDirectory = new File( currentWorkingDirectory, ".metadata" );
                logger.debug( "Checking for eclipse workspace at " + currentWorkingDirectory );
                if ( metadataDirectory.exists() && metadataDirectory.isDirectory() )
                {
                    logger.debug( "  Found workspace at " + currentWorkingDirectory );
                    workspace = currentWorkingDirectory;
                    return;
                }
                currentWorkingDirectory = currentWorkingDirectory.getParentFile();
            }
        }
    }

    public final List getExcludes()
    {
        return excludes;
    }

    /**
     * Utility method that locates a project in the workspace for the given artifact.
     *
     * @param artifact the artifact a project should produce.
     * @return <code>true</code> if the artifact is produced by a reactor projectart.
     */
    private boolean isAvailableAsAWorkspaceProject( Artifact artifact )
    {
        IdeDependency[] workspaceArtefacts = getWorkspaceArtefacts();
        for ( int index = 0; workspaceArtefacts != null && index < workspaceArtefacts.length; index++ )
        {
            IdeDependency workspaceArtefact = workspaceArtefacts[index];
            if ( workspaceArtefact.getGroupId().equals( artifact.getGroupId() )
                && workspaceArtefact.getArtifactId().equals( artifact.getArtifactId() ) )
            {
                if ( workspaceArtefact.getVersion().equals( artifact.getVersion() ) )
                {
                    workspaceArtefact.setAddedToClasspath( true );
                    getLog().debug( "Using workspace project: " + workspaceArtefact.getEclipseProjectName() );
                    return true;
                }
                else
                {
                    getLog().info(
                                   "Artifact "
                                       + artifact.getId()
                                       + " already available as a workspace project, but with different version. Expected: "
                                       + artifact.getVersion() + ", found: " + workspaceArtefact.getVersion() );
                }
            }
        }
        return false;
    }

    /**
     * Checks if jar has to be resolved for the given artifact
     *
     * @param art the artifact to check
     * @return true if resolution should happen
     */
    protected final boolean hasToResolveJar( Artifact art )
    {
        return !( getUseProjectReferences() && isAvailableAsAReactorProject( art ) )
            || ( limitProjectReferencesToWorkspace && !( getUseProjectReferences() && isAvailableAsAWorkspaceProject( art ) ) );
    }

    /**
     * Checks if a projects reference has to be used for the given artifact
     *
     * @param art the artifact to check
     * @return true if a project reference has to be used.
     */
    protected final boolean useProjectReference( Artifact art )
    {
        boolean isReactorProject = getUseProjectReferences() && isAvailableAsAReactorProject( art );
        boolean isWorkspaceProject = getUseProjectReferences() && isAvailableAsAWorkspaceProject( art );
        return ( isReactorProject && !limitProjectReferencesToWorkspace ) || // default
            ( limitProjectReferencesToWorkspace && isWorkspaceProject ) || // limitProjectReferencesToWorkspace
            ( !isReactorProject && isWorkspaceProject ); // default + workspace projects
    }
}