1 package org.apache.maven.plugin.javadoc;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.commons.lang.ClassUtils;
23 import org.apache.commons.lang.SystemUtils;
24 import org.apache.maven.artifact.Artifact;
25 import org.apache.maven.artifact.factory.ArtifactFactory;
26 import org.apache.maven.artifact.handler.ArtifactHandler;
27 import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
28 import org.apache.maven.artifact.repository.ArtifactRepository;
29 import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
30 import org.apache.maven.artifact.resolver.ArtifactResolutionException;
31 import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
32 import org.apache.maven.artifact.resolver.ArtifactResolver;
33 import org.apache.maven.artifact.resolver.MultipleArtifactsNotFoundException;
34 import org.apache.maven.artifact.resolver.filter.AndArtifactFilter;
35 import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
36 import org.apache.maven.artifact.resolver.filter.IncludesArtifactFilter;
37 import org.apache.maven.artifact.versioning.ArtifactVersion;
38 import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
39 import org.apache.maven.execution.MavenSession;
40 import org.apache.maven.model.Dependency;
41 import org.apache.maven.model.Plugin;
42 import org.apache.maven.model.Resource;
43 import org.apache.maven.plugin.AbstractMojo;
44 import org.apache.maven.plugin.MojoExecutionException;
45 import org.apache.maven.plugin.javadoc.options.BootclasspathArtifact;
46 import org.apache.maven.plugin.javadoc.options.DocletArtifact;
47 import org.apache.maven.plugin.javadoc.options.Group;
48 import org.apache.maven.plugin.javadoc.options.JavadocOptions;
49 import org.apache.maven.plugin.javadoc.options.JavadocPathArtifact;
50 import org.apache.maven.plugin.javadoc.options.OfflineLink;
51 import org.apache.maven.plugin.javadoc.options.ResourcesArtifact;
52 import org.apache.maven.plugin.javadoc.options.Tag;
53 import org.apache.maven.plugin.javadoc.options.Taglet;
54 import org.apache.maven.plugin.javadoc.options.TagletArtifact;
55 import org.apache.maven.plugin.javadoc.options.io.xpp3.JavadocOptionsXpp3Writer;
56 import org.apache.maven.plugin.javadoc.resolver.JavadocBundle;
57 import org.apache.maven.plugin.javadoc.resolver.ResourceResolver;
58 import org.apache.maven.plugin.javadoc.resolver.SourceResolverConfig;
59 import org.apache.maven.plugins.annotations.Component;
60 import org.apache.maven.plugins.annotations.Parameter;
61 import org.apache.maven.project.MavenProject;
62 import org.apache.maven.project.MavenProjectBuilder;
63 import org.apache.maven.project.ProjectBuildingException;
64 import org.apache.maven.project.artifact.InvalidDependencyVersionException;
65 import org.apache.maven.reporting.MavenReportException;
66 import org.apache.maven.settings.Proxy;
67 import org.apache.maven.settings.Settings;
68 import org.apache.maven.shared.artifact.filter.PatternExcludesArtifactFilter;
69 import org.apache.maven.shared.artifact.filter.PatternIncludesArtifactFilter;
70 import org.apache.maven.shared.invoker.MavenInvocationException;
71 import org.apache.maven.toolchain.Toolchain;
72 import org.apache.maven.toolchain.ToolchainManager;
73 import org.apache.maven.wagon.PathUtils;
74 import org.codehaus.plexus.archiver.ArchiverException;
75 import org.codehaus.plexus.archiver.UnArchiver;
76 import org.codehaus.plexus.archiver.manager.ArchiverManager;
77 import org.codehaus.plexus.archiver.manager.NoSuchArchiverException;
78 import org.codehaus.plexus.components.io.fileselectors.IncludeExcludeFileSelector;
79 import org.codehaus.plexus.util.FileUtils;
80 import org.codehaus.plexus.util.IOUtil;
81 import org.codehaus.plexus.util.ReaderFactory;
82 import org.codehaus.plexus.util.StringUtils;
83 import org.codehaus.plexus.util.WriterFactory;
84 import org.codehaus.plexus.util.cli.CommandLineException;
85 import org.codehaus.plexus.util.cli.CommandLineUtils;
86 import org.codehaus.plexus.util.cli.Commandline;
87 import org.codehaus.plexus.util.xml.Xpp3Dom;
88
89 import java.io.File;
90 import java.io.FileOutputStream;
91 import java.io.IOException;
92 import java.io.InputStream;
93 import java.io.OutputStream;
94 import java.io.Writer;
95 import java.net.MalformedURLException;
96 import java.net.URI;
97 import java.net.URISyntaxException;
98 import java.net.URL;
99 import java.net.URLClassLoader;
100 import java.util.ArrayList;
101 import java.util.Arrays;
102 import java.util.Calendar;
103 import java.util.Collection;
104 import java.util.Collections;
105 import java.util.HashMap;
106 import java.util.HashSet;
107 import java.util.LinkedHashSet;
108 import java.util.LinkedList;
109 import java.util.List;
110 import java.util.Locale;
111 import java.util.Map;
112 import java.util.Properties;
113 import java.util.Set;
114 import java.util.StringTokenizer;
115
116 import static org.apache.maven.plugin.javadoc.JavadocUtil.isEmpty;
117 import static org.apache.maven.plugin.javadoc.JavadocUtil.isNotEmpty;
118 import static org.apache.maven.plugin.javadoc.JavadocUtil.toList;
119 import static org.apache.maven.plugin.javadoc.JavadocUtil.toRelative;
120 import static org.codehaus.plexus.util.IOUtil.close;
121
122
123
124
125
126
127
128
129
130
131
132 public abstract class AbstractJavadocMojo
133 extends AbstractMojo
134 {
135
136
137
138
139
140
141
142 public static final String JAVADOC_RESOURCES_ATTACHMENT_CLASSIFIER = "javadoc-resources";
143
144
145
146
147
148
149
150
151 public static final String TEST_JAVADOC_RESOURCES_ATTACHMENT_CLASSIFIER = "test-javadoc-resources";
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 public static final Properties DEFAULT_JAVA_API_LINKS = new Properties();
184
185
186
187
188 protected static final String DEBUG_JAVADOC_SCRIPT_NAME = "javadoc." + ( SystemUtils.IS_OS_WINDOWS ? "bat" : "sh" );
189
190
191
192
193
194 protected static final String OPTIONS_FILE_NAME = "options";
195
196
197
198
199
200 protected static final String PACKAGES_FILE_NAME = "packages";
201
202
203
204
205
206 protected static final String ARGFILE_FILE_NAME = "argfile";
207
208
209
210
211
212 protected static final String FILES_FILE_NAME = "files";
213
214
215
216
217 private static final String RESOURCE_DIR = ClassUtils.getPackageName( JavadocReport.class ).replace( '.', '/' );
218
219
220
221
222 private static final String DEFAULT_CSS_NAME = "stylesheet.css";
223
224
225
226
227 private static final String RESOURCE_CSS_DIR = RESOURCE_DIR + "/css";
228
229
230
231
232
233
234
235
236 private static final float SINCE_JAVADOC_1_4 = 1.4f;
237
238
239
240
241
242
243
244
245 private static final float SINCE_JAVADOC_1_4_2 = 1.42f;
246
247
248
249
250
251
252
253
254 private static final float SINCE_JAVADOC_1_5 = 1.5f;
255
256
257
258
259
260
261
262
263 private static final float SINCE_JAVADOC_1_6 = 1.6f;
264
265
266
267
268
269
270
271
272
273
274 @Component
275 private ArchiverManager archiverManager;
276
277
278
279
280 @Component
281 private ArtifactFactory factory;
282
283
284
285
286
287
288 @Component
289 private ArtifactMetadataSource artifactMetadataSource;
290
291
292
293
294 @Component
295 private ArtifactResolver resolver;
296
297
298
299
300
301
302 @Component
303 private MavenProjectBuilder mavenProjectBuilder;
304
305
306 @Component
307 private ToolchainManager toolchainManager;
308
309
310
311
312
313
314
315
316
317 @Component
318 private MavenSession session;
319
320
321
322
323
324
325 @Component
326 private Settings settings;
327
328
329
330
331 @Component
332 protected MavenProject project;
333
334
335
336
337 @Parameter( defaultValue = "${settings.offline}", required = true, readonly = true )
338 private boolean isOffline;
339
340
341
342
343
344
345
346
347
348
349
350 @Parameter( defaultValue = "${basedir}/src/main/javadoc" )
351 private File javadocDirectory;
352
353
354
355
356
357 @Parameter( property = "additionalparam" )
358 private String additionalparam;
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374 @Parameter( property = "additionalJOption" )
375 private String additionalJOption;
376
377
378
379
380
381
382
383
384
385
386
387 @Parameter
388 private String[] additionalJOptions;
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410 @Parameter( property = "resourcesArtifacts" )
411 private ResourcesArtifact[] resourcesArtifacts;
412
413
414
415
416 @Parameter( property = "localRepository" )
417 private ArtifactRepository localRepository;
418
419
420
421
422 @Parameter( property = "project.remoteArtifactRepositories" )
423 private List<ArtifactRepository> remoteRepositories;
424
425
426
427
428 @Parameter( property = "reactorProjects", readonly = true )
429 private List<MavenProject> reactorProjects;
430
431
432
433
434
435
436 @Parameter( property = "aggregate", defaultValue = "false" )
437 protected boolean aggregate;
438
439
440
441
442
443
444
445
446 @Parameter( property = "debug", defaultValue = "false" )
447 private boolean debug;
448
449
450
451
452
453
454
455 @Parameter( property = "javadocExecutable" )
456 private String javadocExecutable;
457
458
459
460
461
462
463 @Parameter( property = "javadocVersion" )
464 private String javadocVersion;
465
466
467
468
469 private float fJavadocVersion = 0.0f;
470
471
472
473
474
475
476 @Parameter( property = "maven.javadoc.skip", defaultValue = "false" )
477 protected boolean skip;
478
479
480
481
482
483
484 @Parameter( property = "maven.javadoc.failOnError", defaultValue = "true" )
485 protected boolean failOnError;
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505 @Parameter( property = "useStandardDocletOptions", defaultValue = "true" )
506 protected boolean useStandardDocletOptions;
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525 @Parameter( property = "detectLinks", defaultValue = "false" )
526 private boolean detectLinks;
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544 @Parameter( property = "detectOfflineLinks", defaultValue = "true" )
545 private boolean detectOfflineLinks;
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564 @Parameter( property = "detectJavaApiLink", defaultValue = "true" )
565 private boolean detectJavaApiLink;
566
567
568
569
570
571
572
573
574
575
576
577
578 @Parameter( property = "javaApiLinks" )
579 private Properties javaApiLinks;
580
581
582
583
584
585
586
587 @Parameter( property = "validateLinks", defaultValue = "false" )
588 private boolean validateLinks;
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603 @Parameter( property = "bootclasspath" )
604 private String bootclasspath;
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627 @Parameter( property = "bootclasspathArtifacts" )
628 private BootclasspathArtifact[] bootclasspathArtifacts;
629
630
631
632
633
634
635
636
637
638 @Parameter( property = "breakiterator", defaultValue = "false" )
639 private boolean breakiterator;
640
641
642
643
644
645
646 @Parameter( property = "doclet" )
647 private String doclet;
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667 @Parameter( property = "docletArtifact" )
668 private DocletArtifact docletArtifact;
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692 @Parameter( property = "docletArtifacts" )
693 private DocletArtifact[] docletArtifacts;
694
695
696
697
698
699
700
701
702 @Parameter( property = "docletPath" )
703 private String docletPath;
704
705
706
707
708
709
710
711
712
713
714
715 @Parameter( property = "encoding", defaultValue = "${project.build.sourceEncoding}" )
716 private String encoding;
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732 @Parameter( property = "excludePackageNames" )
733 private String excludePackageNames;
734
735
736
737
738
739
740
741 @Parameter( property = "extdirs" )
742 private String extdirs;
743
744
745
746
747
748
749 @Parameter( property = "locale" )
750 private String locale;
751
752
753
754
755
756
757
758
759 @Parameter( property = "maxmemory" )
760 private String maxmemory;
761
762
763
764
765
766
767
768
769 @Parameter( property = "minmemory" )
770 private String minmemory;
771
772
773
774
775
776
777
778
779 @Parameter( property = "old", defaultValue = "false" )
780 private boolean old;
781
782
783
784
785
786
787
788
789
790
791 @Parameter( property = "overview", defaultValue = "${basedir}/src/main/javadoc/overview.html" )
792 private File overview;
793
794
795
796
797
798
799
800
801
802 @Parameter( property = "proxyHost" )
803 private String proxyHost;
804
805
806
807
808
809
810
811
812
813 @Parameter( property = "proxyPort" )
814 private int proxyPort;
815
816
817
818
819
820
821
822
823
824
825
826
827
828 @Parameter( property = "quiet", defaultValue = "false" )
829 private boolean quiet;
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846 @Parameter( property = "show", defaultValue = "protected" )
847 private String show;
848
849
850
851
852
853
854
855
856 @Parameter( property = "source" )
857 private String source;
858
859
860
861
862
863
864
865 @Parameter( property = "sourcepath" )
866 private String sourcepath;
867
868
869
870
871
872
873
874
875
876 @Parameter( property = "subpackages" )
877 private String subpackages;
878
879
880
881
882
883
884
885 @Parameter( property = "verbose", defaultValue = "false" )
886 private boolean verbose;
887
888
889
890
891
892
893
894
895
896
897
898 @Parameter( property = "author", defaultValue = "true" )
899 private boolean author;
900
901
902
903
904
905
906
907
908
909 @Parameter( property = "bottom",
910 defaultValue = "Copyright © {inceptionYear}-{currentYear} {organizationName}. All Rights Reserved." )
911 private String bottom;
912
913
914
915
916
917
918
919
920 @Parameter( property = "charset" )
921 private String charset;
922
923
924
925
926
927
928
929 @Parameter( property = "docencoding", defaultValue = "${project.reporting.outputEncoding}" )
930 private String docencoding;
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948 @Parameter( property = "docfilessubdirs", defaultValue = "false" )
949 private boolean docfilessubdirs;
950
951
952
953
954
955
956
957 @Parameter( property = "doctitle", defaultValue = "${project.name} ${project.version} API" )
958 private String doctitle;
959
960
961
962
963
964
965
966
967
968
969
970
971 @Parameter( property = "excludedocfilessubdir" )
972 private String excludedocfilessubdir;
973
974
975
976
977
978
979 @Parameter( property = "footer" )
980 private String footer;
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 @Parameter( property = "groups" )
1015 private Group[] groups;
1016
1017
1018
1019
1020
1021
1022 @Parameter( property = "header" )
1023 private String header;
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 @Parameter( property = "helpfile" )
1068 private String helpfile;
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084 @Parameter( property = "keywords", defaultValue = "false" )
1085 private boolean keywords;
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 @Parameter( property = "links" )
1111 protected ArrayList<String> links;
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122 @Parameter( property = "linksource", defaultValue = "false" )
1123 private boolean linksource;
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133 @Parameter( property = "nocomment", defaultValue = "false" )
1134 private boolean nocomment;
1135
1136
1137
1138
1139
1140
1141
1142 @Parameter( property = "nodeprecated", defaultValue = "false" )
1143 private boolean nodeprecated;
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153 @Parameter( property = "nodeprecatedlist", defaultValue = "false" )
1154 private boolean nodeprecatedlist;
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164 @Parameter( property = "nohelp", defaultValue = "false" )
1165 private boolean nohelp;
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175 @Parameter( property = "noindex", defaultValue = "false" )
1176 private boolean noindex;
1177
1178
1179
1180
1181
1182
1183
1184 @Parameter( property = "nonavbar", defaultValue = "false" )
1185 private boolean nonavbar;
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197 @Parameter( property = "nooverview", defaultValue = "false" )
1198 private boolean nooverview;
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212 @Parameter( property = "noqualifier" )
1213 private String noqualifier;
1214
1215
1216
1217
1218
1219
1220
1221 @Parameter( property = "nosince", defaultValue = "false" )
1222 private boolean nosince;
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235 @Parameter( property = "notimestamp", defaultValue = "false" )
1236 private boolean notimestamp;
1237
1238
1239
1240
1241
1242
1243
1244 @Parameter( property = "notree", defaultValue = "false" )
1245 private boolean notree;
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269 @Parameter( property = "offlineLinks" )
1270 private OfflineLink[] offlineLinks;
1271
1272
1273
1274
1275
1276
1277
1278 @Parameter( property = "destDir", alias = "destDir", defaultValue = "${project.build.directory}/apidocs",
1279 required = true )
1280 protected File outputDirectory;
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290 @Parameter( property = "packagesheader" )
1291 private String packagesheader;
1292
1293
1294
1295
1296
1297
1298
1299 @Parameter( property = "serialwarn", defaultValue = "false" )
1300 private boolean serialwarn;
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316 @Parameter( property = "sourcetab", alias = "linksourcetab" )
1317 private int sourcetab;
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328 @Parameter( property = "splitindex", defaultValue = "false" )
1329 private boolean splitindex;
1330
1331
1332
1333
1334
1335
1336
1337
1338 @Parameter( property = "stylesheet", defaultValue = "java" )
1339 private String stylesheet;
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 @Parameter( property = "stylesheetfile" )
1382 private String stylesheetfile;
1383
1384
1385
1386
1387
1388
1389
1390
1391 @Parameter( property = "taglet" )
1392 private String taglet;
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 @Parameter( property = "tagletArtifact" )
1423 private TagletArtifact tagletArtifact;
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 @Parameter( property = "tagletArtifacts" )
1451 private TagletArtifact[] tagletArtifacts;
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461 @Parameter( property = "tagletpath" )
1462 private String tagletpath;
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 @Parameter( property = "taglets" )
1492 private Taglet[] taglets;
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 @Parameter( property = "tags" )
1526 private Tag[] tags;
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537 @Parameter( property = "top" )
1538 private String top;
1539
1540
1541
1542
1543
1544
1545
1546 @Parameter( property = "use", defaultValue = "true" )
1547 private boolean use;
1548
1549
1550
1551
1552
1553
1554
1555 @Parameter( property = "version", defaultValue = "true" )
1556 private boolean version;
1557
1558
1559
1560
1561
1562
1563
1564 @Parameter( property = "windowtitle", defaultValue = "${project.name} ${project.version} API" )
1565 private String windowtitle;
1566
1567
1568
1569
1570
1571
1572
1573 @Parameter( defaultValue = "false" )
1574 private boolean includeDependencySources;
1575
1576
1577
1578
1579
1580
1581
1582 @Parameter( defaultValue = "${project.build.directory}/distro-javadoc-sources" )
1583 private File sourceDependencyCacheDir;
1584
1585
1586
1587
1588
1589
1590
1591
1592 @Parameter( defaultValue = "false" )
1593 private boolean includeTransitiveDependencySources;
1594
1595
1596
1597
1598
1599
1600
1601 @Parameter
1602 private List<String> dependencySourceIncludes;
1603
1604
1605
1606
1607
1608
1609
1610 @Parameter
1611 private List<String> dependencySourceExcludes;
1612
1613
1614
1615
1616
1617
1618
1619 @Parameter( defaultValue = "${project.build.directory}/javadoc-bundle-options", readonly = true )
1620 private File javadocOptionsDir;
1621
1622
1623
1624
1625
1626
1627
1628 private transient List<JavadocBundle> dependencyJavadocBundles;
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645 @Parameter
1646 private List<AdditionalDependency> additionalDependencies;
1647
1648
1649
1650
1651
1652 @Parameter
1653 private List<String> sourceFileIncludes;
1654
1655
1656
1657
1658
1659 @Parameter
1660 private List<String> sourceFileExcludes;
1661
1662
1663
1664
1665
1666 static
1667 {
1668 DEFAULT_JAVA_API_LINKS.put( "api_1.3", "http://docs.oracle.com/javase/1.3/docs/api/" );
1669 DEFAULT_JAVA_API_LINKS.put( "api_1.4", "http://docs.oracle.com/javase/1.4.2/docs/api/" );
1670 DEFAULT_JAVA_API_LINKS.put( "api_1.5", "http://docs.oracle.com/javase/1.5.0/docs/api/" );
1671 DEFAULT_JAVA_API_LINKS.put( "api_1.6", "http://docs.oracle.com/javase/6/docs/api/" );
1672 DEFAULT_JAVA_API_LINKS.put( "api_1.7", "http://docs.oracle.com/javase/7/docs/api/" );
1673 }
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686 protected boolean isAggregator()
1687 {
1688 return false;
1689 }
1690
1691
1692
1693
1694 protected String getOutputDirectory()
1695 {
1696 return outputDirectory.getAbsoluteFile().toString();
1697 }
1698
1699 protected MavenProject getProject()
1700 {
1701 return project;
1702 }
1703
1704
1705
1706
1707
1708
1709 protected List<String> getProjectBuildOutputDirs( MavenProject p )
1710 {
1711 if ( StringUtils.isEmpty( p.getBuild().getOutputDirectory() ) )
1712 {
1713 return Collections.emptyList();
1714 }
1715
1716 return Collections.singletonList( p.getBuild().getOutputDirectory() );
1717 }
1718
1719
1720
1721
1722
1723 protected List<String> getProjectSourceRoots( MavenProject p )
1724 {
1725 if ( "pom".equals( p.getPackaging().toLowerCase() ) )
1726 {
1727 return Collections.emptyList();
1728 }
1729
1730 return ( p.getCompileSourceRoots() == null
1731 ? Collections.<String>emptyList()
1732 : new LinkedList<String>( p.getCompileSourceRoots() ) );
1733 }
1734
1735
1736
1737
1738
1739 protected List<String> getExecutionProjectSourceRoots( MavenProject p )
1740 {
1741 if ( "pom".equals( p.getExecutionProject().getPackaging().toLowerCase() ) )
1742 {
1743 return Collections.emptyList();
1744 }
1745
1746 return ( p.getExecutionProject().getCompileSourceRoots() == null
1747 ? Collections.<String>emptyList()
1748 : new LinkedList<String>( p.getExecutionProject().getCompileSourceRoots() ) );
1749 }
1750
1751
1752
1753
1754
1755 protected List<Artifact> getProjectArtifacts( MavenProject p )
1756 {
1757 return ( p.getCompileArtifacts() == null
1758 ? Collections.<Artifact>emptyList()
1759 : new LinkedList<Artifact>( p.getCompileArtifacts() ) );
1760 }
1761
1762
1763
1764
1765 protected File getJavadocDirectory()
1766 {
1767 return javadocDirectory;
1768 }
1769
1770
1771
1772
1773 protected String getDoctitle()
1774 {
1775 return doctitle;
1776 }
1777
1778
1779
1780
1781 protected File getOverview()
1782 {
1783 return overview;
1784 }
1785
1786
1787
1788
1789 protected String getWindowtitle()
1790 {
1791 return windowtitle;
1792 }
1793
1794
1795
1796
1797 private String getCharset()
1798 {
1799 return ( StringUtils.isEmpty( charset ) ) ? getDocencoding() : charset;
1800 }
1801
1802
1803
1804
1805 private String getDocencoding()
1806 {
1807 return ( StringUtils.isEmpty( docencoding ) ) ? ReaderFactory.UTF_8 : docencoding;
1808 }
1809
1810
1811
1812
1813 private String getEncoding()
1814 {
1815 return ( StringUtils.isEmpty( encoding ) ) ? ReaderFactory.FILE_ENCODING : encoding;
1816 }
1817
1818
1819
1820
1821
1822
1823
1824
1825 protected void executeReport( Locale unusedLocale )
1826 throws MavenReportException
1827 {
1828 if ( skip )
1829 {
1830 getLog().info( "Skipping javadoc generation" );
1831 return;
1832 }
1833
1834 if ( isAggregator() && !project.isExecutionRoot() )
1835 {
1836 return;
1837 }
1838
1839 if ( getLog().isDebugEnabled() )
1840 {
1841 this.debug = true;
1842 }
1843
1844
1845
1846 try
1847 {
1848 buildJavadocOptions();
1849 }
1850 catch ( IOException e )
1851 {
1852 throw new MavenReportException( "Failed to generate javadoc options file: " + e.getMessage(), e );
1853 }
1854
1855 List<String> sourcePaths = getSourcePaths();
1856 List<String> files = getFiles( sourcePaths );
1857 if ( !canGenerateReport( files ) )
1858 {
1859 return;
1860 }
1861
1862 List<String> packageNames = getPackageNames( sourcePaths, files );
1863 List<String> filesWithUnnamedPackages = getFilesWithUnnamedPackages( sourcePaths, files );
1864
1865
1866
1867
1868
1869 String jExecutable;
1870 try
1871 {
1872 jExecutable = getJavadocExecutable();
1873 }
1874 catch ( IOException e )
1875 {
1876 throw new MavenReportException( "Unable to find javadoc command: " + e.getMessage(), e );
1877 }
1878 setFJavadocVersion( new File( jExecutable ) );
1879
1880
1881
1882
1883
1884 File javadocOutputDirectory = new File( getOutputDirectory() );
1885 if ( javadocOutputDirectory.exists() && !javadocOutputDirectory.isDirectory() )
1886 {
1887 throw new MavenReportException( "IOException: " + getOutputDirectory() + " is not a directory." );
1888 }
1889 if ( javadocOutputDirectory.exists() && !javadocOutputDirectory.canWrite() )
1890 {
1891 throw new MavenReportException( "IOException: " + getOutputDirectory() + " is not writable." );
1892 }
1893 javadocOutputDirectory.mkdirs();
1894
1895
1896
1897
1898
1899 copyAllResources( javadocOutputDirectory );
1900
1901
1902
1903
1904
1905 Commandline cmd = new Commandline();
1906 cmd.getShell().setQuotedArgumentsEnabled( false );
1907 cmd.setWorkingDirectory( javadocOutputDirectory.getAbsolutePath() );
1908 cmd.setExecutable( jExecutable );
1909
1910
1911
1912
1913
1914 addMemoryArg( cmd, "-Xmx", this.maxmemory );
1915 addMemoryArg( cmd, "-Xms", this.minmemory );
1916 addProxyArg( cmd );
1917
1918 if ( StringUtils.isNotEmpty( additionalJOption ) )
1919 {
1920 cmd.createArg().setValue( additionalJOption );
1921 }
1922
1923 if ( additionalJOptions != null && additionalJOptions.length != 0 )
1924 {
1925 for ( String jo : additionalJOptions )
1926 {
1927 cmd.createArg().setValue( jo );
1928 }
1929 }
1930
1931 List<String> arguments = new ArrayList<String>();
1932
1933
1934
1935
1936
1937 addJavadocOptions( arguments, sourcePaths );
1938
1939
1940
1941
1942
1943 if ( StringUtils.isEmpty( doclet ) || useStandardDocletOptions )
1944 {
1945 addStandardDocletOptions( javadocOutputDirectory, arguments );
1946 }
1947
1948
1949
1950
1951
1952 if ( arguments.size() > 0 )
1953 {
1954 addCommandLineOptions( cmd, arguments, javadocOutputDirectory );
1955 }
1956
1957
1958
1959
1960
1961 if ( !packageNames.isEmpty() )
1962 {
1963 addCommandLinePackages( cmd, javadocOutputDirectory, packageNames );
1964
1965
1966
1967
1968
1969 if ( !filesWithUnnamedPackages.isEmpty() )
1970 {
1971 addCommandLineArgFile( cmd, javadocOutputDirectory, filesWithUnnamedPackages );
1972 }
1973 }
1974 else
1975 {
1976
1977
1978
1979
1980 if ( !files.isEmpty() )
1981 {
1982 addCommandLineArgFile( cmd, javadocOutputDirectory, files );
1983 }
1984 }
1985
1986
1987
1988
1989
1990 executeJavadocCommandLine( cmd, javadocOutputDirectory );
1991
1992
1993
1994
1995 if ( !debug )
1996 {
1997 for ( int i = 0; i < cmd.getArguments().length; i++ )
1998 {
1999 String arg = cmd.getArguments()[i].trim();
2000
2001 if ( !arg.startsWith( "@" ) )
2002 {
2003 continue;
2004 }
2005
2006 File argFile = new File( javadocOutputDirectory, arg.substring( 1 ) );
2007 if ( argFile.exists() )
2008 {
2009 argFile.delete();
2010 }
2011 }
2012
2013 File scriptFile = new File( javadocOutputDirectory, DEBUG_JAVADOC_SCRIPT_NAME );
2014 if ( scriptFile.exists() )
2015 {
2016 scriptFile.delete();
2017 }
2018 }
2019 }
2020
2021
2022
2023
2024
2025
2026
2027
2028 protected List<String> getFiles( List<String> sourcePaths )
2029 throws MavenReportException
2030 {
2031 List<String> files = new ArrayList<String>();
2032 if ( StringUtils.isEmpty( subpackages ) )
2033 {
2034 String[] excludedPackages = getExcludedPackages();
2035
2036 for ( String sourcePath : sourcePaths )
2037 {
2038 File sourceDirectory = new File( sourcePath );
2039 JavadocUtil.addFilesFromSource( files, sourceDirectory, sourceFileIncludes, sourceFileExcludes, excludedPackages );
2040 }
2041 }
2042
2043 return files;
2044 }
2045
2046
2047
2048
2049
2050
2051
2052
2053 protected List<String> getSourcePaths()
2054 throws MavenReportException
2055 {
2056 List<String> sourcePaths;
2057
2058 if ( StringUtils.isEmpty( sourcepath ) )
2059 {
2060 sourcePaths = new ArrayList<String>( JavadocUtil.pruneDirs( project, getProjectSourceRoots( project ) ) );
2061
2062 if ( project.getExecutionProject() != null )
2063 {
2064 sourcePaths.addAll( JavadocUtil.pruneDirs( project, getExecutionProjectSourceRoots( project ) ) );
2065 }
2066
2067
2068
2069
2070
2071
2072 if ( getJavadocDirectory() != null )
2073 {
2074 File javadocDir = getJavadocDirectory();
2075 if ( javadocDir.exists() && javadocDir.isDirectory() )
2076 {
2077 List<String> l = JavadocUtil.pruneDirs( project, Collections.singletonList(
2078 getJavadocDirectory().getAbsolutePath() ) );
2079 sourcePaths.addAll( l );
2080 }
2081 }
2082
2083 if ( includeDependencySources )
2084 {
2085 sourcePaths.addAll( getDependencySourcePaths() );
2086 }
2087
2088 if ( isAggregator() && project.isExecutionRoot() )
2089 {
2090 for ( MavenProject subProject : reactorProjects )
2091 {
2092 if ( subProject != project )
2093 {
2094 List<String> sourceRoots = getProjectSourceRoots( subProject );
2095
2096 if ( subProject.getExecutionProject() != null )
2097 {
2098 sourceRoots.addAll( getExecutionProjectSourceRoots( subProject ) );
2099 }
2100
2101 ArtifactHandler artifactHandler = subProject.getArtifact().getArtifactHandler();
2102 if ( "java".equals( artifactHandler.getLanguage() ) )
2103 {
2104 sourcePaths.addAll( JavadocUtil.pruneDirs( subProject, sourceRoots ) );
2105 }
2106
2107 if ( getJavadocDirectory() != null )
2108 {
2109 String javadocDirRelative =
2110 PathUtils.toRelative( project.getBasedir(), getJavadocDirectory().getAbsolutePath() );
2111 File javadocDir = new File( subProject.getBasedir(), javadocDirRelative );
2112 if ( javadocDir.exists() && javadocDir.isDirectory() )
2113 {
2114 List<String> l = JavadocUtil.pruneDirs( subProject, Collections.singletonList(
2115 javadocDir.getAbsolutePath() ) );
2116 sourcePaths.addAll( l );
2117 }
2118 }
2119 }
2120 }
2121 }
2122 }
2123 else
2124 {
2125 sourcePaths = new ArrayList<String>( Arrays.asList( JavadocUtil.splitPath( sourcepath ) ) );
2126 sourcePaths = JavadocUtil.pruneDirs( project, sourcePaths );
2127 if ( getJavadocDirectory() != null )
2128 {
2129 List<String> l = JavadocUtil.pruneDirs( project, Collections.singletonList(
2130 getJavadocDirectory().getAbsolutePath() ) );
2131 sourcePaths.addAll( l );
2132 }
2133 }
2134
2135 sourcePaths = JavadocUtil.pruneDirs( project, sourcePaths );
2136
2137 return sourcePaths;
2138 }
2139
2140
2141
2142
2143
2144 protected SourceResolverConfig configureDependencySourceResolution( final SourceResolverConfig config )
2145 {
2146 return config.withCompileSources();
2147 }
2148
2149
2150
2151
2152
2153 protected final List<String> getDependencySourcePaths()
2154 throws MavenReportException
2155 {
2156 try
2157 {
2158 if ( sourceDependencyCacheDir.exists() )
2159 {
2160 FileUtils.forceDelete( sourceDependencyCacheDir );
2161 sourceDependencyCacheDir.mkdirs();
2162 }
2163 }
2164 catch ( IOException e )
2165 {
2166 throw new MavenReportException(
2167 "Failed to delete cache directory: " + sourceDependencyCacheDir + "\nReason: " + e.getMessage(), e );
2168 }
2169
2170 final SourceResolverConfig config = getDependencySourceResolverConfig();
2171
2172 final AndArtifactFilter andFilter = new AndArtifactFilter();
2173
2174 final List<String> dependencyIncludes = dependencySourceIncludes;
2175 final List<String> dependencyExcludes = dependencySourceExcludes;
2176
2177 if ( !includeTransitiveDependencySources || isNotEmpty( dependencyIncludes ) || isNotEmpty(
2178 dependencyExcludes ) )
2179 {
2180 if ( !includeTransitiveDependencySources )
2181 {
2182 andFilter.add( createDependencyArtifactFilter() );
2183 }
2184
2185 if ( isNotEmpty( dependencyIncludes ) )
2186 {
2187 andFilter.add( new PatternIncludesArtifactFilter( dependencyIncludes, false ) );
2188 }
2189
2190 if ( isNotEmpty( dependencyExcludes ) )
2191 {
2192 andFilter.add( new PatternExcludesArtifactFilter( dependencyExcludes, false ) );
2193 }
2194
2195 config.withFilter( andFilter );
2196 }
2197
2198 try
2199 {
2200 return ResourceResolver.resolveDependencySourcePaths( config );
2201 }
2202 catch ( final ArtifactResolutionException e )
2203 {
2204 throw new MavenReportException(
2205 "Failed to resolve one or more javadoc source/resource artifacts:\n\n" + e.getMessage(), e );
2206 }
2207 catch ( final ArtifactNotFoundException e )
2208 {
2209 throw new MavenReportException(
2210 "Failed to resolve one or more javadoc source/resource artifacts:\n\n" + e.getMessage(), e );
2211 }
2212 }
2213
2214
2215
2216
2217
2218
2219
2220 private ArtifactFilter createDependencyArtifactFilter()
2221 {
2222 Set<Artifact> dependencyArtifacts = project.getDependencyArtifacts();
2223
2224 List<String> artifactPatterns = new ArrayList<String>( dependencyArtifacts.size() );
2225 for ( Artifact artifact : dependencyArtifacts )
2226 {
2227 artifactPatterns.add( artifact.getGroupId() + ":" + artifact.getArtifactId() );
2228 }
2229
2230 return new IncludesArtifactFilter( artifactPatterns );
2231 }
2232
2233
2234
2235
2236
2237
2238
2239 private SourceResolverConfig getDependencySourceResolverConfig()
2240 {
2241 return configureDependencySourceResolution(
2242 new SourceResolverConfig( getLog(), project, localRepository, sourceDependencyCacheDir, resolver, factory,
2243 artifactMetadataSource, archiverManager ).withReactorProjects(
2244 reactorProjects ) );
2245 }
2246
2247
2248
2249
2250
2251
2252
2253
2254 protected boolean canGenerateReport( List<String> files )
2255 {
2256 boolean canGenerate = true;
2257
2258 if ( files.isEmpty() && StringUtils.isEmpty( subpackages ) )
2259 {
2260 canGenerate = false;
2261 }
2262
2263 return canGenerate;
2264 }
2265
2266
2267
2268
2269
2270
2271 protected List<Artifact> getCompileArtifacts( ArtifactResolutionResult result )
2272 {
2273 return JavadocUtil.getCompileArtifacts( result.getArtifacts(), false );
2274 }
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288 private String getExcludedPackages( List<String> sourcePaths )
2289 throws MavenReportException
2290 {
2291 List<String> excludedNames = null;
2292
2293 if ( StringUtils.isNotEmpty( sourcepath ) && StringUtils.isNotEmpty( subpackages ) )
2294 {
2295 String[] excludedPackages = getExcludedPackages();
2296 String[] subpackagesList = subpackages.split( "[:]" );
2297
2298 excludedNames = JavadocUtil.getExcludedNames( sourcePaths, subpackagesList, excludedPackages );
2299 }
2300
2301 String excludeArg = "";
2302 if ( StringUtils.isNotEmpty( subpackages ) && excludedNames != null )
2303 {
2304
2305 excludeArg = StringUtils.join( excludedNames.iterator(), ":" );
2306 }
2307
2308 return excludeArg;
2309 }
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319 private String getSourcePath( List<String> sourcePaths )
2320 {
2321 String sourcePath = null;
2322
2323 if ( StringUtils.isEmpty( subpackages ) || StringUtils.isNotEmpty( sourcepath ) )
2324 {
2325 sourcePath = StringUtils.join( sourcePaths.iterator(), File.pathSeparator );
2326 }
2327
2328 return sourcePath;
2329 }
2330
2331
2332
2333
2334
2335
2336
2337
2338 private String[] getExcludedPackages()
2339 throws MavenReportException
2340 {
2341 Set<String> excluded = new LinkedHashSet<String>();
2342
2343 if ( includeDependencySources )
2344 {
2345 try
2346 {
2347 resolveDependencyBundles();
2348 }
2349 catch ( IOException e )
2350 {
2351 throw new MavenReportException(
2352 "Failed to resolve javadoc bundles from dependencies: " + e.getMessage(), e );
2353 }
2354
2355 if ( isNotEmpty( dependencyJavadocBundles ) )
2356 {
2357 for ( JavadocBundle bundle : dependencyJavadocBundles )
2358 {
2359 JavadocOptions options = bundle.getOptions();
2360 if ( options != null && isNotEmpty( options.getExcludePackageNames() ) )
2361 {
2362 excluded.addAll( options.getExcludePackageNames() );
2363 }
2364 }
2365 }
2366 }
2367
2368
2369 if ( StringUtils.isNotEmpty( excludePackageNames ) )
2370 {
2371 excluded.addAll( Arrays.asList( excludePackageNames.split( "[,:;]" ) ) );
2372 }
2373
2374 String[] result = new String[excluded.size()];
2375 if ( isNotEmpty( excluded ) )
2376 {
2377 int idx = 0;
2378 for ( String exclude : excluded )
2379 {
2380 result[idx] = exclude.replace( '.', File.separatorChar );
2381 idx++;
2382 }
2383 }
2384
2385 return result;
2386 }
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397 private String getClasspath()
2398 throws MavenReportException
2399 {
2400 List<String> classpathElements = new ArrayList<String>();
2401 Map<String, Artifact> compileArtifactMap = new HashMap<String, Artifact>();
2402
2403 classpathElements.addAll( getProjectBuildOutputDirs( project ) );
2404
2405 populateCompileArtifactMap( compileArtifactMap, getProjectArtifacts( project ) );
2406
2407 if ( isAggregator() && project.isExecutionRoot() )
2408 {
2409 try
2410 {
2411 for ( MavenProject subProject : reactorProjects )
2412 {
2413 if ( subProject != project )
2414 {
2415 classpathElements.addAll( getProjectBuildOutputDirs( subProject ) );
2416
2417 Set<Artifact> dependencyArtifacts = subProject.createArtifacts( factory, null, null );
2418 if ( !dependencyArtifacts.isEmpty() )
2419 {
2420 ArtifactResolutionResult result = null;
2421 try
2422 {
2423 result = resolver.resolveTransitively( dependencyArtifacts, subProject.getArtifact(),
2424 subProject.getManagedVersionMap(),
2425 localRepository,
2426 subProject.getRemoteArtifactRepositories(),
2427 artifactMetadataSource );
2428 }
2429 catch ( MultipleArtifactsNotFoundException e )
2430 {
2431 if ( checkMissingArtifactsInReactor( dependencyArtifacts, e.getMissingArtifacts() ) )
2432 {
2433 getLog().warn( "IGNORED to add some artifacts in the classpath. See above." );
2434 }
2435 else
2436 {
2437
2438 throw new MavenReportException( e.getMessage(), e );
2439 }
2440 }
2441 catch ( ArtifactNotFoundException e )
2442 {
2443 throw new MavenReportException( e.getMessage(), e );
2444 }
2445 catch ( ArtifactResolutionException e )
2446 {
2447 throw new MavenReportException( e.getMessage(), e );
2448 }
2449
2450 if ( result == null )
2451 {
2452 continue;
2453 }
2454
2455 populateCompileArtifactMap( compileArtifactMap, getCompileArtifacts( result ) );
2456
2457 if ( getLog().isDebugEnabled() )
2458 {
2459 StringBuilder sb = new StringBuilder();
2460
2461 sb.append( "Compiled artifacts for " );
2462 sb.append( subProject.getGroupId() ).append( ":" );
2463 sb.append( subProject.getArtifactId() ).append( ":" );
2464 sb.append( subProject.getVersion() ).append( '\n' );
2465 for ( Artifact a : compileArtifactMap.values() )
2466 {
2467 sb.append( a.getFile() ).append( '\n' );
2468 }
2469
2470 getLog().debug( sb.toString() );
2471 }
2472 }
2473 }
2474 }
2475 }
2476 catch ( InvalidDependencyVersionException e )
2477 {
2478 throw new MavenReportException( e.getMessage(), e );
2479 }
2480 }
2481
2482 for ( Artifact a : compileArtifactMap.values() )
2483 {
2484 classpathElements.add( a.getFile().toString() );
2485 }
2486
2487 if ( additionalDependencies != null )
2488 {
2489 for ( Dependency dependency : additionalDependencies )
2490 {
2491 Artifact artifact = resolveDependency( dependency );
2492 String path = artifact.getFile().toString();
2493 getLog().debug( "add additional artifact with path " + path );
2494 classpathElements.add( path );
2495 }
2496 }
2497
2498 return StringUtils.join( classpathElements.iterator(), File.pathSeparator );
2499 }
2500
2501 public Artifact resolveDependency( Dependency dependency )
2502 throws MavenReportException
2503 {
2504 Artifact artifact = factory.createArtifactWithClassifier( dependency.getGroupId(), dependency.getArtifactId(),
2505 dependency.getVersion(), dependency.getType(),
2506 dependency.getClassifier() );
2507 try
2508 {
2509 resolver.resolve( artifact, remoteRepositories, localRepository );
2510 }
2511 catch ( ArtifactNotFoundException e )
2512 {
2513 throw new MavenReportException( "artifact not found - " + e.getMessage(), e );
2514 }
2515 catch ( ArtifactResolutionException e )
2516 {
2517 throw new MavenReportException( "artifact resolver problem - " + e.getMessage(), e );
2518 }
2519 return artifact;
2520 }
2521
2522
2523
2524
2525
2526
2527
2528
2529 private Toolchain getToolchain()
2530 {
2531 Toolchain tc = null;
2532 if ( toolchainManager != null )
2533 {
2534 tc = toolchainManager.getToolchainFromBuildContext( "jdk", session );
2535 }
2536
2537 return tc;
2538 }
2539
2540
2541
2542
2543
2544
2545
2546
2547 private void populateCompileArtifactMap( Map<String, Artifact> compileArtifactMap,
2548 Collection<Artifact> artifactList )
2549 throws MavenReportException
2550 {
2551 if ( artifactList == null )
2552 {
2553 return;
2554 }
2555
2556 for ( Artifact newArtifact : artifactList )
2557 {
2558 File file = newArtifact.getFile();
2559
2560 if ( file == null )
2561 {
2562 throw new MavenReportException(
2563 "Error in plugin descriptor - " + "dependency was not resolved for artifact: "
2564 + newArtifact.getGroupId() + ":" + newArtifact.getArtifactId() + ":"
2565 + newArtifact.getVersion() );
2566 }
2567
2568 if ( compileArtifactMap.get( newArtifact.getDependencyConflictId() ) != null )
2569 {
2570 Artifact oldArtifact = compileArtifactMap.get( newArtifact.getDependencyConflictId() );
2571
2572 ArtifactVersion oldVersion = new DefaultArtifactVersion( oldArtifact.getVersion() );
2573 ArtifactVersion newVersion = new DefaultArtifactVersion( newArtifact.getVersion() );
2574 if ( newVersion.compareTo( oldVersion ) > 0 )
2575 {
2576 compileArtifactMap.put( newArtifact.getDependencyConflictId(), newArtifact );
2577 }
2578 }
2579 else
2580 {
2581 compileArtifactMap.put( newArtifact.getDependencyConflictId(), newArtifact );
2582 }
2583 }
2584 }
2585
2586
2587
2588
2589
2590
2591
2592 private String getBottomText()
2593 {
2594 int actualYear = Calendar.getInstance().get( Calendar.YEAR );
2595 String year = String.valueOf( actualYear );
2596
2597 String inceptionYear = project.getInceptionYear();
2598
2599 String theBottom = StringUtils.replace( this.bottom, "{currentYear}", year );
2600
2601 if ( inceptionYear != null )
2602 {
2603 if ( inceptionYear.equals( year ) )
2604 {
2605 theBottom = StringUtils.replace( theBottom, "{inceptionYear}-", "" );
2606 }
2607 else
2608 {
2609 theBottom = StringUtils.replace( theBottom, "{inceptionYear}", inceptionYear );
2610 }
2611 }
2612 else
2613 {
2614 theBottom = StringUtils.replace( theBottom, "{inceptionYear}-", "" );
2615 }
2616
2617 if ( project.getOrganization() == null )
2618 {
2619 theBottom = StringUtils.replace( theBottom, " {organizationName}", "" );
2620 }
2621 else
2622 {
2623 if ( StringUtils.isNotEmpty( project.getOrganization().getName() ) )
2624 {
2625 if ( StringUtils.isNotEmpty( project.getOrganization().getUrl() ) )
2626 {
2627 theBottom = StringUtils.replace( theBottom, "{organizationName}",
2628 "<a href=\"" + project.getOrganization().getUrl() + "\">"
2629 + project.getOrganization().getName() + "</a>" );
2630 }
2631 else
2632 {
2633 theBottom =
2634 StringUtils.replace( theBottom, "{organizationName}", project.getOrganization().getName() );
2635 }
2636 }
2637 else
2638 {
2639 theBottom = StringUtils.replace( theBottom, " {organizationName}", "" );
2640 }
2641 }
2642
2643 return theBottom;
2644 }
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661 private String getStylesheetFile( final File javadocOutputDirectory )
2662 {
2663 if ( StringUtils.isEmpty( stylesheetfile ) )
2664 {
2665 if ( "java".equalsIgnoreCase( stylesheet ) )
2666 {
2667
2668 return null;
2669 }
2670
2671
2672 return new File( javadocOutputDirectory, DEFAULT_CSS_NAME ).getAbsolutePath();
2673 }
2674
2675 if ( new File( stylesheetfile ).exists() )
2676 {
2677 return new File( stylesheetfile ).getAbsolutePath();
2678 }
2679
2680 return getResource( new File( javadocOutputDirectory, DEFAULT_CSS_NAME ), stylesheetfile );
2681 }
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695 private String getHelpFile( final File javadocOutputDirectory )
2696 {
2697 if ( StringUtils.isEmpty( helpfile ) )
2698 {
2699 return null;
2700 }
2701
2702 if ( new File( helpfile ).exists() )
2703 {
2704 return new File( helpfile ).getAbsolutePath();
2705 }
2706
2707 return getResource( new File( javadocOutputDirectory, "help-doc.html" ), helpfile );
2708 }
2709
2710
2711
2712
2713
2714
2715
2716
2717 private String getAccessLevel()
2718 {
2719 String accessLevel;
2720 if ( "public".equalsIgnoreCase( show ) || "protected".equalsIgnoreCase( show ) || "package".equalsIgnoreCase(
2721 show ) || "private".equalsIgnoreCase( show ) )
2722 {
2723 accessLevel = "-" + show;
2724 }
2725 else
2726 {
2727 if ( getLog().isErrorEnabled() )
2728 {
2729 getLog().error( "Unrecognized access level to show '" + show + "'. Defaulting to protected." );
2730 }
2731 accessLevel = "-protected";
2732 }
2733
2734 return accessLevel;
2735 }
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745 private String getBootclassPath()
2746 throws MavenReportException
2747 {
2748 Set<BootclasspathArtifact> bootclasspathArtifacts = collectBootClasspathArtifacts();
2749
2750 List<String> bootclassPath = new ArrayList<String>();
2751 for ( BootclasspathArtifact aBootclasspathArtifact : bootclasspathArtifacts )
2752 {
2753 if ( ( StringUtils.isNotEmpty( aBootclasspathArtifact.getGroupId() ) ) && ( StringUtils.isNotEmpty(
2754 aBootclasspathArtifact.getArtifactId() ) ) && ( StringUtils.isNotEmpty(
2755 aBootclasspathArtifact.getVersion() ) ) )
2756 {
2757 bootclassPath.addAll( getArtifactsAbsolutePath( aBootclasspathArtifact ) );
2758 }
2759 }
2760
2761 bootclassPath = JavadocUtil.pruneFiles( bootclassPath );
2762
2763 StringBuilder path = new StringBuilder();
2764 path.append( StringUtils.join( bootclassPath.iterator(), File.pathSeparator ) );
2765
2766 if ( StringUtils.isNotEmpty( bootclasspath ) )
2767 {
2768 path.append( JavadocUtil.unifyPathSeparator( bootclasspath ) );
2769 }
2770
2771 return path.toString();
2772 }
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786 private String getDocletPath()
2787 throws MavenReportException
2788 {
2789 Set<DocletArtifact> docletArtifacts = collectDocletArtifacts();
2790 List<String> pathParts = new ArrayList<String>();
2791
2792 for ( DocletArtifact docletArtifact : docletArtifacts )
2793 {
2794 if ( !isDocletArtifactEmpty( docletArtifact ) )
2795 {
2796 pathParts.addAll( getArtifactsAbsolutePath( docletArtifact ) );
2797 }
2798 }
2799
2800 if ( !StringUtils.isEmpty( docletPath ) )
2801 {
2802 pathParts.add( JavadocUtil.unifyPathSeparator( docletPath ) );
2803 }
2804
2805 String path = StringUtils.join( pathParts.iterator(), File.pathSeparator );
2806
2807 if ( StringUtils.isEmpty( path ) && getLog().isWarnEnabled() )
2808 {
2809 getLog().warn( "No docletpath option was found. Please review <docletpath/> or <docletArtifact/>"
2810 + " or <doclets/>." );
2811 }
2812
2813 return path.toString();
2814 }
2815
2816
2817
2818
2819
2820
2821
2822
2823 private boolean isDocletArtifactEmpty( DocletArtifact aDocletArtifact )
2824 {
2825 if ( aDocletArtifact == null )
2826 {
2827 return true;
2828 }
2829
2830 return StringUtils.isEmpty( aDocletArtifact.getGroupId() ) && StringUtils.isEmpty(
2831 aDocletArtifact.getArtifactId() ) && StringUtils.isEmpty( aDocletArtifact.getVersion() );
2832 }
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842 private String getTagletPath()
2843 throws MavenReportException
2844 {
2845 Set<TagletArtifact> tArtifacts = collectTagletArtifacts();
2846 List<String> pathParts = new ArrayList<String>();
2847
2848 for ( TagletArtifact tagletArtifact : tArtifacts )
2849 {
2850 if ( ( tagletArtifact != null ) && ( StringUtils.isNotEmpty( tagletArtifact.getGroupId() ) )
2851 && ( StringUtils.isNotEmpty( tagletArtifact.getArtifactId() ) ) && ( StringUtils.isNotEmpty(
2852 tagletArtifact.getVersion() ) ) )
2853 {
2854 pathParts.addAll( getArtifactsAbsolutePath( tagletArtifact ) );
2855 }
2856 }
2857
2858 Set<Taglet> taglets = collectTaglets();
2859 for ( Taglet taglet : taglets )
2860 {
2861 if ( taglet == null )
2862 {
2863 continue;
2864 }
2865
2866 if ( ( taglet.getTagletArtifact() != null ) && ( StringUtils.isNotEmpty(
2867 taglet.getTagletArtifact().getGroupId() ) ) && ( StringUtils.isNotEmpty(
2868 taglet.getTagletArtifact().getArtifactId() ) ) && ( StringUtils.isNotEmpty(
2869 taglet.getTagletArtifact().getVersion() ) ) )
2870 {
2871 pathParts.addAll( getArtifactsAbsolutePath( taglet.getTagletArtifact() ) );
2872
2873 pathParts = JavadocUtil.pruneFiles( pathParts );
2874 }
2875 else if ( StringUtils.isNotEmpty( taglet.getTagletpath() ) )
2876 {
2877 pathParts.add( taglet.getTagletpath() );
2878
2879 pathParts = JavadocUtil.pruneDirs( project, pathParts );
2880 }
2881 }
2882
2883 StringBuilder path = new StringBuilder();
2884 path.append( StringUtils.join( pathParts.iterator(), File.pathSeparator ) );
2885
2886 if ( StringUtils.isNotEmpty( tagletpath ) )
2887 {
2888 path.append( JavadocUtil.unifyPathSeparator( tagletpath ) );
2889 }
2890
2891 return path.toString();
2892 }
2893
2894 private Set<String> collectLinks()
2895 throws MavenReportException
2896 {
2897 Set<String> links = new LinkedHashSet<String>();
2898
2899 if ( includeDependencySources )
2900 {
2901 try
2902 {
2903 resolveDependencyBundles();
2904 }
2905 catch ( IOException e )
2906 {
2907 throw new MavenReportException(
2908 "Failed to resolve javadoc bundles from dependencies: " + e.getMessage(), e );
2909 }
2910
2911 if ( isNotEmpty( dependencyJavadocBundles ) )
2912 {
2913 for ( JavadocBundle bundle : dependencyJavadocBundles )
2914 {
2915 JavadocOptions options = bundle.getOptions();
2916 if ( options != null && isNotEmpty( options.getLinks() ) )
2917 {
2918 links.addAll( options.getLinks() );
2919 }
2920 }
2921 }
2922 }
2923
2924 if ( isNotEmpty( this.links ) )
2925 {
2926 links.addAll( this.links );
2927 }
2928
2929 links.addAll( getDependenciesLinks() );
2930
2931 return links;
2932 }
2933
2934 private Set<Group> collectGroups()
2935 throws MavenReportException
2936 {
2937 Set<Group> groups = new LinkedHashSet<Group>();
2938
2939 if ( includeDependencySources )
2940 {
2941 try
2942 {
2943 resolveDependencyBundles();
2944 }
2945 catch ( IOException e )
2946 {
2947 throw new MavenReportException(
2948 "Failed to resolve javadoc bundles from dependencies: " + e.getMessage(), e );
2949 }
2950
2951 if ( isNotEmpty( dependencyJavadocBundles ) )
2952 {
2953 for ( JavadocBundle bundle : dependencyJavadocBundles )
2954 {
2955 JavadocOptions options = bundle.getOptions();
2956 if ( options != null && isNotEmpty( options.getGroups() ) )
2957 {
2958 groups.addAll( options.getGroups() );
2959 }
2960 }
2961 }
2962 }
2963
2964 if ( this.groups != null && this.groups.length > 0 )
2965 {
2966 groups.addAll( Arrays.asList( this.groups ) );
2967 }
2968
2969 return groups;
2970 }
2971
2972 private Set<ResourcesArtifact> collectResourcesArtifacts()
2973 throws MavenReportException
2974 {
2975 Set<ResourcesArtifact> result = new LinkedHashSet<ResourcesArtifact>();
2976
2977 if ( includeDependencySources )
2978 {
2979 try
2980 {
2981 resolveDependencyBundles();
2982 }
2983 catch ( IOException e )
2984 {
2985 throw new MavenReportException(
2986 "Failed to resolve javadoc bundles from dependencies: " + e.getMessage(), e );
2987 }
2988
2989 if ( isNotEmpty( dependencyJavadocBundles ) )
2990 {
2991 for ( JavadocBundle bundle : dependencyJavadocBundles )
2992 {
2993 JavadocOptions options = bundle.getOptions();
2994 if ( options != null && isNotEmpty( options.getResourcesArtifacts() ) )
2995 {
2996 result.addAll( options.getResourcesArtifacts() );
2997 }
2998 }
2999 }
3000 }
3001
3002 if ( this.resourcesArtifacts != null && this.resourcesArtifacts.length > 0 )
3003 {
3004 result.addAll( Arrays.asList( this.resourcesArtifacts ) );
3005 }
3006
3007 return result;
3008 }
3009
3010 private Set<BootclasspathArtifact> collectBootClasspathArtifacts()
3011 throws MavenReportException
3012 {
3013 Set<BootclasspathArtifact> result = new LinkedHashSet<BootclasspathArtifact>();
3014
3015 if ( includeDependencySources )
3016 {
3017 try
3018 {
3019 resolveDependencyBundles();
3020 }
3021 catch ( IOException e )
3022 {
3023 throw new MavenReportException(
3024 "Failed to resolve javadoc bundles from dependencies: " + e.getMessage(), e );
3025 }
3026
3027 if ( isNotEmpty( dependencyJavadocBundles ) )
3028 {
3029 for ( JavadocBundle bundle : dependencyJavadocBundles )
3030 {
3031 JavadocOptions options = bundle.getOptions();
3032 if ( options != null && isNotEmpty( options.getBootclasspathArtifacts() ) )
3033 {
3034 result.addAll( options.getBootclasspathArtifacts() );
3035 }
3036 }
3037 }
3038 }
3039
3040 if ( this.bootclasspathArtifacts != null && this.bootclasspathArtifacts.length > 0 )
3041 {
3042 result.addAll( Arrays.asList( this.bootclasspathArtifacts ) );
3043 }
3044
3045 return result;
3046 }
3047
3048 private Set<OfflineLink> collectOfflineLinks()
3049 throws MavenReportException
3050 {
3051 Set<OfflineLink> result = new LinkedHashSet<OfflineLink>();
3052
3053 OfflineLink javaApiLink = getDefaultJavadocApiLink();
3054 if ( javaApiLink != null )
3055 {
3056 result.add( javaApiLink );
3057 }
3058
3059 if ( includeDependencySources )
3060 {
3061 try
3062 {
3063 resolveDependencyBundles();
3064 }
3065 catch ( IOException e )
3066 {
3067 throw new MavenReportException(
3068 "Failed to resolve javadoc bundles from dependencies: " + e.getMessage(), e );
3069 }
3070
3071 if ( isNotEmpty( dependencyJavadocBundles ) )
3072 {
3073 for ( JavadocBundle bundle : dependencyJavadocBundles )
3074 {
3075 JavadocOptions options = bundle.getOptions();
3076 if ( options != null && isNotEmpty( options.getOfflineLinks() ) )
3077 {
3078 result.addAll( options.getOfflineLinks() );
3079 }
3080 }
3081 }
3082 }
3083
3084 if ( this.offlineLinks != null && this.offlineLinks.length > 0 )
3085 {
3086 result.addAll( Arrays.asList( this.offlineLinks ) );
3087 }
3088
3089 return result;
3090 }
3091
3092 private Set<Tag> collectTags()
3093 throws MavenReportException
3094 {
3095 Set<Tag> tags = new LinkedHashSet<Tag>();
3096
3097 if ( includeDependencySources )
3098 {
3099 try
3100 {
3101 resolveDependencyBundles();
3102 }
3103 catch ( IOException e )
3104 {
3105 throw new MavenReportException(
3106 "Failed to resolve javadoc bundles from dependencies: " + e.getMessage(), e );
3107 }
3108
3109 if ( isNotEmpty( dependencyJavadocBundles ) )
3110 {
3111 for ( JavadocBundle bundle : dependencyJavadocBundles )
3112 {
3113 JavadocOptions options = bundle.getOptions();
3114 if ( options != null && isNotEmpty( options.getTags() ) )
3115 {
3116 tags.addAll( options.getTags() );
3117 }
3118 }
3119 }
3120 }
3121
3122 if ( this.tags != null && this.tags.length > 0 )
3123 {
3124 tags.addAll( Arrays.asList( this.tags ) );
3125 }
3126
3127 return tags;
3128 }
3129
3130 private Set<TagletArtifact> collectTagletArtifacts()
3131 throws MavenReportException
3132 {
3133 Set<TagletArtifact> tArtifacts = new LinkedHashSet<TagletArtifact>();
3134
3135 if ( includeDependencySources )
3136 {
3137 try
3138 {
3139 resolveDependencyBundles();
3140 }
3141 catch ( IOException e )
3142 {
3143 throw new MavenReportException(
3144 "Failed to resolve javadoc bundles from dependencies: " + e.getMessage(), e );
3145 }
3146
3147 if ( isNotEmpty( dependencyJavadocBundles ) )
3148 {
3149 for ( JavadocBundle bundle : dependencyJavadocBundles )
3150 {
3151 JavadocOptions options = bundle.getOptions();
3152 if ( options != null && isNotEmpty( options.getTagletArtifacts() ) )
3153 {
3154 tArtifacts.addAll( options.getTagletArtifacts() );
3155 }
3156 }
3157 }
3158 }
3159
3160 if ( tagletArtifact != null )
3161 {
3162 tArtifacts.add( tagletArtifact );
3163 }
3164
3165 if ( tagletArtifacts != null && tagletArtifacts.length > 0 )
3166 {
3167 tArtifacts.addAll( Arrays.asList( tagletArtifacts ) );
3168 }
3169
3170 return tArtifacts;
3171 }
3172
3173 private Set<DocletArtifact> collectDocletArtifacts()
3174 throws MavenReportException
3175 {
3176 Set<DocletArtifact> dArtifacts = new LinkedHashSet<DocletArtifact>();
3177
3178 if ( includeDependencySources )
3179 {
3180 try
3181 {
3182 resolveDependencyBundles();
3183 }
3184 catch ( IOException e )
3185 {
3186 throw new MavenReportException(
3187 "Failed to resolve javadoc bundles from dependencies: " + e.getMessage(), e );
3188 }
3189
3190 if ( isNotEmpty( dependencyJavadocBundles ) )
3191 {
3192 for ( JavadocBundle bundle : dependencyJavadocBundles )
3193 {
3194 JavadocOptions options = bundle.getOptions();
3195 if ( options != null && isNotEmpty( options.getDocletArtifacts() ) )
3196 {
3197 dArtifacts.addAll( options.getDocletArtifacts() );
3198 }
3199 }
3200 }
3201 }
3202
3203 if ( docletArtifact != null )
3204 {
3205 dArtifacts.add( docletArtifact );
3206 }
3207
3208 if ( docletArtifacts != null && docletArtifacts.length > 0 )
3209 {
3210 dArtifacts.addAll( Arrays.asList( docletArtifacts ) );
3211 }
3212
3213 return dArtifacts;
3214 }
3215
3216 private Set<Taglet> collectTaglets()
3217 throws MavenReportException
3218 {
3219 Set<Taglet> result = new LinkedHashSet<Taglet>();
3220
3221 if ( includeDependencySources )
3222 {
3223 try
3224 {
3225 resolveDependencyBundles();
3226 }
3227 catch ( IOException e )
3228 {
3229 throw new MavenReportException(
3230 "Failed to resolve javadoc bundles from dependencies: " + e.getMessage(), e );
3231 }
3232
3233 if ( isNotEmpty( dependencyJavadocBundles ) )
3234 {
3235 for ( JavadocBundle bundle : dependencyJavadocBundles )
3236 {
3237 JavadocOptions options = bundle.getOptions();
3238 if ( options != null && isNotEmpty( options.getTaglets() ) )
3239 {
3240 result.addAll( options.getTaglets() );
3241 }
3242 }
3243 }
3244 }
3245
3246 if ( taglets != null && taglets.length > 0 )
3247 {
3248 result.addAll( Arrays.asList( taglets ) );
3249 }
3250
3251 return result;
3252 }
3253
3254
3255
3256
3257
3258
3259
3260
3261 private List<String> getArtifactsAbsolutePath( JavadocPathArtifact javadocArtifact )
3262 throws MavenReportException
3263 {
3264 if ( ( StringUtils.isEmpty( javadocArtifact.getGroupId() ) ) && ( StringUtils.isEmpty(
3265 javadocArtifact.getArtifactId() ) ) && ( StringUtils.isEmpty( javadocArtifact.getVersion() ) ) )
3266 {
3267 return Collections.emptyList();
3268 }
3269
3270 List<String> path = new ArrayList<String>();
3271
3272 try
3273 {
3274 Artifact artifact = createAndResolveArtifact( javadocArtifact );
3275 path.add( artifact.getFile().getAbsolutePath() );
3276
3277
3278 MavenProject artifactProject =
3279 mavenProjectBuilder.buildFromRepository( artifact, remoteRepositories, localRepository );
3280 Set<Artifact> dependencyArtifacts = artifactProject.createArtifacts( factory, null, null );
3281 if ( !dependencyArtifacts.isEmpty() )
3282 {
3283 ArtifactResolutionResult result =
3284 resolver.resolveTransitively( dependencyArtifacts, artifactProject.getArtifact(),
3285 artifactProject.getRemoteArtifactRepositories(), localRepository,
3286 artifactMetadataSource );
3287 Set<Artifact> artifacts = result.getArtifacts();
3288
3289 Map<String, Artifact> compileArtifactMap = new HashMap<String, Artifact>();
3290 populateCompileArtifactMap( compileArtifactMap, artifacts );
3291
3292 for ( Artifact a : compileArtifactMap.values() )
3293 {
3294 path.add( a.getFile().getAbsolutePath() );
3295 }
3296 }
3297
3298 return path;
3299 }
3300 catch ( ArtifactResolutionException e )
3301 {
3302 throw new MavenReportException( "Unable to resolve artifact:" + javadocArtifact, e );
3303 }
3304 catch ( ArtifactNotFoundException e )
3305 {
3306 throw new MavenReportException( "Unable to find artifact:" + javadocArtifact, e );
3307 }
3308 catch ( ProjectBuildingException e )
3309 {
3310 throw new MavenReportException( "Unable to build the Maven project for the artifact:" + javadocArtifact,
3311 e );
3312 }
3313 catch ( InvalidDependencyVersionException e )
3314 {
3315 throw new MavenReportException( "Unable to resolve artifact:" + javadocArtifact, e );
3316 }
3317 }
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328 private Artifact createAndResolveArtifact( JavadocPathArtifact javadocArtifact )
3329 throws ArtifactResolutionException, ArtifactNotFoundException, ProjectBuildingException
3330 {
3331 Artifact artifact =
3332 factory.createProjectArtifact( javadocArtifact.getGroupId(), javadocArtifact.getArtifactId(),
3333 javadocArtifact.getVersion(), Artifact.SCOPE_COMPILE );
3334
3335 if ( artifact.getFile() == null )
3336 {
3337 MavenProject pluginProject =
3338 mavenProjectBuilder.buildFromRepository( artifact, remoteRepositories, localRepository );
3339 artifact = pluginProject.getArtifact();
3340
3341 resolver.resolve( artifact, remoteRepositories, localRepository );
3342 }
3343
3344 return artifact;
3345 }
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355 private void addMemoryArg( Commandline cmd, String arg, String memory )
3356 {
3357 if ( StringUtils.isNotEmpty( memory ) )
3358 {
3359 try
3360 {
3361 cmd.createArg().setValue( "-J" + arg + JavadocUtil.parseJavadocMemory( memory ) );
3362 }
3363 catch ( IllegalArgumentException e )
3364 {
3365 if ( getLog().isErrorEnabled() )
3366 {
3367 getLog().error( "Malformed memory pattern for '" + arg + memory + "'. Ignore this option." );
3368 }
3369 }
3370 }
3371 }
3372
3373
3374
3375
3376
3377
3378 private void addProxyArg( Commandline cmd )
3379 {
3380
3381 if ( StringUtils.isNotEmpty( proxyHost ) )
3382 {
3383 if ( getLog().isWarnEnabled() )
3384 {
3385 getLog().warn( "The Javadoc plugin parameter 'proxyHost' is deprecated since 2.4. "
3386 + "Please configure an active proxy in your settings.xml." );
3387 }
3388 cmd.createArg().setValue( "-J-DproxyHost=" + proxyHost );
3389
3390 if ( proxyPort > 0 )
3391 {
3392 if ( getLog().isWarnEnabled() )
3393 {
3394 getLog().warn( "The Javadoc plugin parameter 'proxyPort' is deprecated since 2.4. "
3395 + "Please configure an active proxy in your settings.xml." );
3396 }
3397 cmd.createArg().setValue( "-J-DproxyPort=" + proxyPort );
3398 }
3399 }
3400
3401 if ( settings == null || settings.getActiveProxy() == null )
3402 {
3403 return;
3404 }
3405
3406 Proxy activeProxy = settings.getActiveProxy();
3407 String protocol = StringUtils.isNotEmpty( activeProxy.getProtocol() ) ? activeProxy.getProtocol() + "." : "";
3408
3409 if ( StringUtils.isNotEmpty( activeProxy.getHost() ) )
3410 {
3411 cmd.createArg().setValue( "-J-D" + protocol + "proxySet=true" );
3412 cmd.createArg().setValue( "-J-D" + protocol + "proxyHost=" + activeProxy.getHost() );
3413
3414 if ( activeProxy.getPort() > 0 )
3415 {
3416 cmd.createArg().setValue( "-J-D" + protocol + "proxyPort=" + activeProxy.getPort() );
3417 }
3418
3419 if ( StringUtils.isNotEmpty( activeProxy.getNonProxyHosts() ) )
3420 {
3421 cmd.createArg().setValue(
3422 "-J-D" + protocol + "nonProxyHosts=\"" + activeProxy.getNonProxyHosts() + "\"" );
3423 }
3424
3425 if ( StringUtils.isNotEmpty( activeProxy.getUsername() ) )
3426 {
3427 cmd.createArg().setValue( "-J-Dhttp.proxyUser=\"" + activeProxy.getUsername() + "\"" );
3428
3429 if ( StringUtils.isNotEmpty( activeProxy.getPassword() ) )
3430 {
3431 cmd.createArg().setValue( "-J-Dhttp.proxyPassword=\"" + activeProxy.getPassword() + "\"" );
3432 }
3433 }
3434 }
3435 }
3436
3437
3438
3439
3440
3441
3442
3443
3444 private String getJavadocExecutable()
3445 throws IOException
3446 {
3447 Toolchain tc = getToolchain();
3448
3449 if ( tc != null )
3450 {
3451 getLog().info( "Toolchain in javadoc-plugin: " + tc );
3452 if ( javadocExecutable != null )
3453 {
3454 getLog().warn( "Toolchains are ignored, 'javadocExecutable' parameter is set to " + javadocExecutable );
3455 }
3456 else
3457 {
3458 javadocExecutable = tc.findTool( "javadoc" );
3459 }
3460 }
3461
3462 String javadocCommand = "javadoc" + ( SystemUtils.IS_OS_WINDOWS ? ".exe" : "" );
3463
3464 File javadocExe;
3465
3466
3467
3468
3469 if ( StringUtils.isNotEmpty( javadocExecutable ) )
3470 {
3471 javadocExe = new File( javadocExecutable );
3472
3473 if ( javadocExe.isDirectory() )
3474 {
3475 javadocExe = new File( javadocExe, javadocCommand );
3476 }
3477
3478 if ( SystemUtils.IS_OS_WINDOWS && javadocExe.getName().indexOf( '.' ) < 0 )
3479 {
3480 javadocExe = new File( javadocExe.getPath() + ".exe" );
3481 }
3482
3483 if ( !javadocExe.isFile() )
3484 {
3485 throw new IOException( "The javadoc executable '" + javadocExe
3486 + "' doesn't exist or is not a file. Verify the <javadocExecutable/> parameter." );
3487 }
3488
3489 return javadocExe.getAbsolutePath();
3490 }
3491
3492
3493
3494
3495
3496
3497
3498 if ( SystemUtils.IS_OS_AIX )
3499 {
3500 javadocExe =
3501 new File( SystemUtils.getJavaHome() + File.separator + ".." + File.separator + "sh", javadocCommand );
3502 }
3503 else if ( SystemUtils.IS_OS_MAC_OSX )
3504 {
3505 javadocExe = new File( SystemUtils.getJavaHome() + File.separator + "bin", javadocCommand );
3506 }
3507 else
3508 {
3509 javadocExe =
3510 new File( SystemUtils.getJavaHome() + File.separator + ".." + File.separator + "bin", javadocCommand );
3511 }
3512
3513
3514
3515
3516 if ( !javadocExe.exists() || !javadocExe.isFile() )
3517 {
3518 Properties env = CommandLineUtils.getSystemEnvVars();
3519 String javaHome = env.getProperty( "JAVA_HOME" );
3520 if ( StringUtils.isEmpty( javaHome ) )
3521 {
3522 throw new IOException( "The environment variable JAVA_HOME is not correctly set." );
3523 }
3524 if ( ( !new File( javaHome ).exists() ) || ( !new File( javaHome ).isDirectory() ) )
3525 {
3526 throw new IOException(
3527 "The environment variable JAVA_HOME=" + javaHome + " doesn't exist or is not a valid directory." );
3528 }
3529
3530 javadocExe = new File( env.getProperty( "JAVA_HOME" ) + File.separator + "bin", javadocCommand );
3531 }
3532
3533 if ( !javadocExe.exists() || !javadocExe.isFile() )
3534 {
3535 throw new IOException( "The javadoc executable '" + javadocExe
3536 + "' doesn't exist or is not a file. Verify the JAVA_HOME environment variable." );
3537 }
3538
3539 return javadocExe.getAbsolutePath();
3540 }
3541
3542
3543
3544
3545
3546
3547
3548
3549 private void setFJavadocVersion( File jExecutable )
3550 throws MavenReportException
3551 {
3552 float jVersion;
3553 try
3554 {
3555 jVersion = JavadocUtil.getJavadocVersion( jExecutable );
3556 }
3557 catch ( IOException e )
3558 {
3559 if ( getLog().isWarnEnabled() )
3560 {
3561 getLog().warn( "Unable to find the javadoc version: " + e.getMessage() );
3562 getLog().warn( "Using the Java version instead of, i.e. " + SystemUtils.JAVA_VERSION_FLOAT );
3563 }
3564 jVersion = SystemUtils.JAVA_VERSION_FLOAT;
3565 }
3566 catch ( CommandLineException e )
3567 {
3568 if ( getLog().isWarnEnabled() )
3569 {
3570 getLog().warn( "Unable to find the javadoc version: " + e.getMessage() );
3571 getLog().warn( "Using the Java the version instead of, i.e. " + SystemUtils.JAVA_VERSION_FLOAT );
3572 }
3573 jVersion = SystemUtils.JAVA_VERSION_FLOAT;
3574 }
3575 catch ( IllegalArgumentException e )
3576 {
3577 if ( getLog().isWarnEnabled() )
3578 {
3579 getLog().warn( "Unable to find the javadoc version: " + e.getMessage() );
3580 getLog().warn( "Using the Java the version instead of, i.e. " + SystemUtils.JAVA_VERSION_FLOAT );
3581 }
3582 jVersion = SystemUtils.JAVA_VERSION_FLOAT;
3583 }
3584
3585 if ( StringUtils.isNotEmpty( javadocVersion ) )
3586 {
3587 try
3588 {
3589 fJavadocVersion = Float.parseFloat( javadocVersion );
3590 }
3591 catch ( NumberFormatException e )
3592 {
3593 throw new MavenReportException( "Unable to parse javadoc version: " + e.getMessage(), e );
3594 }
3595
3596 if ( fJavadocVersion != jVersion && getLog().isWarnEnabled() )
3597 {
3598 getLog().warn( "Are you sure about the <javadocVersion/> parameter? It seems to be " + jVersion );
3599 }
3600 }
3601 else
3602 {
3603 fJavadocVersion = jVersion;
3604 }
3605 }
3606
3607
3608
3609
3610
3611
3612
3613
3614 private boolean isJavaDocVersionAtLeast( float requiredVersion )
3615 {
3616 return fJavadocVersion >= requiredVersion;
3617 }
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627 private void addArgIf( List<String> arguments, boolean b, String value )
3628 {
3629 if ( b )
3630 {
3631 arguments.add( value );
3632 }
3633 }
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646 private void addArgIf( List<String> arguments, boolean b, String value, float requiredJavaVersion )
3647 {
3648 if ( b )
3649 {
3650 if ( isJavaDocVersionAtLeast( requiredJavaVersion ) )
3651 {
3652 addArgIf( arguments, b, value );
3653 }
3654 else
3655 {
3656 if ( getLog().isWarnEnabled() )
3657 {
3658 getLog().warn( value + " option is not supported on Java version < " + requiredJavaVersion
3659 + ". Ignore this option." );
3660 }
3661 }
3662 }
3663 }
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676 private void addArgIfNotEmpty( List<String> arguments, String key, String value )
3677 {
3678 addArgIfNotEmpty( arguments, key, value, false );
3679 }
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696 private void addArgIfNotEmpty( List<String> arguments, String key, String value, boolean repeatKey,
3697 boolean splitValue, float requiredJavaVersion )
3698 {
3699 if ( StringUtils.isNotEmpty( value ) )
3700 {
3701 if ( isJavaDocVersionAtLeast( requiredJavaVersion ) )
3702 {
3703 addArgIfNotEmpty( arguments, key, value, repeatKey, splitValue );
3704 }
3705 else
3706 {
3707 if ( getLog().isWarnEnabled() )
3708 {
3709 getLog().warn( key + " option is not supported on Java version < " + requiredJavaVersion
3710 + ". Ignore this option." );
3711 }
3712 }
3713 }
3714 }
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728 private void addArgIfNotEmpty( List<String> arguments, String key, String value, boolean repeatKey,
3729 boolean splitValue )
3730 {
3731 if ( StringUtils.isNotEmpty( value ) )
3732 {
3733 if ( StringUtils.isNotEmpty( key ) )
3734 {
3735 arguments.add( key );
3736 }
3737
3738 if ( splitValue )
3739 {
3740 StringTokenizer token = new StringTokenizer( value, "," );
3741 while ( token.hasMoreTokens() )
3742 {
3743 String current = token.nextToken().trim();
3744
3745 if ( StringUtils.isNotEmpty( current ) )
3746 {
3747 arguments.add( current );
3748
3749 if ( token.hasMoreTokens() && repeatKey )
3750 {
3751 arguments.add( key );
3752 }
3753 }
3754 }
3755 }
3756 else
3757 {
3758 arguments.add( value );
3759 }
3760 }
3761 }
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774 private void addArgIfNotEmpty( List<String> arguments, String key, String value, boolean repeatKey )
3775 {
3776 addArgIfNotEmpty( arguments, key, value, repeatKey, true );
3777 }
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789 private void addArgIfNotEmpty( List<String> arguments, String key, String value, float requiredJavaVersion )
3790 {
3791 addArgIfNotEmpty( arguments, key, value, requiredJavaVersion, false );
3792 }
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806 private void addArgIfNotEmpty( List<String> arguments, String key, String value, float requiredJavaVersion,
3807 boolean repeatKey )
3808 {
3809 if ( StringUtils.isNotEmpty( value ) )
3810 {
3811 if ( isJavaDocVersionAtLeast( requiredJavaVersion ) )
3812 {
3813 addArgIfNotEmpty( arguments, key, value, repeatKey );
3814 }
3815 else
3816 {
3817 if ( getLog().isWarnEnabled() )
3818 {
3819 getLog().warn( key + " option is not supported on Java version < " + requiredJavaVersion );
3820 }
3821 }
3822 }
3823 }
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838 private void addLinkofflineArguments( List<String> arguments )
3839 throws MavenReportException
3840 {
3841 Set<OfflineLink> offlineLinksList = collectOfflineLinks();
3842
3843 offlineLinksList.addAll( getModulesLinks() );
3844
3845 for ( OfflineLink offlineLink : offlineLinksList )
3846 {
3847 String url = offlineLink.getUrl();
3848 if ( StringUtils.isEmpty( url ) )
3849 {
3850 continue;
3851 }
3852 url = cleanUrl( url );
3853
3854 String location = offlineLink.getLocation();
3855 if ( StringUtils.isEmpty( location ) )
3856 {
3857 continue;
3858 }
3859 if ( isValidJavadocLink( location ) )
3860 {
3861 addArgIfNotEmpty( arguments, "-linkoffline",
3862 JavadocUtil.quotedPathArgument( url ) + " " + JavadocUtil.quotedPathArgument(
3863 location ), true );
3864 }
3865 }
3866 }
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887 private void addLinkArguments( List<String> arguments )
3888 throws MavenReportException
3889 {
3890 Set<String> links = collectLinks();
3891
3892 for ( String link : links )
3893 {
3894 if ( StringUtils.isEmpty( link ) )
3895 {
3896 continue;
3897 }
3898
3899 while ( link.endsWith( "/" ) )
3900 {
3901 link = link.substring( 0, link.lastIndexOf( "/" ) );
3902 }
3903
3904 addArgIfNotEmpty( arguments, "-link", JavadocUtil.quotedPathArgument( link ), true, false );
3905 }
3906 }
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917 private void copyAllResources( File javadocOutputDirectory )
3918 throws MavenReportException
3919 {
3920
3921
3922
3923
3924 try
3925 {
3926 copyDefaultStylesheet( javadocOutputDirectory );
3927 }
3928 catch ( IOException e )
3929 {
3930 throw new MavenReportException( "Unable to copy default stylesheet: " + e.getMessage(), e );
3931 }
3932
3933
3934
3935
3936
3937 if ( docfilessubdirs )
3938 {
3939
3940
3941
3942
3943 try
3944 {
3945 copyJavadocResources( javadocOutputDirectory );
3946 }
3947 catch ( IOException e )
3948 {
3949 throw new MavenReportException( "Unable to copy javadoc resources: " + e.getMessage(), e );
3950 }
3951 }
3952
3953
3954
3955
3956
3957 copyAdditionalJavadocResources( javadocOutputDirectory );
3958 }
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970 private void copyDefaultStylesheet( File anOutputDirectory )
3971 throws IOException
3972 {
3973 if ( StringUtils.isNotEmpty( stylesheetfile ) )
3974 {
3975 return;
3976 }
3977
3978 if ( !stylesheet.equalsIgnoreCase( "maven" ) )
3979 {
3980 return;
3981 }
3982
3983 URL url = getClass().getClassLoader().getResource( RESOURCE_CSS_DIR + "/" + DEFAULT_CSS_NAME );
3984 File outFile = new File( anOutputDirectory, DEFAULT_CSS_NAME );
3985 JavadocUtil.copyResource( url, outFile );
3986 }
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998 private void copyJavadocResources( File anOutputDirectory )
3999 throws IOException
4000 {
4001 if ( anOutputDirectory == null || !anOutputDirectory.exists() )
4002 {
4003 throw new IOException( "The outputDirectory " + anOutputDirectory + " doesn't exists." );
4004 }
4005
4006 if ( includeDependencySources )
4007 {
4008 resolveDependencyBundles();
4009 if ( isNotEmpty( dependencyJavadocBundles ) )
4010 {
4011 for ( JavadocBundle bundle : dependencyJavadocBundles )
4012 {
4013 File dir = bundle.getResourcesDirectory();
4014 JavadocOptions options = bundle.getOptions();
4015 if ( dir != null && dir.isDirectory() )
4016 {
4017 JavadocUtil.copyJavadocResources( anOutputDirectory, dir, options == null
4018 ? null
4019 : options.getExcludedDocfilesSubdirs() );
4020 }
4021 }
4022 }
4023 }
4024
4025 if ( getJavadocDirectory() != null )
4026 {
4027 JavadocUtil.copyJavadocResources( anOutputDirectory, getJavadocDirectory(), excludedocfilessubdir );
4028 }
4029
4030 if ( isAggregator() && project.isExecutionRoot() )
4031 {
4032 for ( MavenProject subProject : reactorProjects )
4033 {
4034 if ( subProject != project && getJavadocDirectory() != null )
4035 {
4036 String javadocDirRelative =
4037 PathUtils.toRelative( project.getBasedir(), getJavadocDirectory().getAbsolutePath() );
4038 File javadocDir = new File( subProject.getBasedir(), javadocDirRelative );
4039 JavadocUtil.copyJavadocResources( anOutputDirectory, javadocDir, excludedocfilessubdir );
4040 }
4041 }
4042 }
4043 }
4044
4045 private synchronized void resolveDependencyBundles()
4046 throws IOException
4047 {
4048 if ( dependencyJavadocBundles == null )
4049 {
4050 dependencyJavadocBundles =
4051 ResourceResolver.resolveDependencyJavadocBundles( getDependencySourceResolverConfig() );
4052 if ( dependencyJavadocBundles == null )
4053 {
4054 dependencyJavadocBundles = new ArrayList<JavadocBundle>();
4055 }
4056 }
4057 }
4058
4059
4060
4061
4062
4063
4064
4065
4066 private void copyAdditionalJavadocResources( File anOutputDirectory )
4067 throws MavenReportException
4068 {
4069 Set<ResourcesArtifact> resourcesArtifacts = collectResourcesArtifacts();
4070 if ( isEmpty( resourcesArtifacts ) )
4071 {
4072 return;
4073 }
4074
4075 UnArchiver unArchiver;
4076 try
4077 {
4078 unArchiver = archiverManager.getUnArchiver( "jar" );
4079 }
4080 catch ( NoSuchArchiverException e )
4081 {
4082 throw new MavenReportException(
4083 "Unable to extract resources artifact. " + "No archiver for 'jar' available.", e );
4084 }
4085
4086 for ( ResourcesArtifact item : resourcesArtifacts )
4087 {
4088 Artifact artifact;
4089 try
4090 {
4091 artifact = createAndResolveArtifact( item );
4092 }
4093 catch ( ArtifactResolutionException e )
4094 {
4095 throw new MavenReportException( "Unable to resolve artifact:" + item, e );
4096 }
4097 catch ( ArtifactNotFoundException e )
4098 {
4099 throw new MavenReportException( "Unable to find artifact:" + item, e );
4100 }
4101 catch ( ProjectBuildingException e )
4102 {
4103 throw new MavenReportException( "Unable to build the Maven project for the artifact:" + item, e );
4104 }
4105
4106 unArchiver.setSourceFile( artifact.getFile() );
4107 unArchiver.setDestDirectory( anOutputDirectory );
4108
4109 IncludeExcludeFileSelector[] selectors =
4110 new IncludeExcludeFileSelector[]{ new IncludeExcludeFileSelector() };
4111 selectors[0].setExcludes( new String[]{ "META-INF/**" } );
4112 unArchiver.setFileSelectors( selectors );
4113
4114 getLog().info( "Extracting contents of resources artifact: " + artifact.getArtifactId() );
4115 try
4116 {
4117 unArchiver.extract();
4118 }
4119 catch ( ArchiverException e )
4120 {
4121 throw new MavenReportException(
4122 "Extraction of resources failed. Artifact that failed was: " + artifact.getArtifactId(), e );
4123 }
4124 }
4125 }
4126
4127
4128
4129
4130
4131
4132 private List<String> getPackageNames( List<String> sourcePaths, List<String> files )
4133 {
4134 return getPackageNamesOrFilesWithUnnamedPackages( sourcePaths, files, true );
4135 }
4136
4137
4138
4139
4140
4141
4142 private List<String> getFilesWithUnnamedPackages( List<String> sourcePaths, List<String> files )
4143 {
4144 return getPackageNamesOrFilesWithUnnamedPackages( sourcePaths, files, false );
4145 }
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155 private List<String> getPackageNamesOrFilesWithUnnamedPackages( List<String> sourcePaths, List<String> files,
4156 boolean onlyPackageName )
4157 {
4158 List<String> returnList = new ArrayList<String>();
4159
4160 if ( !StringUtils.isEmpty( sourcepath ) )
4161 {
4162 return returnList;
4163 }
4164
4165 for ( String currentFile : files )
4166 {
4167 currentFile = currentFile.replace( '\\', '/' );
4168
4169 for ( String currentSourcePath : sourcePaths )
4170 {
4171 currentSourcePath = currentSourcePath.replace( '\\', '/' );
4172
4173 if ( !currentSourcePath.endsWith( "/" ) )
4174 {
4175 currentSourcePath += "/";
4176 }
4177
4178 if ( currentFile.indexOf( currentSourcePath ) != -1 )
4179 {
4180 String packagename = currentFile.substring( currentSourcePath.length() + 1 );
4181
4182
4183
4184
4185
4186 if ( packagename.indexOf( "doc-files" ) != -1 )
4187 {
4188 continue;
4189 }
4190
4191 if ( onlyPackageName && packagename.lastIndexOf( "/" ) != -1 )
4192 {
4193 packagename = packagename.substring( 0, packagename.lastIndexOf( "/" ) );
4194 packagename = packagename.replace( '/', '.' );
4195
4196 if ( !returnList.contains( packagename ) )
4197 {
4198 returnList.add( packagename );
4199 }
4200 }
4201 if ( !onlyPackageName && packagename.lastIndexOf( "/" ) == -1 )
4202 {
4203 returnList.add( currentFile );
4204 }
4205 }
4206 }
4207 }
4208
4209 return returnList;
4210 }
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224 private void addCommandLineOptions( Commandline cmd, List<String> arguments, File javadocOutputDirectory )
4225 throws MavenReportException
4226 {
4227 File optionsFile = new File( javadocOutputDirectory, OPTIONS_FILE_NAME );
4228
4229 StringBuilder options = new StringBuilder();
4230 options.append( StringUtils.join( arguments.toArray( new String[0] ), SystemUtils.LINE_SEPARATOR ) );
4231
4232 try
4233 {
4234 FileUtils.fileWrite( optionsFile.getAbsolutePath(), options.toString() );
4235 }
4236 catch ( IOException e )
4237 {
4238 throw new MavenReportException(
4239 "Unable to write '" + optionsFile.getName() + "' temporary file for command execution", e );
4240 }
4241
4242 cmd.createArg().setValue( "@" + OPTIONS_FILE_NAME );
4243 }
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263 private void addCommandLineArgFile( Commandline cmd, File javadocOutputDirectory, List<String> files )
4264 throws MavenReportException
4265 {
4266 File argfileFile;
4267 if ( isJavaDocVersionAtLeast( SINCE_JAVADOC_1_4 ) )
4268 {
4269 argfileFile = new File( javadocOutputDirectory, ARGFILE_FILE_NAME );
4270 cmd.createArg().setValue( "@" + ARGFILE_FILE_NAME );
4271 }
4272 else
4273 {
4274 argfileFile = new File( javadocOutputDirectory, FILES_FILE_NAME );
4275 cmd.createArg().setValue( "@" + FILES_FILE_NAME );
4276 }
4277
4278 try
4279 {
4280 FileUtils.fileWrite( argfileFile.getAbsolutePath(), null
4281 StringUtils.join( files.iterator(), SystemUtils.LINE_SEPARATOR ) );
4282 }
4283 catch ( IOException e )
4284 {
4285 throw new MavenReportException(
4286 "Unable to write '" + argfileFile.getName() + "' temporary file for command execution", e );
4287 }
4288 }
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302 private void addCommandLinePackages( Commandline cmd, File javadocOutputDirectory, List<String> packageNames )
4303 throws MavenReportException
4304 {
4305 File packagesFile = new File( javadocOutputDirectory, PACKAGES_FILE_NAME );
4306
4307 try
4308 {
4309 FileUtils.fileWrite( packagesFile.getAbsolutePath(), null
4310 StringUtils.join( packageNames.iterator(), SystemUtils.LINE_SEPARATOR ) );
4311 }
4312 catch ( IOException e )
4313 {
4314 throw new MavenReportException(
4315 "Unable to write '" + packagesFile.getName() + "' temporary file for command execution", e );
4316 }
4317
4318 cmd.createArg().setValue( "@" + PACKAGES_FILE_NAME );
4319 }
4320
4321
4322
4323
4324
4325
4326 private void validateJavadocOptions()
4327 throws MavenReportException
4328 {
4329
4330 if ( StringUtils.isNotEmpty( getEncoding() ) && !JavadocUtil.validateEncoding( getEncoding() ) )
4331 {
4332 throw new MavenReportException( "Unsupported option <encoding/> '" + getEncoding() + "'" );
4333 }
4334
4335
4336 if ( StringUtils.isNotEmpty( this.locale ) )
4337 {
4338 StringTokenizer tokenizer = new StringTokenizer( this.locale, "_" );
4339 final int maxTokens = 3;
4340 if ( tokenizer.countTokens() > maxTokens )
4341 {
4342 throw new MavenReportException(
4343 "Unsupported option <locale/> '" + this.locale + "', should be language_country_variant." );
4344 }
4345
4346 Locale localeObject = null;
4347 if ( tokenizer.hasMoreTokens() )
4348 {
4349 String language = tokenizer.nextToken().toLowerCase( Locale.ENGLISH );
4350 if ( !Arrays.asList( Locale.getISOLanguages() ).contains( language ) )
4351 {
4352 throw new MavenReportException(
4353 "Unsupported language '" + language + "' in option <locale/> '" + this.locale + "'" );
4354 }
4355 localeObject = new Locale( language );
4356
4357 if ( tokenizer.hasMoreTokens() )
4358 {
4359 String country = tokenizer.nextToken().toUpperCase( Locale.ENGLISH );
4360 if ( !Arrays.asList( Locale.getISOCountries() ).contains( country ) )
4361 {
4362 throw new MavenReportException(
4363 "Unsupported country '" + country + "' in option <locale/> '" + this.locale + "'" );
4364 }
4365 localeObject = new Locale( language, country );
4366
4367 if ( tokenizer.hasMoreTokens() )
4368 {
4369 String variant = tokenizer.nextToken();
4370 localeObject = new Locale( language, country, variant );
4371 }
4372 }
4373 }
4374
4375 if ( localeObject == null )
4376 {
4377 throw new MavenReportException(
4378 "Unsupported option <locale/> '" + this.locale + "', should be language_country_variant." );
4379 }
4380
4381 this.locale = localeObject.toString();
4382 final List<Locale> availableLocalesList = Arrays.asList( Locale.getAvailableLocales() );
4383 if ( StringUtils.isNotEmpty( localeObject.getVariant() ) && !availableLocalesList.contains( localeObject ) )
4384 {
4385 StringBuilder sb = new StringBuilder();
4386 sb.append( "Unsupported option <locale/> with variant '" ).append( this.locale );
4387 sb.append( "'" );
4388
4389 localeObject = new Locale( localeObject.getLanguage(), localeObject.getCountry() );
4390 this.locale = localeObject.toString();
4391
4392 sb.append( ", trying to use <locale/> without variant, i.e. '" ).append( this.locale ).append( "'" );
4393 if ( getLog().isWarnEnabled() )
4394 {
4395 getLog().warn( sb.toString() );
4396 }
4397 }
4398
4399 if ( !availableLocalesList.contains( localeObject ) )
4400 {
4401 throw new MavenReportException( "Unsupported option <locale/> '" + this.locale + "'" );
4402 }
4403 }
4404 }
4405
4406
4407
4408
4409
4410
4411
4412
4413 private void validateStandardDocletOptions()
4414 throws MavenReportException
4415 {
4416
4417 if ( StringUtils.isNotEmpty( getDocencoding() ) && !JavadocUtil.validateEncoding( getDocencoding() ) )
4418 {
4419 throw new MavenReportException( "Unsupported option <docencoding/> '" + getDocencoding() + "'" );
4420 }
4421
4422
4423 if ( StringUtils.isNotEmpty( getCharset() ) && !JavadocUtil.validateEncoding( getCharset() ) )
4424 {
4425 throw new MavenReportException( "Unsupported option <charset/> '" + getCharset() + "'" );
4426 }
4427
4428
4429 if ( StringUtils.isNotEmpty( helpfile ) && nohelp )
4430 {
4431 throw new MavenReportException( "Option <nohelp/> conflicts with <helpfile/>" );
4432 }
4433
4434
4435 if ( ( getOverview() != null ) && nooverview )
4436 {
4437 throw new MavenReportException( "Option <nooverview/> conflicts with <overview/>" );
4438 }
4439
4440
4441 if ( splitindex && noindex )
4442 {
4443 throw new MavenReportException( "Option <noindex/> conflicts with <splitindex/>" );
4444 }
4445
4446
4447 if ( StringUtils.isNotEmpty( stylesheet ) && !( stylesheet.equalsIgnoreCase( "maven" )
4448 || stylesheet.equalsIgnoreCase( "java" ) ) )
4449 {
4450 throw new MavenReportException( "Option <stylesheet/> supports only \"maven\" or \"java\" value." );
4451 }
4452
4453
4454 if ( javaApiLinks == null || javaApiLinks.size() == 0 )
4455 {
4456 javaApiLinks = DEFAULT_JAVA_API_LINKS;
4457 }
4458 }
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469 private boolean checkMissingArtifactsInReactor( Collection<Artifact> dependencyArtifacts,
4470 Collection<Artifact> missing )
4471 {
4472 Set<MavenProject> foundInReactor = new HashSet<MavenProject>();
4473 for ( Artifact mArtifact : missing )
4474 {
4475 for ( MavenProject p : reactorProjects )
4476 {
4477 if ( p.getArtifactId().equals( mArtifact.getArtifactId() ) && p.getGroupId().equals(
4478 mArtifact.getGroupId() ) && p.getVersion().equals( mArtifact.getVersion() ) )
4479 {
4480 getLog().warn( "The dependency: [" + p.getId()
4481 + "] can't be resolved but has been found in the reactor (probably snapshots).\n"
4482 + "This dependency has been excluded from the Javadoc classpath. "
4483 + "You should rerun javadoc after executing mvn install." );
4484
4485
4486 foundInReactor.add( p );
4487 break;
4488 }
4489 }
4490 }
4491
4492
4493 return foundInReactor.size() == missing.size();
4494 }
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507 private void addJavadocOptions( List<String> arguments, List<String> sourcePaths )
4508 throws MavenReportException
4509 {
4510 validateJavadocOptions();
4511
4512
4513 addArgIfNotEmpty( arguments, "-locale", JavadocUtil.quotedArgument( this.locale ) );
4514
4515
4516
4517 if ( old && isJavaDocVersionAtLeast( SINCE_JAVADOC_1_4 ) )
4518 {
4519 if ( getLog().isWarnEnabled() )
4520 {
4521 getLog().warn( "Javadoc 1.4+ doesn't support the -1.1 switch anymore. Ignore this option." );
4522 }
4523 }
4524 else
4525 {
4526 addArgIf( arguments, old, "-1.1" );
4527 }
4528
4529 addArgIfNotEmpty( arguments, "-bootclasspath", JavadocUtil.quotedPathArgument( getBootclassPath() ) );
4530
4531 if ( isJavaDocVersionAtLeast( SINCE_JAVADOC_1_5 ) )
4532 {
4533 addArgIf( arguments, breakiterator, "-breakiterator", SINCE_JAVADOC_1_5 );
4534 }
4535
4536 addArgIfNotEmpty( arguments, "-classpath", JavadocUtil.quotedPathArgument( getClasspath() ) );
4537
4538 if ( StringUtils.isNotEmpty( doclet ) )
4539 {
4540 addArgIfNotEmpty( arguments, "-doclet", JavadocUtil.quotedArgument( doclet ) );
4541 addArgIfNotEmpty( arguments, "-docletpath", JavadocUtil.quotedPathArgument( getDocletPath() ) );
4542 }
4543
4544 if ( StringUtils.isEmpty( encoding ) )
4545 {
4546 getLog().warn(
4547 "Source files encoding has not been set, using platform encoding " + ReaderFactory.FILE_ENCODING
4548 + ", i.e. build is platform dependent!" );
4549 }
4550 addArgIfNotEmpty( arguments, "-encoding", JavadocUtil.quotedArgument( getEncoding() ) );
4551
4552 addArgIfNotEmpty( arguments, "-exclude", getExcludedPackages( sourcePaths ), SINCE_JAVADOC_1_4 );
4553
4554 addArgIfNotEmpty( arguments, "-extdirs",
4555 JavadocUtil.quotedPathArgument( JavadocUtil.unifyPathSeparator( extdirs ) ) );
4556
4557 if ( ( getOverview() != null ) && ( getOverview().exists() ) )
4558 {
4559 addArgIfNotEmpty( arguments, "-overview",
4560 JavadocUtil.quotedPathArgument( getOverview().getAbsolutePath() ) );
4561 }
4562
4563 arguments.add( getAccessLevel() );
4564
4565 if ( isJavaDocVersionAtLeast( SINCE_JAVADOC_1_5 ) )
4566 {
4567 addArgIf( arguments, quiet, "-quiet", SINCE_JAVADOC_1_5 );
4568 }
4569
4570 addArgIfNotEmpty( arguments, "-source", JavadocUtil.quotedArgument( source ), SINCE_JAVADOC_1_4 );
4571
4572 if ( ( StringUtils.isEmpty( sourcepath ) ) && ( StringUtils.isNotEmpty( subpackages ) ) )
4573 {
4574 sourcepath = StringUtils.join( sourcePaths.iterator(), File.pathSeparator );
4575 }
4576 addArgIfNotEmpty( arguments, "-sourcepath", JavadocUtil.quotedPathArgument( getSourcePath( sourcePaths ) ) );
4577
4578 if ( StringUtils.isNotEmpty( sourcepath ) && isJavaDocVersionAtLeast( SINCE_JAVADOC_1_5 ) )
4579 {
4580 addArgIfNotEmpty( arguments, "-subpackages", subpackages, SINCE_JAVADOC_1_5 );
4581 }
4582
4583 addArgIf( arguments, verbose, "-verbose" );
4584
4585 addArgIfNotEmpty( arguments, null, additionalparam );
4586 }
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600 private void addStandardDocletOptions( File javadocOutputDirectory, List<String> arguments )
4601 throws MavenReportException
4602 {
4603 validateStandardDocletOptions();
4604
4605
4606
4607 addArgIf( arguments, author, "-author" );
4608
4609 addArgIfNotEmpty( arguments, "-bottom", JavadocUtil.quotedArgument( getBottomText() ), false, false );
4610
4611 if ( !isJavaDocVersionAtLeast( SINCE_JAVADOC_1_5 ) )
4612 {
4613 addArgIf( arguments, breakiterator, "-breakiterator", SINCE_JAVADOC_1_4 );
4614 }
4615
4616 addArgIfNotEmpty( arguments, "-charset", JavadocUtil.quotedArgument( getCharset() ) );
4617
4618 addArgIfNotEmpty( arguments, "-d", JavadocUtil.quotedPathArgument( javadocOutputDirectory.toString() ) );
4619
4620 addArgIfNotEmpty( arguments, "-docencoding", JavadocUtil.quotedArgument( getDocencoding() ) );
4621
4622 addArgIf( arguments, docfilessubdirs, "-docfilessubdirs", SINCE_JAVADOC_1_4 );
4623
4624 addArgIfNotEmpty( arguments, "-doctitle", JavadocUtil.quotedArgument( getDoctitle() ), false, false );
4625
4626 if ( docfilessubdirs )
4627 {
4628 addArgIfNotEmpty( arguments, "-excludedocfilessubdir",
4629 JavadocUtil.quotedPathArgument( excludedocfilessubdir ), SINCE_JAVADOC_1_4 );
4630 }
4631
4632 addArgIfNotEmpty( arguments, "-footer", JavadocUtil.quotedArgument( footer ), false, false );
4633
4634 addGroups( arguments );
4635
4636 addArgIfNotEmpty( arguments, "-header", JavadocUtil.quotedArgument( header ), false, false );
4637
4638 addArgIfNotEmpty( arguments, "-helpfile",
4639 JavadocUtil.quotedPathArgument( getHelpFile( javadocOutputDirectory ) ) );
4640
4641 addArgIf( arguments, keywords, "-keywords", SINCE_JAVADOC_1_4_2 );
4642
4643 if ( !isOffline )
4644 {
4645 addLinkArguments( arguments );
4646 }
4647
4648 addLinkofflineArguments( arguments );
4649
4650 addArgIf( arguments, linksource, "-linksource", SINCE_JAVADOC_1_4 );
4651
4652 if ( sourcetab > 0 )
4653 {
4654 if ( fJavadocVersion == SINCE_JAVADOC_1_4_2 )
4655 {
4656 addArgIfNotEmpty( arguments, "-linksourcetab", String.valueOf( sourcetab ) );
4657 }
4658 addArgIfNotEmpty( arguments, "-sourcetab", String.valueOf( sourcetab ), SINCE_JAVADOC_1_5 );
4659 }
4660
4661 addArgIf( arguments, nocomment, "-nocomment", SINCE_JAVADOC_1_4 );
4662
4663 addArgIf( arguments, nodeprecated, "-nodeprecated" );
4664
4665 addArgIf( arguments, nodeprecatedlist, "-nodeprecatedlist" );
4666
4667 addArgIf( arguments, nohelp, "-nohelp" );
4668
4669 addArgIf( arguments, noindex, "-noindex" );
4670
4671 addArgIf( arguments, nonavbar, "-nonavbar" );
4672
4673 addArgIf( arguments, nooverview, "-nooverview" );
4674
4675 addArgIfNotEmpty( arguments, "-noqualifier", JavadocUtil.quotedArgument( noqualifier ), SINCE_JAVADOC_1_4 );
4676
4677 addArgIf( arguments, nosince, "-nosince" );
4678
4679 addArgIf( arguments, notimestamp, "-notimestamp", SINCE_JAVADOC_1_5 );
4680
4681 addArgIf( arguments, notree, "-notree" );
4682
4683 addArgIfNotEmpty( arguments, "-packagesheader", JavadocUtil.quotedArgument( packagesheader ),
4684 SINCE_JAVADOC_1_4_2 );
4685
4686 if ( !isJavaDocVersionAtLeast( SINCE_JAVADOC_1_5 ) )
4687 {
4688 addArgIf( arguments, quiet, "-quiet", SINCE_JAVADOC_1_4 );
4689 }
4690
4691 addArgIf( arguments, serialwarn, "-serialwarn" );
4692
4693 addArgIf( arguments, splitindex, "-splitindex" );
4694
4695 addArgIfNotEmpty( arguments, "-stylesheetfile",
4696 JavadocUtil.quotedPathArgument( getStylesheetFile( javadocOutputDirectory ) ) );
4697
4698 if ( StringUtils.isNotEmpty( sourcepath ) && !isJavaDocVersionAtLeast( SINCE_JAVADOC_1_5 ) )
4699 {
4700 addArgIfNotEmpty( arguments, "-subpackages", subpackages, SINCE_JAVADOC_1_4 );
4701 }
4702
4703 addArgIfNotEmpty( arguments, "-taglet", JavadocUtil.quotedArgument( taglet ), SINCE_JAVADOC_1_4 );
4704 addTaglets( arguments );
4705 addTagletsFromTagletArtifacts( arguments );
4706 addArgIfNotEmpty( arguments, "-tagletpath", JavadocUtil.quotedPathArgument( getTagletPath() ),
4707 SINCE_JAVADOC_1_4 );
4708
4709 addTags( arguments );
4710
4711 addArgIfNotEmpty( arguments, "-top", JavadocUtil.quotedArgument( top ), false, false, SINCE_JAVADOC_1_6 );
4712
4713 addArgIf( arguments, use, "-use" );
4714
4715 addArgIf( arguments, version, "-version" );
4716
4717 addArgIfNotEmpty( arguments, "-windowtitle", JavadocUtil.quotedArgument( getWindowtitle() ), false, false );
4718 }
4719
4720
4721
4722
4723
4724
4725
4726 private void addGroups( List<String> arguments )
4727 throws MavenReportException
4728 {
4729 Set<Group> groups = collectGroups();
4730 if ( isEmpty( groups ) )
4731 {
4732 return;
4733 }
4734
4735 for ( Group group : groups )
4736 {
4737 if ( group == null || StringUtils.isEmpty( group.getTitle() ) || StringUtils.isEmpty(
4738 group.getPackages() ) )
4739 {
4740 if ( getLog().isWarnEnabled() )
4741 {
4742 getLog().warn( "A group option is empty. Ignore this option." );
4743 }
4744 }
4745 else
4746 {
4747 String groupTitle = StringUtils.replace( group.getTitle(), ",", "," );
4748 addArgIfNotEmpty( arguments, "-group",
4749 JavadocUtil.quotedArgument( groupTitle ) + " " + JavadocUtil.quotedArgument(
4750 group.getPackages() ), true );
4751 }
4752 }
4753 }
4754
4755
4756
4757
4758
4759
4760
4761 private void addTags( List<String> arguments )
4762 throws MavenReportException
4763 {
4764 Set<Tag> tags = collectTags();
4765
4766 if ( isEmpty( tags ) )
4767 {
4768 return;
4769 }
4770
4771 for ( Tag tag : tags )
4772 {
4773 if ( StringUtils.isEmpty( tag.getName() ) )
4774 {
4775 if ( getLog().isWarnEnabled() )
4776 {
4777 getLog().warn( "A tag name is empty. Ignore this option." );
4778 }
4779 }
4780 else
4781 {
4782 String value = "\"" + tag.getName();
4783 if ( StringUtils.isNotEmpty( tag.getPlacement() ) )
4784 {
4785 value += ":" + tag.getPlacement();
4786 if ( StringUtils.isNotEmpty( tag.getHead() ) )
4787 {
4788 value += ":" + tag.getHead();
4789 }
4790 }
4791 value += "\"";
4792 addArgIfNotEmpty( arguments, "-tag", value, SINCE_JAVADOC_1_4 );
4793 }
4794 }
4795 }
4796
4797
4798
4799
4800
4801
4802 private void addTaglets( List<String> arguments )
4803 {
4804 if ( taglets == null )
4805 {
4806 return;
4807 }
4808
4809 for ( int i = 0; i < taglets.length; i++ )
4810 {
4811 if ( ( taglets[i] == null ) || ( StringUtils.isEmpty( taglets[i].getTagletClass() ) ) )
4812 {
4813 if ( getLog().isWarnEnabled() )
4814 {
4815 getLog().warn( "A taglet option is empty. Ignore this option." );
4816 }
4817 }
4818 else
4819 {
4820 addArgIfNotEmpty( arguments, "-taglet", JavadocUtil.quotedArgument( taglets[i].getTagletClass() ),
4821 SINCE_JAVADOC_1_4 );
4822 }
4823 }
4824 }
4825
4826
4827
4828
4829
4830
4831
4832
4833 private void addTagletsFromTagletArtifacts( List<String> arguments )
4834 throws MavenReportException
4835 {
4836 Set<TagletArtifact> tArtifacts = new LinkedHashSet<TagletArtifact>();
4837 if ( tagletArtifacts != null && tagletArtifacts.length > 0 )
4838 {
4839 tArtifacts.addAll( Arrays.asList( tagletArtifacts ) );
4840 }
4841
4842 if ( includeDependencySources )
4843 {
4844 try
4845 {
4846 resolveDependencyBundles();
4847 }
4848 catch ( IOException e )
4849 {
4850 throw new MavenReportException(
4851 "Failed to resolve javadoc bundles from dependencies: " + e.getMessage(), e );
4852 }
4853
4854 if ( isNotEmpty( dependencyJavadocBundles ) )
4855 {
4856 for ( JavadocBundle bundle : dependencyJavadocBundles )
4857 {
4858 JavadocOptions options = bundle.getOptions();
4859 if ( options != null && isNotEmpty( options.getTagletArtifacts() ) )
4860 {
4861 tArtifacts.addAll( options.getTagletArtifacts() );
4862 }
4863 }
4864 }
4865 }
4866
4867 if ( isEmpty( tArtifacts ) )
4868 {
4869 return;
4870 }
4871
4872 List<String> tagletsPath = new ArrayList<String>();
4873
4874 for ( TagletArtifact aTagletArtifact : tArtifacts )
4875 {
4876 if ( ( StringUtils.isNotEmpty( aTagletArtifact.getGroupId() ) ) && ( StringUtils.isNotEmpty(
4877 aTagletArtifact.getArtifactId() ) ) && ( StringUtils.isNotEmpty( aTagletArtifact.getVersion() ) ) )
4878 {
4879 Artifact artifact;
4880 try
4881 {
4882 artifact = createAndResolveArtifact( aTagletArtifact );
4883 }
4884 catch ( ArtifactResolutionException e )
4885 {
4886 throw new MavenReportException( "Unable to resolve artifact:" + aTagletArtifact, e );
4887 }
4888 catch ( ArtifactNotFoundException e )
4889 {
4890 throw new MavenReportException( "Unable to find artifact:" + aTagletArtifact, e );
4891 }
4892 catch ( ProjectBuildingException e )
4893 {
4894 throw new MavenReportException(
4895 "Unable to build the Maven project for the artifact:" + aTagletArtifact, e );
4896 }
4897
4898 tagletsPath.add( artifact.getFile().getAbsolutePath() );
4899 }
4900 }
4901
4902 tagletsPath = JavadocUtil.pruneFiles( tagletsPath );
4903
4904 for ( String tagletJar : tagletsPath )
4905 {
4906 if ( !tagletJar.toLowerCase( Locale.ENGLISH ).endsWith( ".jar" ) )
4907 {
4908 continue;
4909 }
4910
4911 List<String> tagletClasses;
4912 try
4913 {
4914 tagletClasses = JavadocUtil.getTagletClassNames( new File( tagletJar ) );
4915 }
4916 catch ( IOException e )
4917 {
4918 if ( getLog().isWarnEnabled() )
4919 {
4920 getLog().warn( "Unable to auto-detect Taglet class names from '" + tagletJar
4921 + "'. Try to specify them with <taglets/>." );
4922 }
4923 if ( getLog().isDebugEnabled() )
4924 {
4925 getLog().debug( "IOException: " + e.getMessage(), e );
4926 }
4927 continue;
4928 }
4929 catch ( ClassNotFoundException e )
4930 {
4931 if ( getLog().isWarnEnabled() )
4932 {
4933 getLog().warn( "Unable to auto-detect Taglet class names from '" + tagletJar
4934 + "'. Try to specify them with <taglets/>." );
4935 }
4936 if ( getLog().isDebugEnabled() )
4937 {
4938 getLog().debug( "ClassNotFoundException: " + e.getMessage(), e );
4939 }
4940 continue;
4941 }
4942 catch ( NoClassDefFoundError e )
4943 {
4944 if ( getLog().isWarnEnabled() )
4945 {
4946 getLog().warn( "Unable to auto-detect Taglet class names from '" + tagletJar
4947 + "'. Try to specify them with <taglets/>." );
4948 }
4949 if ( getLog().isDebugEnabled() )
4950 {
4951 getLog().debug( "NoClassDefFoundError: " + e.getMessage(), e );
4952 }
4953 continue;
4954 }
4955
4956 if ( tagletClasses != null && !tagletClasses.isEmpty() )
4957 {
4958 for ( String tagletClass : tagletClasses )
4959 {
4960 addArgIfNotEmpty( arguments, "-taglet", JavadocUtil.quotedArgument( tagletClass ),
4961 SINCE_JAVADOC_1_4 );
4962 }
4963 }
4964 }
4965 }
4966
4967
4968
4969
4970
4971
4972
4973
4974 private void executeJavadocCommandLine( Commandline cmd, File javadocOutputDirectory )
4975 throws MavenReportException
4976 {
4977 if ( getLog().isDebugEnabled() )
4978 {
4979
4980 getLog().debug( CommandLineUtils.toString( cmd.getCommandline() ).replaceAll( "'", "" ) );
4981 }
4982
4983 String cmdLine = null;
4984 if ( debug )
4985 {
4986 cmdLine = CommandLineUtils.toString( cmd.getCommandline() ).replaceAll( "'", "" );
4987 cmdLine = JavadocUtil.hideProxyPassword( cmdLine, settings );
4988
4989 writeDebugJavadocScript( cmdLine, javadocOutputDirectory );
4990 }
4991
4992 CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();
4993 CommandLineUtils.StringStreamConsumer out = new CommandLineUtils.StringStreamConsumer();
4994 try
4995 {
4996 int exitCode = CommandLineUtils.executeCommandLine( cmd, out, err );
4997
4998 String output = ( StringUtils.isEmpty( out.getOutput() ) ? null : '\n' + out.getOutput().trim() );
4999
5000 if ( exitCode != 0 )
5001 {
5002 if ( cmdLine == null )
5003 {
5004 cmdLine = CommandLineUtils.toString( cmd.getCommandline() ).replaceAll( "'", "" );
5005 cmdLine = JavadocUtil.hideProxyPassword( cmdLine, settings );
5006 }
5007 writeDebugJavadocScript( cmdLine, javadocOutputDirectory );
5008
5009 if ( StringUtils.isNotEmpty( output ) && StringUtils.isEmpty( err.getOutput() ) && isJavadocVMInitError(
5010 output ) )
5011 {
5012 StringBuilder msg = new StringBuilder();
5013 msg.append( output );
5014 msg.append( '\n' ).append( '\n' );
5015 msg.append( JavadocUtil.ERROR_INIT_VM ).append( '\n' );
5016 msg.append( "Or, try to reduce the Java heap size for the Javadoc goal using " );
5017 msg.append( "-Dminmemory=<size> and -Dmaxmemory=<size>." ).append( '\n' ).append( '\n' );
5018
5019 msg.append( "Command line was: " ).append( cmdLine ).append( '\n' ).append( '\n' );
5020 msg.append( "Refer to the generated Javadoc files in '" ).append( javadocOutputDirectory ).append(
5021 "' dir.\n" );
5022
5023 throw new MavenReportException( msg.toString() );
5024 }
5025
5026 if ( StringUtils.isNotEmpty( output ) )
5027 {
5028 getLog().info( output );
5029 }
5030
5031 StringBuilder msg = new StringBuilder( "\nExit code: " );
5032 msg.append( exitCode );
5033 if ( StringUtils.isNotEmpty( err.getOutput() ) )
5034 {
5035 msg.append( " - " ).append( err.getOutput() );
5036 }
5037 msg.append( '\n' );
5038 msg.append( "Command line was: " ).append( cmdLine ).append( '\n' ).append( '\n' );
5039
5040 msg.append( "Refer to the generated Javadoc files in '" ).append( javadocOutputDirectory ).append(
5041 "' dir.\n" );
5042
5043 throw new MavenReportException( msg.toString() );
5044 }
5045
5046 if ( StringUtils.isNotEmpty( output ) )
5047 {
5048 getLog().info( output );
5049 }
5050 }
5051 catch ( CommandLineException e )
5052 {
5053 throw new MavenReportException( "Unable to execute javadoc command: " + e.getMessage(), e );
5054 }
5055
5056
5057
5058
5059
5060 if ( StringUtils.isNotEmpty( err.getOutput() ) && getLog().isWarnEnabled() )
5061 {
5062 getLog().warn( "Javadoc Warnings" );
5063
5064 StringTokenizer token = new StringTokenizer( err.getOutput(), "\n" );
5065 while ( token.hasMoreTokens() )
5066 {
5067 String current = token.nextToken().trim();
5068
5069 getLog().warn( current );
5070 }
5071 }
5072 }
5073
5074
5075
5076
5077
5078
5079
5080
5081 private String getResource( File outputFile, String inputResourceName )
5082 {
5083 if ( inputResourceName.startsWith( "/" ) )
5084 {
5085 inputResourceName = inputResourceName.replaceFirst( "//*", "" );
5086 }
5087
5088 List<String> classPath = new ArrayList<String>();
5089 classPath.add( project.getBuild().getSourceDirectory() );
5090
5091 URL resourceURL = getResource( classPath, inputResourceName );
5092 if ( resourceURL != null )
5093 {
5094 getLog().debug( inputResourceName + " found in the main src directory of the project." );
5095 return FileUtils.toFile( resourceURL ).getAbsolutePath();
5096 }
5097
5098 classPath.clear();
5099 List<Resource> resources = project.getBuild().getResources();
5100 for ( Resource resource : resources )
5101 {
5102 classPath.add( resource.getDirectory() );
5103 }
5104 resourceURL = getResource( classPath, inputResourceName );
5105 if ( resourceURL != null )
5106 {
5107 getLog().debug( inputResourceName + " found in the main resources directories of the project." );
5108 return FileUtils.toFile( resourceURL ).getAbsolutePath();
5109 }
5110
5111 if ( javadocDirectory.exists() )
5112 {
5113 classPath.clear();
5114 classPath.add( javadocDirectory.getAbsolutePath() );
5115 resourceURL = getResource( classPath, inputResourceName );
5116 if ( resourceURL != null )
5117 {
5118 getLog().debug( inputResourceName + " found in the main javadoc directory of the project." );
5119 return FileUtils.toFile( resourceURL ).getAbsolutePath();
5120 }
5121 }
5122
5123 classPath.clear();
5124 final String pluginId = "org.apache.maven.plugins:maven-javadoc-plugin";
5125 Plugin javadocPlugin = getPlugin( project, pluginId );
5126 if ( javadocPlugin != null && javadocPlugin.getDependencies() != null )
5127 {
5128 List<Dependency> dependencies = javadocPlugin.getDependencies();
5129 for ( Dependency dependency : dependencies )
5130 {
5131 JavadocPathArtifact javadocPathArtifact = new JavadocPathArtifact();
5132 javadocPathArtifact.setGroupId( dependency.getGroupId() );
5133 javadocPathArtifact.setArtifactId( dependency.getArtifactId() );
5134 javadocPathArtifact.setVersion( dependency.getVersion() );
5135 Artifact artifact = null;
5136 try
5137 {
5138 artifact = createAndResolveArtifact( javadocPathArtifact );
5139 }
5140 catch ( Exception e )
5141 {
5142 logError( "Unable to retrieve the dependency: " + dependency + ". Ignored.", e );
5143 }
5144
5145 if ( artifact != null && artifact.getFile().exists() )
5146 {
5147 classPath.add( artifact.getFile().getAbsolutePath() );
5148 }
5149 }
5150 resourceURL = getResource( classPath, inputResourceName );
5151 if ( resourceURL != null )
5152 {
5153 getLog().debug( inputResourceName + " found in javadoc plugin dependencies." );
5154 try
5155 {
5156 JavadocUtil.copyResource( resourceURL, outputFile );
5157
5158 return outputFile.getAbsolutePath();
5159 }
5160 catch ( IOException e )
5161 {
5162 logError( "IOException: " + e.getMessage(), e );
5163 }
5164 }
5165 }
5166
5167 getLog().warn( "Unable to find the resource '" + inputResourceName + "'. Using default Javadoc resources." );
5168
5169 return null;
5170 }
5171
5172
5173
5174
5175
5176
5177
5178
5179 private URL getResource( final List<String> classPath, final String resource )
5180 {
5181 List<URL> urls = new ArrayList<URL>( classPath.size() );
5182 for ( String filename : classPath )
5183 {
5184 try
5185 {
5186 urls.add( new File( filename ).toURL() );
5187 }
5188 catch ( MalformedURLException e )
5189 {
5190 getLog().error( "MalformedURLException: " + e.getMessage() );
5191 }
5192 }
5193
5194 ClassLoader javadocClassLoader = new URLClassLoader( (URL[]) urls.toArray( new URL[urls.size()] ), null );
5195
5196 return javadocClassLoader.getResource( resource );
5197 }
5198
5199
5200
5201
5202
5203
5204 private String getFullJavadocGoal()
5205 {
5206 String javadocPluginVersion = null;
5207 InputStream resourceAsStream = null;
5208 try
5209 {
5210 String resource = "META-INF/maven/org.apache.maven.plugins/maven-javadoc-plugin/pom.properties";
5211 resourceAsStream = AbstractJavadocMojo.class.getClassLoader().getResourceAsStream( resource );
5212
5213 if ( resourceAsStream != null )
5214 {
5215 Properties properties = new Properties();
5216 properties.load( resourceAsStream );
5217
5218 if ( StringUtils.isNotEmpty( properties.getProperty( "version" ) ) )
5219 {
5220 javadocPluginVersion = properties.getProperty( "version" );
5221 }
5222 }
5223 }
5224 catch ( IOException e )
5225 {
5226
5227 }
5228 finally
5229 {
5230 IOUtil.close( resourceAsStream );
5231 }
5232
5233 StringBuilder sb = new StringBuilder();
5234
5235 sb.append( "org.apache.maven.plugins:maven-javadoc-plugin:" );
5236 if ( StringUtils.isNotEmpty( javadocPluginVersion ) )
5237 {
5238 sb.append( javadocPluginVersion ).append( ":" );
5239 }
5240
5241 if ( this instanceof TestJavadocReport )
5242 {
5243 sb.append( "test-javadoc" );
5244 }
5245 else
5246 {
5247 sb.append( "javadoc" );
5248 }
5249
5250 return sb.toString();
5251 }
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263 private List<OfflineLink> getModulesLinks()
5264 throws MavenReportException
5265 {
5266 if ( !detectOfflineLinks || isAggregator() || reactorProjects == null )
5267 {
5268 return Collections.emptyList();
5269 }
5270
5271 getLog().debug( "Trying to add links for modules..." );
5272
5273 Set<String> dependencyArtifactIds = new HashSet<String>();
5274 final Set<Artifact> dependencyArtifacts = project.getDependencyArtifacts();
5275 for ( Artifact artifact : dependencyArtifacts )
5276 {
5277 dependencyArtifactIds.add( artifact.getId() );
5278 }
5279
5280 List<OfflineLink> modulesLinks = new ArrayList<OfflineLink>();
5281 String javadocDirRelative = PathUtils.toRelative( project.getBasedir(), getOutputDirectory() );
5282 for ( MavenProject p : reactorProjects )
5283 {
5284 if ( !dependencyArtifactIds.contains( p.getArtifact().getId() ) || ( p.getUrl() == null ) )
5285 {
5286 continue;
5287 }
5288
5289 File location = new File( p.getBasedir(), javadocDirRelative );
5290
5291 if ( !location.exists() )
5292 {
5293 if ( getLog().isDebugEnabled() )
5294 {
5295 getLog().debug( "Javadoc directory not found: " + location );
5296 }
5297
5298 String javadocGoal = getFullJavadocGoal();
5299 getLog().info(
5300 "The goal '" + javadocGoal + "' has not been previously called for the module: '" + p.getId()
5301 + "'. Trying to invoke it..." );
5302
5303 File invokerDir = new File( project.getBuild().getDirectory(), "invoker" );
5304 invokerDir.mkdirs();
5305 File invokerLogFile = FileUtils.createTempFile( "maven-javadoc-plugin", ".txt", invokerDir );
5306 try
5307 {
5308 JavadocUtil.invokeMaven( getLog(), new File( localRepository.getBasedir() ), p.getFile(),
5309 Collections.singletonList( javadocGoal ), null, invokerLogFile );
5310 }
5311 catch ( MavenInvocationException e )
5312 {
5313 logError( "MavenInvocationException: " + e.getMessage(), e );
5314
5315 String invokerLogContent = JavadocUtil.readFile( invokerLogFile, null
5316
5317
5318
5319
5320 if ( invokerLogContent != null && invokerLogContent.contains( JavadocUtil.ERROR_INIT_VM ) )
5321 {
5322 throw new MavenReportException( e.getMessage(), e );
5323 }
5324 }
5325 finally
5326 {
5327
5328 if ( !location.exists() )
5329 {
5330 getLog().warn( "Creating fake javadoc directory to prevent repeated invocations: " + location );
5331 location.mkdirs();
5332 }
5333 }
5334 }
5335
5336 if ( location.exists() )
5337 {
5338 String url = getJavadocLink( p );
5339
5340 OfflineLink ol = new OfflineLink();
5341 ol.setUrl( url );
5342 ol.setLocation( location.getAbsolutePath() );
5343
5344 if ( getLog().isDebugEnabled() )
5345 {
5346 getLog().debug( "Added Javadoc offline link: " + url + " for the module: " + p.getId() );
5347 }
5348
5349 modulesLinks.add( ol );
5350 }
5351 }
5352
5353 return modulesLinks;
5354 }
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365 private List<String> getDependenciesLinks()
5366 {
5367 if ( !detectLinks )
5368 {
5369 return Collections.emptyList();
5370 }
5371
5372 getLog().debug( "Trying to add links for dependencies..." );
5373
5374 List<String> dependenciesLinks = new ArrayList<String>();
5375
5376 final Set<Artifact> dependencies = project.getDependencyArtifacts();
5377 for ( Artifact artifact : dependencies )
5378 {
5379 if ( artifact.getFile() == null || !artifact.getFile().exists() )
5380 {
5381 continue;
5382 }
5383
5384 try
5385 {
5386 MavenProject artifactProject =
5387 mavenProjectBuilder.buildFromRepository( artifact, remoteRepositories, localRepository );
5388
5389 if ( StringUtils.isNotEmpty( artifactProject.getUrl() ) )
5390 {
5391 String url = getJavadocLink( artifactProject );
5392
5393 if ( isValidJavadocLink( url ) )
5394 {
5395 getLog().debug( "Added Javadoc link: " + url + " for " + artifactProject.getId() );
5396
5397 dependenciesLinks.add( url );
5398 }
5399 }
5400 }
5401 catch ( ProjectBuildingException e )
5402 {
5403 logError( "ProjectBuildingException for " + artifact.toString() + ": " + e.getMessage(), e );
5404 }
5405 }
5406
5407 return dependenciesLinks;
5408 }
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421 private OfflineLink getDefaultJavadocApiLink()
5422 {
5423 if ( !detectJavaApiLink )
5424 {
5425 return null;
5426 }
5427
5428 final String pluginId = "org.apache.maven.plugins:maven-compiler-plugin";
5429 float sourceVersion = fJavadocVersion;
5430 String sourceConfigured = getPluginParameter( project, pluginId, "source" );
5431 if ( sourceConfigured != null )
5432 {
5433 try
5434 {
5435 sourceVersion = Float.parseFloat( sourceConfigured );
5436 }
5437 catch ( NumberFormatException e )
5438 {
5439 getLog().debug(
5440 "NumberFormatException for the source parameter in the maven-compiler-plugin. " + "Ignored it", e );
5441 }
5442 }
5443 else
5444 {
5445 getLog().debug( "No maven-compiler-plugin defined in ${build.plugins} or in "
5446 + "${project.build.pluginManagement} for the " + project.getId()
5447 + ". Added Javadoc API link according the javadoc executable version i.e.: "
5448 + fJavadocVersion );
5449 }
5450
5451 String apiVersion = null;
5452 if ( sourceVersion >= 1.3f && sourceVersion < 1.4f )
5453 {
5454 apiVersion = "1.3";
5455 }
5456 else if ( sourceVersion >= 1.4f && sourceVersion < 1.5f )
5457 {
5458 apiVersion = "1.4";
5459 }
5460 else if ( sourceVersion >= 1.5f && sourceVersion < 1.6f )
5461 {
5462 apiVersion = "1.5";
5463 }
5464 else if ( sourceVersion >= 1.6f && sourceVersion < 1.7f )
5465 {
5466 apiVersion = "1.6";
5467 }
5468 else if ( sourceVersion >= 1.7f )
5469 {
5470 apiVersion = "1.7";
5471 }
5472 String javaApiLink = javaApiLinks.getProperty( "api_" + apiVersion, null );
5473
5474 if ( getLog().isDebugEnabled() )
5475 {
5476 if ( StringUtils.isNotEmpty( javaApiLink ) )
5477 {
5478 getLog().debug( "Found Java API link: " + javaApiLink );
5479 }
5480 else
5481 {
5482 getLog().debug( "No Java API link found." );
5483 }
5484 }
5485
5486 if ( javaApiLink == null )
5487 {
5488 return null;
5489 }
5490
5491 File javaApiPackageListFile = new File( getJavadocOptionsFile().getParentFile(), "package-list" );
5492
5493 OfflineLink link = new OfflineLink();
5494 link.setLocation( javaApiPackageListFile.getParentFile().getAbsolutePath() );
5495 link.setUrl( javaApiLink );
5496
5497 InputStream in = this.getClass().getResourceAsStream( "java-api-package-list-" + apiVersion );
5498 OutputStream out = null;
5499 try
5500 {
5501 out = new FileOutputStream( javaApiPackageListFile );
5502 IOUtil.copy( in, out );
5503 }
5504 catch ( IOException ioe )
5505 {
5506 logError( "Can't get java-api-package-list-" + apiVersion + ": " + ioe.getMessage(), ioe );
5507 return null;
5508 }
5509 finally
5510 {
5511 IOUtil.close( in );
5512 IOUtil.close( out );
5513 }
5514
5515 return link;
5516 }
5517
5518
5519
5520
5521
5522
5523
5524
5525 private boolean isValidJavadocLink( String link )
5526 {
5527 try
5528 {
5529 URI linkUri;
5530 if ( link.trim().toLowerCase( Locale.ENGLISH ).startsWith( "http:" ) || link.trim().toLowerCase(
5531 Locale.ENGLISH ).startsWith( "https:" ) || link.trim().toLowerCase( Locale.ENGLISH ).startsWith(
5532 "ftp:" ) || link.trim().toLowerCase( Locale.ENGLISH ).startsWith( "file:" ) )
5533 {
5534 linkUri = new URI( link + "/package-list" );
5535 }
5536 else
5537 {
5538
5539 File dir = new File( link );
5540 if ( !dir.isAbsolute() )
5541 {
5542 dir = new File( getOutputDirectory(), link );
5543 }
5544 if ( !dir.isDirectory() )
5545 {
5546 getLog().error( "The given File link: " + dir + " is not a dir." );
5547 }
5548 linkUri = new File( dir, "package-list" ).toURI();
5549 }
5550
5551 if ( !JavadocUtil.isValidPackageList( linkUri.toURL(), settings, validateLinks ) )
5552 {
5553 if ( getLog().isErrorEnabled() )
5554 {
5555 getLog().error( "Invalid link: " + link + "/package-list. Ignored it." );
5556 }
5557
5558 return false;
5559 }
5560
5561 return true;
5562 }
5563 catch ( URISyntaxException e )
5564 {
5565 if ( getLog().isErrorEnabled() )
5566 {
5567 getLog().error( "Malformed link: " + link + "/package-list. Ignored it." );
5568 }
5569 return false;
5570 }
5571 catch ( IOException e )
5572 {
5573 if ( getLog().isErrorEnabled() )
5574 {
5575 getLog().error( "Error fetching link: " + link + "/package-list. Ignored it." );
5576 }
5577 return false;
5578 }
5579 }
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589 private void writeDebugJavadocScript( String cmdLine, File javadocOutputDirectory )
5590 {
5591 File commandLineFile = new File( javadocOutputDirectory, DEBUG_JAVADOC_SCRIPT_NAME );
5592 commandLineFile.getParentFile().mkdirs();
5593
5594 try
5595 {
5596 FileUtils.fileWrite( commandLineFile.getAbsolutePath(), null
5597
5598 if ( !SystemUtils.IS_OS_WINDOWS )
5599 {
5600 Runtime.getRuntime().exec( new String[]{ "chmod", "a+x", commandLineFile.getAbsolutePath() } );
5601 }
5602 }
5603 catch ( IOException e )
5604 {
5605 logError( "Unable to write '" + commandLineFile.getName() + "' debug script file", e );
5606 }
5607 }
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617 private boolean isJavadocVMInitError( String output )
5618 {
5619
5620
5621
5622
5623 return !( output.contains( "Javadoc" ) || output.contains( "javadoc" ) );
5624 }
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636 private static String getJavadocLink( MavenProject p )
5637 {
5638 if ( p.getUrl() == null )
5639 {
5640 return null;
5641 }
5642
5643 String url = cleanUrl( p.getUrl() );
5644 String destDir = "apidocs";
5645
5646 final String pluginId = "org.apache.maven.plugins:maven-javadoc-plugin";
5647 String destDirConfigured = getPluginParameter( p, pluginId, "destDir" );
5648 if ( destDirConfigured != null )
5649 {
5650 destDir = destDirConfigured;
5651 }
5652
5653 return url + "/" + destDir;
5654 }
5655
5656
5657
5658
5659
5660
5661 private static String cleanUrl( String url )
5662 {
5663 if ( url == null )
5664 {
5665 return "";
5666 }
5667
5668 url = url.trim();
5669 while ( url.endsWith( "/" ) )
5670 {
5671 url = url.substring( 0, url.lastIndexOf( "/" ) );
5672 }
5673
5674 return url;
5675 }
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685 private static Plugin getPlugin( MavenProject p, String pluginId )
5686 {
5687 if ( ( p.getBuild() == null ) || ( p.getBuild().getPluginsAsMap() == null ) )
5688 {
5689 return null;
5690 }
5691
5692 Plugin plugin = (Plugin) p.getBuild().getPluginsAsMap().get( pluginId );
5693
5694 if ( ( plugin == null ) && ( p.getBuild().getPluginManagement() != null ) && (
5695 p.getBuild().getPluginManagement().getPluginsAsMap() != null ) )
5696 {
5697 plugin = (Plugin) p.getBuild().getPluginManagement().getPluginsAsMap().get( pluginId );
5698 }
5699
5700 return plugin;
5701 }
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711 private static String getPluginParameter( MavenProject p, String pluginId, String param )
5712 {
5713
5714 Plugin plugin = getPlugin( p, pluginId );
5715 if ( plugin != null )
5716 {
5717 Xpp3Dom xpp3Dom = (Xpp3Dom) plugin.getConfiguration();
5718 if ( xpp3Dom != null && xpp3Dom.getChild( param ) != null
5719 && StringUtils.isNotEmpty( xpp3Dom.getChild( param ).getValue() ) )
5720 {
5721 return xpp3Dom.getChild( param ).getValue();
5722 }
5723 }
5724
5725 return null;
5726 }
5727
5728
5729
5730
5731
5732
5733
5734 protected final File getJavadocOptionsFile()
5735 {
5736 if ( javadocOptionsDir != null && !javadocOptionsDir.exists() )
5737 {
5738 javadocOptionsDir.mkdirs();
5739 }
5740
5741 return new File( javadocOptionsDir, "javadoc-options-" + getAttachmentClassifier() + ".xml" );
5742 }
5743
5744
5745
5746
5747
5748
5749
5750
5751 protected final JavadocOptions buildJavadocOptions()
5752 throws IOException
5753 {
5754 JavadocOptions options = new JavadocOptions();
5755
5756 options.setBootclasspathArtifacts( toList( bootclasspathArtifacts ) );
5757 options.setDocfilesSubdirsUsed( docfilessubdirs );
5758 options.setDocletArtifacts( toList( docletArtifact, docletArtifacts ) );
5759 options.setExcludedDocfilesSubdirs( excludedocfilessubdir );
5760 options.setExcludePackageNames( toList( excludePackageNames ) );
5761 options.setGroups( toList( groups ) );
5762 options.setLinks( links );
5763 options.setOfflineLinks( toList( offlineLinks ) );
5764 options.setResourcesArtifacts( toList( resourcesArtifacts ) );
5765 options.setTagletArtifacts( toList( tagletArtifact, tagletArtifacts ) );
5766 options.setTaglets( toList( taglets ) );
5767 options.setTags( toList( tags ) );
5768
5769 if ( getProject() != null && getJavadocDirectory() != null )
5770 {
5771 options.setJavadocResourcesDirectory(
5772 toRelative( getProject().getBasedir(), getJavadocDirectory().getAbsolutePath() ) );
5773 }
5774
5775 File optionsFile = getJavadocOptionsFile();
5776 Writer writer = null;
5777 try
5778 {
5779 writer = WriterFactory.newXmlWriter( optionsFile );
5780 new JavadocOptionsXpp3Writer().write( writer, options );
5781 }
5782 finally
5783 {
5784 close( writer );
5785 }
5786
5787 return options;
5788 }
5789
5790
5791
5792
5793
5794 protected String getAttachmentClassifier()
5795 {
5796 return JAVADOC_RESOURCES_ATTACHMENT_CLASSIFIER;
5797 }
5798
5799
5800
5801
5802
5803
5804
5805 protected void logError( String message, Throwable t )
5806 {
5807 if ( getLog().isDebugEnabled() )
5808 {
5809 getLog().error( message, t );
5810 }
5811 else
5812 {
5813 getLog().error( message );
5814 }
5815 }
5816
5817 protected void failOnError( String prefix, Exception e )
5818 throws MojoExecutionException
5819 {
5820 if ( failOnError )
5821 {
5822 if ( e instanceof RuntimeException )
5823 {
5824 throw (RuntimeException) e;
5825 }
5826 throw new MojoExecutionException( prefix + ": " + e.getMessage(), e );
5827 }
5828
5829 getLog().error( prefix + ": " + e.getMessage(), e );
5830 }
5831 }