langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/Start.java
author jjg
Wed, 22 Jun 2016 17:20:53 -0700
changeset 39179 c04b68e23fa4
parent 38918 bf1ed1a40f5b
child 40232 4995ab1a4558
permissions -rw-r--r--
8154399: Need replacement for jdk.javadoc/com.sun.tools.doclets.standard.Standard 8159096: Expose (new) Standard doclet class. Reviewed-by: alanb, erikj, ksrini
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: 31936
diff changeset
     2
 * Copyright (c) 1997, 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
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
    26
package jdk.javadoc.internal.tool;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
14258
8d2148961366 8000663: clean up langtools imports
jjg
parents: 11052
diff changeset
    28
import java.io.File;
8d2148961366 8000663: clean up langtools imports
jjg
parents: 11052
diff changeset
    29
import java.io.FileNotFoundException;
8d2148961366 8000663: clean up langtools imports
jjg
parents: 11052
diff changeset
    30
import java.io.IOException;
8d2148961366 8000663: clean up langtools imports
jjg
parents: 11052
diff changeset
    31
import java.io.PrintWriter;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35426
diff changeset
    32
import java.lang.reflect.Method;
31936
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents: 29780
diff changeset
    33
import java.nio.file.Path;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
    34
import java.text.BreakIterator;
14545
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
    35
import java.util.ArrayList;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
    36
import java.util.Arrays;
14545
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
    37
import java.util.Collection;
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
    38
import java.util.Collections;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
    39
import java.util.List;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
    40
import java.util.Locale;
29291
076c277565f7 8073550: java* tools: replace obj.getClass hacks with Assert.checkNonNull or Objects.requireNonNull
mcimadamore
parents: 27379
diff changeset
    41
import java.util.Objects;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
    42
import java.util.Set;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35426
diff changeset
    43
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
    44
import static javax.tools.DocumentationTool.Location.*;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35426
diff changeset
    45
14545
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
    46
import javax.tools.JavaFileManager;
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
    47
import javax.tools.JavaFileObject;
31936
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents: 29780
diff changeset
    48
import javax.tools.StandardJavaFileManager;
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents: 29780
diff changeset
    49
import javax.tools.StandardLocation;
14258
8d2148961366 8000663: clean up langtools imports
jjg
parents: 11052
diff changeset
    50
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
    51
import com.sun.tools.javac.api.JavacTrees;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
    52
import com.sun.tools.javac.file.BaseFileManager;
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
    53
import com.sun.tools.javac.file.JavacFileManager;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
import com.sun.tools.javac.main.CommandLine;
37393
a9ba8bd6697b 8152818: Javadoc must support module options supported by javac.
ksrini
parents: 36526
diff changeset
    55
import com.sun.tools.javac.main.OptionHelper;
a9ba8bd6697b 8152818: Javadoc must support module options supported by javac.
ksrini
parents: 36526
diff changeset
    56
import com.sun.tools.javac.main.OptionHelper.GrumpyHelper;
31936
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents: 29780
diff changeset
    57
import com.sun.tools.javac.platform.PlatformDescription;
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents: 29780
diff changeset
    58
import com.sun.tools.javac.platform.PlatformUtils;
14545
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
    59
import com.sun.tools.javac.util.ClientCodeException;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
import com.sun.tools.javac.util.Context;
11052
65b9fa7eaf55 7108668: allow Log to be initialized and used earlier
jjg
parents: 8633
diff changeset
    61
import com.sun.tools.javac.util.Log;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
import com.sun.tools.javac.util.Options;
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
    63
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
    64
import jdk.javadoc.doclet.Doclet;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
    65
import jdk.javadoc.doclet.Doclet.Option;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
    66
import jdk.javadoc.doclet.DocletEnvironment;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
    68
import static com.sun.tools.javac.main.Option.*;
37750
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
    69
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
 * Main program of Javadoc.
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
 * Previously named "Main".
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
 *
14260
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    74
 *  <p><b>This is NOT part of any supported API.
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    75
 *  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: 14258
diff changeset
    76
 *  This code and its internal interfaces are subject to change or
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    77
 *  deletion without notice.</b>
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    78
 *
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
 * @author Robert Field
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
 * @author Neal Gafter (rewrite)
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
 */
14543
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14442
diff changeset
    82
