author | jjg |
Wed, 10 Aug 2016 15:47:46 -0700 | |
changeset 40308 | 274367a99f98 |
parent 40232 | 4995ab1a4558 |
child 42260 | 2b4da2bf6660 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
36526 | 2 |
* Copyright (c) 1997, 2016, 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 |
||
37938
42baa89d2156
8075703: jdk.javadoc module exports com.sun.tools.javadoc package which contains a lot of internal API.
jjg
parents:
36526
diff
changeset
|
26 |
package com.sun.tools.javadoc.main; |
10 | 27 |
|
14258 | 28 |
import java.io.File; |
29 |
import java.io.FileNotFoundException; |
|
30 |
import java.io.IOException; |
|
31 |
import java.io.PrintWriter; |
|
31936 | 32 |
import java.nio.file.Path; |
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
33 |
import java.util.ArrayList; |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
34 |
import java.util.Collection; |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
35 |
import java.util.Collections; |
29291
076c277565f7
8073550: java* tools: replace obj.getClass hacks with Assert.checkNonNull or Objects.requireNonNull
mcimadamore
parents:
27379
diff
changeset
|
36 |
import java.util.Objects; |
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
37 |
|
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
38 |
import javax.tools.JavaFileManager; |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
39 |
import javax.tools.JavaFileObject; |
31936 | 40 |
import javax.tools.StandardJavaFileManager; |
41 |
import javax.tools.StandardLocation; |
|
14258 | 42 |
|
10 | 43 |
import com.sun.javadoc.*; |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
44 |
import com.sun.tools.javac.file.JavacFileManager; |
10 | 45 |
import com.sun.tools.javac.main.CommandLine; |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
46 |
import com.sun.tools.javac.main.Option; |
29780
8f8e54a1fa20
8076420: Consolidate javac file handling in javac.file package
jjg
parents:
29291
diff
changeset
|
47 |
import com.sun.tools.javac.file.BaseFileManager; |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
48 |
import com.sun.tools.javac.main.OptionHelper; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
49 |
import com.sun.tools.javac.main.OptionHelper.GrumpyHelper; |
31936 | 50 |
import com.sun.tools.javac.platform.PlatformDescription; |
51 |
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
|
52 |
import com.sun.tools.javac.util.ClientCodeException; |
10 | 53 |
import com.sun.tools.javac.util.Context; |
54 |
import com.sun.tools.javac.util.List; |
|
55 |
import com.sun.tools.javac.util.ListBuffer; |
|
11052 | 56 |
import com.sun.tools.javac.util.Log; |
10 | 57 |
import com.sun.tools.javac.util.Options; |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
58 |
|
10 | 59 |
import static com.sun.tools.javac.code.Flags.*; |
60 |
||
61 |
/** |
|
62 |
* Main program of Javadoc. |
|
63 |
* Previously named "Main". |
|
64 |
* |
|
14260
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
65 |
* <p><b>This is NOT part of any supported API. |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
66 |
* 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
|
67 |
* 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
|
68 |
* deletion without notice.</b> |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
69 |
* |
10 | 70 |
* @since 1.2 |
71 |
* @author Robert Field |
|
72 |
* @author Neal Gafter (rewrite) |
|
73 |
*/ |
|
38617 | 74 |
@Deprecated |
14543 | 75 |
public class Start extends ToolOption.Helper { |
14442 | 76 |
/** Context for this invocation. */ |
77 |
private final Context context; |
|
10 | 78 |
|
79 |
private final String defaultDocletClassName; |
|
1365 | 80 |
private final ClassLoader docletParentClassLoader; |
10 | 81 |
|
82 |
private static final String javadocName = "javadoc"; |
|
83 |
||
84 |
private static final String standardDocletClassName = |
|
85 |
"com.sun.tools.doclets.standard.Standard"; |
|
86 |
||
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
87 |
private final long defaultFilter = PUBLIC | PROTECTED; |
10 | 88 |
|
14442 | 89 |
private final Messager messager; |
10 | 90 |
|
91 |
private DocletInvoker docletInvoker; |
|
92 |
||
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
93 |
/** |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
94 |
* 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
|
95 |
* propagated using ClientCodeException. |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
96 |
*/ |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
97 |
private boolean apiMode; |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
98 |
|
27320
f0739350a62d
8062504: javadoc Start does not close file managers that it opens
jjg
parents:
25874
diff
changeset
|
99 |
private JavaFileManager fileManager; |
f0739350a62d
8062504: javadoc Start does not close file managers that it opens
jjg
parents:
25874
diff
changeset
|
100 |
|
37938
42baa89d2156
8075703: jdk.javadoc module exports com.sun.tools.javadoc package which contains a lot of internal API.
jjg
parents:
36526
diff
changeset
|
101 |
public Start(String programName, |
10 | 102 |
PrintWriter errWriter, |
103 |
PrintWriter warnWriter, |
|
104 |
PrintWriter noticeWriter, |
|
105 |
String defaultDocletClassName) { |
|
1365 | 106 |
this(programName, errWriter, warnWriter, noticeWriter, defaultDocletClassName, null); |
107 |
} |
|
108 |
||
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
109 |
public Start(PrintWriter pw) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
110 |
this(javadocName, pw, pw, pw, standardDocletClassName); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
111 |
} |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
112 |
|
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
113 |
public Start(String programName, |
1365 | 114 |
PrintWriter errWriter, |
115 |
PrintWriter warnWriter, |
|
116 |
PrintWriter noticeWriter, |
|
117 |
String defaultDocletClassName, |
|
118 |
ClassLoader docletParentClassLoader) { |
|
14442 | 119 |
context = new Context(); |
120 |
messager = new Messager(context, programName, errWriter, warnWriter, noticeWriter); |
|
10 | 121 |
this.defaultDocletClassName = defaultDocletClassName; |
1365 | 122 |
this.docletParentClassLoader = docletParentClassLoader; |
10 | 123 |
} |
124 |
||
37938
42baa89d2156
8075703: jdk.javadoc module exports com.sun.tools.javadoc package which contains a lot of internal API.
jjg
parents:
36526
diff
changeset
|
125 |
public Start(String programName, String defaultDocletClassName) { |
1365 | 126 |
this(programName, defaultDocletClassName, null); |
127 |
} |
|
128 |
||
37938
42baa89d2156
8075703: jdk.javadoc module exports com.sun.tools.javadoc package which contains a lot of internal API.
jjg
parents:
36526
diff
changeset
|
129 |
public Start(String programName, String defaultDocletClassName, |
1365 | 130 |
ClassLoader docletParentClassLoader) { |
14442 | 131 |
context = new Context(); |
132 |
messager = new Messager(context, programName); |
|
10 | 133 |
this.defaultDocletClassName = defaultDocletClassName; |
1365 | 134 |
this.docletParentClassLoader = docletParentClassLoader; |
135 |
} |
|
136 |
||
37938
42baa89d2156
8075703: jdk.javadoc module exports com.sun.tools.javadoc package which contains a lot of internal API.
jjg
parents:
36526
diff
changeset
|
137 |
public Start(String programName, ClassLoader docletParentClassLoader) { |
1365 | 138 |
this(programName, standardDocletClassName, docletParentClassLoader); |
10 | 139 |
} |
140 |
||
37938
42baa89d2156
8075703: jdk.javadoc module exports com.sun.tools.javadoc package which contains a lot of internal API.
jjg
parents:
36526
diff
changeset
|
141 |
public Start(String programName) { |
10 | 142 |
this(programName, standardDocletClassName); |
143 |
} |
|
144 |
||
37938
42baa89d2156
8075703: jdk.javadoc module exports com.sun.tools.javadoc package which contains a lot of internal API.
jjg
parents:
36526
diff
changeset
|
145 |
public Start(ClassLoader docletParentClassLoader) { |
1365 | 146 |
this(javadocName, docletParentClassLoader); |
147 |
} |
|
148 |
||
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
149 |
public Start() { |
10 | 150 |
this(javadocName); |
151 |
} |
|
152 |
||
14543 | 153 |
public Start(Context context) { |
29291
076c277565f7
8073550: java* tools: replace obj.getClass hacks with Assert.checkNonNull or Objects.requireNonNull
mcimadamore
parents:
27379
diff
changeset
|
154 |
this.context = Objects.requireNonNull(context); |
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
155 |
apiMode = true; |
14543 | 156 |
defaultDocletClassName = standardDocletClassName; |
157 |
docletParentClassLoader = null; |
|
158 |
||
159 |
Log log = context.get(Log.logKey); |
|
160 |
if (log instanceof Messager) |
|
161 |
messager = (Messager) log; |
|
162 |
else { |
|
40232
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
38617
diff
changeset
|
163 |
PrintWriter out = context.get(Log.errKey); |
14543 | 164 |
messager = (out == null) ? new Messager(context, javadocName) |
165 |
: new Messager(context, javadocName, out, out, out); |
|
166 |
} |
|
167 |
} |
|
168 |
||
10 | 169 |
/** |
170 |
* Usage |
|
171 |
*/ |
|
14543 | 172 |
@Override |
173 |
void usage() { |
|
174 |
usage(true); |
|
175 |
} |
|
176 |
||
18005 | 177 |
void usage(boolean exit) { |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
178 |
usage("main.usage", "-help", "main.usage.foot", exit); |
14543 | 179 |
} |
180 |
||
181 |
@Override |
|
182 |
void Xusage() { |
|
183 |
Xusage(true); |
|
10 | 184 |
} |
185 |
||
18005 | 186 |
void Xusage(boolean exit) { |
187 |
usage("main.Xusage", "-X", "main.Xusage.foot", exit); |
|
188 |
} |
|
189 |
||
190 |
private void usage(String main, String doclet, String foot, boolean exit) { |
|
191 |
// RFE: it would be better to replace the following with code to |
|
192 |
// write a header, then help for each option, then a footer. |
|
193 |
messager.notice(main); |
|
194 |
||
195 |
// let doclet print usage information (does nothing on error) |
|
196 |
if (docletInvoker != null) { |
|
197 |
// RFE: this is a pretty bad way to get the doclet to show |
|
198 |
// help info. Moreover, the output appears on stdout, |
|
199 |
// and <i>not</i> on any of the standard streams passed |
|
200 |
// to javadoc, and in particular, not to the noticeWriter |
|
201 |
// But, to fix this, we need to fix the Doclet API. |
|
202 |
docletInvoker.optionLength(doclet); |
|
203 |
} |
|
204 |
||
205 |
if (foot != null) |
|
206 |
messager.notice(foot); |
|
207 |
||
14543 | 208 |
if (exit) exit(); |
5850
6f095ff5b469
6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents:
5520
diff
changeset
|
209 |
} |
6f095ff5b469
6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents:
5520
diff
changeset
|
210 |
|
6f095ff5b469
6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents:
5520
diff
changeset
|
211 |
/** |
10 | 212 |
* Exit |
213 |
*/ |
|
214 |
private void exit() { |
|
215 |
messager.exit(); |
|
216 |
} |
|
217 |
||
218 |
||
219 |
/** |
|
220 |
* Main program - external wrapper |
|
221 |
*/ |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31936
diff
changeset
|
222 |
public int begin(String... argv) { |
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
223 |
boolean ok = begin(null, argv, Collections.<JavaFileObject> emptySet()); |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
224 |
return ok ? 0 : 1; |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
225 |
} |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
226 |
|
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
227 |
public boolean begin(Class<?> docletClass, Iterable<String> options, Iterable<? extends JavaFileObject> fileObjects) { |
22163 | 228 |
Collection<String> opts = new ArrayList<>(); |
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
229 |
for (String opt: options) opts.add(opt); |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
230 |
return begin(docletClass, opts.toArray(new String[opts.size()]), fileObjects); |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
231 |
} |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
232 |
|
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
233 |
private boolean begin(Class<?> docletClass, String[] options, Iterable<? extends JavaFileObject> fileObjects) { |
10 | 234 |
boolean failed = false; |
235 |
||
236 |
try { |
|
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
237 |
failed = !parseAndExecute(docletClass, options, fileObjects); |
14543 | 238 |
} catch (Messager.ExitJavadoc exc) { |
10 | 239 |
// ignore, we just exit this way |
240 |
} catch (OutOfMemoryError ee) { |
|
14543 | 241 |
messager.error(Messager.NOPOS, "main.out.of.memory"); |
10 | 242 |
failed = true; |
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
243 |
} catch (ClientCodeException e) { |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
244 |
// 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
|
245 |
throw e; |
10 | 246 |
} catch (Error ee) { |
11052 | 247 |
ee.printStackTrace(System.err); |
14543 | 248 |
messager.error(Messager.NOPOS, "main.fatal.error"); |
10 | 249 |
failed = true; |
250 |
} catch (Exception ee) { |
|
11052 | 251 |
ee.printStackTrace(System.err); |
14543 | 252 |
messager.error(Messager.NOPOS, "main.fatal.exception"); |
10 | 253 |
failed = true; |
254 |
} finally { |
|
27379
5ae894733e09
8062579: JavacTask, DocumentationTask impls should close file manager when possible
jjg
parents:
27320
diff
changeset
|
255 |
if (fileManager != null |
5ae894733e09
8062579: JavacTask, DocumentationTask impls should close file manager when possible
jjg
parents:
27320
diff
changeset
|
256 |
&& fileManager instanceof BaseFileManager |
5ae894733e09
8062579: JavacTask, DocumentationTask impls should close file manager when possible
jjg
parents:
27320
diff
changeset
|
257 |
&& ((BaseFileManager) fileManager).autoClose) { |
27320
f0739350a62d
8062504: javadoc Start does not close file managers that it opens
jjg
parents:
25874
diff
changeset
|
258 |
try { |
f0739350a62d
8062504: javadoc Start does not close file managers that it opens
jjg
parents:
25874
diff
changeset
|
259 |
fileManager.close(); |
f0739350a62d
8062504: javadoc Start does not close file managers that it opens
jjg
parents:
25874
diff
changeset
|
260 |
} catch (IOException ignore) { |
f0739350a62d
8062504: javadoc Start does not close file managers that it opens
jjg
parents:
25874
diff
changeset
|
261 |
} |
f0739350a62d
8062504: javadoc Start does not close file managers that it opens
jjg
parents:
25874
diff
changeset
|
262 |
} |
10 | 263 |
messager.exitNotice(); |
264 |
messager.flush(); |
|
265 |
} |
|
266 |
failed |= messager.nerrors() > 0; |
|
267 |
failed |= rejectWarnings && messager.nwarnings() > 0; |
|
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
268 |
return !failed; |
10 | 269 |
} |
270 |
||
271 |
/** |
|
272 |
* Main program - internal |
|
273 |
*/ |
|
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
274 |
private boolean parseAndExecute( |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
275 |
Class<?> docletClass, |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
276 |
String[] argv, |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
277 |
Iterable<? extends JavaFileObject> fileObjects) throws IOException { |
10 | 278 |
long tm = System.currentTimeMillis(); |
279 |
||
22163 | 280 |
ListBuffer<String> javaNames = new ListBuffer<>(); |
10 | 281 |
|
282 |
// Preprocess @file arguments |
|
283 |
try { |
|
284 |
argv = CommandLine.parse(argv); |
|
285 |
} catch (FileNotFoundException e) { |
|
14543 | 286 |
messager.error(Messager.NOPOS, "main.cant.read", e.getMessage()); |
10 | 287 |
exit(); |
288 |
} catch (IOException e) { |
|
11052 | 289 |
e.printStackTrace(System.err); |
10 | 290 |
exit(); |
291 |
} |
|
292 |
||
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
293 |
|
27320
f0739350a62d
8062504: javadoc Start does not close file managers that it opens
jjg
parents:
25874
diff
changeset
|
294 |
fileManager = context.get(JavaFileManager.class); |
f0739350a62d
8062504: javadoc Start does not close file managers that it opens
jjg
parents:
25874
diff
changeset
|
295 |
|
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
296 |
setDocletInvoker(docletClass, fileManager, argv); |
5850
6f095ff5b469
6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents:
5520
diff
changeset
|
297 |
|
14543 | 298 |
compOpts = Options.instance(context); |
19508
e2cd0ed6c9b0
8011043: Warn about use of 1.5 and earlier source and target values
darcy
parents:
18005
diff
changeset
|
299 |
// Make sure no obsolete source/target messages are reported |
e2cd0ed6c9b0
8011043: Warn about use of 1.5 and earlier source and target values
darcy
parents:
18005
diff
changeset
|
300 |
compOpts.put("-Xlint:-options", "-Xlint:-options"); |
10 | 301 |
|
302 |
// Parse arguments |
|
303 |
for (int i = 0 ; i < argv.length ; i++) { |
|
304 |
String arg = argv[i]; |
|
14543 | 305 |
|
306 |
ToolOption o = ToolOption.get(arg); |
|
307 |
if (o != null) { |
|
308 |
// hack: this restriction should be removed |
|
309 |
if (o == ToolOption.LOCALE && i > 0) |
|
310 |
usageError("main.locale_first"); |
|
311 |
||
312 |
if (o.hasArg) { |
|
313 |
oneArg(argv, i++); |
|
314 |
o.process(this, argv[i]); |
|
315 |
} else { |
|
316 |
setOption(arg); |
|
317 |
o.process(this); |
|
10 | 318 |
} |
36526 | 319 |
} else if (arg.equals("-XDaccessInternalAPI")) { |
320 |
// pass this hidden option down to the doclet, if it wants it |
|
321 |
if (docletInvoker.optionLength("-XDaccessInternalAPI") == 1) { |
|
322 |
setOption(arg); |
|
323 |
} |
|
10 | 324 |
} else if (arg.startsWith("-XD")) { |
14543 | 325 |
// hidden javac options |
10 | 326 |
String s = arg.substring("-XD".length()); |
327 |
int eq = s.indexOf('='); |
|
328 |
String key = (eq < 0) ? s : s.substring(0, eq); |
|
329 |
String value = (eq < 0) ? s : s.substring(eq+1); |
|
330 |
compOpts.put(key, value); |
|
331 |
} |
|
332 |
// call doclet for its options |
|
333 |
// other arg starts with - is invalid |
|
14543 | 334 |
else if (arg.startsWith("-")) { |
10 | 335 |
int optionLength; |
336 |
optionLength = docletInvoker.optionLength(arg); |
|
337 |
if (optionLength < 0) { |
|
338 |
// error already displayed |
|
339 |
exit(); |
|
340 |
} else if (optionLength == 0) { |
|
341 |
// option not found |
|
342 |
usageError("main.invalid_flag", arg); |
|
343 |
} else { |
|
344 |
// doclet added option |
|
345 |
if ((i + optionLength) > argv.length) { |
|
346 |
usageError("main.requires_argument", arg); |
|
347 |
} |
|
22163 | 348 |
ListBuffer<String> args = new ListBuffer<>(); |
10 | 349 |
for (int j = 0; j < optionLength-1; ++j) { |
350 |
args.append(argv[++i]); |
|
351 |
} |
|
352 |
setOption(arg, args.toList()); |
|
353 |
} |
|
354 |
} else { |
|
355 |
javaNames.append(arg); |
|
356 |
} |
|
357 |
} |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
358 |
|
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
359 |
if (fileManager == null) { |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
360 |
JavacFileManager.preRegister(context); |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
361 |
fileManager = context.get(JavaFileManager.class); |
27379
5ae894733e09
8062579: JavacTask, DocumentationTask impls should close file manager when possible
jjg
parents:
27320
diff
changeset
|
362 |
if (fileManager instanceof BaseFileManager) { |
5ae894733e09
8062579: JavacTask, DocumentationTask impls should close file manager when possible
jjg
parents:
27320
diff
changeset
|
363 |
((BaseFileManager) fileManager).autoClose = true; |
5ae894733e09
8062579: JavacTask, DocumentationTask impls should close file manager when possible
jjg
parents:
27320
diff
changeset
|
364 |
} |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
365 |
} |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
366 |
if (fileManager instanceof BaseFileManager) { |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
367 |
((BaseFileManager) fileManager).handleOptions(fileManagerOpts); |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
368 |
} |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
369 |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
370 |
String platformString = compOpts.get("--release"); |
31936 | 371 |
|
372 |
if (platformString != null) { |
|
373 |
if (compOpts.isSet("-source")) { |
|
374 |
usageError("main.release.bootclasspath.conflict", "-source"); |
|
375 |
} |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
376 |
if (fileManagerOpts.containsKey(Option.BOOT_CLASS_PATH)) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
377 |
usageError("main.release.bootclasspath.conflict", Option.BOOT_CLASS_PATH.getPrimaryName()); |
31936 | 378 |
} |
379 |
||
380 |
PlatformDescription platformDescription = |
|
381 |
PlatformUtils.lookupPlatformDescription(platformString); |
|
382 |
||
383 |
if (platformDescription == null) { |
|
384 |
usageError("main.unsupported.release.version", platformString); |
|
385 |
} |
|
386 |
||
387 |
compOpts.put(Option.SOURCE, platformDescription.getSourceVersion()); |
|
388 |
||
389 |
context.put(PlatformDescription.class, platformDescription); |
|
390 |
||
391 |
Collection<Path> platformCP = platformDescription.getPlatformPath(); |
|
392 |
||
393 |
if (platformCP != null) { |
|
394 |
if (fileManager instanceof StandardJavaFileManager) { |
|
395 |
StandardJavaFileManager sfm = (StandardJavaFileManager) fileManager; |
|
396 |
||
397 |
sfm.setLocationFromPaths(StandardLocation.PLATFORM_CLASS_PATH, platformCP); |
|
398 |
} else { |
|
399 |
usageError("main.release.not.standard.file.manager", platformString); |
|
400 |
} |
|
401 |
} |
|
402 |
} |
|
403 |
||
14442 | 404 |
compOpts.notifyListeners(); |
10 | 405 |
|
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
406 |
if (javaNames.isEmpty() && subPackages.isEmpty() && isEmpty(fileObjects)) { |
10 | 407 |
usageError("main.No_packages_or_classes_specified"); |
408 |
} |
|
409 |
||
410 |
if (!docletInvoker.validOptions(options.toList())) { |
|
411 |
// error message already displayed |
|
412 |
exit(); |
|
413 |
} |
|
414 |
||
415 |
JavadocTool comp = JavadocTool.make0(context); |
|
416 |
if (comp == null) return false; |
|
417 |
||
418 |
if (showAccess == null) { |
|
419 |
setFilter(defaultFilter); |
|
420 |
} |
|
421 |
||
422 |
LanguageVersion languageVersion = docletInvoker.languageVersion(); |
|
423 |
RootDocImpl root = comp.getRootDocImpl( |
|
14543 | 424 |
docLocale, |
425 |
encoding, |
|
426 |
showAccess, |
|
427 |
javaNames.toList(), |
|
428 |
options.toList(), |
|
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
429 |
fileObjects, |
14543 | 430 |
breakiterator, |
431 |
subPackages.toList(), |
|
432 |
excludedPackages.toList(), |
|
10 | 433 |
docClasses, |
434 |
// legacy? |
|
14543 | 435 |
languageVersion == null || languageVersion == LanguageVersion.JAVA_1_1, |
436 |
quiet); |
|
10 | 437 |
|
14441
6c066a762e05
8002146: javadoc doesn't release resources in a timely manner
jjg
parents:
14260
diff
changeset
|
438 |
// release resources |
6c066a762e05
8002146: javadoc doesn't release resources in a timely manner
jjg
parents:
14260
diff
changeset
|
439 |
comp = null; |
6c066a762e05
8002146: javadoc doesn't release resources in a timely manner
jjg
parents:
14260
diff
changeset
|
440 |
|
10 | 441 |
// pass off control to the doclet |
442 |
boolean ok = root != null; |
|
443 |
if (ok) ok = docletInvoker.start(root); |
|
444 |
||
445 |
// We're done. |
|
446 |
if (compOpts.get("-verbose") != null) { |
|
447 |
tm = System.currentTimeMillis() - tm; |
|
448 |
messager.notice("main.done_in", Long.toString(tm)); |
|
449 |
} |
|
450 |
||
451 |
return ok; |
|
452 |
} |
|
453 |
||
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
454 |
private <T> boolean isEmpty(Iterable<T> iter) { |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
455 |
return !iter.iterator().hasNext(); |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
456 |
} |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
457 |
|
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
458 |
/** |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
459 |
* Init the doclet invoker. |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
460 |
* The doclet class may be given explicitly, or via the -doclet option in |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
461 |
* argv. |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
462 |
* If the doclet class is not given explicitly, it will be loaded from |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
463 |
* the file manager's DOCLET_PATH location, if available, or via the |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
464 |
* -doclet path option in argv. |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
465 |
* @param docletClass The doclet class. May be null. |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
466 |
* @param fileManager The file manager used to get the class loader to load |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
467 |
* the doclet class if required. May be null. |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
468 |
* @param argv Args containing -doclet and -docletpath, in case they are required. |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
469 |
*/ |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
470 |
private void setDocletInvoker(Class<?> docletClass, JavaFileManager fileManager, String[] argv) { |
36526 | 471 |
boolean exportInternalAPI = false; |
10 | 472 |
String docletClassName = null; |
473 |
String docletPath = null; |
|
474 |
||
475 |
// Parse doclet specifying arguments |
|
476 |
for (int i = 0 ; i < argv.length ; i++) { |
|
477 |
String arg = argv[i]; |
|
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
478 |
if (arg.equals(ToolOption.DOCLET.opt)) { |
10 | 479 |
oneArg(argv, i++); |
480 |
if (docletClassName != null) { |
|
481 |
usageError("main.more_than_one_doclet_specified_0_and_1", |
|
482 |
docletClassName, argv[i]); |
|
483 |
} |
|
484 |
docletClassName = argv[i]; |
|
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
485 |
} else if (arg.equals(ToolOption.DOCLETPATH.opt)) { |
10 | 486 |
oneArg(argv, i++); |
487 |
if (docletPath == null) { |
|
488 |
docletPath = argv[i]; |
|
489 |
} else { |
|
490 |
docletPath += File.pathSeparator + argv[i]; |
|
491 |
} |
|
36526 | 492 |
} else if (arg.equals("-XDaccessInternalAPI")) { |
493 |
exportInternalAPI = true; |
|
10 | 494 |
} |
495 |
} |
|
496 |
||
36526 | 497 |
if (docletClass != null) { |
498 |
// TODO, check no -doclet, -docletpath |
|
499 |
docletInvoker = new DocletInvoker(messager, docletClass, apiMode, exportInternalAPI); |
|
500 |
} else { |
|
501 |
if (docletClassName == null) { |
|
502 |
docletClassName = defaultDocletClassName; |
|
503 |
} |
|
10 | 504 |
|
36526 | 505 |
// attempt to find doclet |
506 |
docletInvoker = new DocletInvoker(messager, fileManager, |
|
507 |
docletClassName, docletPath, |
|
508 |
docletParentClassLoader, |
|
509 |
apiMode, |
|
510 |
exportInternalAPI); |
|
511 |
} |
|
10 | 512 |
} |
513 |
||
514 |
/** |
|
515 |
* Set one arg option. |
|
516 |
* Error and exit if one argument is not provided. |
|
517 |
*/ |
|
518 |
private void oneArg(String[] args, int index) { |
|
519 |
if ((index + 1) < args.length) { |
|
520 |
setOption(args[index], args[index+1]); |
|
521 |
} else { |
|
522 |
usageError("main.requires_argument", args[index]); |
|
523 |
} |
|
524 |
} |
|
525 |
||
14543 | 526 |
@Override |
527 |
void usageError(String key, Object... args) { |
|
528 |
messager.error(Messager.NOPOS, key, args); |
|
529 |
usage(true); |
|
10 | 530 |
} |
531 |
||
532 |
/** |
|
533 |
* indicate an option with no arguments was given. |
|
534 |
*/ |
|
535 |
private void setOption(String opt) { |
|
536 |
String[] option = { opt }; |
|
537 |
options.append(option); |
|
538 |
} |
|
539 |
||
540 |
/** |
|
541 |
* indicate an option with one argument was given. |
|
542 |
*/ |
|
543 |
private void setOption(String opt, String argument) { |
|
544 |
String[] option = { opt, argument }; |
|
545 |
options.append(option); |
|
546 |
} |
|
547 |
||
548 |
/** |
|
549 |
* indicate an option with the specified list of arguments was given. |
|
550 |
*/ |
|
551 |
private void setOption(String opt, List<String> arguments) { |
|
552 |
String[] args = new String[arguments.length() + 1]; |
|
553 |
int k = 0; |
|
554 |
args[k++] = opt; |
|
555 |
for (List<String> i = arguments; i.nonEmpty(); i=i.tail) { |
|
556 |
args[k++] = i.head; |
|
557 |
} |
|
14543 | 558 |
options.append(args); |
10 | 559 |
} |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
560 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
561 |
@Override |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
562 |
OptionHelper getOptionHelper() { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
563 |
return new GrumpyHelper(null) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
564 |
@Override |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
565 |
public String get(com.sun.tools.javac.main.Option option) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
566 |
return compOpts.get(option); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
567 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
568 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
569 |
@Override |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
570 |
public void put(String name, String value) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
571 |
compOpts.put(name, value); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
572 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
573 |
}; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
574 |
} |
10 | 575 |
} |