author | pmuthuswamy |
Sat, 15 Jul 2017 11:06:32 -0700 | |
changeset 45912 | 865870b7fe9b |
parent 45742 | 36bf0f2436ad |
permissions | -rw-r--r-- |
10 | 1 |
/* |
44020
ef5f709f4fd8
8175055: Errors reported by Arguments.validate should (probably) be fatal
ksrini
parents:
42828
diff
changeset
|
2 |
* Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. |
10 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
10 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5520 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
10 | 24 |
*/ |
25 |
||
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
26 |
package jdk.javadoc.internal.tool; |
10 | 27 |
|
14258 | 28 |
import java.io.File; |
29 |
import java.io.IOException; |
|
30 |
import java.io.PrintWriter; |
|
31936 | 31 |
import java.nio.file.Path; |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
32 |
import java.text.BreakIterator; |
41252
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
33 |
import java.text.Collator; |
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
34 |
import java.util.ArrayList; |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
35 |
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
|
36 |
import java.util.Collection; |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
37 |
import java.util.Collections; |
41252
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
38 |
import java.util.Comparator; |
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; |
45912
865870b7fe9b
8177048: javadoc should support -version and/or --version
pmuthuswamy
parents:
45742
diff
changeset
|
41 |
import java.util.MissingResourceException; |
29291
076c277565f7
8073550: java* tools: replace obj.getClass hacks with Assert.checkNonNull or Objects.requireNonNull
mcimadamore
parents:
27379
diff
changeset
|
42 |
import java.util.Objects; |
45912
865870b7fe9b
8177048: javadoc should support -version and/or --version
pmuthuswamy
parents:
45742
diff
changeset
|
43 |
import java.util.ResourceBundle; |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
44 |
import java.util.Set; |
41252
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
45 |
import java.util.stream.Collectors; |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
46 |
import java.util.stream.Stream; |
36526 | 47 |
|
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
48 |
import javax.tools.JavaFileManager; |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
49 |
import javax.tools.JavaFileObject; |
31936 | 50 |
import javax.tools.StandardJavaFileManager; |
51 |
import javax.tools.StandardLocation; |
|
14258 | 52 |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
53 |
import com.sun.tools.javac.api.JavacTrees; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
54 |
import com.sun.tools.javac.file.BaseFileManager; |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
55 |
import com.sun.tools.javac.file.JavacFileManager; |
42260
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41990
diff
changeset
|
56 |
import com.sun.tools.javac.main.Arguments; |
10 | 57 |
import com.sun.tools.javac.main.CommandLine; |
37393
a9ba8bd6697b
8152818: Javadoc must support module options supported by javac.
ksrini
parents:
36526
diff
changeset
|
58 |
import com.sun.tools.javac.main.OptionHelper; |
a9ba8bd6697b
8152818: Javadoc must support module options supported by javac.
ksrini
parents:
36526
diff
changeset
|
59 |
import com.sun.tools.javac.main.OptionHelper.GrumpyHelper; |
31936 | 60 |
import com.sun.tools.javac.platform.PlatformDescription; |
61 |
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
|
62 |
import com.sun.tools.javac.util.ClientCodeException; |
10 | 63 |
import com.sun.tools.javac.util.Context; |
11052 | 64 |
import com.sun.tools.javac.util.Log; |
42260
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41990
diff
changeset
|
65 |
import com.sun.tools.javac.util.Log.WriterKind; |
10 | 66 |
import com.sun.tools.javac.util.Options; |
42277 | 67 |
import com.sun.tools.javac.util.StringUtils; |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
68 |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
69 |
import jdk.javadoc.doclet.Doclet; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
70 |
import jdk.javadoc.doclet.Doclet.Option; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
71 |
import jdk.javadoc.doclet.DocletEnvironment; |
41451 | 72 |
import jdk.javadoc.internal.tool.Main.Result; |
10 | 73 |
|
40508
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40308
diff
changeset
|
74 |
import static javax.tools.DocumentationTool.Location.*; |
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40308
diff
changeset
|
75 |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
76 |
import static com.sun.tools.javac.main.Option.*; |
41451 | 77 |
import static jdk.javadoc.internal.tool.Main.Result.*; |
37750
d213951c811b
8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents:
37393
diff
changeset
|
78 |
|
10 | 79 |
/** |
80 |
* Main program of Javadoc. |
|
81 |
* Previously named "Main". |
|
82 |
* |
|
14260
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
83 |
* <p><b>This is NOT part of any supported API. |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
84 |
* 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
|
85 |
* 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
|
86 |
* deletion without notice.</b> |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
87 |
* |
10 | 88 |
* @author Robert Field |
89 |
* @author Neal Gafter (rewrite) |
|
90 |
*/ |
|
14543 | 91 |
public class Start extends ToolOption.Helper { |
37750
d213951c811b
8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents:
37393
diff
changeset
|
92 |
|
d213951c811b
8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents:
37393
diff
changeset
|
93 |
private static final Class<?> StdDoclet = |
44189 | 94 |
jdk.javadoc.doclet.StandardDoclet.class; |
14442 | 95 |
/** Context for this invocation. */ |
96 |
private final Context context; |
|
10 | 97 |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
98 |
private static final String ProgramName = "javadoc"; |
10 | 99 |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
100 |
private Messager messager; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
101 |
|
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
102 |
private final String docletName; |
10 | 103 |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
104 |
private final ClassLoader classLoader; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
105 |
|
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
106 |
private Class<?> docletClass; |
10 | 107 |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
108 |
private Doclet doclet; |
10 | 109 |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
110 |
// used to determine the locale for the messager |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
111 |
private Locale locale; |
10 | 112 |
|
113 |
||
14545
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 |
* 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
|
116 |
* propagated using ClientCodeException. |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
117 |
*/ |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
118 |
private boolean apiMode; |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
119 |
|
27320
f0739350a62d
8062504: javadoc Start does not close file managers that it opens
jjg
parents:
25874
diff
changeset
|
120 |
private JavaFileManager fileManager; |
f0739350a62d
8062504: javadoc Start does not close file managers that it opens
jjg
parents:
25874
diff
changeset
|
121 |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
122 |
Start() { |
41448 | 123 |
this(null, null, null, null, null, null); |
1365 | 124 |
} |
125 |
||
41448 | 126 |
Start(PrintWriter outWriter, PrintWriter errWriter) { |
127 |
this(null, null, outWriter, errWriter, null, null); |
|
10 | 128 |
} |
129 |
||
41448 | 130 |
Start(Context context, String programName, |
131 |
PrintWriter outWriter, PrintWriter errWriter, |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
132 |
String docletName, ClassLoader classLoader) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
133 |
this.context = context == null ? new Context() : context; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
134 |
String pname = programName == null ? ProgramName : programName; |
41448 | 135 |
this.messager = (outWriter == null && errWriter == null) |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
136 |
? new Messager(this.context, pname) |
41448 | 137 |
: new Messager(this.context, pname, outWriter, errWriter); |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
138 |
this.docletName = docletName; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
139 |
this.classLoader = classLoader; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
140 |
this.docletClass = null; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
141 |
this.locale = Locale.getDefault(); |
10 | 142 |
} |
143 |
||
14543 | 144 |
public Start(Context context) { |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
145 |
this.docletClass = null; |
29291
076c277565f7
8073550: java* tools: replace obj.getClass hacks with Assert.checkNonNull or Objects.requireNonNull
mcimadamore
parents:
27379
diff
changeset
|
146 |
this.context = Objects.requireNonNull(context); |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
147 |
this.apiMode = true; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
148 |
this.docletName = null; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
149 |
this.classLoader = null; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
150 |
this.locale = Locale.getDefault(); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
151 |
} |
14543 | 152 |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
153 |
void initMessager() { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
154 |
if (!apiMode) |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
155 |
return; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
156 |
if (messager == null) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
157 |
Log log = context.get(Log.logKey); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
158 |
if (log instanceof Messager) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
159 |
messager = (Messager) log; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
160 |
} else { |
40232
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
39179
diff
changeset
|
161 |
PrintWriter out = context.get(Log.errKey); |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
162 |
messager = (out == null) |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
163 |
? new Messager(context, ProgramName) |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
164 |
: new Messager(context, ProgramName, out, out); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
165 |
} |
14543 | 166 |
} |
167 |
} |
|
168 |
||
10 | 169 |
/** |
170 |
* Usage |
|
171 |
*/ |
|
14543 | 172 |
@Override |
173 |
void usage() { |
|
41451 | 174 |
usage("main.usage", OptionKind.STANDARD, "main.usage.foot"); |
14543 | 175 |
} |
176 |
||
177 |
@Override |
|
178 |
void Xusage() { |
|
41451 | 179 |
usage("main.Xusage", OptionKind.EXTENDED, "main.Xusage.foot"); |
10 | 180 |
} |
181 |
||
45912
865870b7fe9b
8177048: javadoc should support -version and/or --version
pmuthuswamy
parents:
45742
diff
changeset
|
182 |
@Override |
865870b7fe9b
8177048: javadoc should support -version and/or --version
pmuthuswamy
parents:
45742
diff
changeset
|
183 |
void version() { |
865870b7fe9b
8177048: javadoc should support -version and/or --version
pmuthuswamy
parents:
45742
diff
changeset
|
184 |
messager.notice("javadoc.version", messager.programName, version("release")); |
865870b7fe9b
8177048: javadoc should support -version and/or --version
pmuthuswamy
parents:
45742
diff
changeset
|
185 |
} |
865870b7fe9b
8177048: javadoc should support -version and/or --version
pmuthuswamy
parents:
45742
diff
changeset
|
186 |
|
865870b7fe9b
8177048: javadoc should support -version and/or --version
pmuthuswamy
parents:
45742
diff
changeset
|
187 |
@Override |
865870b7fe9b
8177048: javadoc should support -version and/or --version
pmuthuswamy
parents:
45742
diff
changeset
|
188 |
void fullVersion() { |
865870b7fe9b
8177048: javadoc should support -version and/or --version
pmuthuswamy
parents:
45742
diff
changeset
|
189 |
messager.notice("javadoc.fullversion", messager.programName, version("full")); |
865870b7fe9b
8177048: javadoc should support -version and/or --version
pmuthuswamy
parents:
45742
diff
changeset
|
190 |
} |
865870b7fe9b
8177048: javadoc should support -version and/or --version
pmuthuswamy
parents:
45742
diff
changeset
|
191 |
|
41451 | 192 |
private void usage(String headerKey, OptionKind kind, String footerKey) { |
193 |
messager.notice(headerKey); |
|
194 |
showToolOptions(kind); |
|
41252
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
195 |
|
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
196 |
// let doclet print usage information |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
197 |
if (docletClass != null) { |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
198 |
String name = doclet.getName(); |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
199 |
messager.notice("main.doclet.usage.header", name); |
41451 | 200 |
showDocletOptions(kind == OptionKind.EXTENDED |
201 |
? Option.Kind.EXTENDED |
|
202 |
: Option.Kind.STANDARD); |
|
41252
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
203 |
} |
41451 | 204 |
if (footerKey != null) |
205 |
messager.notice(footerKey); |
|
41252
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
206 |
} |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
207 |
|
45912
865870b7fe9b
8177048: javadoc should support -version and/or --version
pmuthuswamy
parents:
45742
diff
changeset
|
208 |
private static final String versionRBName = "jdk.javadoc.internal.tool.resources.version"; |
865870b7fe9b
8177048: javadoc should support -version and/or --version
pmuthuswamy
parents:
45742
diff
changeset
|
209 |
private static ResourceBundle versionRB; |
865870b7fe9b
8177048: javadoc should support -version and/or --version
pmuthuswamy
parents:
45742
diff
changeset
|
210 |
|
865870b7fe9b
8177048: javadoc should support -version and/or --version
pmuthuswamy
parents:
45742
diff
changeset
|
211 |
private static String version(String key) { |
865870b7fe9b
8177048: javadoc should support -version and/or --version
pmuthuswamy
parents:
45742
diff
changeset
|
212 |
if (versionRB == null) { |
865870b7fe9b
8177048: javadoc should support -version and/or --version
pmuthuswamy
parents:
45742
diff
changeset
|
213 |
try { |
865870b7fe9b
8177048: javadoc should support -version and/or --version
pmuthuswamy
parents:
45742
diff
changeset
|
214 |
versionRB = ResourceBundle.getBundle(versionRBName); |
865870b7fe9b
8177048: javadoc should support -version and/or --version
pmuthuswamy
parents:
45742
diff
changeset
|
215 |
} catch (MissingResourceException e) { |
865870b7fe9b
8177048: javadoc should support -version and/or --version
pmuthuswamy
parents:
45742
diff
changeset
|
216 |
return Log.getLocalizedString("version.not.available"); |
865870b7fe9b
8177048: javadoc should support -version and/or --version
pmuthuswamy
parents:
45742
diff
changeset
|
217 |
} |
865870b7fe9b
8177048: javadoc should support -version and/or --version
pmuthuswamy
parents:
45742
diff
changeset
|
218 |
} |
865870b7fe9b
8177048: javadoc should support -version and/or --version
pmuthuswamy
parents:
45742
diff
changeset
|
219 |
try { |
865870b7fe9b
8177048: javadoc should support -version and/or --version
pmuthuswamy
parents:
45742
diff
changeset
|
220 |
return versionRB.getString(key); |
865870b7fe9b
8177048: javadoc should support -version and/or --version
pmuthuswamy
parents:
45742
diff
changeset
|
221 |
} catch (MissingResourceException e) { |
865870b7fe9b
8177048: javadoc should support -version and/or --version
pmuthuswamy
parents:
45742
diff
changeset
|
222 |
return Log.getLocalizedString("version.not.available"); |
865870b7fe9b
8177048: javadoc should support -version and/or --version
pmuthuswamy
parents:
45742
diff
changeset
|
223 |
} |
865870b7fe9b
8177048: javadoc should support -version and/or --version
pmuthuswamy
parents:
45742
diff
changeset
|
224 |
} |
865870b7fe9b
8177048: javadoc should support -version and/or --version
pmuthuswamy
parents:
45742
diff
changeset
|
225 |
|
41252
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
226 |
void showToolOptions(OptionKind kind) { |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
227 |
Comparator<ToolOption> comp = new Comparator<ToolOption>() { |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
228 |
final Collator collator = Collator.getInstance(Locale.US); |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
229 |
{ collator.setStrength(Collator.PRIMARY); } |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
230 |
|
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
231 |
@Override |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
232 |
public int compare(ToolOption o1, ToolOption o2) { |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
233 |
return collator.compare(o1.primaryName, o2.primaryName); |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
234 |
} |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
235 |
}; |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
236 |
|
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
237 |
Stream.of(ToolOption.values()) |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
238 |
.filter(opt -> opt.kind == kind) |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
239 |
.sorted(comp) |
42827
36468b5fa7f4
8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents:
42277
diff
changeset
|
240 |
.forEach(this::showToolOption); |
41252
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
241 |
} |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
242 |
|
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
243 |
void showToolOption(ToolOption option) { |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
244 |
List<String> names = option.getNames(); |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
245 |
String parameters; |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
246 |
if (option.hasArg || option.primaryName.endsWith(":")) { |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
247 |
String sep = (option == ToolOption.J) || option.primaryName.endsWith(":") ? "" : " "; |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
248 |
parameters = sep + option.getParameters(messager); |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
249 |
} else { |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
250 |
parameters = ""; |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
251 |
} |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
252 |
String description = option.getDescription(messager); |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
253 |
showUsage(names, parameters, description); |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
254 |
} |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
255 |
|
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
256 |
void showDocletOptions(Option.Kind kind) { |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
257 |
Comparator<Doclet.Option> comp = new Comparator<Doclet.Option>() { |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
258 |
final Collator collator = Collator.getInstance(Locale.US); |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
259 |
{ collator.setStrength(Collator.PRIMARY); } |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
260 |
|
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
261 |
@Override |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
262 |
public int compare(Doclet.Option o1, Doclet.Option o2) { |
42277 | 263 |
return collator.compare(o1.getNames().get(0), o2.getNames().get(0)); |
41252
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
264 |
} |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
265 |
}; |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
266 |
|
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
267 |
doclet.getSupportedOptions().stream() |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
268 |
.filter(opt -> opt.getKind() == kind) |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
269 |
.sorted(comp) |
42827
36468b5fa7f4
8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents:
42277
diff
changeset
|
270 |
.forEach(this::showDocletOption); |
41252
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
271 |
} |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
272 |
|
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
273 |
void showDocletOption(Doclet.Option option) { |
42277 | 274 |
List<String> names = option.getNames(); |
41252
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
275 |
String parameters; |
42277 | 276 |
String optname = names.get(0); |
277 |
if (option.getArgumentCount() > 0 || optname.endsWith(":")) { |
|
278 |
String sep = optname.endsWith(":") ? "" : " "; |
|
41252
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
279 |
parameters = sep + option.getParameters(); |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
280 |
} else { |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
281 |
parameters = ""; |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
282 |
} |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
283 |
String description = option.getDescription(); |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
284 |
showUsage(names, parameters, description); |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
285 |
} |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
286 |
|
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
287 |
// The following constants are intended to format the output to |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
288 |
// be similar to that of the java launcher: i.e. "java -help". |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
289 |
|
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
290 |
/** The indent for the option synopsis. */ |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
291 |
private static final String SMALL_INDENT = " "; |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
292 |
/** The automatic indent for the description. */ |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
293 |
private static final String LARGE_INDENT = " "; |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
294 |
/** The space allowed for the synopsis, if the description is to be shown on the same line. */ |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
295 |
private static final int DEFAULT_SYNOPSIS_WIDTH = 13; |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
296 |
/** The nominal maximum line length, when seeing if text will fit on a line. */ |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
297 |
private static final int DEFAULT_MAX_LINE_LENGTH = 80; |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
298 |
/** The format for a single-line help entry. */ |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
299 |
private static final String COMPACT_FORMAT = SMALL_INDENT + "%-" + DEFAULT_SYNOPSIS_WIDTH + "s %s"; |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
300 |
|
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
301 |
void showUsage(List<String> names, String parameters, String description) { |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
302 |
String synopses = names.stream() |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
303 |
.map(s -> s + parameters) |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
304 |
.collect(Collectors.joining(", ")); |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
305 |
// If option synopses and description fit on a single line of reasonable length, |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
306 |
// display using COMPACT_FORMAT |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
307 |
if (synopses.length() < DEFAULT_SYNOPSIS_WIDTH |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
308 |
&& !description.contains("\n") |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
309 |
&& (SMALL_INDENT.length() + DEFAULT_SYNOPSIS_WIDTH + 1 + description.length() <= DEFAULT_MAX_LINE_LENGTH)) { |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
310 |
messager.printNotice(String.format(COMPACT_FORMAT, synopses, description)); |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
311 |
return; |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
312 |
} |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
313 |
|
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
314 |
// If option synopses fit on a single line of reasonable length, show that; |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
315 |
// otherwise, show 1 per line |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
316 |
if (synopses.length() <= DEFAULT_MAX_LINE_LENGTH) { |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
317 |
messager.printNotice(SMALL_INDENT + synopses); |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
318 |
} else { |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
319 |
for (String name: names) { |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
320 |
messager.printNotice(SMALL_INDENT + name + parameters); |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
321 |
} |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
322 |
} |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
323 |
|
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
324 |
// Finally, show the description |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
325 |
messager.printNotice(LARGE_INDENT + description.replace("\n", "\n" + LARGE_INDENT)); |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
326 |
} |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
327 |
|
37750
d213951c811b
8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents:
37393
diff
changeset
|
328 |
|
5850
6f095ff5b469
6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents:
5520
diff
changeset
|
329 |
/** |
37750
d213951c811b
8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents:
37393
diff
changeset
|
330 |
* Main program - external wrapper. In order to maintain backward |
45742 | 331 |
* CLI compatibility, the execution is dispatched to the appropriate |
332 |
* Start mechanism, depending on the doclet variant. |
|
37750
d213951c811b
8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents:
37393
diff
changeset
|
333 |
* |
45742 | 334 |
* The doclet tests are performed in the begin method, further on, |
37750
d213951c811b
8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents:
37393
diff
changeset
|
335 |
* this is to minimize argument processing and most importantly the impact |
45742 | 336 |
* of class loader creation, needed to detect the doclet class variants. |
10 | 337 |
*/ |
38614 | 338 |
@SuppressWarnings("deprecation") |
41451 | 339 |
Result begin(String... argv) { |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
340 |
// Preprocess @file arguments |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
341 |
try { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
342 |
argv = CommandLine.parse(argv); |
45742 | 343 |
return begin(Arrays.asList(argv), Collections.emptySet()); |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
344 |
} catch (IOException e) { |
41451 | 345 |
error("main.cant.read", e.getMessage()); |
346 |
return ERROR; |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
347 |
} |
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
348 |
} |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
349 |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
350 |
// Called by 199 API. |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
351 |
public boolean begin(Class<?> docletClass, |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
352 |
Iterable<String> options, |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
353 |
Iterable<? extends JavaFileObject> fileObjects) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
354 |
this.docletClass = docletClass; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
355 |
List<String> opts = new ArrayList<>(); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
356 |
for (String opt: options) |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
357 |
opts.add(opt); |
37750
d213951c811b
8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents:
37393
diff
changeset
|
358 |
|
41451 | 359 |
return begin(opts, fileObjects).isOK(); |
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
360 |
} |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
361 |
|
38614 | 362 |
@SuppressWarnings("deprecation") |
41451 | 363 |
private Result begin(List<String> options, Iterable<? extends JavaFileObject> fileObjects) { |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
364 |
fileManager = context.get(JavaFileManager.class); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
365 |
if (fileManager == null) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
366 |
JavacFileManager.preRegister(context); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
367 |
fileManager = context.get(JavaFileManager.class); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
368 |
if (fileManager instanceof BaseFileManager) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
369 |
((BaseFileManager) fileManager).autoClose = true; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
370 |
} |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
371 |
} |
41451 | 372 |
|
37750
d213951c811b
8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents:
37393
diff
changeset
|
373 |
// locale, doclet and maybe taglet, needs to be determined first |
41451 | 374 |
try { |
375 |
docletClass = preprocess(fileManager, options); |
|
376 |
} catch (ToolException te) { |
|
377 |
if (!te.result.isOK()) { |
|
378 |
if (te.message != null) { |
|
379 |
messager.printError(te.message); |
|
380 |
} |
|
381 |
Throwable t = te.getCause(); |
|
382 |
dumpStack(t == null ? te : t); |
|
383 |
} |
|
384 |
return te.result; |
|
385 |
} catch (OptionException oe) { |
|
386 |
if (oe.message != null) { |
|
387 |
messager.printError(oe.message); |
|
388 |
} |
|
389 |
oe.m.run(); |
|
390 |
Throwable t = oe.getCause(); |
|
391 |
dumpStack(t == null ? oe : t); |
|
392 |
return oe.result; |
|
393 |
} |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
394 |
if (jdk.javadoc.doclet.Doclet.class.isAssignableFrom(docletClass)) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
395 |
// no need to dispatch to old, safe to init now |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
396 |
initMessager(); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
397 |
messager.setLocale(locale); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
398 |
try { |
38918
bf1ed1a40f5b
8155880: Fix langtools usage of the deprecated Class.newInstance method
darcy
parents:
38617
diff
changeset
|
399 |
Object o = docletClass.getConstructor().newInstance(); |
37759
f0b5daef41b6
8155516: Suppress warnings from uses of deprecated Class.newInstance langtools
darcy
parents:
37757
diff
changeset
|
400 |
doclet = (Doclet) o; |
38918
bf1ed1a40f5b
8155880: Fix langtools usage of the deprecated Class.newInstance method
darcy
parents:
38617
diff
changeset
|
401 |
} catch (ReflectiveOperationException exc) { |
41451 | 402 |
if (apiMode) { |
403 |
throw new ClientCodeException(exc); |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
404 |
} |
41451 | 405 |
error("main.could_not_instantiate_class", docletClass); |
406 |
return ERROR; |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
407 |
} |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
408 |
} else { |
41451 | 409 |
if (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
|
410 |
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
|
411 |
= new com.sun.tools.javadoc.main.Start(context); |
41451 | 412 |
return ostart.begin(docletClass, options, fileObjects) |
413 |
? OK |
|
414 |
: ERROR; |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
415 |
} |
37750
d213951c811b
8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents:
37393
diff
changeset
|
416 |
warn("main.legacy_api"); |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
417 |
String[] array = options.toArray(new String[options.size()]); |
42260
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41990
diff
changeset
|
418 |
int rc = com.sun.tools.javadoc.Main.execute( |
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41990
diff
changeset
|
419 |
messager.programName, |
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41990
diff
changeset
|
420 |
messager.getWriter(WriterKind.ERROR), |
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41990
diff
changeset
|
421 |
messager.getWriter(WriterKind.WARNING), |
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41990
diff
changeset
|
422 |
messager.getWriter(WriterKind.NOTICE), |
45742 | 423 |
docletClass.getName(), |
42260
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41990
diff
changeset
|
424 |
array); |
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41990
diff
changeset
|
425 |
return (rc == 0) ? OK : ERROR; |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
426 |
} |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
427 |
|
41451 | 428 |
Result result = OK; |
10 | 429 |
try { |
44020
ef5f709f4fd8
8175055: Errors reported by Arguments.validate should (probably) be fatal
ksrini
parents:
42828
diff
changeset
|
430 |
result = parseAndExecute(options, fileObjects); |
42260
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41990
diff
changeset
|
431 |
} catch (com.sun.tools.javac.main.Option.InvalidValueException e) { |
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41990
diff
changeset
|
432 |
messager.printError(e.getMessage()); |
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41990
diff
changeset
|
433 |
Throwable t = e.getCause(); |
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41990
diff
changeset
|
434 |
dumpStack(t == null ? e : t); |
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41990
diff
changeset
|
435 |
return ERROR; |
41451 | 436 |
} catch (OptionException toe) { |
437 |
if (toe.message != null) |
|
438 |
messager.printError(toe.message); |
|
439 |
||
440 |
toe.m.run(); |
|
441 |
Throwable t = toe.getCause(); |
|
442 |
dumpStack(t == null ? toe : t); |
|
443 |
return toe.result; |
|
444 |
} catch (ToolException exc) { |
|
445 |
if (exc.message != null) { |
|
446 |
messager.printError(exc.message); |
|
447 |
} |
|
448 |
Throwable t = exc.getCause(); |
|
449 |
if (result == ABNORMAL) { |
|
450 |
reportInternalError(t == null ? exc : t); |
|
451 |
} else { |
|
452 |
dumpStack(t == null ? exc : t); |
|
453 |
} |
|
454 |
return exc.result; |
|
10 | 455 |
} catch (OutOfMemoryError ee) { |
41451 | 456 |
error("main.out.of.memory"); |
457 |
result = SYSERR; |
|
458 |
dumpStack(ee); |
|
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
459 |
} catch (ClientCodeException e) { |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
460 |
// 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
|
461 |
throw e; |
41451 | 462 |
} catch (Error | Exception ee) { |
463 |
error("main.fatal.error", ee); |
|
464 |
reportInternalError(ee); |
|
465 |
result = ABNORMAL; |
|
10 | 466 |
} finally { |
27379
5ae894733e09
8062579: JavacTask, DocumentationTask impls should close file manager when possible
jjg
parents:
27320
diff
changeset
|
467 |
if (fileManager != null |
5ae894733e09
8062579: JavacTask, DocumentationTask impls should close file manager when possible
jjg
parents:
27320
diff
changeset
|
468 |
&& fileManager instanceof BaseFileManager |
5ae894733e09
8062579: JavacTask, DocumentationTask impls should close file manager when possible
jjg
parents:
27320
diff
changeset
|
469 |
&& ((BaseFileManager) fileManager).autoClose) { |
27320
f0739350a62d
8062504: javadoc Start does not close file managers that it opens
jjg
parents:
25874
diff
changeset
|
470 |
try { |
f0739350a62d
8062504: javadoc Start does not close file managers that it opens
jjg
parents:
25874
diff
changeset
|
471 |
fileManager.close(); |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
472 |
} catch (IOException ignore) {} |
27320
f0739350a62d
8062504: javadoc Start does not close file managers that it opens
jjg
parents:
25874
diff
changeset
|
473 |
} |
41451 | 474 |
boolean haveErrorWarnings = messager.hasErrors() |
475 |
|| (rejectWarnings && messager.hasWarnings()); |
|
476 |
if (!result.isOK() && !haveErrorWarnings) { |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
477 |
// the doclet failed, but nothing reported, flag it!. |
41451 | 478 |
error("main.unknown.error"); |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
479 |
} |
41451 | 480 |
if (haveErrorWarnings && result.isOK()) { |
481 |
result = ERROR; |
|
482 |
} |
|
483 |
messager.printErrorWarningCounts(); |
|
10 | 484 |
messager.flush(); |
485 |
} |
|
41451 | 486 |
return result; |
487 |
} |
|
488 |
||
489 |
private void reportInternalError(Throwable t) { |
|
490 |
messager.printErrorUsingKey("doclet.internal.report.bug"); |
|
491 |
dumpStack(true, t); |
|
492 |
} |
|
493 |
||
494 |
private void dumpStack(Throwable t) { |
|
495 |
dumpStack(false, t); |
|
496 |
} |
|
497 |
||
498 |
private void dumpStack(boolean enabled, Throwable t) { |
|
499 |
if (t != null && (enabled || dumpOnError)) { |
|
500 |
t.printStackTrace(System.err); |
|
501 |
} |
|
10 | 502 |
} |
503 |
||
504 |
/** |
|
505 |
* Main program - internal |
|
506 |
*/ |
|
40508
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40308
diff
changeset
|
507 |
@SuppressWarnings("unchecked") |
44020
ef5f709f4fd8
8175055: Errors reported by Arguments.validate should (probably) be fatal
ksrini
parents:
42828
diff
changeset
|
508 |
private Result parseAndExecute(List<String> argList, Iterable<? extends JavaFileObject> fileObjects) |
42260
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41990
diff
changeset
|
509 |
throws ToolException, OptionException, com.sun.tools.javac.main.Option.InvalidValueException { |
10 | 510 |
long tm = System.currentTimeMillis(); |
511 |
||
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
512 |
List<String> javaNames = new ArrayList<>(); |
5850
6f095ff5b469
6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents:
5520
diff
changeset
|
513 |
|
14543 | 514 |
compOpts = Options.instance(context); |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
515 |
|
19508
e2cd0ed6c9b0
8011043: Warn about use of 1.5 and earlier source and target values
darcy
parents:
18005
diff
changeset
|
516 |
// Make sure no obsolete source/target messages are reported |
42260
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41990
diff
changeset
|
517 |
try { |
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41990
diff
changeset
|
518 |
com.sun.tools.javac.main.Option.XLINT_CUSTOM.process(getOptionHelper(), "-Xlint:-options"); |
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41990
diff
changeset
|
519 |
} catch (com.sun.tools.javac.main.Option.InvalidValueException ignore) { |
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41990
diff
changeset
|
520 |
} |
10 | 521 |
|
44450
eb4f067bae4c
8175277: javadoc AssertionError when specified with release 8
ksrini
parents:
44189
diff
changeset
|
522 |
Arguments arguments = Arguments.instance(context); |
eb4f067bae4c
8175277: javadoc AssertionError when specified with release 8
ksrini
parents:
44189
diff
changeset
|
523 |
arguments.init(ProgramName); |
eb4f067bae4c
8175277: javadoc AssertionError when specified with release 8
ksrini
parents:
44189
diff
changeset
|
524 |
arguments.allowEmpty(); |
eb4f067bae4c
8175277: javadoc AssertionError when specified with release 8
ksrini
parents:
44189
diff
changeset
|
525 |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
526 |
doclet.init(locale, messager); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
527 |
parseArgs(argList, javaNames); |
14543 | 528 |
|
44450
eb4f067bae4c
8175277: javadoc AssertionError when specified with release 8
ksrini
parents:
44189
diff
changeset
|
529 |
if (!arguments.handleReleaseOptions(extra -> true)) { |
eb4f067bae4c
8175277: javadoc AssertionError when specified with release 8
ksrini
parents:
44189
diff
changeset
|
530 |
// Arguments does not always increase the error count in the |
eb4f067bae4c
8175277: javadoc AssertionError when specified with release 8
ksrini
parents:
44189
diff
changeset
|
531 |
// case of errors, so increment the error count only if it has |
eb4f067bae4c
8175277: javadoc AssertionError when specified with release 8
ksrini
parents:
44189
diff
changeset
|
532 |
// not been updated previously, preventing complaints by callers |
eb4f067bae4c
8175277: javadoc AssertionError when specified with release 8
ksrini
parents:
44189
diff
changeset
|
533 |
if (!messager.hasErrors() && !messager.hasWarnings()) |
eb4f067bae4c
8175277: javadoc AssertionError when specified with release 8
ksrini
parents:
44189
diff
changeset
|
534 |
messager.nerrors++; |
eb4f067bae4c
8175277: javadoc AssertionError when specified with release 8
ksrini
parents:
44189
diff
changeset
|
535 |
return CMDERR; |
eb4f067bae4c
8175277: javadoc AssertionError when specified with release 8
ksrini
parents:
44189
diff
changeset
|
536 |
} |
eb4f067bae4c
8175277: javadoc AssertionError when specified with release 8
ksrini
parents:
44189
diff
changeset
|
537 |
|
44020
ef5f709f4fd8
8175055: Errors reported by Arguments.validate should (probably) be fatal
ksrini
parents:
42828
diff
changeset
|
538 |
if (!arguments.validate()) { |
ef5f709f4fd8
8175055: Errors reported by Arguments.validate should (probably) be fatal
ksrini
parents:
42828
diff
changeset
|
539 |
// Arguments does not always increase the error count in the |
ef5f709f4fd8
8175055: Errors reported by Arguments.validate should (probably) be fatal
ksrini
parents:
42828
diff
changeset
|
540 |
// case of errors, so increment the error count only if it has |
ef5f709f4fd8
8175055: Errors reported by Arguments.validate should (probably) be fatal
ksrini
parents:
42828
diff
changeset
|
541 |
// not been updated previously, preventing complaints by callers |
ef5f709f4fd8
8175055: Errors reported by Arguments.validate should (probably) be fatal
ksrini
parents:
42828
diff
changeset
|
542 |
if (!messager.hasErrors() && !messager.hasWarnings()) |
ef5f709f4fd8
8175055: Errors reported by Arguments.validate should (probably) be fatal
ksrini
parents:
42828
diff
changeset
|
543 |
messager.nerrors++; |
ef5f709f4fd8
8175055: Errors reported by Arguments.validate should (probably) be fatal
ksrini
parents:
42828
diff
changeset
|
544 |
return CMDERR; |
ef5f709f4fd8
8175055: Errors reported by Arguments.validate should (probably) be fatal
ksrini
parents:
42828
diff
changeset
|
545 |
} |
42260
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41990
diff
changeset
|
546 |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
547 |
if (fileManager instanceof BaseFileManager) { |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
548 |
((BaseFileManager) fileManager).handleOptions(fileManagerOpts); |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
549 |
} |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
550 |
|
14442 | 551 |
compOpts.notifyListeners(); |
40508
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40308
diff
changeset
|
552 |
List<String> modules = (List<String>) jdtoolOpts.computeIfAbsent(ToolOption.MODULE, |
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40308
diff
changeset
|
553 |
s -> Collections.EMPTY_LIST); |
10 | 554 |
|
40508
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40308
diff
changeset
|
555 |
if (modules.isEmpty()) { |
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40308
diff
changeset
|
556 |
List<String> subpkgs = (List<String>) jdtoolOpts.computeIfAbsent(ToolOption.SUBPACKAGES, |
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40308
diff
changeset
|
557 |
s -> Collections.EMPTY_LIST); |
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40308
diff
changeset
|
558 |
if (subpkgs.isEmpty()) { |
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40308
diff
changeset
|
559 |
if (javaNames.isEmpty() && isEmpty(fileObjects)) { |
41451 | 560 |
String text = messager.getText("main.No_modules_packages_or_classes_specified"); |
561 |
throw new ToolException(CMDERR, text); |
|
40508
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40308
diff
changeset
|
562 |
} |
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40308
diff
changeset
|
563 |
} |
10 | 564 |
} |
565 |
||
566 |
JavadocTool comp = JavadocTool.make0(context); |
|
44020
ef5f709f4fd8
8175055: Errors reported by Arguments.validate should (probably) be fatal
ksrini
parents:
42828
diff
changeset
|
567 |
if (comp == null) return ABNORMAL; |
10 | 568 |
|
40508
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40308
diff
changeset
|
569 |
DocletEnvironment docEnv = comp.getEnvironment(jdtoolOpts, |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
570 |
javaNames, |
40508
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40308
diff
changeset
|
571 |
fileObjects); |
10 | 572 |
|
14441
6c066a762e05
8002146: javadoc doesn't release resources in a timely manner
jjg
parents:
14260
diff
changeset
|
573 |
// release resources |
6c066a762e05
8002146: javadoc doesn't release resources in a timely manner
jjg
parents:
14260
diff
changeset
|
574 |
comp = null; |
6c066a762e05
8002146: javadoc doesn't release resources in a timely manner
jjg
parents:
14260
diff
changeset
|
575 |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
576 |
if (breakiterator || !locale.getLanguage().equals(Locale.ENGLISH.getLanguage())) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
577 |
JavacTrees trees = JavacTrees.instance(context); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
578 |
trees.setBreakIterator(BreakIterator.getSentenceInstance(locale)); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
579 |
} |
10 | 580 |
// pass off control to the doclet |
44020
ef5f709f4fd8
8175055: Errors reported by Arguments.validate should (probably) be fatal
ksrini
parents:
42828
diff
changeset
|
581 |
Result returnStatus = docEnv != null && doclet.run(docEnv) |
ef5f709f4fd8
8175055: Errors reported by Arguments.validate should (probably) be fatal
ksrini
parents:
42828
diff
changeset
|
582 |
? OK |
ef5f709f4fd8
8175055: Errors reported by Arguments.validate should (probably) be fatal
ksrini
parents:
42828
diff
changeset
|
583 |
: ERROR; |
10 | 584 |
|
585 |
// We're done. |
|
586 |
if (compOpts.get("-verbose") != null) { |
|
587 |
tm = System.currentTimeMillis() - tm; |
|
588 |
messager.notice("main.done_in", Long.toString(tm)); |
|
589 |
} |
|
590 |
||
44020
ef5f709f4fd8
8175055: Errors reported by Arguments.validate should (probably) be fatal
ksrini
parents:
42828
diff
changeset
|
591 |
return returnStatus; |
10 | 592 |
} |
593 |
||
42277 | 594 |
boolean matches(List<String> names, String arg) { |
595 |
for (String name : names) { |
|
596 |
if (StringUtils.toLowerCase(name).equals(StringUtils.toLowerCase(arg))) |
|
597 |
return true; |
|
598 |
} |
|
599 |
return false; |
|
600 |
} |
|
601 |
||
602 |
boolean matches(Doclet.Option option, String arg) { |
|
603 |
if (matches(option.getNames(), arg)) |
|
604 |
return true; |
|
605 |
int sep = arg.indexOf(':'); |
|
606 |
String targ = arg.substring(0, sep + 1); |
|
607 |
return matches(option.getNames(), targ); |
|
608 |
} |
|
609 |
||
610 |
Set<? extends Doclet.Option> docletOptions = null; |
|
41451 | 611 |
int handleDocletOptions(int idx, List<String> args, boolean isToolOption) |
612 |
throws OptionException { |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
613 |
if (docletOptions == null) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
614 |
docletOptions = doclet.getSupportedOptions(); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
615 |
} |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
616 |
String arg = args.get(idx); |
41252
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
617 |
String argBase, argVal; |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
618 |
if (arg.startsWith("--") && arg.contains("=")) { |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
619 |
int sep = arg.indexOf("="); |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
620 |
argBase = arg.substring(0, sep); |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
621 |
argVal = arg.substring(sep + 1); |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
622 |
} else { |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
623 |
argBase = arg; |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
624 |
argVal = null; |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
625 |
} |
41451 | 626 |
String text = null; |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
627 |
for (Doclet.Option opt : docletOptions) { |
42277 | 628 |
if (matches(opt, argBase)) { |
41252
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
629 |
if (argVal != null) { |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
630 |
switch (opt.getArgumentCount()) { |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
631 |
case 0: |
41451 | 632 |
text = messager.getText("main.unnecessary_arg_provided", argBase); |
633 |
throw new OptionException(ERROR, this::usage, text); |
|
41252
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
634 |
case 1: |
42277 | 635 |
opt.process(arg, Arrays.asList(argVal)); |
41252
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
636 |
break; |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
637 |
default: |
41451 | 638 |
text = messager.getText("main.only_one_argument_with_equals", argBase); |
639 |
throw new OptionException(ERROR, this::usage, text); |
|
41252
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
640 |
} |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
641 |
} else { |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
642 |
if (args.size() - idx -1 < opt.getArgumentCount()) { |
41451 | 643 |
text = messager.getText("main.requires_argument", arg); |
644 |
throw new OptionException(ERROR, this::usage, text); |
|
41252
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
645 |
} |
42277 | 646 |
opt.process(arg, args.subList(idx + 1, args.size())); |
41252
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
647 |
idx += opt.getArgumentCount(); |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
648 |
} |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
649 |
return idx; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
650 |
} |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
651 |
} |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
652 |
// check if arg is accepted by the tool before emitting error |
41451 | 653 |
if (!isToolOption) { |
654 |
text = messager.getText("main.invalid_flag", arg); |
|
655 |
throw new OptionException(ERROR, this::usage, text); |
|
656 |
} |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
657 |
return idx; |
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
658 |
} |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
659 |
|
41451 | 660 |
private Class<?> preprocess(JavaFileManager jfm, |
661 |
List<String> argv) throws ToolException, OptionException { |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
662 |
// doclet specifying arguments |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
663 |
String userDocletPath = null; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
664 |
String userDocletName = null; |
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
665 |
|
37750
d213951c811b
8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents:
37393
diff
changeset
|
666 |
// taglet specifying arguments, since tagletpath is a doclet |
d213951c811b
8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents:
37393
diff
changeset
|
667 |
// functionality, assume they are repeated and inspect all. |
d213951c811b
8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents:
37393
diff
changeset
|
668 |
List<File> userTagletPath = new ArrayList<>(); |
d213951c811b
8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents:
37393
diff
changeset
|
669 |
List<String> userTagletNames = new ArrayList<>(); |
d213951c811b
8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents:
37393
diff
changeset
|
670 |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
671 |
// 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
|
672 |
for (int i = 0 ; i < argv.size() ; i++) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
673 |
String arg = argv.get(i); |
41451 | 674 |
if (arg.equals(ToolOption.DUMPONERROR.primaryName)) { |
675 |
dumpOnError = true; |
|
676 |
} else if (arg.equals(ToolOption.LOCALE.primaryName)) { |
|
40508
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40308
diff
changeset
|
677 |
checkOneArg(argv, i++); |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
678 |
String lname = argv.get(i); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
679 |
locale = getLocale(lname); |
41252
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
680 |
} else if (arg.equals(ToolOption.DOCLET.primaryName)) { |
40508
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40308
diff
changeset
|
681 |
checkOneArg(argv, i++); |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
682 |
if (userDocletName != null) { |
41451 | 683 |
if (apiMode) { |
684 |
throw new IllegalArgumentException("More than one doclet specified (" + |
|
685 |
userDocletName + " and " + argv.get(i) + ")."); |
|
686 |
} |
|
687 |
String text = messager.getText("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
|
688 |
userDocletName, argv.get(i)); |
41451 | 689 |
throw new ToolException(CMDERR, text); |
10 | 690 |
} |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
691 |
if (docletName != null) { |
41451 | 692 |
if (apiMode) { |
693 |
throw new IllegalArgumentException("More than one doclet specified (" + |
|
694 |
docletName + " and " + argv.get(i) + ")."); |
|
695 |
} |
|
696 |
String text = messager.getText("main.more_than_one_doclet_specified_0_and_1", |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
697 |
docletName, argv.get(i)); |
41451 | 698 |
throw new ToolException(CMDERR, text); |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
699 |
} |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
700 |
userDocletName = argv.get(i); |
41252
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
701 |
} else if (arg.equals(ToolOption.DOCLETPATH.primaryName)) { |
40508
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40308
diff
changeset
|
702 |
checkOneArg(argv, i++); |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
703 |
if (userDocletPath == null) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
704 |
userDocletPath = argv.get(i); |
10 | 705 |
} else { |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
706 |
userDocletPath += File.pathSeparator + argv.get(i); |
10 | 707 |
} |
37750
d213951c811b
8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents:
37393
diff
changeset
|
708 |
} else if ("-taglet".equals(arg)) { |
d213951c811b
8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents:
37393
diff
changeset
|
709 |
userTagletNames.add(argv.get(i + 1)); |
d213951c811b
8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents:
37393
diff
changeset
|
710 |
} else if ("-tagletpath".equals(arg)) { |
d213951c811b
8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents:
37393
diff
changeset
|
711 |
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
|
712 |
userTagletPath.add(new File(pathname)); |
d213951c811b
8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents:
37393
diff
changeset
|
713 |
} |
10 | 714 |
} |
715 |
} |
|
37750
d213951c811b
8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents:
37393
diff
changeset
|
716 |
|
d213951c811b
8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents:
37393
diff
changeset
|
717 |
// Step 2: a doclet is provided, nothing more to do. |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
718 |
if (docletClass != null) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
719 |
return docletClass; |
10 | 720 |
} |
37750
d213951c811b
8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents:
37393
diff
changeset
|
721 |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
722 |
// Step 3: doclet name specified ? if so find a ClassLoader, |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
723 |
// and load it. |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
724 |
if (userDocletName != null) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
725 |
ClassLoader cl = classLoader; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
726 |
if (cl == null) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
727 |
if (!fileManager.hasLocation(DOCLET_PATH)) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
728 |
List<File> paths = new ArrayList<>(); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
729 |
if (userDocletPath != null) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
730 |
for (String pathname : userDocletPath.split(File.pathSeparator)) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
731 |
paths.add(new File(pathname)); |
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 |
try { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
735 |
((StandardJavaFileManager)fileManager).setLocation(DOCLET_PATH, paths); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
736 |
} catch (IOException ioe) { |
41451 | 737 |
if (apiMode) { |
738 |
throw new IllegalArgumentException("Could not set location for " + |
|
739 |
userDocletPath, ioe); |
|
740 |
} |
|
741 |
String text = messager.getText("main.doclet_could_not_set_location", |
|
742 |
userDocletPath); |
|
743 |
throw new ToolException(CMDERR, text, ioe); |
|
35426
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 |
cl = fileManager.getClassLoader(DOCLET_PATH); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
747 |
if (cl == null) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
748 |
// despite doclet specified on cmdline no classloader found! |
41451 | 749 |
if (apiMode) { |
750 |
throw new IllegalArgumentException("Could not obtain classloader to load " |
|
751 |
+ userDocletPath); |
|
752 |
} |
|
753 |
String text = messager.getText("main.doclet_no_classloader_found", |
|
754 |
userDocletName); |
|
755 |
throw new ToolException(CMDERR, text); |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
756 |
} |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
757 |
} |
37750
d213951c811b
8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents:
37393
diff
changeset
|
758 |
try { |
45742 | 759 |
return cl.loadClass(userDocletName); |
37750
d213951c811b
8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents:
37393
diff
changeset
|
760 |
} catch (ClassNotFoundException cnfe) { |
41451 | 761 |
if (apiMode) { |
762 |
throw new IllegalArgumentException("Cannot find doclet class " + userDocletName, |
|
763 |
cnfe); |
|
764 |
} |
|
765 |
String text = messager.getText("main.doclet_class_not_found", userDocletName); |
|
766 |
throw new ToolException(CMDERR, text, cnfe); |
|
37750
d213951c811b
8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents:
37393
diff
changeset
|
767 |
} |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
768 |
} |
37750
d213951c811b
8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents:
37393
diff
changeset
|
769 |
|
d213951c811b
8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents:
37393
diff
changeset
|
770 |
// Step 4: we have a doclet, try loading it |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
771 |
if (docletName != null) { |
44457
0cca46f400f7
8177484: The old standard doclet should be deprecated for removal.
jjg
parents:
44450
diff
changeset
|
772 |
return loadDocletClass(docletName); |
37750
d213951c811b
8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents:
37393
diff
changeset
|
773 |
} |
d213951c811b
8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents:
37393
diff
changeset
|
774 |
|
d213951c811b
8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents:
37393
diff
changeset
|
775 |
// finally |
d213951c811b
8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents:
37393
diff
changeset
|
776 |
return StdDoclet; |
d213951c811b
8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents:
37393
diff
changeset
|
777 |
} |
d213951c811b
8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents:
37393
diff
changeset
|
778 |
|
44457
0cca46f400f7
8177484: The old standard doclet should be deprecated for removal.
jjg
parents:
44450
diff
changeset
|
779 |
private Class<?> loadDocletClass(String docletName) throws ToolException { |
0cca46f400f7
8177484: The old standard doclet should be deprecated for removal.
jjg
parents:
44450
diff
changeset
|
780 |
try { |
0cca46f400f7
8177484: The old standard doclet should be deprecated for removal.
jjg
parents:
44450
diff
changeset
|
781 |
return Class.forName(docletName, true, getClass().getClassLoader()); |
0cca46f400f7
8177484: The old standard doclet should be deprecated for removal.
jjg
parents:
44450
diff
changeset
|
782 |
} catch (ClassNotFoundException cnfe) { |
0cca46f400f7
8177484: The old standard doclet should be deprecated for removal.
jjg
parents:
44450
diff
changeset
|
783 |
if (apiMode) { |
0cca46f400f7
8177484: The old standard doclet should be deprecated for removal.
jjg
parents:
44450
diff
changeset
|
784 |
throw new IllegalArgumentException("Cannot find doclet class " + docletName); |
0cca46f400f7
8177484: The old standard doclet should be deprecated for removal.
jjg
parents:
44450
diff
changeset
|
785 |
} |
0cca46f400f7
8177484: The old standard doclet should be deprecated for removal.
jjg
parents:
44450
diff
changeset
|
786 |
String text = messager.getText("main.doclet_class_not_found", docletName); |
0cca46f400f7
8177484: The old standard doclet should be deprecated for removal.
jjg
parents:
44450
diff
changeset
|
787 |
throw new ToolException(CMDERR, text, cnfe); |
0cca46f400f7
8177484: The old standard doclet should be deprecated for removal.
jjg
parents:
44450
diff
changeset
|
788 |
} |
0cca46f400f7
8177484: The old standard doclet should be deprecated for removal.
jjg
parents:
44450
diff
changeset
|
789 |
} |
0cca46f400f7
8177484: The old standard doclet should be deprecated for removal.
jjg
parents:
44450
diff
changeset
|
790 |
|
41451 | 791 |
private void parseArgs(List<String> args, List<String> javaNames) throws ToolException, |
42260
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41990
diff
changeset
|
792 |
OptionException, com.sun.tools.javac.main.Option.InvalidValueException { |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
793 |
for (int i = 0 ; i < args.size() ; i++) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
794 |
String arg = args.get(i); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
795 |
ToolOption o = ToolOption.get(arg); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
796 |
if (o != null) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
797 |
// handle a doclet argument that may be needed however |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
798 |
// 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
|
799 |
handleDocletOptions(i, args, true); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
800 |
if (o.hasArg) { |
41252
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
801 |
if (arg.startsWith("--") && arg.contains("=")) { |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
802 |
o.process(this, arg.substring(arg.indexOf('=') + 1)); |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
803 |
} else { |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
804 |
checkOneArg(args, i++); |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
805 |
o.process(this, args.get(i)); |
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40508
diff
changeset
|
806 |
} |
37393
a9ba8bd6697b
8152818: Javadoc must support module options supported by javac.
ksrini
parents:
36526
diff
changeset
|
807 |
} else if (o.hasSuffix) { |
a9ba8bd6697b
8152818: Javadoc must support module options supported by javac.
ksrini
parents:
36526
diff
changeset
|
808 |
o.process(this, arg); |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
809 |
} else { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
810 |
o.process(this); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
811 |
} |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
812 |
} else if (arg.startsWith("-XD")) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
813 |
// hidden javac options |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
814 |
String s = arg.substring("-XD".length()); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
815 |
int eq = s.indexOf('='); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
816 |
String key = (eq < 0) ? s : s.substring(0, eq); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
817 |
String value = (eq < 0) ? s : s.substring(eq+1); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
818 |
compOpts.put(key, value); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
819 |
} else if (arg.startsWith("-")) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
820 |
i = handleDocletOptions(i, args, false); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
821 |
} else { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
822 |
javaNames.add(arg); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
823 |
} |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
824 |
} |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
825 |
} |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
826 |
|
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
827 |
private <T> boolean isEmpty(Iterable<T> iter) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
828 |
return !iter.iterator().hasNext(); |
10 | 829 |
} |
830 |
||
831 |
/** |
|
40508
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40308
diff
changeset
|
832 |
* Check the one arg option. |
10 | 833 |
* Error and exit if one argument is not provided. |
834 |
*/ |
|
41451 | 835 |
private void checkOneArg(List<String> args, int index) throws OptionException { |
40508
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40308
diff
changeset
|
836 |
if ((index + 1) >= args.size() || args.get(index + 1).startsWith("-d")) { |
41451 | 837 |
String text = messager.getText("main.requires_argument", args.get(index)); |
838 |
throw new OptionException(CMDERR, this::usage, text); |
|
10 | 839 |
} |
840 |
} |
|
841 |
||
37750
d213951c811b
8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents:
37393
diff
changeset
|
842 |
void error(String key, Object... args) { |
41451 | 843 |
messager.printErrorUsingKey(key, args); |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
844 |
} |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
845 |
|
37750
d213951c811b
8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents:
37393
diff
changeset
|
846 |
void warn(String key, Object... args) { |
41451 | 847 |
messager.printWarningUsingKey(key, args); |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
848 |
} |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
849 |
|
10 | 850 |
/** |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
851 |
* Get the locale if specified on the command line |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
852 |
* else return null and if locale option is not used |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
853 |
* then return default locale. |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
854 |
*/ |
41451 | 855 |
private Locale getLocale(String localeName) throws ToolException { |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
856 |
Locale userlocale = null; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
857 |
if (localeName == null || localeName.isEmpty()) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
858 |
return Locale.getDefault(); |
10 | 859 |
} |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
860 |
int firstuscore = localeName.indexOf('_'); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
861 |
int seconduscore = -1; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
862 |
String language = null; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
863 |
String country = null; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
864 |
String variant = null; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
865 |
if (firstuscore == 2) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
866 |
language = localeName.substring(0, firstuscore); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
867 |
seconduscore = localeName.indexOf('_', firstuscore + 1); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
868 |
if (seconduscore > 0) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
869 |
if (seconduscore != firstuscore + 3 |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
870 |
|| localeName.length() <= seconduscore + 1) { |
41451 | 871 |
String text = messager.getText("main.malformed_locale_name", localeName); |
872 |
throw new ToolException(CMDERR, text); |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
873 |
} |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
874 |
country = localeName.substring(firstuscore + 1, |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
875 |
seconduscore); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
876 |
variant = localeName.substring(seconduscore + 1); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
877 |
} else if (localeName.length() == firstuscore + 3) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
878 |
country = localeName.substring(firstuscore + 1); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
879 |
} else { |
41451 | 880 |
String text = messager.getText("main.malformed_locale_name", localeName); |
881 |
throw new ToolException(CMDERR, text); |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
882 |
} |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
883 |
} else if (firstuscore == -1 && localeName.length() == 2) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
884 |
language = localeName; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
885 |
} else { |
41451 | 886 |
String text = messager.getText("main.malformed_locale_name", localeName); |
887 |
throw new ToolException(CMDERR, text); |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
888 |
} |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
889 |
userlocale = searchLocale(language, country, variant); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
890 |
if (userlocale == null) { |
41451 | 891 |
String text = messager.getText("main.illegal_locale_name", localeName); |
892 |
throw new ToolException(CMDERR, text); |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
893 |
} else { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
894 |
return userlocale; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
895 |
} |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
896 |
} |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
897 |
|
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
898 |
/** |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
899 |
* Search the locale for specified language, specified country and |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
900 |
* specified variant. |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
901 |
*/ |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
902 |
private Locale searchLocale(String language, String country, |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
903 |
String variant) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
904 |
for (Locale loc : Locale.getAvailableLocales()) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
905 |
if (loc.getLanguage().equals(language) && |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
906 |
(country == null || loc.getCountry().equals(country)) && |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
907 |
(variant == null || loc.getVariant().equals(variant))) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
908 |
return loc; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
909 |
} |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
910 |
} |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
911 |
return null; |
10 | 912 |
} |
37393
a9ba8bd6697b
8152818: Javadoc must support module options supported by javac.
ksrini
parents:
36526
diff
changeset
|
913 |
|
a9ba8bd6697b
8152818: Javadoc must support module options supported by javac.
ksrini
parents:
36526
diff
changeset
|
914 |
@Override |
a9ba8bd6697b
8152818: Javadoc must support module options supported by javac.
ksrini
parents:
36526
diff
changeset
|
915 |
OptionHelper getOptionHelper() { |
42260
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41990
diff
changeset
|
916 |
return new GrumpyHelper(messager) { |
37393
a9ba8bd6697b
8152818: Javadoc must support module options supported by javac.
ksrini
parents:
36526
diff
changeset
|
917 |
@Override |
a9ba8bd6697b
8152818: Javadoc must support module options supported by javac.
ksrini
parents:
36526
diff
changeset
|
918 |
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
|
919 |
return compOpts.get(option); |
a9ba8bd6697b
8152818: Javadoc must support module options supported by javac.
ksrini
parents:
36526
diff
changeset
|
920 |
} |
a9ba8bd6697b
8152818: Javadoc must support module options supported by javac.
ksrini
parents:
36526
diff
changeset
|
921 |
|
a9ba8bd6697b
8152818: Javadoc must support module options supported by javac.
ksrini
parents:
36526
diff
changeset
|
922 |
@Override |
a9ba8bd6697b
8152818: Javadoc must support module options supported by javac.
ksrini
parents:
36526
diff
changeset
|
923 |
public void put(String name, String value) { |
a9ba8bd6697b
8152818: Javadoc must support module options supported by javac.
ksrini
parents:
36526
diff
changeset
|
924 |
compOpts.put(name, value); |
a9ba8bd6697b
8152818: Javadoc must support module options supported by javac.
ksrini
parents:
36526
diff
changeset
|
925 |
} |
41990
ffaf4e59538a
8166379: IAE while invoking javadoc with --patch-module
ksrini
parents:
41451
diff
changeset
|
926 |
|
ffaf4e59538a
8166379: IAE while invoking javadoc with --patch-module
ksrini
parents:
41451
diff
changeset
|
927 |
@Override |
ffaf4e59538a
8166379: IAE while invoking javadoc with --patch-module
ksrini
parents:
41451
diff
changeset
|
928 |
public void remove(String name) { |
ffaf4e59538a
8166379: IAE while invoking javadoc with --patch-module
ksrini
parents:
41451
diff
changeset
|
929 |
compOpts.remove(name); |
ffaf4e59538a
8166379: IAE while invoking javadoc with --patch-module
ksrini
parents:
41451
diff
changeset
|
930 |
} |
ffaf4e59538a
8166379: IAE while invoking javadoc with --patch-module
ksrini
parents:
41451
diff
changeset
|
931 |
|
ffaf4e59538a
8166379: IAE while invoking javadoc with --patch-module
ksrini
parents:
41451
diff
changeset
|
932 |
@Override |
ffaf4e59538a
8166379: IAE while invoking javadoc with --patch-module
ksrini
parents:
41451
diff
changeset
|
933 |
public boolean handleFileManagerOption(com.sun.tools.javac.main.Option option, String value) { |
ffaf4e59538a
8166379: IAE while invoking javadoc with --patch-module
ksrini
parents:
41451
diff
changeset
|
934 |
fileManagerOpts.put(option, value); |
ffaf4e59538a
8166379: IAE while invoking javadoc with --patch-module
ksrini
parents:
41451
diff
changeset
|
935 |
return true; |
ffaf4e59538a
8166379: IAE while invoking javadoc with --patch-module
ksrini
parents:
41451
diff
changeset
|
936 |
} |
37393
a9ba8bd6697b
8152818: Javadoc must support module options supported by javac.
ksrini
parents:
36526
diff
changeset
|
937 |
}; |
a9ba8bd6697b
8152818: Javadoc must support module options supported by javac.
ksrini
parents:
36526
diff
changeset
|
938 |
} |
41451 | 939 |
|
940 |
@Override |
|
941 |
String getLocalizedMessage(String msg, Object... args) { |
|
942 |
return messager.getText(msg, args); |
|
943 |
} |
|
10 | 944 |
} |