public class Start extends ToolOption.Helper {
37750
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
    83
38617
d93a7f64e231 8157606: deprecate com.sun.javadoc API
jjg
parents: 38614
diff changeset
    84
    @SuppressWarnings("deprecation")
37750
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
    85
    private static final Class<?> OldStdDoclet =
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
    86
            com.sun.tools.doclets.standard.Standard.class;
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
    87
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
    88
    private static final Class<?> StdDoclet =
39179
c04b68e23fa4 8154399: Need replacement for jdk.javadoc/com.sun.tools.doclets.standard.Standard
jjg
parents: 38918
diff changeset
    89
            jdk.javadoc.doclets.StandardDoclet.class;
14442
6dc10c88c07a 8002168: Cleanup initialization of javadoc Messager
jjg
parents: 14441
diff changeset
    90
    /** Context for this invocation. */
6dc10c88c07a 8002168: Cleanup initialization of javadoc Messager
jjg
parents: 14441
diff changeset
    91
    private final Context context;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
    93
    private static final String ProgramName = "javadoc";
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
    95
    // meaning we allow all visibility of PROTECTED and PUBLIC
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
    96
    private static final String defaultModifier = "protected";
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
    97
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
    98
    private Messager messager;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
    99
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   100
    private final String docletName;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   102
    private final ClassLoader classLoader;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   103
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   104
    private Class<?> docletClass;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   106
    private Doclet doclet;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   108
    // used to determine the locale for the messager
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   109
    private Locale locale;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
14545
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   112
    /**
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   113
     * In API mode, exceptions thrown while calling the doclet are
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   114
     * propagated using ClientCodeException.
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   115
     */
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   116
    private boolean apiMode;
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   117
27320
f0739350a62d 8062504: javadoc Start does not close file managers that it opens
jjg
parents: 25874
diff changeset
   118
    private JavaFileManager fileManager;
f0739350a62d 8062504: javadoc Start does not close file managers that it opens
jjg
parents: 25874
diff changeset
   119
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   120
    Start() {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   121
        this(null, null, null, null, null);
1365
ced0e3c4678f 6748546: javadoc API should be classloader-friendly
jjg
parents: 1363
diff changeset
   122
    }
ced0e3c4678f 6748546: javadoc API should be classloader-friendly
jjg
parents: 1363
diff changeset
   123
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   124
    Start(PrintWriter writer) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   125
        this(null, null, writer, null, null);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   128
    Start(Context context, String programName, PrintWriter writer,
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   129
            String docletName, ClassLoader classLoader) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   130
        this.context = context == null ? new Context() : context;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   131
        String pname = programName == null ? ProgramName : programName;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   132
        this.messager = writer == null
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   133
                ? new Messager(this.context, pname)
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   134
                : new Messager(this.context, pname, writer, writer);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   135
        this.docletName = docletName;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   136
        this.classLoader = classLoader;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   137
        this.docletClass = null;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   138
        this.locale = Locale.getDefault();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
14543
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14442
diff changeset
   141
    public Start(Context context) {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   142
        this.docletClass = null;
29291
076c277565f7 8073550: java* tools: replace obj.getClass hacks with Assert.checkNonNull or Objects.requireNonNull
mcimadamore
parents: 27379
diff changeset
   143
        this.context = Objects.requireNonNull(context);
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   144
        this.apiMode = true;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   145
        this.docletName = null;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   146
        this.classLoader = null;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   147
        this.locale = Locale.getDefault();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   148
    }
14543
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14442
diff changeset
   149
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   150
    void initMessager() {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   151
        if (!apiMode)
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   152
            return;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   153
        if (messager == null) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   154
            Log log = context.get(Log.logKey);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   155
            if (log instanceof Messager) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   156
                messager = (Messager) log;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   157
            } else {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   158
                PrintWriter out = context.get(Log.outKey);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   159
                messager = (out == null)
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   160
                        ? new Messager(context, ProgramName)
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   161
                        : new Messager(context, ProgramName, out, out);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   162
            }
14543
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14442
diff changeset
   163
        }
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14442
diff changeset
   164
    }
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14442
diff changeset
   165
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
     * Usage
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
     */
14543
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14442
diff changeset
   169
    @Override
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14442
diff changeset
   170
    void usage() {
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14442
diff changeset
   171
        usage(true);
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14442
diff changeset
   172
    }
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14442
diff changeset
   173
18005
598e2e068668 8007687: javadoc -X does not include -Xdoclint
jjg
parents: 14545
diff changeset
   174
    void usage(boolean exit) {
598e2e068668 8007687: javadoc -X does not include -Xdoclint
jjg
parents: 14545
diff changeset
   175
        usage("main.usage", "-help", null, exit);
14543
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14442
diff changeset
   176
    }
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14442
diff changeset
   177
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14442
diff changeset
   178
    @Override
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14442
diff changeset
   179
    void Xusage() {
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14442
diff changeset
   180
        Xusage(true);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
18005
598e2e068668 8007687: javadoc -X does not include -Xdoclint
jjg
parents: 14545
diff changeset
   183
    void Xusage(boolean exit) {
598e2e068668 8007687: javadoc -X does not include -Xdoclint
jjg
parents: 14545
diff changeset
   184
        usage("main.Xusage", "-X", "main.Xusage.foot", exit);
598e2e068668 8007687: javadoc -X does not include -Xdoclint
jjg
parents: 14545
diff changeset
   185
    }
598e2e068668 8007687: javadoc -X does not include -Xdoclint
jjg
parents: 14545
diff changeset
   186
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   187
    private void usage(String main, String option, String foot, boolean exit) {
18005
598e2e068668 8007687: javadoc -X does not include -Xdoclint
jjg
parents: 14545
diff changeset
   188
        messager.notice(main);
598e2e068668 8007687: javadoc -X does not include -Xdoclint
jjg
parents: 14545
diff changeset
   189
        // let doclet print usage information (does nothing on error)
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   190
        if (docletClass != null) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   191
            String name = doclet.getName();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   192
            Set<Option> supportedOptions = doclet.getSupportedOptions();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   193
            messager.notice("main.doclet.usage.header", name);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   194
            Option.Kind myKind = option.equals("-X")
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   195
                    ? Option.Kind.EXTENDED
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   196
                    : Option.Kind.STANDARD;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   197
            supportedOptions.stream()
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   198
                    .filter(opt -> opt.getKind() == myKind)
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   199
                    .forEach(opt -> messager.printNotice(opt.toString()));
18005
598e2e068668 8007687: javadoc -X does not include -Xdoclint
jjg
parents: 14545
diff changeset
   200
        }
598e2e068668 8007687: javadoc -X does not include -Xdoclint
jjg
parents: 14545
diff changeset
   201
        if (foot != null)
598e2e068668 8007687: javadoc -X does not include -Xdoclint
jjg
parents: 14545
diff changeset
   202
            messager.notice(foot);
598e2e068668 8007687: javadoc -X does not include -Xdoclint
jjg
parents: 14545
diff changeset
   203
37750
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   204
        if (exit)
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   205
            throw new Messager.ExitJavadoc();
5850
6f095ff5b469 6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents: 5520
diff changeset
   206
    }
