1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package net.sf.jfxdplugin;
19
20 import java.io.File;
21 import java.io.FileNotFoundException;
22 import java.io.IOException;
23 import java.text.MessageFormat;
24 import java.util.ArrayList;
25 import java.util.Arrays;
26 import java.util.Collection;
27 import java.util.Collections;
28 import java.util.HashMap;
29 import java.util.List;
30 import java.util.Locale;
31 import java.util.Map;
32 import java.util.Properties;
33 import java.util.ResourceBundle;
34 import java.util.regex.PatternSyntaxException;
35 import org.apache.commons.lang.SystemUtils;
36 import org.apache.maven.artifact.Artifact;
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.plugin.AbstractMojo;
41 import org.apache.maven.project.MavenProject;
42 import org.apache.maven.reporting.MavenReportException;
43 import org.apache.maven.toolchain.Toolchain;
44 import org.apache.maven.toolchain.ToolchainManager;
45 import org.codehaus.plexus.util.FileUtils;
46 import org.codehaus.plexus.util.ReaderFactory;
47 import org.codehaus.plexus.util.StringUtils;
48 import org.codehaus.plexus.util.cli.CommandLineException;
49 import org.codehaus.plexus.util.cli.CommandLineUtils;
50 import org.codehaus.plexus.util.cli.Commandline;
51 import org.codehaus.plexus.util.cli.DefaultConsumer;
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68 public abstract class AbstractJavafxdocMojo extends AbstractMojo {
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94 public static final Properties DEFAULT_JAVA_API_LINKS = new Properties();
95
96
97
98
99 protected static final String DEBUG_JAVAFXDOC_SCRIPT_NAME;
100
101 static {
102 String name = "javafxdoc.sh";
103
104 if (SystemUtils.IS_OS_WINDOWS) {
105 name = "javafxdoc.bat";
106 }
107
108 DEBUG_JAVAFXDOC_SCRIPT_NAME = name;
109 }
110
111
112
113
114
115 protected static final String FILES_FILE_NAME = "files";
116
117
118
119
120
121 protected static final String OPTIONS_FILE_NAME = "options";
122
123
124
125
126 protected static final float DEFAULT_JAVAFX_VERSION = 1.0f;
127
128
129
130 protected static final float SINCE_JAVAFXDOC_1_3 = 1.3f;
131
132 private ToolchainManager toolchainManager;
133
134
135
136
137
138
139
140
141 private boolean debug = false;
142
143
144
145
146
147 private boolean failOnError = false;
148
149
150
151
152
153
154
155 private String javafxdocExecutable;
156
157
158
159
160
161
162
163 private MavenProject project;
164
165
166
167
168
169
170
171
172 private MavenSession session;
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187 private String[] additionalJOptions;
188
189
190
191
192
193
194
195 private String bootclasspath;
196
197
198
199
200
201
202 private boolean breakiterator = false;
203
204
205
206
207
208
209 private String doclet;
210
211
212
213
214
215
216 private String docletPath;
217
218
219
220
221
222
223
224 private String encoding;
225
226
227
228
229
230
231 private String excludePackageNames;
232
233
234
235
236
237
238
239 private String extdirs;
240
241
242
243
244
245 private String locale;
246
247
248
249
250
251
252 private String profile = "desktop";
253
254
255
256
257
258 private boolean quiet = false;
259
260
261
262
263
264
265
266
267
268
269
270
271
272 private String show = "protected";
273
274
275
276
277
278 private String source;
279
280
281
282
283
284
285
286 private String sourcePath;
287
288
289
290
291
292
293 private String subpackages;
294
295
296
297
298
299 private boolean verbose = false;
300
301
302
303
304
305
306
307
308 private boolean nohtml = false;
309
310
311
312
313
314
315 private File outputDirectory;
316
317
318
319
320
321 private File outputFile;
322
323
324
325
326
327 private File xsltfile;
328
329
330
331
332
333 private String mastercss;
334
335
336
337
338
339 private String extracss;
340
341
342
343
344
345 private String extrajs;
346
347
348
349
350
351
352
353
354
355
356
357 private String[] additionalXslOptions;
358
359
360
361
362
363
364 private File[] inputFiles;
365 private Locale cachedLocale;
366 private float javafxdocVersion = DEFAULT_JAVAFX_VERSION;
367
368
369
370
371
372
373 public String[] getAdditionalJOptions() {
374 return additionalJOptions;
375 }
376
377
378
379
380
381
382 public void setAdditionalJOptions(final String[] additionalJOptions) {
383 this.additionalJOptions = additionalJOptions;
384 }
385
386
387
388
389
390
391 public String[] getAdditionalXslOptions() {
392 return additionalXslOptions;
393 }
394
395
396
397
398
399
400 public void setAdditionalXslOptions(final String[] additionalXslOptions) {
401 this.additionalXslOptions = additionalXslOptions;
402 }
403
404
405
406
407
408
409 public String getBootclasspath() {
410 return bootclasspath;
411 }
412
413
414
415
416
417
418 public void setBootclasspath(final String bootclasspath) {
419 this.bootclasspath = bootclasspath;
420 }
421
422
423
424
425
426
427 public boolean isBreakiterator() {
428 return breakiterator;
429 }
430
431
432
433
434
435
436 public void setBreakiterator(final boolean breakiterator) {
437 this.breakiterator = breakiterator;
438 }
439
440
441
442
443
444
445 public boolean isDebug() {
446 return debug;
447 }
448
449
450
451
452
453
454 public void setDebug(final boolean debug) {
455 this.debug = debug;
456 }
457
458
459
460
461
462
463 public String getDoclet() {
464 return doclet;
465 }
466
467
468
469
470
471
472 public void setDoclet(final String doclet) {
473 this.doclet = doclet;
474 }
475
476
477
478
479
480
481 public String getDocletPath() {
482 return docletPath;
483 }
484
485
486
487
488
489
490 public void setDocletPath(final String docletPath) {
491 this.docletPath = docletPath;
492 }
493
494
495
496
497
498
499 public String getEncoding() {
500 return encoding;
501 }
502
503
504
505
506
507
508 public void setEncoding(final String encoding) {
509 this.encoding = encoding;
510 }
511
512
513
514
515
516
517 public String getExcludePackageNames() {
518 return excludePackageNames;
519 }
520
521
522
523
524
525
526 public void setExcludePackageNames(final String excludePackageNames) {
527 this.excludePackageNames = excludePackageNames;
528 }
529
530
531
532
533
534
535 public String getExtdirs() {
536 return extdirs;
537 }
538
539
540
541
542
543
544 public void setExtdirs(final String extdirs) {
545 this.extdirs = extdirs;
546 }
547
548
549
550
551
552
553 public String getExtracss() {
554 return extracss;
555 }
556
557
558
559
560
561
562 public void setExtracss(final String extracss) {
563 this.extracss = extracss;
564 }
565
566
567
568
569
570
571 public String getExtrajs() {
572 return extrajs;
573 }
574
575
576
577
578
579
580 public void setExtrajs(final String extrajs) {
581 this.extrajs = extrajs;
582 }
583
584
585
586
587
588
589 public boolean isFailOnError() {
590 return failOnError;
591 }
592
593
594
595
596
597
598 public void setFailOnError(final boolean failOnError) {
599 this.failOnError = failOnError;
600 }
601
602
603
604
605
606
607 public File[] getInputFiles() {
608 return inputFiles;
609 }
610
611
612
613
614
615
616 public void setInputFiles(final File[] inputFiles) {
617 this.inputFiles = inputFiles;
618 }
619
620
621
622
623
624
625 public String getJavafxdocExecutable() {
626 return javafxdocExecutable;
627 }
628
629
630
631
632
633
634 public void setJavafxdocExecutable(final String javafxdocExecutable) {
635 this.javafxdocExecutable = javafxdocExecutable;
636 }
637
638
639
640
641
642
643 public String getLocale() {
644 if (null == locale) {
645 locale = Locale.getDefault().toString();
646 }
647 return locale;
648 }
649
650
651
652
653
654
655 public void setLocale(final String locale) {
656 this.locale = locale;
657 this.cachedLocale = null;
658 }
659
660
661
662
663
664
665 public String getMastercss() {
666 return mastercss;
667 }
668
669
670
671
672
673
674 public void setMastercss(final String mastercss) {
675 this.mastercss = mastercss;
676 }
677
678
679
680
681
682
683 public boolean isNohtml() {
684 return nohtml;
685 }
686
687
688
689
690
691
692 public void setNohtml(final boolean nohtml) {
693 this.nohtml = nohtml;
694 }
695
696
697
698
699
700
701 public File getOutputDirectory() {
702 return outputDirectory;
703 }
704
705
706
707
708
709
710 public void setOutputDirectory(final File outputDirectory) {
711 this.outputDirectory = outputDirectory;
712 }
713
714
715
716
717
718
719 public File getOutputFile() {
720 return outputFile;
721 }
722
723
724
725
726
727
728 public void setOutputFile(final File outputFile) {
729 this.outputFile = outputFile;
730 }
731
732
733
734
735
736
737 public MavenProject getProject() {
738 return project;
739 }
740
741
742
743
744
745
746 public void setProject(final MavenProject project) {
747 this.project = project;
748 }
749
750
751
752
753
754
755 public String getProfile() {
756 return profile;
757 }
758
759
760
761
762
763
764 public void setProfile(String profile) {
765 if ("desktop".equals(profile)) {
766 this.profile = profile;
767 } else if ("mobile".equals(profile)) {
768 this.profile = profile;
769 } else if ("tv".equals(profile)) {
770 this.profile = profile;
771 }
772 }
773
774
775
776
777
778
779 public boolean isQuiet() {
780 return quiet;
781 }
782
783
784
785
786
787
788 public void setQuiet(final boolean quiet) {
789 this.quiet = quiet;
790 }
791
792
793
794
795
796
797 public MavenSession getSession() {
798 return session;
799 }
800
801
802
803
804
805
806 public String getShow() {
807 return show;
808 }
809
810
811
812
813
814
815 public void setShow(final String show) {
816 this.show = show;
817 }
818
819
820
821
822
823
824
825 public String getSource() {
826 return source;
827 }
828
829
830
831
832
833
834 public void setSource(final String source) {
835 this.source = source;
836 }
837
838
839
840
841
842
843 public String getSourcePath() {
844 return sourcePath;
845 }
846
847
848
849
850
851
852 public void setSourcePath(final String sourcePath) {
853 this.sourcePath = sourcePath;
854 }
855
856
857
858
859
860
861 public String getSubpackages() {
862 return subpackages;
863 }
864
865
866
867
868
869
870 public void setSubpackages(final String subpackages) {
871 this.subpackages = subpackages;
872 }
873
874
875
876
877
878
879 protected ToolchainManager getToolchainManager() {
880 return toolchainManager;
881 }
882
883
884
885
886
887
888 protected void setToolchainManager(
889 final ToolchainManager toolchainManager) {
890 this.toolchainManager = toolchainManager;
891 }
892
893
894
895
896
897
898 public boolean isVerbose() {
899 return verbose;
900 }
901
902
903
904
905
906
907 public void setVerbose(final boolean verbose) {
908 this.verbose = verbose;
909 }
910
911
912
913
914
915
916 public File getXsltfile() {
917 return xsltfile;
918 }
919
920
921
922
923
924
925 public void setXsltfile(final File xsltfile) {
926 this.xsltfile = xsltfile;
927 }
928
929
930
931
932
933
934
935
936
937
938 protected boolean canGenerateReport(final List<String> files) {
939 boolean canGenerate = true;
940
941 if ((files.isEmpty()) && (StringUtils.isEmpty(getSubpackages()))) {
942 canGenerate = false;
943 }
944
945 return canGenerate;
946 }
947
948
949
950
951
952
953 protected void executeReport() throws MavenReportException {
954 List<String> sourcePaths = getSourcePaths();
955 List<String> files = getFiles(sourcePaths);
956 if (!canGenerateReport(files)) {
957 return;
958 }
959
960 List<String> packageNames = getPackageNames(sourcePaths, files);
961 List<String> filesWithUnnamedPackages =
962 getFilesWithUnnamedPackages(sourcePaths, files);
963
964
965 String jExecutable;
966 try {
967 jExecutable = findJavafxdocExecutable();
968 } catch (IOException ex) {
969 throw new MavenReportException(ex.getMessage(), ex);
970 }
971
972
973 setJavafxdocVersion(new File(jExecutable));
974
975
976 if (getOutputDirectory().exists()) {
977 if (!getOutputDirectory().isDirectory()) {
978 throw new MavenReportException(formatMessage(
979 "report.javafxdoc.not.directory",
980 getOutputDirectory()));
981 }
982 if (!getOutputDirectory().canWrite()) {
983 throw new MavenReportException(formatMessage(
984 "report.javafxdoc.not.writable", getOutputDirectory()));
985 }
986 }
987 getOutputDirectory().mkdirs();
988
989
990 Commandline cmd = new Commandline();
991 cmd.getShell().setQuotedArgumentsEnabled(false);
992 cmd.setWorkingDirectory(getOutputDirectory().getAbsolutePath());
993 cmd.setExecutable(jExecutable);
994
995
996 if (null != getAdditionalJOptions()) {
997 for (String opt : getAdditionalJOptions()) {
998 cmd.createArg().setValue("-J" + opt);
999 }
1000 }
1001
1002
1003 cmd.createArg().setValue("-profile");
1004 if ((getJavafxdocVersion() < SINCE_JAVAFXDOC_1_3) && "tv".equals(
1005 getProfile())) {
1006 cmd.createArg().setValue("desktop");
1007 } else {
1008 cmd.createArg().setValue(getProfile());
1009 }
1010
1011 List<String> arguments = new ArrayList<String>();
1012
1013
1014 addJavafxdocOptions(arguments, sourcePaths);
1015
1016
1017 if (StringUtils.isEmpty(doclet)) {
1018 addStandardDocletOptions(arguments, getOutputDirectory());
1019 }
1020
1021 addCommandLineOptions(cmd, arguments, getOutputDirectory());
1022
1023
1024 if (!packageNames.isEmpty()) {
1025
1026 addCommandLineArgFile(cmd, getOutputDirectory(),
1027 filesWithUnnamedPackages);
1028 } else {
1029
1030 addCommandLineArgFile(cmd, getOutputDirectory(), files);
1031 }
1032
1033
1034 executeJavafxdocCommandLine(cmd, getOutputDirectory());
1035 }
1036
1037
1038
1039
1040
1041
1042
1043
1044 protected String formatMessage(final String message, final Object... args) {
1045 String msg = getBundle(getLocaleObject()).getString(message);
1046 MessageFormat formatter = new MessageFormat("", getLocaleObject());
1047 formatter.applyPattern(msg);
1048 return formatter.format(args);
1049 }
1050
1051
1052
1053
1054
1055
1056
1057 protected ResourceBundle getBundle(final Locale specificLocale) {
1058 Locale localeToUse = specificLocale;
1059
1060 if (null == specificLocale) {
1061 localeToUse = Locale.getDefault();
1062 }
1063
1064 return ResourceBundle.getBundle("javafxdoc-report", localeToUse,
1065 getClass().getClassLoader());
1066 }
1067
1068
1069
1070
1071
1072
1073
1074 protected List<String> getFiles(final List<String> sourcePaths) {
1075 List<String> files = new ArrayList<String>();
1076
1077 if (StringUtils.isEmpty(getSubpackages())) {
1078 String[] excludedPackages = getExcludedPackages();
1079
1080 for (String path : sourcePaths) {
1081 File sourceDirectory = new File(path);
1082 JavafxdocUtil.addFilesFromSource(files, sourceDirectory,
1083 excludedPackages);
1084 }
1085 }
1086
1087 return files;
1088 }
1089
1090
1091
1092
1093
1094
1095 protected float getJavafxdocVersion() {
1096 return javafxdocVersion;
1097 }
1098
1099
1100
1101
1102
1103
1104
1105 protected Locale getLocaleObject() {
1106 if (null == cachedLocale) {
1107 String result[] = getLocale().split("_");
1108
1109 String language = result[0];
1110
1111 String country = "";
1112 if (result.length > 1) {
1113 country = result[1];
1114 }
1115
1116 String variant = "";
1117 if (result.length > 2) {
1118 variant = result[2];
1119 }
1120
1121 cachedLocale = new Locale(language, country, variant);
1122 }
1123
1124 return cachedLocale;
1125 }
1126
1127
1128
1129
1130
1131
1132
1133 @SuppressWarnings("unchecked")
1134 protected List<Artifact> getProjectArtifacts(final MavenProject p) {
1135 return p.getCompileArtifacts();
1136 }
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146 protected List<String> getSourcePaths() {
1147 List<String> sourcePaths;
1148
1149 if (StringUtils.isEmpty(getSourcePath())) {
1150 sourcePaths = new ArrayList<String>(JavafxdocUtil.pruneDirs(
1151 getProject(),
1152 getProjectSourceRoots(getProject())));
1153
1154 if (null != getProject().getExecutionProject()) {
1155 sourcePaths.addAll(JavafxdocUtil.pruneDirs(getProject(),
1156 getExecutionProjectSourceRoots(getProject())));
1157 }
1158 } else {
1159 String separator = "[:]";
1160 if (SystemUtils.IS_OS_WINDOWS) {
1161 separator = "[;]";
1162 }
1163 sourcePaths = new ArrayList<String>(Arrays.asList(getSourcePath().
1164 split(separator)));
1165 }
1166
1167 sourcePaths = JavafxdocUtil.pruneDirs(getProject(), sourcePaths);
1168
1169 return sourcePaths;
1170 }
1171
1172 private void addArgIf(final List<String> arguments, final boolean b,
1173 final String value) {
1174 if (b) {
1175 arguments.add(value);
1176 }
1177 }
1178
1179 private void addArgIfNotEmpty(final List<String> arguments,
1180 final String key, final String value) {
1181 if (StringUtils.isNotEmpty(value)) {
1182 if (StringUtils.isNotEmpty(key)) {
1183 arguments.add(key);
1184 }
1185
1186 String[] result = value.split(",");
1187 for (String token : result) {
1188 token = token.trim();
1189
1190 if (StringUtils.isNotEmpty(token)) {
1191 arguments.add(token);
1192 }
1193 }
1194 }
1195 }
1196
1197 private void addCommandLineArgFile(final Commandline cmd,
1198 final File outputDir, final List<String> files) throws
1199 MavenReportException {
1200 File argfileFile = new File(outputDir, FILES_FILE_NAME);
1201
1202 try {
1203 FileUtils.fileWrite(argfileFile.getAbsolutePath(),
1204 StringUtils.join(files.iterator(),
1205 SystemUtils.LINE_SEPARATOR));
1206 } catch (IOException ex) {
1207 throw new MavenReportException(
1208 formatMessage("report.javafxdoc.tempfile.write.fail",
1209 argfileFile.getName()), ex);
1210 }
1211
1212 cmd.createArg().setValue("@" + FILES_FILE_NAME);
1213
1214 if (!isDebug()) {
1215 argfileFile.deleteOnExit();
1216 }
1217 }
1218
1219 private void addCommandLineOptions(final Commandline cmd,
1220 final List<String> arguments, final File javadocOutputDirectory)
1221 throws MavenReportException {
1222 File optionsFile = new File(javadocOutputDirectory, OPTIONS_FILE_NAME);
1223
1224 StringBuilder options = new StringBuilder();
1225 options.append(StringUtils.join(arguments.toArray(new String[0]),
1226 SystemUtils.LINE_SEPARATOR));
1227
1228 try {
1229 FileUtils.fileWrite(optionsFile.getAbsolutePath(),
1230 StringUtils.join(arguments.iterator(),
1231 SystemUtils.LINE_SEPARATOR));
1232 } catch (IOException ex) {
1233 throw new MavenReportException(
1234 formatMessage("report.javafxdoc.tempfile.write.fail",
1235 optionsFile.getName()), ex);
1236 }
1237
1238 cmd.createArg().setValue("@" + OPTIONS_FILE_NAME);
1239
1240 if (!isDebug()) {
1241 optionsFile.deleteOnExit();
1242 }
1243 }
1244
1245 private void addJavafxdocOptions(final List<String> arguments,
1246 final List<String> sourcePaths) throws MavenReportException {
1247 validateJavafxdocOptions();
1248
1249
1250 addArgIfNotEmpty(arguments, "-locale", getLocale());
1251
1252 addArgIfNotEmpty(arguments, "-bootclasspath",
1253 JavafxdocUtil.quotedPathArgument(getBootclasspath()));
1254
1255 addArgIf(arguments, isBreakiterator(), "-breakiterator");
1256
1257 addArgIfNotEmpty(arguments, "-classpath",
1258 JavafxdocUtil.quotedPathArgument(getClassPath()));
1259
1260 if (StringUtils.isNotEmpty(getDoclet())) {
1261 addArgIfNotEmpty(arguments, "-doclet",
1262 JavafxdocUtil.quotedArgument(getDoclet()));
1263 addArgIfNotEmpty(arguments, "-docletpath",
1264 JavafxdocUtil.quotedPathArgument(getDocletPath()));
1265 }
1266
1267 if (StringUtils.isEmpty(getEncoding())) {
1268 getLog().warn(formatMessage("report.javafxdoc.encoding.warning",
1269 ReaderFactory.FILE_ENCODING));
1270 }
1271 addArgIfNotEmpty(arguments, "-encoding", getEncoding());
1272
1273 addArgIfNotEmpty(arguments, "-exclude",
1274 getExcludedPackages(sourcePaths));
1275
1276 addArgIfNotEmpty(arguments, "-extdirs",
1277 JavafxdocUtil.quotedPathArgument(getExtdirs()));
1278
1279
1280 addArgIf(arguments, StringUtils.isNotEmpty(getAccessLevel()),
1281 getAccessLevel());
1282
1283 addArgIf(arguments, isQuiet(), "-quiet");
1284
1285 addArgIfNotEmpty(arguments, "-source", JavafxdocUtil.quotedArgument(
1286 getSource()));
1287
1288 if ((StringUtils.isEmpty(getSourcePath()))
1289 && (StringUtils.isNotEmpty(getSubpackages()))) {
1290 setSourcePath(StringUtils.join(sourcePaths.iterator(),
1291 File.pathSeparator));
1292 }
1293 if (StringUtils.isNotEmpty(getSourcePath())) {
1294 addArgIfNotEmpty(arguments, "-sourcepath",
1295 JavafxdocUtil.quotedPathArgument(
1296 buildSourcePath(sourcePaths)));
1297 addArgIfNotEmpty(arguments, "-subpackages", getSubpackages());
1298 }
1299
1300 addArgIf(arguments, isVerbose(), "-verbose");
1301 }
1302
1303 private void addStandardDocletOptions(final List<String> arguments,
1304 final File outputDir) {
1305
1306 addArgIfNotEmpty(arguments, "-d",
1307 JavafxdocUtil.quotedPathArgument(outputDir.toString()));
1308
1309 addArgIfNotEmpty(arguments, "-extracss", JavafxdocUtil.
1310 quotedPathArgument(getExtracss()));
1311
1312 addArgIfNotEmpty(arguments, "-extrajs", JavafxdocUtil.
1313 quotedPathArgument(getExtrajs()));
1314
1315 if (null != getInputFiles()) {
1316 for (File file : getInputFiles()) {
1317 addArgIfNotEmpty(arguments, "-i", JavafxdocUtil.
1318 quotedPathArgument(file.toString()));
1319 }
1320 }
1321
1322 addArgIfNotEmpty(arguments, "-mastercss", JavafxdocUtil.
1323 quotedPathArgument(getMastercss()));
1324
1325 addArgIf(arguments, isNohtml(), "-nohtml");
1326
1327 if (null != getOutputFile()) {
1328 addArgIfNotEmpty(arguments, "-o",
1329 JavafxdocUtil.quotedPathArgument(
1330 getOutputFile().toString()));
1331 }
1332
1333 if (null != getAdditionalXslOptions()) {
1334 for (String opt : getAdditionalXslOptions()) {
1335 addArgIfNotEmpty(arguments, "-xsl:", opt);
1336 }
1337 }
1338
1339 if (null != getXsltfile()) {
1340 addArgIfNotEmpty(arguments, "-xsltfile", JavafxdocUtil.
1341 quotedPathArgument(getXsltfile().getAbsolutePath()));
1342 }
1343 }
1344
1345 private String buildSourcePath(final List<String> sourcePaths) {
1346 String srcPath = null;
1347
1348 if ((StringUtils.isEmpty(getSubpackages()))
1349 || (StringUtils.isNotEmpty(getSourcePath()))) {
1350 srcPath = StringUtils.join(sourcePaths.iterator(),
1351 File.pathSeparator);
1352 }
1353
1354 return srcPath;
1355 }
1356
1357 private void executeJavafxdocCommandLine(final Commandline cmd,
1358 final File outputDir) throws MavenReportException {
1359 String cmdLine = CommandLineUtils.toString(cmd.getCommandline()).
1360 replaceAll("'", "");
1361
1362 getLog().debug(cmdLine);
1363
1364 if (isDebug()) {
1365 File commandLineFile = new File(outputDir,
1366 DEBUG_JAVAFXDOC_SCRIPT_NAME);
1367 try {
1368 FileUtils.fileWrite(commandLineFile.getAbsolutePath(), cmdLine);
1369
1370 if (!SystemUtils.IS_OS_WINDOWS) {
1371 Runtime.getRuntime().exec(new String[]{
1372 "chmod",
1373 "a+x",
1374 commandLineFile.getAbsolutePath()
1375 });
1376 }
1377 } catch (IOException ex) {
1378 throw new MavenReportException(
1379 formatMessage("report.javafxdoc.debug.write.fail",
1380 commandLineFile.getName()), ex);
1381 }
1382 }
1383
1384 CommandLineUtils.StringStreamConsumer err =
1385 new CommandLineUtils.StringStreamConsumer();
1386 try {
1387 int exitCode = CommandLineUtils.executeCommandLine(cmd,
1388 new DefaultConsumer(), err);
1389
1390 if (0 != exitCode) {
1391 throw new MavenReportException(
1392 formatMessage("report.javafxdoc.execution.fail",
1393 exitCode, err.getOutput(), cmdLine));
1394 }
1395 } catch (CommandLineException ex) {
1396 throw new MavenReportException(
1397 formatMessage("report.javafxdoc.execution.exception",
1398 ex.getMessage()), ex);
1399 }
1400
1401 if (StringUtils.isNotEmpty(err.getOutput())) {
1402 getLog().warn(formatMessage("report.javafxdoc.warnings"));
1403
1404 String result[] = err.getOutput().split("\n");
1405 for (String token : result) {
1406 getLog().warn(token.trim());
1407 }
1408 }
1409 }
1410
1411 private String findJavafxdocExecutable() throws IOException {
1412 Toolchain tc = getToolchain();
1413
1414 if (tc != null) {
1415 getLog().info(formatMessage("report.javafxdoc.toolchain.info", tc));
1416 if (getJavafxdocExecutable() != null) {
1417 getLog().warn(
1418 formatMessage("report.javafxdoc.toolchain.ignored",
1419 getJavafxdocExecutable()));
1420 } else {
1421 setJavafxdocExecutable(tc.findTool("javafxdoc"));
1422 }
1423 }
1424
1425 String javafxdocCommand = "javafxdoc";
1426 if (SystemUtils.IS_OS_WINDOWS) {
1427 javafxdocCommand = javafxdocCommand + ".exe";
1428 }
1429
1430 File javafxdocExe = null;
1431
1432
1433 if (StringUtils.isNotEmpty(getJavafxdocExecutable())) {
1434 javafxdocExe = new File(getJavafxdocExecutable());
1435
1436 if (javafxdocExe.isDirectory()) {
1437 javafxdocExe = new File(javafxdocExe, javafxdocCommand);
1438 }
1439
1440 if (SystemUtils.IS_OS_WINDOWS
1441 && javafxdocExe.getName().indexOf('.') < 0) {
1442 javafxdocExe = new File(javafxdocExe.getPath() + ".exe");
1443 }
1444
1445 if (!javafxdocExe.isFile()) {
1446 throw new IOException(
1447 formatMessage("report.javafxdoc.no.executable",
1448 javafxdocExe));
1449 }
1450
1451 return javafxdocExe.getAbsolutePath();
1452 }
1453
1454
1455 Properties env = CommandLineUtils.getSystemEnvVars();
1456 String javafxHome = env.getProperty("JAVAFX_HOME");
1457
1458 if (StringUtils.isEmpty(javafxHome)) {
1459 throw new IOException(formatMessage(
1460 "report.javafxdoc.no.javafx.home"));
1461 }
1462
1463 File homeFile = new File(javafxHome);
1464 if ((!homeFile.exists()) || (!homeFile.isDirectory())) {
1465 throw new IOException(formatMessage(
1466 "report.javafxdoc.invalid.javafx.home", javafxHome));
1467 }
1468
1469 javafxdocExe = new File(javafxHome + File.separator + "bin",
1470 javafxdocCommand);
1471
1472 if ((!javafxdocExe.exists()) || (!javafxdocExe.isFile())) {
1473 throw new IOException(
1474 formatMessage("report.javafxdoc.invalid.executable",
1475 javafxdocExe));
1476 }
1477
1478 return javafxdocExe.getAbsolutePath();
1479 }
1480
1481 private String getAccessLevel() {
1482 String accessLevel = "-protected";
1483 if ("public".equalsIgnoreCase(getShow())
1484 || "protected".equalsIgnoreCase(getShow())
1485 || "package".equalsIgnoreCase(getShow())
1486 || "private".equalsIgnoreCase(getShow())) {
1487 accessLevel = "-" + getShow().toLowerCase();
1488 } else {
1489 getLog().error(formatMessage(
1490 "report.javafxdoc.illegal.access.level", getShow()));
1491 }
1492
1493 return accessLevel;
1494 }
1495
1496 private String getClassPath() throws MavenReportException {
1497 List<File> classpathElements = new ArrayList<File>();
1498 Map<String, Artifact> compileArtifactMap =
1499 new HashMap<String, Artifact>();
1500
1501 classpathElements.addAll(getProjectBuildOutputDirs(getProject()));
1502
1503 populateCompileArtifactMap(compileArtifactMap, getProjectArtifacts(
1504 getProject()));
1505
1506 for (String key : compileArtifactMap.keySet()) {
1507 Artifact a = compileArtifactMap.get(key);
1508 classpathElements.add(a.getFile());
1509 }
1510
1511
1512 try {
1513 Properties env = CommandLineUtils.getSystemEnvVars();
1514 String javafxHome = env.getProperty("JAVAFX_HOME");
1515 File libDir = new File(javafxHome + File.separator + "lib");
1516 if ((libDir.exists()) && (libDir.isDirectory())) {
1517 for (File f : libDir.listFiles()) {
1518 if ((f.isFile()) && (f.getName().toLowerCase().endsWith(
1519 ".jar"))) {
1520 classpathElements.add(f);
1521 } else {
1522 if (f.isDirectory()) {
1523 for (File sf : f.listFiles()) {
1524 if ((sf.isFile()) && (sf.getName().
1525 toLowerCase().endsWith(".jar"))) {
1526 classpathElements.add(sf);
1527 }
1528 }
1529 }
1530 }
1531 }
1532 }
1533 } catch (IOException ex) {
1534
1535 getLog().error(ex.getMessage());
1536 }
1537
1538 return StringUtils.join(classpathElements.iterator(),
1539 File.pathSeparator);
1540 }
1541
1542 private String[] getExcludedPackages() {
1543 String[] excludePackages = {};
1544
1545 if (getExcludePackageNames() != null) {
1546 excludePackages = getExcludePackageNames().split("[ ,:;]");
1547 }
1548 for (int i = 0; i < excludePackages.length; i++) {
1549 excludePackages[i] = excludePackages[i].replace('.',
1550 File.separatorChar);
1551 }
1552
1553 return excludePackages;
1554 }
1555
1556 private String getExcludedPackages(final List<String> sourcePaths) {
1557 List<String> excludedNames = null;
1558
1559 if (StringUtils.isNotEmpty(getSourcePath()) && StringUtils.isNotEmpty(
1560 getSubpackages())) {
1561 String[] excludedPackages = getExcludedPackages();
1562 String[] subpackagesList = subpackages.split("[:]");
1563
1564 excludedNames = JavafxdocUtil.getExcludedNames(sourcePaths,
1565 subpackagesList, excludedPackages);
1566 }
1567
1568 String excludeArg = "";
1569 if ((StringUtils.isNotEmpty(getSubpackages()))
1570 && (null != excludedNames) && (0 < excludedNames.size())) {
1571
1572 for (String str : excludedNames) {
1573 excludeArg = excludeArg + str + ":";
1574 }
1575 excludeArg = excludeArg.substring(0, excludeArg.length() - 1);
1576 }
1577
1578 return excludeArg;
1579 }
1580
1581 private List<String> getExecutionProjectSourceRoots(final MavenProject p) {
1582 if ("pom".equals(
1583 p.getExecutionProject().getPackaging().toLowerCase())) {
1584 return Collections.emptyList();
1585 }
1586
1587 return p.getExecutionProject().getCompileSourceRoots();
1588 }
1589
1590 private List<String> getFilesWithUnnamedPackages(
1591 final List<String> sourcePaths, final List<String> files) {
1592 return getPackageNamesOrFilesWithUnnamedPackages(sourcePaths, files,
1593 false);
1594 }
1595
1596 private List<File> getProjectBuildOutputDirs(final MavenProject p) {
1597 if (StringUtils.isEmpty(p.getBuild().getOutputDirectory())) {
1598 return Collections.emptyList();
1599 }
1600
1601 return Collections.singletonList(new File(p.getBuild().
1602 getOutputDirectory()));
1603 }
1604
1605 private List<String> getPackageNames(final List<String> sourcePaths,
1606 final List<String> files) {
1607 return getPackageNamesOrFilesWithUnnamedPackages(sourcePaths, files,
1608 true);
1609 }
1610
1611 private List<String> getPackageNamesOrFilesWithUnnamedPackages(
1612 final List<String> sourcePaths, final List<String> files,
1613 final boolean onlyPackageName) {
1614 List<String> returnList = new ArrayList<String>();
1615
1616 if (!StringUtils.isEmpty(getSourcePath())) {
1617 return returnList;
1618 }
1619
1620 for (String currentFile : files) {
1621 currentFile = currentFile.replace('\\', '/');
1622
1623 for (String currentSourcePath : sourcePaths) {
1624 currentSourcePath = currentSourcePath.replace('\\', '/');
1625
1626 if (!currentSourcePath.endsWith("/")) {
1627 currentSourcePath += "/";
1628 }
1629
1630 if (currentFile.indexOf(currentSourcePath) != -1) {
1631 String packagename =
1632 currentFile.substring(currentSourcePath.length()
1633 + 1);
1634 if (onlyPackageName && packagename.lastIndexOf("/") != -1) {
1635 packagename = packagename.substring(0, packagename.
1636 lastIndexOf("/"));
1637 packagename = packagename.replace('/', '.');
1638
1639 if (!returnList.contains(packagename)) {
1640 returnList.add(packagename);
1641 }
1642 }
1643 if ((!onlyPackageName)
1644 && (packagename.lastIndexOf("/") == -1)) {
1645 returnList.add(currentFile);
1646 }
1647 }
1648 }
1649 }
1650
1651 return returnList;
1652 }
1653
1654 private List<String> getProjectSourceRoots(final MavenProject p) {
1655 if ("pom".equals(p.getPackaging().toLowerCase())) {
1656 return Collections.emptyList();
1657 }
1658
1659 return p.getCompileSourceRoots();
1660 }
1661
1662 private Toolchain getToolchain() {
1663 Toolchain tc = null;
1664 if (getToolchainManager() != null) {
1665 tc = getToolchainManager().getToolchainFromBuildContext("jdk",
1666 getSession());
1667 }
1668
1669 return tc;
1670 }
1671
1672 private void populateCompileArtifactMap(
1673 final Map<String, Artifact> compileArtifactMap,
1674 final Collection<Artifact> artifactList)
1675 throws MavenReportException {
1676 if (artifactList != null) {
1677 for (Artifact newArtifact : artifactList) {
1678 File file = newArtifact.getFile();
1679
1680 if (null == file) {
1681 throw new MavenReportException(
1682 formatMessage("report.javafxdoc.artifact.error",
1683 newArtifact.getGroupId(),
1684 newArtifact.getArtifactId(),
1685 newArtifact.getVersion()));
1686 }
1687
1688 if (null != compileArtifactMap.get(newArtifact.
1689 getDependencyConflictId())) {
1690 Artifact oldArtifact =
1691 compileArtifactMap.get(newArtifact.
1692 getDependencyConflictId());
1693 ArtifactVersion oldVersion = new DefaultArtifactVersion(
1694 oldArtifact.getVersion());
1695 ArtifactVersion newVersion = new DefaultArtifactVersion(
1696 newArtifact.getVersion());
1697
1698 if (newVersion.compareTo(oldVersion) > 0) {
1699 compileArtifactMap.put(newArtifact.
1700 getDependencyConflictId(),
1701 newArtifact);
1702 }
1703 } else {
1704 compileArtifactMap.put(
1705 newArtifact.getDependencyConflictId(), newArtifact);
1706 }
1707 }
1708 }
1709 }
1710
1711 private void setJavafxdocVersion(File file) {
1712 float version = DEFAULT_JAVAFX_VERSION;
1713
1714 try {
1715 version = JavafxdocUtil.getJavafxdocVersion(file);
1716 } catch (CommandLineException ex) {
1717 getLog().warn(ex.getMessage());
1718 } catch (FileNotFoundException ex) {
1719 getLog().warn(ex.getMessage());
1720 } catch (PatternSyntaxException ex) {
1721 getLog().warn(ex.getMessage());
1722 } catch (IllegalArgumentException ex) {
1723 getLog().warn(ex.getMessage());
1724 }
1725
1726 javafxdocVersion = version;
1727 }
1728
1729 private void validateJavafxdocOptions() throws MavenReportException {
1730
1731 if ((StringUtils.isNotEmpty(getEncoding()))
1732 && (!JavafxdocUtil.validateEncoding(getEncoding()))) {
1733 throw new MavenReportException(formatMessage(
1734 "report.javafxdoc.unsupported.encoding", getEncoding()));
1735 }
1736 }
1737 }