src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/Main.java
author jlahoda
Fri, 09 Mar 2018 09:42:10 +0100
changeset 49197 cc2673fa8c20
parent 47216 71c04702a3d5
permissions -rw-r--r--
8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure. Summary: Catching CompletionFailures that would be thrown to API clients, and re-completing the symbols again when javac itself needs it. Reviewed-by: cushon, jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
     2
 * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1652
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1652
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1652
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1652
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1652
diff changeset
    23
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    25
package jdk.javadoc.internal.tool;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
import java.io.PrintWriter;
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
/**
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    30
 * Provides external entry points (tool and programmatic) for the javadoc program.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
 *
14260
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 5520
diff changeset
    32
 *  <p><b>This is NOT part of any supported API.
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 5520
diff changeset
    33
 *  If you write code that depends on this, you do so at your own risk.
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 5520
diff changeset
    34
 *  This code and its internal interfaces are subject to change or
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 5520
diff changeset
    35
 *  deletion without notice.</b>
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
 */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    37
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
public class Main {
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
     * Constructor should never be called.
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    43
    private Main() {}
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
    /**
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    46
     * The main entry point called by the launcher. This will call
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    47
     * System.exit with an appropriate return value.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    48
     *
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    49
     * @param args The command line parameters.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
     */
1363
d7fc53d64560 6748601: javadoc API should allow varargs use
jjg
parents: 10
diff changeset
    51
    public static void main(String... args) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
        System.exit(execute(args));
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
     * Programmatic interface.
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    57
     *
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    58
     * @param args The command line parameters.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
     * @return The return code.
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
     */
1363
d7fc53d64560 6748601: javadoc API should allow varargs use
jjg
parents: 10
diff changeset
    61
    public static int execute(String... args) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
        Start jdoc = new Start();
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
    63
        return jdoc.begin(args).exitCode;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
     * Programmatic interface.
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    68
     *
41448
6689bce0cd65 8159855: Create an SPI for tools
jjg
parents: 37750
diff changeset
    69
     * @param writer a stream for all output
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    70
     * @param args The command line parameters.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
     * @return The return code.
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    73
    public static int execute(String[] args, PrintWriter writer) {
41448
6689bce0cd65 8159855: Create an SPI for tools
jjg
parents: 37750
diff changeset
    74
        Start jdoc = new Start(writer, writer);
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
    75
        return jdoc.begin(args).exitCode;
41448
6689bce0cd65 8159855: Create an SPI for tools
jjg
parents: 37750
diff changeset
    76
    }
6689bce0cd65 8159855: Create an SPI for tools
jjg
parents: 37750
diff changeset
    77
6689bce0cd65 8159855: Create an SPI for tools
jjg
parents: 37750
diff changeset
    78
    /**
6689bce0cd65 8159855: Create an SPI for tools
jjg
parents: 37750
diff changeset
    79
     * Programmatic interface.
6689bce0cd65 8159855: Create an SPI for tools
jjg
parents: 37750
diff changeset
    80
     *
6689bce0cd65 8159855: Create an SPI for tools
jjg
parents: 37750
diff changeset
    81
     * @param outWriter a stream for expected output
6689bce0cd65 8159855: Create an SPI for tools
jjg
parents: 37750
diff changeset
    82
     * @param errWriter a stream for diagnostic output
6689bce0cd65 8159855: Create an SPI for tools
jjg
parents: 37750
diff changeset
    83
     * @param args The command line parameters.
6689bce0cd65 8159855: Create an SPI for tools
jjg
parents: 37750
diff changeset
    84
     * @return The return code.
6689bce0cd65 8159855: Create an SPI for tools
jjg
parents: 37750
diff changeset
    85
     */
6689bce0cd65 8159855: Create an SPI for tools
jjg
parents: 37750
diff changeset
    86
    public static int execute(String[] args, PrintWriter outWriter, PrintWriter errWriter) {
6689bce0cd65 8159855: Create an SPI for tools
jjg
parents: 37750
diff changeset
    87
        Start jdoc = new Start(outWriter, errWriter);
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
    88
        return jdoc.begin(args).exitCode;
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
    89
    }
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
    90
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
    91
    public static enum Result {
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
    92
        /** completed with no errors */
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
    93
        OK(0),
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
    94
        /** Completed with reported errors */
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
    95
        ERROR(1),
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
    96
        /** Bad command-line arguments */
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
    97
        CMDERR(2),
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
    98
        /** System error or resource exhaustion */
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
    99
        SYSERR(3),
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
   100
        /** Terminated abnormally */
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
   101
        ABNORMAL(4);
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
   102
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
   103
        private static final long serialVersionUID = 1L;
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
   104
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
   105
        Result(int exitCode) {
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
   106
            this.exitCode = exitCode;
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
   107
        }
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
   108
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
   109
        public boolean isOK() {
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
   110
            return (exitCode == 0);
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
   111
        }
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
   112
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
   113
        public final int exitCode;
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
   114
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
   115
        @Override
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
   116
        public String toString() {
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
   117
            return name() + '(' + exitCode + ')';
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
   118
        }
1365
ced0e3c4678f 6748546: javadoc API should be classloader-friendly
jjg
parents: 1363
diff changeset
   119
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
}