6f095ff5b469 6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents: 5520
diff changeset
   207
37750
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   208
5850
6f095ff5b469 6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents: 5520
diff changeset
   209
    /**
37750
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   210
     * Main program - external wrapper. In order to maintain backward
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   211
     * CLI  compatibility, we dispatch to the old tool or the old doclet's
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   212
     * Start mechanism, based on the options present on the command line
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   213
     * with the following precedence:
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   214
     *   1. presence of -Xold, dispatch to old tool
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   215
     *   2. doclet variant, if old, dispatch to old Start
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   216
     *   3. taglet variant, if old, dispatch to old Start
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   217
     *
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   218
     * Thus the presence of -Xold switches the tool, soon after command files
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   219
     * if any, are expanded, this is performed here, noting that the messager
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   220
     * is available at this point in time.
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   221
     * The doclet/taglet tests are performed in the begin method, further on,
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   222
     * this is to minimize argument processing and most importantly the impact
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   223
     * of class loader creation, needed to detect the doclet/taglet class variants.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
     */
38614
364c1a6618c0 8157608: deprecate old entry points for javadoc tool
jjg
parents: 37938
diff changeset
   225
    @SuppressWarnings("deprecation")
1363
d7fc53d64560 6748601: javadoc API should allow varargs use
jjg
parents: 10
diff changeset
   226
    int begin(String... argv) {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   227
        // Preprocess @file arguments
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   228
        try {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   229
            argv = CommandLine.parse(argv);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   230
        } catch (FileNotFoundException e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   231
            messager.error("main.cant.read", e.getMessage());
37750
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   232
            throw new Messager.ExitJavadoc();
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   233
        } catch (IOException e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   234
            e.printStackTrace(System.err);
37750
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   235
            throw new Messager.ExitJavadoc();
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   236
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   237
37750
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   238
        if (argv.length > 0 && "-Xold".equals(argv[0])) {
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   239
            messager.warning("main.legacy_api");
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   240
            String[] nargv = Arrays.copyOfRange(argv, 1, argv.length);
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   241
            return com.sun.tools.javadoc.Main.execute(nargv);
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   242
        }
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   243
        boolean ok = begin(Arrays.asList(argv), Collections.<JavaFileObject> emptySet());
14545
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   244
        return ok ? 0 : 1;
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   245
    }
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   246
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   247
    // Called by 199 API.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   248
    public boolean begin(Class<?> docletClass,
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   249
            Iterable<String> options,
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   250
            Iterable<? extends JavaFileObject> fileObjects) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   251
        this.docletClass = docletClass;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   252
        List<String> opts = new ArrayList<>();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   253
        for (String opt: options)
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   254
            opts.add(opt);
37750
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   255
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   256
        return begin(opts, fileObjects);
14545
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   257
    }
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   258
38614
364c1a6618c0 8157608: deprecate old entry points for javadoc tool
jjg
parents: 37938
diff changeset
   259
    @SuppressWarnings("deprecation")
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   260
    private boolean begin(List<String> options, Iterable<? extends JavaFileObject> fileObjects) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   261
        fileManager = context.get(JavaFileManager.class);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   262
        if (fileManager == null) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   263
            JavacFileManager.preRegister(context);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   264
            fileManager = context.get(JavaFileManager.class);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   265
            if (fileManager instanceof BaseFileManager) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   266
                ((BaseFileManager) fileManager).autoClose = true;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   267
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   268
        }
37750
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   269
        // locale, doclet and maybe taglet, needs to be determined first
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   270
        docletClass = preProcess(fileManager, options);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   271
        if (jdk.javadoc.doclet.Doclet.class.isAssignableFrom(docletClass)) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   272
            // no need to dispatch to old, safe to init now
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   273
            initMessager();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   274
            messager.setLocale(locale);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   275
            try {
38918
bf1ed1a40f5b 8155880: Fix langtools usage of the deprecated Class.newInstance method
darcy
parents: 38617
diff changeset
   276
                Object o = docletClass.getConstructor().newInstance();
37759
f0b5daef41b6 8155516: Suppress warnings from uses of deprecated Class.newInstance langtools
darcy
parents: 37757
diff changeset
   277
                doclet = (Doclet) o;
38918
bf1ed1a40f5b 8155880: Fix langtools usage of the deprecated Class.newInstance method
darcy
parents: 38617
diff changeset
   278
            } catch (ReflectiveOperationException exc) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35426
