/* * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package com.sun.tools.javadoc; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import javax.tools.JavaFileManager; import javax.tools.JavaFileObject; import com.sun.javadoc.*; import com.sun.tools.javac.main.CommandLine; import com.sun.tools.javac.util.ClientCodeException; import com.sun.tools.javac.util.Context; import com.sun.tools.javac.util.List; import com.sun.tools.javac.util.ListBuffer; import com.sun.tools.javac.util.Log; import com.sun.tools.javac.util.Options; import static com.sun.tools.javac.code.Flags.*; /** * Main program of Javadoc. * Previously named "Main". * *
This is NOT part of any supported API.
* If you write code that depends on this, you do so at your own risk.
* This code and its internal interfaces are subject to change or
* deletion without notice.
*
* @since 1.2
* @author Robert Field
* @author Neal Gafter (rewrite)
*/
public class Start extends ToolOption.Helper {
/** Context for this invocation. */
private final Context context;
private final String defaultDocletClassName;
private final ClassLoader docletParentClassLoader;
private static final String javadocName = "javadoc";
private static final String standardDocletClassName =
"com.sun.tools.doclets.standard.Standard";
private long defaultFilter = PUBLIC | PROTECTED;
private final Messager messager;
private DocletInvoker docletInvoker;
/**
* In API mode, exceptions thrown while calling the doclet are
* propagated using ClientCodeException.
*/
private boolean apiMode;
Start(String programName,
PrintWriter errWriter,
PrintWriter warnWriter,
PrintWriter noticeWriter,
String defaultDocletClassName) {
this(programName, errWriter, warnWriter, noticeWriter, defaultDocletClassName, null);
}
Start(String programName,
PrintWriter errWriter,
PrintWriter warnWriter,
PrintWriter noticeWriter,
String defaultDocletClassName,
ClassLoader docletParentClassLoader) {
context = new Context();
messager = new Messager(context, programName, errWriter, warnWriter, noticeWriter);
this.defaultDocletClassName = defaultDocletClassName;
this.docletParentClassLoader = docletParentClassLoader;
}
Start(String programName, String defaultDocletClassName) {
this(programName, defaultDocletClassName, null);
}
Start(String programName, String defaultDocletClassName,
ClassLoader docletParentClassLoader) {
context = new Context();
messager = new Messager(context, programName);
this.defaultDocletClassName = defaultDocletClassName;
this.docletParentClassLoader = docletParentClassLoader;
}
Start(String programName, ClassLoader docletParentClassLoader) {
this(programName, standardDocletClassName, docletParentClassLoader);
}
Start(String programName) {
this(programName, standardDocletClassName);
}
Start(ClassLoader docletParentClassLoader) {
this(javadocName, docletParentClassLoader);
}
Start() {
this(javadocName);
}
public Start(Context context) {
context.getClass(); // null check
this.context = context;
apiMode = true;
defaultDocletClassName = standardDocletClassName;
docletParentClassLoader = null;
Log log = context.get(Log.logKey);
if (log instanceof Messager)
messager = (Messager) log;
else {
PrintWriter out = context.get(Log.outKey);
messager = (out == null) ? new Messager(context, javadocName)
: new Messager(context, javadocName, out, out, out);
}
}
/**
* Usage
*/
@Override
void usage() {
usage(true);
}
void usage(boolean exit) {
usage("main.usage", "-help", null, exit);
}
@Override
void Xusage() {
Xusage(true);
}
void Xusage(boolean exit) {
usage("main.Xusage", "-X", "main.Xusage.foot", exit);
}
private void usage(String main, String doclet, String foot, boolean exit) {
// RFE: it would be better to replace the following with code to
// write a header, then help for each option, then a footer.
messager.notice(main);
// let doclet print usage information (does nothing on error)
if (docletInvoker != null) {
// RFE: this is a pretty bad way to get the doclet to show
// help info. Moreover, the output appears on stdout,
// and not on any of the standard streams passed
// to javadoc, and in particular, not to the noticeWriter
// But, to fix this, we need to fix the Doclet API.
docletInvoker.optionLength(doclet);
}
if (foot != null)
messager.notice(foot);
if (exit) exit();
}
/**
* Exit
*/
private void exit() {
messager.exit();
}
/**
* Main program - external wrapper
*/
int begin(String... argv) {
boolean ok = begin(null, argv, Collections.