71
72 import static javax.tools.DocumentationTool.Location.*;
73
74 import static com.sun.tools.javac.main.Option.*;
75 import static jdk.javadoc.internal.tool.Main.Result.*;
76
77 /**
78 * Main program of Javadoc.
79 * Previously named "Main".
80 *
81 * <p><b>This is NOT part of any supported API.
82 * If you write code that depends on this, you do so at your own risk.
83 * This code and its internal interfaces are subject to change or
84 * deletion without notice.</b>
85 *
86 * @author Robert Field
87 * @author Neal Gafter (rewrite)
88 */
89 public class Start extends ToolOption.Helper {
90
91 @SuppressWarnings("deprecation")
92 private static final Class<?> OldStdDoclet =
93 com.sun.tools.doclets.standard.Standard.class;
94
95 private static final Class<?> StdDoclet =
96 jdk.javadoc.doclet.StandardDoclet.class;
97 /** Context for this invocation. */
98 private final Context context;
99
100 private static final String ProgramName = "javadoc";
101
102 private Messager messager;
103
104 private final String docletName;
105
106 private final ClassLoader classLoader;
107
108 private Class<?> docletClass;
109
110 private Doclet doclet;
111
112 // used to determine the locale for the messager
113 private Locale locale;
317 * of class loader creation, needed to detect the doclet/taglet class variants.
318 */
319 @SuppressWarnings("deprecation")
320 Result begin(String... argv) {
321 // Preprocess @file arguments
322 try {
323 argv = CommandLine.parse(argv);
324 } catch (IOException e) {
325 error("main.cant.read", e.getMessage());
326 return ERROR;
327 }
328
329 if (argv.length > 0 && "-Xold".equals(argv[0])) {
330 warn("main.legacy_api");
331 String[] nargv = Arrays.copyOfRange(argv, 1, argv.length);
332 int rc = com.sun.tools.javadoc.Main.execute(
333 messager.programName,
334 messager.getWriter(WriterKind.ERROR),
335 messager.getWriter(WriterKind.WARNING),
336 messager.getWriter(WriterKind.NOTICE),
337 "com.sun.tools.doclets.standard.Standard",
338 nargv);
339 return (rc == 0) ? OK : ERROR;
340 }
341 return begin(Arrays.asList(argv), Collections.emptySet());
342 }
343
344 // Called by 199 API.
345 public boolean begin(Class<?> docletClass,
346 Iterable<String> options,
347 Iterable<? extends JavaFileObject> fileObjects) {
348 this.docletClass = docletClass;
349 List<String> opts = new ArrayList<>();
350 for (String opt: options)
351 opts.add(opt);
352
353 return begin(opts, fileObjects).isOK();
354 }
355
356 @SuppressWarnings("deprecation")
357 private Result begin(List<String> options, Iterable<? extends JavaFileObject> fileObjects) {
780 String text = messager.getText("main.doclet_no_classloader_found",
781 userDocletName);
782 throw new ToolException(CMDERR, text);
783 }
784 }
785 try {
786 Class<?> klass = cl.loadClass(userDocletName);
787 return klass;
788 } catch (ClassNotFoundException cnfe) {
789 if (apiMode) {
790 throw new IllegalArgumentException("Cannot find doclet class " + userDocletName,
791 cnfe);
792 }
793 String text = messager.getText("main.doclet_class_not_found", userDocletName);
794 throw new ToolException(CMDERR, text, cnfe);
795 }
796 }
797
798 // Step 4: we have a doclet, try loading it
799 if (docletName != null) {
800 try {
801 return Class.forName(docletName, true, getClass().getClassLoader());
802 } catch (ClassNotFoundException cnfe) {
803 if (apiMode) {
804 throw new IllegalArgumentException("Cannot find doclet class " + userDocletName);
805 }
806 String text = messager.getText("main.doclet_class_not_found", userDocletName);
807 throw new ToolException(CMDERR, text, cnfe);
808 }
809 }
810
811 // Step 5: we don't have a doclet specified, do we have taglets ?
812 if (!userTagletNames.isEmpty() && hasOldTaglet(userTagletNames, userTagletPath)) {
813 // found a bogey, return the old doclet
814 return OldStdDoclet;
815 }
816
817 // finally
818 return StdDoclet;
819 }
820
821 /*
822 * This method returns true iff it finds a legacy taglet, but for
823 * all other conditions including errors it returns false, allowing
824 * nature to take its own course.
825 */
826 @SuppressWarnings("deprecation")
827 private boolean hasOldTaglet(List<String> tagletNames, List<File> tagletPaths) throws ToolException {
828 if (!fileManager.hasLocation(TAGLET_PATH)) {
829 try {
830 ((StandardJavaFileManager) fileManager).setLocation(TAGLET_PATH, tagletPaths);
831 } catch (IOException ioe) {
832 String text = messager.getText("main.doclet_could_not_set_location", tagletPaths);
833 throw new ToolException(CMDERR, text, ioe);
834 }
835 }
836 ClassLoader cl = fileManager.getClassLoader(TAGLET_PATH);
837 if (cl == null) {
838 // no classloader found!
|
71
72 import static javax.tools.DocumentationTool.Location.*;
73
74 import static com.sun.tools.javac.main.Option.*;
75 import static jdk.javadoc.internal.tool.Main.Result.*;
76
77 /**
78 * Main program of Javadoc.
79 * Previously named "Main".
80 *
81 * <p><b>This is NOT part of any supported API.
82 * If you write code that depends on this, you do so at your own risk.
83 * This code and its internal interfaces are subject to change or
84 * deletion without notice.</b>
85 *
86 * @author Robert Field
87 * @author Neal Gafter (rewrite)
88 */
89 public class Start extends ToolOption.Helper {
90
91 private static final String OldStdDocletName =
92 "com.sun.tools.doclets.standard.Standard";
93
94 private static final Class<?> StdDoclet =
95 jdk.javadoc.doclet.StandardDoclet.class;
96 /** Context for this invocation. */
97 private final Context context;
98
99 private static final String ProgramName = "javadoc";
100
101 private Messager messager;
102
103 private final String docletName;
104
105 private final ClassLoader classLoader;
106
107 private Class<?> docletClass;
108
109 private Doclet doclet;
110
111 // used to determine the locale for the messager
112 private Locale locale;
316 * of class loader creation, needed to detect the doclet/taglet class variants.
317 */
318 @SuppressWarnings("deprecation")
319 Result begin(String... argv) {
320 // Preprocess @file arguments
321 try {
322 argv = CommandLine.parse(argv);
323 } catch (IOException e) {
324 error("main.cant.read", e.getMessage());
325 return ERROR;
326 }
327
328 if (argv.length > 0 && "-Xold".equals(argv[0])) {
329 warn("main.legacy_api");
330 String[] nargv = Arrays.copyOfRange(argv, 1, argv.length);
331 int rc = com.sun.tools.javadoc.Main.execute(
332 messager.programName,
333 messager.getWriter(WriterKind.ERROR),
334 messager.getWriter(WriterKind.WARNING),
335 messager.getWriter(WriterKind.NOTICE),
336 OldStdDocletName,
337 nargv);
338 return (rc == 0) ? OK : ERROR;
339 }
340 return begin(Arrays.asList(argv), Collections.emptySet());
341 }
342
343 // Called by 199 API.
344 public boolean begin(Class<?> docletClass,
345 Iterable<String> options,
346 Iterable<? extends JavaFileObject> fileObjects) {
347 this.docletClass = docletClass;
348 List<String> opts = new ArrayList<>();
349 for (String opt: options)
350 opts.add(opt);
351
352 return begin(opts, fileObjects).isOK();
353 }
354
355 @SuppressWarnings("deprecation")
356 private Result begin(List<String> options, Iterable<? extends JavaFileObject> fileObjects) {
779 String text = messager.getText("main.doclet_no_classloader_found",
780 userDocletName);
781 throw new ToolException(CMDERR, text);
782 }
783 }
784 try {
785 Class<?> klass = cl.loadClass(userDocletName);
786 return klass;
787 } catch (ClassNotFoundException cnfe) {
788 if (apiMode) {
789 throw new IllegalArgumentException("Cannot find doclet class " + userDocletName,
790 cnfe);
791 }
792 String text = messager.getText("main.doclet_class_not_found", userDocletName);
793 throw new ToolException(CMDERR, text, cnfe);
794 }
795 }
796
797 // Step 4: we have a doclet, try loading it
798 if (docletName != null) {
799 return loadDocletClass(docletName);
800 }
801
802 // Step 5: we don't have a doclet specified, do we have taglets ?
803 if (!userTagletNames.isEmpty() && hasOldTaglet(userTagletNames, userTagletPath)) {
804 // found a bogey, return the old doclet
805 return loadDocletClass(OldStdDocletName);
806 }
807
808 // finally
809 return StdDoclet;
810 }
811
812 private Class<?> loadDocletClass(String docletName) throws ToolException {
813 try {
814 return Class.forName(docletName, true, getClass().getClassLoader());
815 } catch (ClassNotFoundException cnfe) {
816 if (apiMode) {
817 throw new IllegalArgumentException("Cannot find doclet class " + docletName);
818 }
819 String text = messager.getText("main.doclet_class_not_found", docletName);
820 throw new ToolException(CMDERR, text, cnfe);
821 }
822 }
823
824 /*
825 * This method returns true iff it finds a legacy taglet, but for
826 * all other conditions including errors it returns false, allowing
827 * nature to take its own course.
828 */
829 @SuppressWarnings("deprecation")
830 private boolean hasOldTaglet(List<String> tagletNames, List<File> tagletPaths) throws ToolException {
831 if (!fileManager.hasLocation(TAGLET_PATH)) {
832 try {
833 ((StandardJavaFileManager) fileManager).setLocation(TAGLET_PATH, tagletPaths);
834 } catch (IOException ioe) {
835 String text = messager.getText("main.doclet_could_not_set_location", tagletPaths);
836 throw new ToolException(CMDERR, text, ioe);
837 }
838 }
839 ClassLoader cl = fileManager.getClassLoader(TAGLET_PATH);
840 if (cl == null) {
841 // no classloader found!
|