diff changeset
   279
                exc.printStackTrace();
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   280
                if (!apiMode) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   281
                    error("main.could_not_instantiate_class", docletClass);
37750
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   282
                    throw new Messager.ExitJavadoc();
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   283
                }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   284
                throw new ClientCodeException(exc);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   285
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   286
        } else {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   287
            if (this.apiMode) {
37938
42baa89d2156 8075703: jdk.javadoc module exports com.sun.tools.javadoc package which contains a lot of internal API.
jjg
parents: 37759
diff changeset
   288
                com.sun.tools.javadoc.main.Start ostart
42baa89d2156 8075703: jdk.javadoc module exports com.sun.tools.javadoc package which contains a lot of internal API.
jjg
parents: 37759
diff changeset
   289
                        = new com.sun.tools.javadoc.main.Start(context);
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   290
                return ostart.begin(docletClass, options, fileObjects);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   291
            }
37750
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   292
            warn("main.legacy_api");
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   293
            String[] array = options.toArray(new String[options.size()]);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   294
            return com.sun.tools.javadoc.Main.execute(array) == 0;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   295
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   296
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   297
        boolean failed = false;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
        try {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   299
            failed = !parseAndExecute(options, fileObjects);
14543
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14442
diff changeset
   300
        } catch (Messager.ExitJavadoc exc) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
            // ignore, we just exit this way
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
        } catch (OutOfMemoryError ee) {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   303
            messager.error("main.out.of.memory");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
            failed = true;
14545
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   305
        } catch (ClientCodeException e) {
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   306
            // simply rethrow these exceptions, to be caught and handled by JavadocTaskImpl
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   307
            throw e;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
        } catch (Error ee) {
11052
65b9fa7eaf55 7108668: allow Log to be initialized and used earlier
jjg
parents: 8633
diff changeset
   309
            ee.printStackTrace(System.err);
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   310
            messager.error("main.fatal.error");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
            failed = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
        } catch (Exception ee) {
11052
65b9fa7eaf55 7108668: allow Log to be initialized and used earlier
jjg
parents: 8633
diff changeset
   313
            ee.printStackTrace(System.err);
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   314
            messager.error("main.fatal.exception");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
            failed = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
        } finally {
27379
5ae894733e09 8062579: JavacTask, DocumentationTask impls should close file manager when possible
jjg
parents: 27320
diff changeset
   317
            if (fileManager != null
5ae894733e09 8062579: JavacTask, DocumentationTask impls should close file manager when possible
jjg
parents: 27320
diff changeset
   318
                    && fileManager instanceof BaseFileManager
5ae894733e09 8062579: JavacTask, DocumentationTask impls should close file manager when possible
jjg
parents: 27320
diff changeset
   319
                    && ((BaseFileManager) fileManager).autoClose) {
27320
f0739350a62d 8062504: javadoc Start does not close file managers that it opens
jjg
parents: 25874
diff changeset
   320
                try {
f0739350a62d 8062504: javadoc Start does not close file managers that it opens
jjg
parents: 25874
diff changeset
   321
                    fileManager.close();
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   322
                } catch (IOException ignore) {}
27320
f0739350a62d 8062504: javadoc Start does not close file managers that it opens
jjg
parents: 25874
diff changeset
   323
            }
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   324
            boolean haveErrorWarnings = messager.nerrors() > 0 ||
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   325
                    (rejectWarnings && messager.nwarnings() > 0);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   326
            if (failed && !haveErrorWarnings) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   327
                // the doclet failed, but nothing reported, flag it!.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   328
                messager.error("main.unknown.error");
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   329
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   330
            failed |= haveErrorWarnings;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   331
            messager.exitNotice();
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
            messager.flush();
06bc494ca11e Initial load
duke
parents:
diff changeset
   333
        }
14545
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   334
        return !failed;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   336
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   338
     * Main program - internal
