81 cpString = appendPath(System.getProperty("env.class.path"), cpString); |
81 cpString = appendPath(System.getProperty("env.class.path"), cpString); |
82 cpString = appendPath(System.getProperty("java.class.path"), cpString); |
82 cpString = appendPath(System.getProperty("java.class.path"), cpString); |
83 cpString = appendPath(docletPath, cpString); |
83 cpString = appendPath(docletPath, cpString); |
84 URL[] urls = pathToURLs(cpString); |
84 URL[] urls = pathToURLs(cpString); |
85 if (docletParentClassLoader == null) |
85 if (docletParentClassLoader == null) |
86 appClassLoader = new URLClassLoader(urls); |
86 appClassLoader = new URLClassLoader(urls, getDelegationClassLoader(docletClassName)); |
87 else |
87 else |
88 appClassLoader = new URLClassLoader(urls, docletParentClassLoader); |
88 appClassLoader = new URLClassLoader(urls, docletParentClassLoader); |
89 |
89 |
90 // attempt to find doclet |
90 // attempt to find doclet |
91 Class<?> dc = null; |
91 Class<?> dc = null; |
94 } catch (ClassNotFoundException exc) { |
94 } catch (ClassNotFoundException exc) { |
95 messager.error(null, "main.doclet_class_not_found", docletClassName); |
95 messager.error(null, "main.doclet_class_not_found", docletClassName); |
96 messager.exit(); |
96 messager.exit(); |
97 } |
97 } |
98 docletClass = dc; |
98 docletClass = dc; |
|
99 } |
|
100 |
|
101 /* |
|
102 * Returns the delegation class loader to use when creating |
|
103 * appClassLoader (used to load the doclet). The context class |
|
104 * loader is the best choice, but legacy behavior was to use the |
|
105 * default delegation class loader (aka system class loader). |
|
106 * |
|
107 * Here we favor using the context class loader. To ensure |
|
108 * compatibility with existing apps, we revert to legacy |
|
109 * behavior if either or both of the following conditions hold: |
|
110 * |
|
111 * 1) the doclet is loadable from the system class loader but not |
|
112 * from the context class loader, |
|
113 * |
|
114 * 2) this.getClass() is loadable from the system class loader but not |
|
115 * from the context class loader. |
|
116 */ |
|
117 private ClassLoader getDelegationClassLoader(String docletClassName) { |
|
118 ClassLoader ctxCL = Thread.currentThread().getContextClassLoader(); |
|
119 ClassLoader sysCL = ClassLoader.getSystemClassLoader(); |
|
120 if (sysCL == null) |
|
121 return ctxCL; |
|
122 if (ctxCL == null) |
|
123 return sysCL; |
|
124 |
|
125 // Condition 1. |
|
126 try { |
|
127 sysCL.loadClass(docletClassName); |
|
128 try { |
|
129 ctxCL.loadClass(docletClassName); |
|
130 } catch (ClassNotFoundException e) { |
|
131 return sysCL; |
|
132 } |
|
133 } catch (ClassNotFoundException e) { |
|
134 } |
|
135 |
|
136 // Condition 2. |
|
137 try { |
|
138 if (getClass() == sysCL.loadClass(getClass().getName())) { |
|
139 try { |
|
140 if (getClass() != ctxCL.loadClass(getClass().getName())) |
|
141 return sysCL; |
|
142 } catch (ClassNotFoundException e) { |
|
143 return sysCL; |
|
144 } |
|
145 } |
|
146 } catch (ClassNotFoundException e) { |
|
147 } |
|
148 |
|
149 return ctxCL; |
99 } |
150 } |
100 |
151 |
101 /** |
152 /** |
102 * Generate documentation here. Return true on success. |
153 * Generate documentation here. Return true on success. |
103 */ |
154 */ |
229 if (!Modifier.isStatic(meth.getModifiers())) { |
280 if (!Modifier.isStatic(meth.getModifiers())) { |
230 messager.error(null, "main.doclet_method_must_be_static", |
281 messager.error(null, "main.doclet_method_must_be_static", |
231 docletClassName, methodName); |
282 docletClassName, methodName); |
232 throw new DocletInvokeException(); |
283 throw new DocletInvokeException(); |
233 } |
284 } |
|
285 ClassLoader savedCCL = |
|
286 Thread.currentThread().getContextClassLoader(); |
234 try { |
287 try { |
235 Thread.currentThread().setContextClassLoader(appClassLoader); |
288 Thread.currentThread().setContextClassLoader(appClassLoader); |
236 return meth.invoke(null , params); |
289 return meth.invoke(null , params); |
237 } catch (IllegalArgumentException exc) { |
290 } catch (IllegalArgumentException exc) { |
238 messager.error(null, "main.internal_error_exception_thrown", |
291 messager.error(null, "main.internal_error_exception_thrown", |
254 messager.error(null, "main.exception_thrown", |
307 messager.error(null, "main.exception_thrown", |
255 docletClassName, methodName, exc.toString()); |
308 docletClassName, methodName, exc.toString()); |
256 exc.getTargetException().printStackTrace(); |
309 exc.getTargetException().printStackTrace(); |
257 } |
310 } |
258 throw new DocletInvokeException(); |
311 throw new DocletInvokeException(); |
|
312 } finally { |
|
313 Thread.currentThread().setContextClassLoader(savedCCL); |
259 } |
314 } |
260 } |
315 } |
261 |
316 |
262 /** |
317 /** |
263 * Utility method for converting a search path string to an array |
318 * Utility method for converting a search path string to an array |