1 /* |
1 /* |
2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
53 * even if it's not available in the tool launcher classpath. |
53 * even if it's not available in the tool launcher classpath. |
54 * |
54 * |
55 * @author Kohsuke Kawaguchi |
55 * @author Kohsuke Kawaguchi |
56 */ |
56 */ |
57 public final class Invoker { |
57 public final class Invoker { |
|
58 |
|
59 /** |
|
60 * The list of package prefixes we want the |
|
61 * {@link MaskingClassLoader} to prevent the parent |
|
62 * classLoader from loading |
|
63 */ |
|
64 static final String[] maskedPackages = new String[]{ |
|
65 "com.sun.istack.internal.tools.", |
|
66 "com.sun.tools.internal.jxc.", |
|
67 "com.sun.tools.internal.xjc.", |
|
68 "com.sun.tools.internal.ws.", |
|
69 "com.sun.codemodel.internal.", |
|
70 "com.sun.relaxng.", |
|
71 "com.sun.xml.internal.xsom.", |
|
72 "com.sun.xml.internal.bind.", |
|
73 "com.ctc.wstx.", //wsimport, wsgen ant task |
|
74 "org.codehaus.stax2.", //wsimport, wsgen ant task |
|
75 "com.sun.xml.internal.messaging.saaj.", //wsgen ant task |
|
76 "com.sun.xml.internal.ws.", |
|
77 "com.oracle.webservices.internal.api." //wsgen |
|
78 }; |
|
79 |
|
80 /** |
|
81 * Escape hatch to work around IBM JDK problem. |
|
82 * See http://www-128.ibm.com/developerworks/forums/dw_thread.jsp?nav=false&forum=367&thread=164718&cat=10 |
|
83 */ |
|
84 public static final boolean noSystemProxies; |
|
85 |
|
86 static { |
|
87 boolean noSysProxiesProperty = false; |
|
88 try { |
|
89 noSysProxiesProperty = Boolean.getBoolean(Invoker.class.getName()+".noSystemProxies"); |
|
90 } catch(SecurityException e) { |
|
91 // ignore |
|
92 } finally { |
|
93 noSystemProxies = noSysProxiesProperty; |
|
94 } |
|
95 } |
|
96 |
58 static int invoke(String mainClass, String[] args) throws Throwable { |
97 static int invoke(String mainClass, String[] args) throws Throwable { |
59 // use the platform default proxy if available. |
98 // use the platform default proxy if available. |
60 // see sun.net.spi.DefaultProxySelector for details. |
99 // see sun.net.spi.DefaultProxySelector for details. |
61 if(!noSystemProxies) { |
100 if(!noSystemProxies) { |
62 try { |
101 try { |
105 // then this classloader loads the API and tools.jar |
144 // then this classloader loads the API and tools.jar |
106 cl = new URLClassLoader(urls.toArray(new URL[urls.size()]), cl); |
145 cl = new URLClassLoader(urls.toArray(new URL[urls.size()]), cl); |
107 |
146 |
108 // finally load the rest of the RI. The actual class files are loaded from ancestors |
147 // finally load the rest of the RI. The actual class files are loaded from ancestors |
109 cl = new ParallelWorldClassLoader(cl,""); |
148 cl = new ParallelWorldClassLoader(cl,""); |
110 } |
149 } |
111 |
150 |
112 } |
151 } |
113 |
152 |
114 Thread.currentThread().setContextClassLoader(cl); |
153 Thread.currentThread().setContextClassLoader(cl); |
115 |
154 |
192 |
231 |
193 return cl; |
232 return cl; |
194 } |
233 } |
195 |
234 |
196 /** |
235 /** |
197 * Creates a classloader for loading JAXB/WS 2.1 jar and tools.jar |
|
198 */ |
|
199 private static URL[] findIstack21APIs(ClassLoader cl) throws ClassNotFoundException, MalformedURLException, ToolsJarNotFoundException { |
|
200 List<URL> urls = new ArrayList<URL>(); |
|
201 |
|
202 if(Service.class.getClassLoader()==null) { |
|
203 // JAX-WS API is loaded from bootstrap classloader |
|
204 URL res = cl.getResource("javax/xml/ws/EndpointReference.class"); |
|
205 if(res==null) |
|
206 throw new ClassNotFoundException("There's no JAX-WS 2.1 API in the classpath"); |
|
207 urls.add(ParallelWorldClassLoader.toJarUrl(res)); |
|
208 |
|
209 res = cl.getResource("javax/xml/bind/annotation/XmlSeeAlso.class"); |
|
210 if(res==null) |
|
211 throw new ClassNotFoundException("There's no JAXB 2.1 API in the classpath"); |
|
212 urls.add(ParallelWorldClassLoader.toJarUrl(res)); |
|
213 } |
|
214 |
|
215 findToolsJar(cl, urls); |
|
216 |
|
217 return urls.toArray(new URL[urls.size()]); |
|
218 } |
|
219 /** |
|
220 * Creates a classloader for loading JAXB/WS 2.2 jar and tools.jar |
236 * Creates a classloader for loading JAXB/WS 2.2 jar and tools.jar |
221 */ |
237 */ |
222 private static URL[] findIstack22APIs(ClassLoader cl) throws ClassNotFoundException, IOException, ToolsJarNotFoundException { |
238 private static URL[] findIstack22APIs(ClassLoader cl) throws ClassNotFoundException, IOException, ToolsJarNotFoundException { |
223 List<URL> urls = new ArrayList<URL>(); |
239 List<URL> urls = new ArrayList<URL>(); |
224 |
240 |
256 } |
272 } |
257 urls.add(toolsJar.toURL()); |
273 urls.add(toolsJar.toURL()); |
258 } |
274 } |
259 } |
275 } |
260 |
276 |
261 /** |
|
262 * The list of package prefixes we want the |
|
263 * {@link MaskingClassLoader} to prevent the parent |
|
264 * classLoader from loading |
|
265 */ |
|
266 public static String[] maskedPackages = new String[]{ |
|
267 "com.sun.istack.internal.tools.", |
|
268 "com.sun.tools.internal.jxc.", |
|
269 "com.sun.tools.internal.xjc.", |
|
270 "com.sun.tools.internal.ws.", |
|
271 "com.sun.codemodel.internal.", |
|
272 "com.sun.relaxng.", |
|
273 "com.sun.xml.internal.xsom.", |
|
274 "com.sun.xml.internal.bind.", |
|
275 "com.ctc.wstx.", //wsimport, wsgen ant task |
|
276 "org.codehaus.stax2.", //wsimport, wsgen ant task |
|
277 "com.sun.xml.internal.messaging.saaj.", //wsgen ant task |
|
278 "com.sun.xml.internal.ws." |
|
279 }; |
|
280 |
|
281 /** |
|
282 * Escape hatch to work around IBM JDK problem. |
|
283 * See http://www-128.ibm.com/developerworks/forums/dw_thread.jsp?nav=false&forum=367&thread=164718&cat=10 |
|
284 */ |
|
285 public static boolean noSystemProxies = false; |
|
286 |
|
287 static { |
|
288 try { |
|
289 noSystemProxies = Boolean.getBoolean(Invoker.class.getName()+".noSystemProxies"); |
|
290 } catch(SecurityException e) { |
|
291 // ignore |
|
292 } |
|
293 } |
|
294 } |
277 } |