06bc494ca11e Initial load
duke
parents:
diff changeset
   339
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   340
    private boolean parseAndExecute(List<String> argList,
14545
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   341
            Iterable<? extends JavaFileObject> fileObjects) throws IOException {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   342
        long tm = System.currentTimeMillis();
06bc494ca11e Initial load
duke
parents:
diff changeset
   343
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   344
        List<String> javaNames = new ArrayList<>();
5850
6f095ff5b469 6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents: 5520
diff changeset
   345
14543
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14442
diff changeset
   346
        compOpts = Options.instance(context);
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   347
19508
e2cd0ed6c9b0 8011043: Warn about use of 1.5 and earlier source and target values
darcy
parents: 18005
diff changeset
   348
        // Make sure no obsolete source/target messages are reported
37393
a9ba8bd6697b 8152818: Javadoc must support module options supported by javac.
ksrini
parents: 36526
diff changeset
   349
        com.sun.tools.javac.main.Option.XLINT.process(getOptionHelper(), "-Xlint:-options");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   350
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   351
        doclet.init(locale, messager);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   352
        parseArgs(argList, javaNames);
14543
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14442
diff changeset
   353
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   354
        if (fileManager instanceof BaseFileManager) {
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   355
            ((BaseFileManager) fileManager).handleOptions(fileManagerOpts);
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   356
        }
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   357
31936
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents: 29780
diff changeset
   358
        String platformString = compOpts.get("-release");
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents: 29780
diff changeset
   359
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents: 29780
diff changeset
   360
        if (platformString != null) {
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents: 29780
diff changeset
   361
            if (compOpts.isSet("-source")) {
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents: 29780
diff changeset
   362
                usageError("main.release.bootclasspath.conflict", "-source");
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents: 29780
diff changeset
   363
            }
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   364
            if (fileManagerOpts.containsKey(BOOTCLASSPATH)) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   365
                usageError("main.release.bootclasspath.conflict", BOOTCLASSPATH.getText());
31936
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents: 29780
diff changeset
   366
            }
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents: 29780
diff changeset
   367
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents: 29780
diff changeset
   368
            PlatformDescription platformDescription =
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents: 29780
diff changeset
   369
                    PlatformUtils.lookupPlatformDescription(platformString);
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents: 29780
diff changeset
   370
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents: 29780
diff changeset
   371
            if (platformDescription == null) {
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents: 29780
diff changeset
   372
                usageError("main.unsupported.release.version", platformString);
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents: 29780
diff changeset
   373
            }
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents: 29780
diff changeset
   374
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   375
            compOpts.put(SOURCE, platformDescription.getSourceVersion());
31936
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents: 29780
diff changeset
   376
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents: 29780
diff changeset
   377
            context.put(PlatformDescription.class, platformDescription);
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents: 29780
diff changeset
   378
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents: 29780
diff changeset
   379
            Collection<Path> platformCP = platformDescription.getPlatformPath();
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents: 29780
diff changeset
   380
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents: 29780
diff changeset
   381
            if (platformCP != null) {
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents: 29780
diff changeset
   382
                if (fileManager instanceof StandardJavaFileManager) {
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents: 29780
diff changeset
   383
                    StandardJavaFileManager sfm = (StandardJavaFileManager) fileManager;
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents: 29780
diff changeset
   384
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents: 29780
diff changeset
   385
                    sfm.setLocationFromPaths(StandardLocation.PLATFORM_CLASS_PATH, platformCP);
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents: 29780
diff changeset
   386
                } else {
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents: 29780
diff changeset
   387
                    usageError("main.release.not.standard.file.manager", platformString);
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents: 29780
diff changeset
   388
                }
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents: 29780
diff changeset
   389
            }
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents: 29780
diff changeset
   390
        }
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents: 29780
diff changeset
   391
14442
6dc10c88c07a 8002168: Cleanup initialization of javadoc Messager
jjg
parents: 14441
diff changeset
   392
        compOpts.notifyListeners();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   393
14545
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   394
        if (javaNames.isEmpty() && subPackages.isEmpty() && isEmpty(fileObjects)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   395
            usageError("main.No_packages_or_classes_specified");
06bc494ca11e Initial load
duke
parents:
diff changeset
   396
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   397
06bc494ca11e Initial load
duke
parents:
diff changeset
   398
        JavadocTool comp = JavadocTool.make0(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   399
        if (comp == null) return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   400
06bc494ca11e Initial load
duke
parents:
diff changeset
   401
        if (showAccess == null) {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   402
            setFilter(defaultModifier);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   403
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   404
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   405
        DocletEnvironment root = comp.getEnvironment(
14543
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14442
diff changeset
   406
                encoding,
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14442
diff changeset
   407
                showAccess,
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   408
                overviewpath,
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   409
                javaNames,
14545
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   410
                fileObjects,
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   411
                subPackages,
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   412
                excludedPackages,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   413
                docClasses,
14543
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14442
diff changeset
   414
                quiet);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   415
14441
6c066a762e05 8002146: javadoc doesn't release resources in a timely manner
jjg
parents: 14260
diff changeset
   416
        // release resources
6c066a762e05 8002146: javadoc doesn't release resources in a timely manner
jjg
parents: 14260
diff changeset
   417
        comp = null;
6c066a762e05 8002146: javadoc doesn't release resources in a timely manner
jjg
parents: 14260
diff changeset
   418
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   419
        if (breakiterator || !locale.getLanguage().equals(Locale.ENGLISH.getLanguage())) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   420
            JavacTrees trees = JavacTrees.instance(context);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   421
            trees.setBreakIterator(BreakIterator.getSentenceInstance(locale));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   422
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   423
        // pass off control to the doclet
06bc494ca11e Initial load
duke
parents:
diff changeset
   424
        boolean ok = root != null;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   425
        if (ok) ok = doclet.run(root);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   426
06bc494ca11e Initial load
duke
parents:
diff changeset
   427
        // We're done.
06bc494ca11e Initial load
duke
parents:
diff changeset
   428
        if (compOpts.get("-verbose") != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   429
            tm = System.currentTimeMillis() - tm;
06bc494ca11e Initial load
duke
parents:
diff changeset
   430
            messager.notice("main.done_in", Long.toString(tm));
06bc494ca11e Initial load
duke
parents:
diff changeset
   431
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   432
06bc494ca11e Initial load
duke
parents:
diff changeset
   433
        return ok;
06bc494ca11e Initial load
duke
parents:
diff changeset
   434
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   435
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   436
    Set<Doclet.Option> docletOptions = null;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   437
    int handleDocletOptions(int idx, List<String> args, boolean isToolOption) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   438
        if (docletOptions == null) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   439
            docletOptions = doclet.getSupportedOptions();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   440
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   441
        String arg = args.get(idx);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   442
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   443
        for (Doclet.Option opt : docletOptions) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   444
            if (opt.matches(arg)) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   445
                if (args.size() - idx < opt.getArgumentCount()) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   446
                    usageError("main.requires_argument", arg);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   447
                }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   448
                opt.process(arg, args.listIterator(idx + 1));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   449
                idx += opt.getArgumentCount();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   450
                return idx;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   451
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   452
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   453
        // check if arg is accepted by the tool before emitting error
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   454
        if (!isToolOption)
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   455
            usageError("main.invalid_flag", arg);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   456
        return idx;
14545
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   457
    }
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   458
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   459
    private Class<?> preProcess(JavaFileManager jfm, List<String> argv) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   460
        // doclet specifying arguments
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   461
        String userDocletPath = null;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   462
        String userDocletName = null;
14545
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   463
37750
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   464
        // taglet specifying arguments, since tagletpath is a doclet
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   465
        // functionality, assume they are repeated and inspect all.
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   466
        List<File> userTagletPath = new ArrayList<>();
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   467
        List<String> userTagletNames = new ArrayList<>();
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   468
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   469
        // Step 1: loop through the args, set locale early on, if found.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   470
        for (int i = 0 ; i < argv.size() ; i++) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   471
            String arg = argv.get(i);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   472
            if (arg.equals(ToolOption.LOCALE.opt)) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   473
                oneArg(argv, i++);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   474
                String lname = argv.get(i);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   475
                locale = getLocale(lname);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   476
            } else if (arg.equals(ToolOption.DOCLET.opt)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   477
                oneArg(argv, i++);
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   478
                if (userDocletName != null) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   479
                    usageError("main.more_than_one_doclet_specified_0_and_1",
37750
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   480
                            userDocletName, argv.get(i));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   481
                }
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   482
                if (docletName != null) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   483
                    usageError("main.more_than_one_doclet_specified_0_and_1",
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   484
                            docletName, argv.get(i));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   485
                }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   486
                userDocletName = argv.get(i);
