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