author | jjg |
Sun, 18 May 2014 19:59:10 -0700 | |
changeset 24604 | 7f68545b5128 |
parent 22159 | 682da512ec17 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
14258 | 2 |
* Copyright (c) 1998, 2012, 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 |
||
26 |
package com.sun.tools.javadoc; |
|
27 |
||
8633
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
7681
diff
changeset
|
28 |
import java.io.File; |
14258 | 29 |
import java.lang.reflect.InvocationTargetException; |
10 | 30 |
import java.lang.reflect.Method; |
31 |
import java.lang.reflect.Modifier; |
|
8633
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
7681
diff
changeset
|
32 |
import java.net.URL; |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
7681
diff
changeset
|
33 |
import java.net.URLClassLoader; |
10 | 34 |
|
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
35 |
import javax.tools.DocumentationTool; |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
36 |
import javax.tools.JavaFileManager; |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
37 |
|
14258 | 38 |
import com.sun.javadoc.*; |
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
39 |
import com.sun.tools.javac.file.Locations; |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
40 |
import com.sun.tools.javac.util.ClientCodeException; |
14258 | 41 |
import com.sun.tools.javac.util.List; |
42 |
import static com.sun.javadoc.LanguageVersion.*; |
|
43 |
||
10 | 44 |
|
45 |
/** |
|
46 |
* Class creates, controls and invokes doclets. |
|
14260
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
47 |
* |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
48 |
* <p><b>This is NOT part of any supported API. |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
49 |
* 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
|
50 |
* 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
|
51 |
* deletion without notice.</b> |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
52 |
* |
10 | 53 |
* @author Neal Gafter (rewrite) |
54 |
*/ |
|
55 |
public class DocletInvoker { |
|
56 |
||
868 | 57 |
private final Class<?> docletClass; |
10 | 58 |
|
59 |
private final String docletClassName; |
|
60 |
||
61 |
private final ClassLoader appClassLoader; |
|
62 |
||
63 |
private final Messager messager; |
|
64 |
||
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
65 |
/** |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
66 |
* 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
|
67 |
* propagated using ClientCodeException. |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
68 |
*/ |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
69 |
private final boolean apiMode; |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
70 |
|
10 | 71 |
private static class DocletInvokeException extends Exception { |
72 |
private static final long serialVersionUID = 0; |
|
73 |
} |
|
74 |
||
75 |
private String appendPath(String path1, String path2) { |
|
76 |
if (path1 == null || path1.length() == 0) { |
|
77 |
return path2 == null ? "." : path2; |
|
78 |
} else if (path2 == null || path2.length() == 0) { |
|
79 |
return path1; |
|
80 |
} else { |
|
81 |
return path1 + File.pathSeparator + path2; |
|
82 |
} |
|
83 |
} |
|
84 |
||
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
85 |
public DocletInvoker(Messager messager, Class<?> docletClass, boolean apiMode) { |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
86 |
this.messager = messager; |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
87 |
this.docletClass = docletClass; |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
88 |
docletClassName = docletClass.getName(); |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
89 |
appClassLoader = null; |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
90 |
this.apiMode = apiMode; |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
91 |
} |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
92 |
|
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
93 |
public DocletInvoker(Messager messager, JavaFileManager fileManager, |
1365 | 94 |
String docletClassName, String docletPath, |
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
95 |
ClassLoader docletParentClassLoader, |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
96 |
boolean apiMode) { |
10 | 97 |
this.messager = messager; |
98 |
this.docletClassName = docletClassName; |
|
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
99 |
this.apiMode = apiMode; |
10 | 100 |
|
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
101 |
if (fileManager != null && fileManager.hasLocation(DocumentationTool.Location.DOCLET_PATH)) { |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
102 |
appClassLoader = fileManager.getClassLoader(DocumentationTool.Location.DOCLET_PATH); |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
103 |
} else { |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
104 |
// construct class loader |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
105 |
String cpString = null; // make sure env.class.path defaults to dot |
10 | 106 |
|
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
107 |
// do prepends to get correct ordering |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
108 |
cpString = appendPath(System.getProperty("env.class.path"), cpString); |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
109 |
cpString = appendPath(System.getProperty("java.class.path"), cpString); |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
110 |
cpString = appendPath(docletPath, cpString); |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
111 |
URL[] urls = Locations.pathToURLs(cpString); |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
112 |
if (docletParentClassLoader == null) |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
113 |
appClassLoader = new URLClassLoader(urls, getDelegationClassLoader(docletClassName)); |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
114 |
else |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
115 |
appClassLoader = new URLClassLoader(urls, docletParentClassLoader); |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
116 |
} |
10 | 117 |
|
118 |
// attempt to find doclet |
|
1789
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1365
diff
changeset
|
119 |
Class<?> dc = null; |
10 | 120 |
try { |
121 |
dc = appClassLoader.loadClass(docletClassName); |
|
122 |
} catch (ClassNotFoundException exc) { |
|
14543 | 123 |
messager.error(Messager.NOPOS, "main.doclet_class_not_found", docletClassName); |
10 | 124 |
messager.exit(); |
125 |
} |
|
126 |
docletClass = dc; |
|
127 |
} |
|
128 |
||
1990
5d90be5d60bb
6176978: current Javadoc's invocation and extension (Doclet) mechanisms are problematic
jjg
parents:
1789
diff
changeset
|
129 |
/* |
5d90be5d60bb
6176978: current Javadoc's invocation and extension (Doclet) mechanisms are problematic
jjg
parents:
1789
diff
changeset
|
130 |
* Returns the delegation class loader to use when creating |
5d90be5d60bb
6176978: current Javadoc's invocation and extension (Doclet) mechanisms are problematic
jjg
parents:
1789
diff
changeset
|
131 |
* appClassLoader (used to load the doclet). The context class |
5d90be5d60bb
6176978: current Javadoc's invocation and extension (Doclet) mechanisms are problematic
jjg
parents:
1789
diff
changeset
|
132 |
* loader is the best choice, but legacy behavior was to use the |
5d90be5d60bb
6176978: current Javadoc's invocation and extension (Doclet) mechanisms are problematic
jjg
parents:
1789
diff
changeset
|
133 |
* default delegation class loader (aka system class loader). |
5d90be5d60bb
6176978: current Javadoc's invocation and extension (Doclet) mechanisms are problematic
jjg
parents:
1789
diff
changeset
|
134 |
* |
5d90be5d60bb
6176978: current Javadoc's invocation and extension (Doclet) mechanisms are problematic
jjg
parents:
1789
diff
changeset
|
135 |
* Here we favor using the context class loader. To ensure |
5d90be5d60bb
6176978: current Javadoc's invocation and extension (Doclet) mechanisms are problematic
jjg
parents:
1789
diff
changeset
|
136 |
* compatibility with existing apps, we revert to legacy |
5d90be5d60bb
6176978: current Javadoc's invocation and extension (Doclet) mechanisms are problematic
jjg
parents:
1789
diff
changeset
|
137 |
* behavior if either or both of the following conditions hold: |
5d90be5d60bb
6176978: current Javadoc's invocation and extension (Doclet) mechanisms are problematic
jjg
parents:
1789
diff
changeset
|
138 |
* |
5d90be5d60bb
6176978: current Javadoc's invocation and extension (Doclet) mechanisms are problematic
jjg
parents:
1789
diff
changeset
|
139 |
* 1) the doclet is loadable from the system class loader but not |
5d90be5d60bb
6176978: current Javadoc's invocation and extension (Doclet) mechanisms are problematic
jjg
parents:
1789
diff
changeset
|
140 |
* from the context class loader, |
5d90be5d60bb
6176978: current Javadoc's invocation and extension (Doclet) mechanisms are problematic
jjg
parents:
1789
diff
changeset
|
141 |
* |
5d90be5d60bb
6176978: current Javadoc's invocation and extension (Doclet) mechanisms are problematic
jjg
parents:
1789
diff
changeset
|
142 |
* 2) this.getClass() is loadable from the system class loader but not |
5d90be5d60bb
6176978: current Javadoc's invocation and extension (Doclet) mechanisms are problematic
jjg
parents:
1789
diff
changeset
|
143 |
* from the context class loader. |
5d90be5d60bb
6176978: current Javadoc's invocation and extension (Doclet) mechanisms are problematic
jjg
parents:
1789
diff
changeset
|
144 |
*/ |
5d90be5d60bb
6176978: current Javadoc's invocation and extension (Doclet) mechanisms are problematic
jjg
parents:
1789
diff
changeset
|
145 |
private ClassLoader getDelegationClassLoader(String docletClassName) { |
5d90be5d60bb
6176978: current Javadoc's invocation and extension (Doclet) mechanisms are problematic
jjg
parents:
1789
diff
changeset
|
146 |
ClassLoader ctxCL = Thread.currentThread().getContextClassLoader(); |
5d90be5d60bb
6176978: current Javadoc's invocation and extension (Doclet) mechanisms are problematic
jjg
parents:
1789
diff
changeset
|
147 |
ClassLoader sysCL = ClassLoader.getSystemClassLoader(); |
5d90be5d60bb
6176978: current Javadoc's invocation and extension (Doclet) mechanisms are problematic
jjg
parents:
1789
diff
changeset
|
148 |
if (sysCL == null) |
5d90be5d60bb
6176978: current Javadoc's invocation and extension (Doclet) mechanisms are problematic
jjg
parents:
1789
diff
changeset
|
149 |
return ctxCL; |
5d90be5d60bb
6176978: current Javadoc's invocation and extension (Doclet) mechanisms are problematic
jjg
parents:
1789
diff
changeset
|
150 |
if (ctxCL == null) |
5d90be5d60bb
6176978: current Javadoc's invocation and extension (Doclet) mechanisms are problematic
jjg
parents:
1789
diff
changeset
|
151 |
return sysCL; |
5d90be5d60bb
6176978: current Javadoc's invocation and extension (Doclet) mechanisms are problematic
jjg
parents:
1789
diff
changeset
|
152 |
|
5d90be5d60bb
6176978: current Javadoc's invocation and extension (Doclet) mechanisms are problematic
jjg
parents:
1789
diff
changeset
|
153 |
// Condition 1. |
5d90be5d60bb
6176978: current Javadoc's invocation and extension (Doclet) mechanisms are problematic
jjg
parents:
1789
diff
changeset
|
154 |
try { |
5d90be5d60bb
6176978: current Javadoc's invocation and extension (Doclet) mechanisms are problematic
jjg
parents:
1789
diff
changeset
|
155 |
sysCL.loadClass(docletClassName); |
5d90be5d60bb
6176978: current Javadoc's invocation and extension (Doclet) mechanisms are problematic
jjg
parents:
1789
diff
changeset
|
156 |
try { |
5d90be5d60bb
6176978: current Javadoc's invocation and extension (Doclet) mechanisms are problematic
jjg
parents:
1789
diff
changeset
|
157 |
ctxCL.loadClass(docletClassName); |
5d90be5d60bb
6176978: current Javadoc's invocation and extension (Doclet) mechanisms are problematic
jjg
parents:
1789
diff
changeset
|
158 |
} catch (ClassNotFoundException e) { |
5d90be5d60bb
6176978: current Javadoc's invocation and extension (Doclet) mechanisms are problematic
jjg
parents:
1789
diff
changeset
|
159 |
return sysCL; |
5d90be5d60bb
6176978: current Javadoc's invocation and extension (Doclet) mechanisms are problematic
jjg
parents:
1789
diff
changeset
|
160 |
} |
5d90be5d60bb
6176978: current Javadoc's invocation and extension (Doclet) mechanisms are problematic
jjg
parents:
1789
diff
changeset
|
161 |
} catch (ClassNotFoundException e) { |
5d90be5d60bb
6176978: current Javadoc's invocation and extension (Doclet) mechanisms are problematic
jjg
parents:
1789
diff
changeset
|
162 |
} |
5d90be5d60bb
6176978: current Javadoc's invocation and extension (Doclet) mechanisms are problematic
jjg
parents:
1789
diff
changeset
|
163 |
|
5d90be5d60bb
6176978: current Javadoc's invocation and extension (Doclet) mechanisms are problematic
jjg
parents:
1789
diff
changeset
|
164 |
// Condition 2. |
5d90be5d60bb
6176978: current Javadoc's invocation and extension (Doclet) mechanisms are problematic
jjg
parents:
1789
diff
changeset
|
165 |
try { |
5d90be5d60bb
6176978: current Javadoc's invocation and extension (Doclet) mechanisms are problematic
jjg
parents:
1789
diff
changeset
|
166 |
if (getClass() == sysCL.loadClass(getClass().getName())) { |
5d90be5d60bb
6176978: current Javadoc's invocation and extension (Doclet) mechanisms are problematic
jjg
parents:
1789
diff
changeset
|
167 |
try { |
5d90be5d60bb
6176978: current Javadoc's invocation and extension (Doclet) mechanisms are problematic
jjg
parents:
1789
diff
changeset
|
168 |
if (getClass() != ctxCL.loadClass(getClass().getName())) |
5d90be5d60bb
6176978: current Javadoc's invocation and extension (Doclet) mechanisms are problematic
jjg
parents:
1789
diff
changeset
|
169 |
return sysCL; |
5d90be5d60bb
6176978: current Javadoc's invocation and extension (Doclet) mechanisms are problematic
jjg
parents:
1789
diff
changeset
|
170 |
} catch (ClassNotFoundException e) { |
5d90be5d60bb
6176978: current Javadoc's invocation and extension (Doclet) mechanisms are problematic
jjg
parents:
1789
diff
changeset
|
171 |
return sysCL; |
5d90be5d60bb
6176978: current Javadoc's invocation and extension (Doclet) mechanisms are problematic
jjg
parents:
1789
diff
changeset
|
172 |
} |
5d90be5d60bb
6176978: current Javadoc's invocation and extension (Doclet) mechanisms are problematic
jjg
parents:
1789
diff
changeset
|
173 |
} |
5d90be5d60bb
6176978: current Javadoc's invocation and extension (Doclet) mechanisms are problematic
jjg
parents:
1789
diff
changeset
|
174 |
} catch (ClassNotFoundException e) { |
5d90be5d60bb
6176978: current Javadoc's invocation and extension (Doclet) mechanisms are problematic
jjg
parents:
1789
diff
changeset
|
175 |
} |
5d90be5d60bb
6176978: current Javadoc's invocation and extension (Doclet) mechanisms are problematic
jjg
parents:
1789
diff
changeset
|
176 |
|
5d90be5d60bb
6176978: current Javadoc's invocation and extension (Doclet) mechanisms are problematic
jjg
parents:
1789
diff
changeset
|
177 |
return ctxCL; |
5d90be5d60bb
6176978: current Javadoc's invocation and extension (Doclet) mechanisms are problematic
jjg
parents:
1789
diff
changeset
|
178 |
} |
5d90be5d60bb
6176978: current Javadoc's invocation and extension (Doclet) mechanisms are problematic
jjg
parents:
1789
diff
changeset
|
179 |
|
10 | 180 |
/** |
181 |
* Generate documentation here. Return true on success. |
|
182 |
*/ |
|
183 |
public boolean start(RootDoc root) { |
|
184 |
Object retVal; |
|
185 |
String methodName = "start"; |
|
5850
6f095ff5b469
6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents:
5520
diff
changeset
|
186 |
Class<?>[] paramTypes = { RootDoc.class }; |
6f095ff5b469
6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents:
5520
diff
changeset
|
187 |
Object[] params = { root }; |
10 | 188 |
try { |
189 |
retVal = invoke(methodName, null, paramTypes, params); |
|
190 |
} catch (DocletInvokeException exc) { |
|
191 |
return false; |
|
192 |
} |
|
193 |
if (retVal instanceof Boolean) { |
|
194 |
return ((Boolean)retVal).booleanValue(); |
|
195 |
} else { |
|
14543 | 196 |
messager.error(Messager.NOPOS, "main.must_return_boolean", |
10 | 197 |
docletClassName, methodName); |
198 |
return false; |
|
199 |
} |
|
200 |
} |
|
201 |
||
202 |
/** |
|
203 |
* Check for doclet added options here. Zero return means |
|
204 |
* option not known. Positive value indicates number of |
|
205 |
* arguments to option. Negative value means error occurred. |
|
206 |
*/ |
|
207 |
public int optionLength(String option) { |
|
208 |
Object retVal; |
|
209 |
String methodName = "optionLength"; |
|
5850
6f095ff5b469
6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents:
5520
diff
changeset
|
210 |
Class<?>[] paramTypes = { String.class }; |
6f095ff5b469
6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents:
5520
diff
changeset
|
211 |
Object[] params = { option }; |
10 | 212 |
try { |
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
14545
diff
changeset
|
213 |
retVal = invoke(methodName, 0, paramTypes, params); |
10 | 214 |
} catch (DocletInvokeException exc) { |
215 |
return -1; |
|
216 |
} |
|
217 |
if (retVal instanceof Integer) { |
|
218 |
return ((Integer)retVal).intValue(); |
|
219 |
} else { |
|
14543 | 220 |
messager.error(Messager.NOPOS, "main.must_return_int", |
10 | 221 |
docletClassName, methodName); |
222 |
return -1; |
|
223 |
} |
|
224 |
} |
|
225 |
||
226 |
/** |
|
227 |
* Let doclet check that all options are OK. Returning true means |
|
228 |
* options are OK. If method does not exist, assume true. |
|
229 |
*/ |
|
230 |
public boolean validOptions(List<String[]> optlist) { |
|
231 |
Object retVal; |
|
232 |
String options[][] = optlist.toArray(new String[optlist.length()][]); |
|
233 |
String methodName = "validOptions"; |
|
234 |
DocErrorReporter reporter = messager; |
|
5850
6f095ff5b469
6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents:
5520
diff
changeset
|
235 |
Class<?>[] paramTypes = { String[][].class, DocErrorReporter.class }; |
6f095ff5b469
6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents:
5520
diff
changeset
|
236 |
Object[] params = { options, reporter }; |
10 | 237 |
try { |
238 |
retVal = invoke(methodName, Boolean.TRUE, paramTypes, params); |
|
239 |
} catch (DocletInvokeException exc) { |
|
240 |
return false; |
|
241 |
} |
|
242 |
if (retVal instanceof Boolean) { |
|
243 |
return ((Boolean)retVal).booleanValue(); |
|
244 |
} else { |
|
14543 | 245 |
messager.error(Messager.NOPOS, "main.must_return_boolean", |
10 | 246 |
docletClassName, methodName); |
247 |
return false; |
|
248 |
} |
|
249 |
} |
|
250 |
||
251 |
/** |
|
252 |
* Return the language version supported by this doclet. |
|
253 |
* If the method does not exist in the doclet, assume version 1.1. |
|
254 |
*/ |
|
255 |
public LanguageVersion languageVersion() { |
|
256 |
try { |
|
257 |
Object retVal; |
|
258 |
String methodName = "languageVersion"; |
|
1789
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1365
diff
changeset
|
259 |
Class<?>[] paramTypes = new Class<?>[0]; |
10 | 260 |
Object[] params = new Object[0]; |
261 |
try { |
|
262 |
retVal = invoke(methodName, JAVA_1_1, paramTypes, params); |
|
263 |
} catch (DocletInvokeException exc) { |
|
264 |
return JAVA_1_1; |
|
265 |
} |
|
266 |
if (retVal instanceof LanguageVersion) { |
|
267 |
return (LanguageVersion)retVal; |
|
268 |
} else { |
|
14543 | 269 |
messager.error(Messager.NOPOS, "main.must_return_languageversion", |
10 | 270 |
docletClassName, methodName); |
271 |
return JAVA_1_1; |
|
272 |
} |
|
273 |
} catch (NoClassDefFoundError ex) { // for boostrapping, no Enum class. |
|
274 |
return null; |
|
275 |
} |
|
276 |
} |
|
277 |
||
278 |
/** |
|
279 |
* Utility method for calling doclet functionality |
|
280 |
*/ |
|
281 |
private Object invoke(String methodName, Object returnValueIfNonExistent, |
|
1789
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1365
diff
changeset
|
282 |
Class<?>[] paramTypes, Object[] params) |
10 | 283 |
throws DocletInvokeException { |
284 |
Method meth; |
|
285 |
try { |
|
286 |
meth = docletClass.getMethod(methodName, paramTypes); |
|
287 |
} catch (NoSuchMethodException exc) { |
|
288 |
if (returnValueIfNonExistent == null) { |
|
14543 | 289 |
messager.error(Messager.NOPOS, "main.doclet_method_not_found", |
10 | 290 |
docletClassName, methodName); |
291 |
throw new DocletInvokeException(); |
|
292 |
} else { |
|
293 |
return returnValueIfNonExistent; |
|
294 |
} |
|
295 |
} catch (SecurityException exc) { |
|
14543 | 296 |
messager.error(Messager.NOPOS, "main.doclet_method_not_accessible", |
10 | 297 |
docletClassName, methodName); |
298 |
throw new DocletInvokeException(); |
|
299 |
} |
|
300 |
if (!Modifier.isStatic(meth.getModifiers())) { |
|
14543 | 301 |
messager.error(Messager.NOPOS, "main.doclet_method_must_be_static", |
10 | 302 |
docletClassName, methodName); |
303 |
throw new DocletInvokeException(); |
|
304 |
} |
|
1990
5d90be5d60bb
6176978: current Javadoc's invocation and extension (Doclet) mechanisms are problematic
jjg
parents:
1789
diff
changeset
|
305 |
ClassLoader savedCCL = |
5d90be5d60bb
6176978: current Javadoc's invocation and extension (Doclet) mechanisms are problematic
jjg
parents:
1789
diff
changeset
|
306 |
Thread.currentThread().getContextClassLoader(); |
10 | 307 |
try { |
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
308 |
if (appClassLoader != null) // will be null if doclet class provided via API |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
309 |
Thread.currentThread().setContextClassLoader(appClassLoader); |
10 | 310 |
return meth.invoke(null , params); |
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
14545
diff
changeset
|
311 |
} catch (IllegalArgumentException | NullPointerException exc) { |
14543 | 312 |
messager.error(Messager.NOPOS, "main.internal_error_exception_thrown", |
10 | 313 |
docletClassName, methodName, exc.toString()); |
314 |
throw new DocletInvokeException(); |
|
315 |
} catch (IllegalAccessException exc) { |
|
14543 | 316 |
messager.error(Messager.NOPOS, "main.doclet_method_not_accessible", |
10 | 317 |
docletClassName, methodName); |
318 |
throw new DocletInvokeException(); |
|
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
14545
diff
changeset
|
319 |
} |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
14545
diff
changeset
|
320 |
catch (InvocationTargetException exc) { |
10 | 321 |
Throwable err = exc.getTargetException(); |
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
322 |
if (apiMode) |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
323 |
throw new ClientCodeException(err); |
10 | 324 |
if (err instanceof java.lang.OutOfMemoryError) { |
14543 | 325 |
messager.error(Messager.NOPOS, "main.out.of.memory"); |
10 | 326 |
} else { |
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14543
diff
changeset
|
327 |
messager.error(Messager.NOPOS, "main.exception_thrown", |
10 | 328 |
docletClassName, methodName, exc.toString()); |
329 |
exc.getTargetException().printStackTrace(); |
|
330 |
} |
|
331 |
throw new DocletInvokeException(); |
|
1990
5d90be5d60bb
6176978: current Javadoc's invocation and extension (Doclet) mechanisms are problematic
jjg
parents:
1789
diff
changeset
|
332 |
} finally { |
5d90be5d60bb
6176978: current Javadoc's invocation and extension (Doclet) mechanisms are problematic
jjg
parents:
1789
diff
changeset
|
333 |
Thread.currentThread().setContextClassLoader(savedCCL); |
10 | 334 |
} |
335 |
} |
|
336 |
} |