14545
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   487
            } else if (arg.equals(ToolOption.DOCLETPATH.opt)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   488
                oneArg(argv, i++);
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   489
                if (userDocletPath == null) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   490
                    userDocletPath = argv.get(i);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   491
                } else {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   492
                    userDocletPath += File.pathSeparator + argv.get(i);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   493
                }
37750
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   494
            } else if ("-taglet".equals(arg)) {
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   495
                userTagletNames.add(argv.get(i + 1));
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   496
            } else if ("-tagletpath".equals(arg)) {
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   497
                for (String pathname : argv.get(i + 1).split(File.pathSeparator)) {
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   498
                    userTagletPath.add(new File(pathname));
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   499
                }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   500
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   501
        }
37750
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   502
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   503
        // Step 2: a doclet is provided, nothing more to do.
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   504
        if (docletClass != null) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   505
            return docletClass;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   506
        }
37750
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   507
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   508
        // Step 3: doclet name specified ? if so find a ClassLoader,
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   509
        // and load it.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   510
        if (userDocletName != null) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   511
            ClassLoader cl = classLoader;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   512
            if (cl == null) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   513
                if (!fileManager.hasLocation(DOCLET_PATH)) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   514
                    List<File> paths = new ArrayList<>();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   515
                    if (userDocletPath != null) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   516
                        for (String pathname : userDocletPath.split(File.pathSeparator)) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   517
                            paths.add(new File(pathname));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   518
                        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   519
                    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   520
                    try {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   521
                        ((StandardJavaFileManager)fileManager).setLocation(DOCLET_PATH, paths);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   522
                    } catch (IOException ioe) {
37750
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   523
                        error("main.doclet_could_not_set_location", paths);
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   524
                        throw new Messager.ExitJavadoc();
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   525
                    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   526
                }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   527
                cl = fileManager.getClassLoader(DOCLET_PATH);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   528
                if (cl == null) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   529
                    // despite doclet specified on cmdline no classloader found!
37750
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   530
                    error("main.doclet_no_classloader_found", userDocletName);
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   531
                    throw new Messager.ExitJavadoc();
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   532
                }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   533
            }
37750
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   534
            try {
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   535
                Class<?> klass = cl.loadClass(userDocletName);
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   536
                return klass;
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   537
            } catch (ClassNotFoundException cnfe) {
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   538
                error("main.doclet_class_not_found", userDocletName);
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   539
                throw new Messager.ExitJavadoc();
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   540
            }
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   541
        }
37750
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   542
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   543
        // Step 4: we have a doclet, try loading it
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   544
        if (docletName != null) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   545
            try {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   546
                return Class.forName(docletName, true, getClass().getClassLoader());
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   547
            } catch (ClassNotFoundException cnfe) {
37750
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   548
                error("main.doclet_class_not_found", userDocletName);
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   549
                throw new Messager.ExitJavadoc();
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   550
            }
37750
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   551
        }
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   552
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   553
        // Step 5: we don't have a doclet specified, do we have taglets ?
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   554
        if (!userTagletNames.isEmpty() && hasOldTaglet(userTagletNames, userTagletPath)) {
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   555
            // found a bogey, return the old doclet
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   556
            return OldStdDoclet;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   557
        }
37750
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   558
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   559
        // finally
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   560
        return StdDoclet;
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   561
    }
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   562
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   563
    /*
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   564
     * This method returns true iff it finds a legacy taglet, but for
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   565
     * all other conditions including errors it returns false, allowing
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   566
     * nature to take its own course.
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   567
     */
38617
d93a7f64e231 8157606: deprecate com.sun.javadoc API
jjg
parents: 38614
diff changeset
   568
    @SuppressWarnings("deprecation")
37750
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   569
    private boolean hasOldTaglet(List<String> tagletNames, List<File> tagletPaths) {
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   570
        if (!fileManager.hasLocation(TAGLET_PATH)) {
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   571
            try {
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   572
                ((StandardJavaFileManager) fileManager).setLocation(TAGLET_PATH, tagletPaths);
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   573
            } catch (IOException ioe) {
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   574
                error("main.doclet_could_not_set_location", tagletPaths);
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   575
                throw new Messager.ExitJavadoc();
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   576
            }
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   577
        }
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   578
        ClassLoader cl = fileManager.getClassLoader(TAGLET_PATH);
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   579
        if (cl == null) {
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   580
            // no classloader found!
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   581
            error("main.doclet_no_classloader_found", tagletNames.get(0));
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   582
            throw new Messager.ExitJavadoc();
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   583
        }
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   584
        for (String tagletName : tagletNames) {
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   585
            try {
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   586
                Class<?> klass = cl.loadClass(tagletName);
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   587
                if (com.sun.tools.doclets.Taglet.class.isAssignableFrom(klass)) {
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   588
                    return true;
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   589
                }
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   590
            } catch (ClassNotFoundException cnfe) {
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   591
                error("main.doclet_class_not_found", tagletName);
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   592
                throw new Messager.ExitJavadoc();
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   593
            }
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   594
        }
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   595
        return false;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   596
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   597
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   598
    private void parseArgs(List<String> args, List<String> javaNames) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   599
        for (int i = 0 ; i < args.size() ; i++) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   600
            String arg = args.get(i);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   601
            ToolOption o = ToolOption.get(arg);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   602
            if (o != null) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   603
                // handle a doclet argument that may be needed however
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   604
                // don't increment the index, and allow the tool to consume args
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   605
                handleDocletOptions(i, args, true);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   606
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   607
                if (o.hasArg) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   608
                    oneArg(args, i++);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   609
                    o.process(this, args.get(i));
37393
a9ba8bd6697b 8152818: Javadoc must support module options supported by javac.
ksrini
parents: 36526
diff changeset
   610
                } else if (o.hasSuffix) {
a9ba8bd6697b 8152818: Javadoc must support module options supported by javac.
ksrini
parents: 36526
diff changeset
   611
                    o.process(this, arg);
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   612
                } else {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   613
                    setOption(arg);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   614
                    o.process(this);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   615
                }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   616
            } else if (arg.startsWith("-XD")) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   617
                // hidden javac options
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   618
                String s = arg.substring("-XD".length());
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   619
                int eq = s.indexOf('=');
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   620
                String key = (eq < 0) ? s : s.substring(0, eq);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   621
                String value = (eq < 0) ? s : s.substring(eq+1);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   622
                compOpts.put(key, value);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   623
            } else if (arg.startsWith("-")) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   624
                i = handleDocletOptions(i, args, false);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   625
            } else {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   626
                javaNames.add(arg);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   627
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   628
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   629
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   630
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   631
    private <T> boolean isEmpty(Iterable<T> iter) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   632
        return !iter.iterator().hasNext();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   633
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   634
06bc494ca11e Initial load
duke
parents:
diff changeset
   635
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   636
     * Set one arg option.
06bc494ca11e Initial load
duke
parents:
diff changeset
   637
     * Error and exit if one argument is not provided.
06bc494ca11e Initial load
duke
parents:
diff changeset
   638
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   639
    private void oneArg(List<String> args, int index) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   640
        if ((index + 1) < args.size()) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   641
            setOption(args.get(index), args.get(index+1));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   642
        } else {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   643
            usageError("main.requires_argument", args.get(index));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   644
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   645
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   646
14543
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14442
diff changeset
   647
    @Override
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14442
diff changeset
   648
    void usageError(String key, Object... args) {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   649
        error(key, args);
14543
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14442
diff changeset
   650
        usage(true);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   651
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   652
37750
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   653
    void error(String key, Object... args) {
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   654
        messager.error(key, args);
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   655
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   656
37750
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   657
    void warn(String key, Object... args)  {
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 37393
diff changeset
   658
        messager.warning(key, args);
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   659
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   660
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   661
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   662
     * indicate an option with no arguments was given.
06bc494ca11e Initial load
duke
parents:
diff changeset
   663
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   664
    private void setOption(String opt) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   665
        String[] option = { opt };
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   666
        options.add(Arrays.asList(option));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   667
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   668
06bc494ca11e Initial load
duke
parents:
diff changeset
   669
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   670
     * indicate an option with one argument was given.
06bc494ca11e Initial load
duke
parents:
diff changeset
   671
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   672
    private void setOption(String opt, String argument) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   673
        String[] option = { opt, argument };
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   674
        options.add(Arrays.asList(option));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   675
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   676
06bc494ca11e Initial load
duke
parents:
diff changeset
   677
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   678
     * indicate an option with the specified list of arguments was given.
06bc494ca11e Initial load
duke
parents:
diff changeset
   679
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   680
    private void setOption(String opt, List<String> arguments) {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   681
        List<String> args = new ArrayList<>(arguments.size() + 1);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   682
        args.add(opt);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   683
        args.addAll(arguments);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   684
        options.add(args);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   685
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   686
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   687
    /**
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   688
     * Get the locale if specified on the command line
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   689
     * else return null and if locale option is not used
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   690
     * then return default locale.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   691
     */
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   692
    private Locale getLocale(String localeName) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   693
        Locale userlocale = null;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   694
        if (localeName == null || localeName.isEmpty()) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   695
            return Locale.getDefault();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   696
        }
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   697
        int firstuscore = localeName.indexOf('_');
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   698
        int seconduscore = -1;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   699
        String language = null;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   700
        String country = null;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   701
        String variant = null;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   702
        if (firstuscore == 2) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   703
            language = localeName.substring(0, firstuscore);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   704
            seconduscore = localeName.indexOf('_', firstuscore + 1);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   705
            if (seconduscore > 0) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   706
                if (seconduscore != firstuscore + 3
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   707
                        || localeName.length() <= seconduscore + 1) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   708
                    usageError("main.malformed_locale_name", localeName);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   709
                    return null;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   710
                }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   711
                country = localeName.substring(firstuscore + 1,
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   712
                        seconduscore);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   713
                variant = localeName.substring(seconduscore + 1);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   714
            } else if (localeName.length() == firstuscore + 3) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   715
                country = localeName.substring(firstuscore + 1);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   716
            } else {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   717
                usageError("main.malformed_locale_name", localeName);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   718
                return null;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   719
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   720
        } else if (firstuscore == -1 && localeName.length() == 2) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   721
            language = localeName;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   722
        } else {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   723
            usageError("main.malformed_locale_name", localeName);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   724
            return null;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   725
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   726
        userlocale = searchLocale(language, country, variant);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   727
        if (userlocale == null) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   728
            usageError("main.illegal_locale_name", localeName);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   729
            return null;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   730
        } else {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   731
            return userlocale;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   732
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   733
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   734
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   735
    /**
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   736
     * Search the locale for specified language, specified country and
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   737
     * specified variant.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   738
     */
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   739
    private Locale searchLocale(String language, String country,
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   740
                                String variant) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   741
        for (Locale loc : Locale.getAvailableLocales()) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   742
            if (loc.getLanguage().equals(language) &&
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   743
                (country == null || loc.getCountry().equals(country)) &&
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   744
                (variant == null || loc.getVariant().equals(variant))) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   745
                return loc;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   746
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   747
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
   748
        return null;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   749
    }
37393
a9ba8bd6697b 8152818: Javadoc must support module options supported by javac.
ksrini
parents: 36526
diff changeset
   750
a9ba8bd6697b 8152818: Javadoc must support module options supported by javac.
ksrini
parents: 36526
diff changeset
   751
    @Override
a9ba8bd6697b 8152818: Javadoc must support module options supported by javac.
ksrini
parents: 36526
diff changeset
   752
    OptionHelper getOptionHelper() {
a9ba8bd6697b 8152818: Javadoc must support module options supported by javac.
ksrini
parents: 36526
diff changeset
   753
        return new GrumpyHelper(null) {
a9ba8bd6697b 8152818: Javadoc must support module options supported by javac.
ksrini
parents: 36526
diff changeset
   754
            @Override
a9ba8bd6697b 8152818: Javadoc must support module options supported by javac.
ksrini
parents: 36526
diff changeset
   755
            public String get(com.sun.tools.javac.main.Option option) {
a9ba8bd6697b 8152818: Javadoc must support module options supported by javac.
ksrini
parents: 36526
diff changeset
   756
                return compOpts.get(option);
a9ba8bd6697b 8152818: Javadoc must support module options supported by javac.
ksrini
parents: 36526
diff changeset
   757
            }
a9ba8bd6697b 8152818: Javadoc must support module options supported by javac.
ksrini
parents: 36526
diff changeset
   758
a9ba8bd6697b 8152818: Javadoc must support module options supported by javac.
ksrini
parents: 36526
diff changeset
   759
            @Override
a9ba8bd6697b 8152818: Javadoc must support module options supported by javac.
ksrini
parents: 36526
diff changeset
   760
            public void put(String name, String value) {
a9ba8bd6697b 8152818: Javadoc must support module options supported by javac.
ksrini
parents: 36526
diff changeset
   761
                compOpts.put(name, value);
a9ba8bd6697b 8152818: Javadoc must support module options supported by javac.
ksrini
parents: 36526
diff changeset
   762
            }
a9ba8bd6697b 8152818: Javadoc must support module options supported by javac.
ksrini
parents: 36526
diff changeset
   763
        };
a9ba8bd6697b 8152818: Javadoc must support module options supported by javac.
ksrini
parents: 36526
diff changeset
   764
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   765
}