8054548: JAX-WS tools need to updated to work with modular image
Removing java reflection API to get JavaCompiler; using standard javax.tools API instead Reviewed-by: alanb
This commit is contained in:
parent
8c15cc3983
commit
78ea4569e2
@ -1,152 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
|
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
||||||
*
|
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
|
||||||
* under the terms of the GNU General Public License version 2 only, as
|
|
||||||
* published by the Free Software Foundation. Oracle designates this
|
|
||||||
* particular file as subject to the "Classpath" exception as provided
|
|
||||||
* by Oracle in the LICENSE file that accompanied this code.
|
|
||||||
*
|
|
||||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
||||||
* version 2 for more details (a copy is included in the LICENSE file that
|
|
||||||
* accompanied this code).
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License version
|
|
||||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
||||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*
|
|
||||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
||||||
* or visit www.oracle.com if you need additional information or have any
|
|
||||||
* questions.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.sun.tools.internal.xjc.api.util;
|
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.File;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLClassLoader;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
|
|
||||||
import com.sun.istack.internal.Nullable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@link ClassLoader} that loads Annotation Processing and specified classes
|
|
||||||
* both into the same classloader, so that they can reference each other.
|
|
||||||
*
|
|
||||||
* @author Bhakti Mehta
|
|
||||||
* @since 2.0 beta
|
|
||||||
*/
|
|
||||||
public final class ApClassLoader extends URLClassLoader {
|
|
||||||
/**
|
|
||||||
* List of package prefixes we want to mask the
|
|
||||||
* parent classLoader from loading
|
|
||||||
*/
|
|
||||||
private final String[] packagePrefixes;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param packagePrefixes
|
|
||||||
* The package prefixes that are forced to resolve within this class loader.
|
|
||||||
* @param parent
|
|
||||||
* The parent class loader to delegate to. Null to indicate bootstrap classloader.
|
|
||||||
*/
|
|
||||||
public ApClassLoader(@Nullable ClassLoader parent, String[] packagePrefixes) throws ToolsJarNotFoundException {
|
|
||||||
super(getToolsJar(parent),parent);
|
|
||||||
if(getURLs().length==0)
|
|
||||||
// if tools.jar was found in our classloader, no need to create
|
|
||||||
// a parallel classes
|
|
||||||
this.packagePrefixes = new String[0];
|
|
||||||
else
|
|
||||||
this.packagePrefixes = packagePrefixes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Class loadClass(String className) throws ClassNotFoundException {
|
|
||||||
for( String prefix : packagePrefixes ) {
|
|
||||||
if (className.startsWith(prefix) ) {
|
|
||||||
// we need to load those classes in this class loader
|
|
||||||
// without delegation.
|
|
||||||
return findClass(className);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return super.loadClass(className);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Class findClass(String name) throws ClassNotFoundException {
|
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder(name.length() + 6);
|
|
||||||
sb.append(name.replace('.','/')).append(".class");
|
|
||||||
|
|
||||||
InputStream is = getResourceAsStream(sb.toString());
|
|
||||||
if (is==null)
|
|
||||||
throw new ClassNotFoundException("Class not found" + sb);
|
|
||||||
|
|
||||||
try {
|
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
||||||
byte[] buf = new byte[1024];
|
|
||||||
int len;
|
|
||||||
while((len=is.read(buf))>=0)
|
|
||||||
baos.write(buf,0,len);
|
|
||||||
|
|
||||||
buf = baos.toByteArray();
|
|
||||||
|
|
||||||
// define package if not defined yet
|
|
||||||
int i = name.lastIndexOf('.');
|
|
||||||
if (i != -1) {
|
|
||||||
String pkgname = name.substring(0, i);
|
|
||||||
Package pkg = getPackage(pkgname);
|
|
||||||
if(pkg==null)
|
|
||||||
definePackage(pkgname, null, null, null, null, null, null, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
return defineClass(name,buf,0,buf.length);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new ClassNotFoundException(name,e);
|
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
is.close();
|
|
||||||
} catch (IOException ioe) {
|
|
||||||
//ignore
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a class loader that can load classes from JDK tools.jar.
|
|
||||||
* @param parent
|
|
||||||
*/
|
|
||||||
private static URL[] getToolsJar(@Nullable ClassLoader parent) throws ToolsJarNotFoundException {
|
|
||||||
|
|
||||||
try {
|
|
||||||
Class.forName("com.sun.tools.javac.Main", false, parent);
|
|
||||||
return new URL[0];
|
|
||||||
// we can already load them in the parent class loader.
|
|
||||||
// so no need to look for tools.jar.
|
|
||||||
// this happens when we are run inside IDE/Ant, or
|
|
||||||
// in Mac OS.
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
// otherwise try to find tools.jar
|
|
||||||
}
|
|
||||||
|
|
||||||
File jreHome = new File(System.getProperty("java.home"));
|
|
||||||
File toolsJar = new File( jreHome.getParent(), "lib/tools.jar" );
|
|
||||||
|
|
||||||
if (!toolsJar.exists()) {
|
|
||||||
throw new ToolsJarNotFoundException(toolsJar);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
return new URL[]{toolsJar.toURL()};
|
|
||||||
} catch (MalformedURLException e) {
|
|
||||||
// impossible
|
|
||||||
throw new AssertionError(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,51 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
|
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
||||||
*
|
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
|
||||||
* under the terms of the GNU General Public License version 2 only, as
|
|
||||||
* published by the Free Software Foundation. Oracle designates this
|
|
||||||
* particular file as subject to the "Classpath" exception as provided
|
|
||||||
* by Oracle in the LICENSE file that accompanied this code.
|
|
||||||
*
|
|
||||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
||||||
* version 2 for more details (a copy is included in the LICENSE file that
|
|
||||||
* accompanied this code).
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License version
|
|
||||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
||||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*
|
|
||||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
||||||
* or visit www.oracle.com if you need additional information or have any
|
|
||||||
* questions.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.sun.tools.internal.xjc.api.util;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Signals an error when tools.jar was not found.
|
|
||||||
*
|
|
||||||
* Simply print out the message obtained by {@link #getMessage()}.
|
|
||||||
*
|
|
||||||
* @author Kohsuke Kawaguchi
|
|
||||||
*/
|
|
||||||
public final class ToolsJarNotFoundException extends Exception {
|
|
||||||
/**
|
|
||||||
* Location where we expected to find tools.jar
|
|
||||||
*/
|
|
||||||
public final File toolsJar;
|
|
||||||
|
|
||||||
public ToolsJarNotFoundException(File toolsJar) {
|
|
||||||
super(calcMessage(toolsJar));
|
|
||||||
this.toolsJar = toolsJar;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String calcMessage(File toolsJar) {
|
|
||||||
return Messages.TOOLS_JAR_NOT_FOUND.format(toolsJar.getPath());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -29,19 +29,16 @@ import com.sun.istack.internal.tools.MaskingClassLoader;
|
|||||||
import com.sun.istack.internal.tools.ParallelWorldClassLoader;
|
import com.sun.istack.internal.tools.ParallelWorldClassLoader;
|
||||||
import com.sun.tools.internal.ws.resources.WscompileMessages;
|
import com.sun.tools.internal.ws.resources.WscompileMessages;
|
||||||
import com.sun.tools.internal.ws.wscompile.Options;
|
import com.sun.tools.internal.ws.wscompile.Options;
|
||||||
import com.sun.tools.internal.xjc.api.util.ToolsJarNotFoundException;
|
|
||||||
import com.sun.xml.internal.bind.util.Which;
|
import com.sun.xml.internal.bind.util.Which;
|
||||||
|
|
||||||
import javax.xml.ws.Service;
|
import javax.xml.ws.Service;
|
||||||
import javax.xml.ws.WebServiceFeature;
|
import javax.xml.ws.WebServiceFeature;
|
||||||
import javax.xml.namespace.QName;
|
import javax.xml.namespace.QName;
|
||||||
import java.io.File;
|
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -59,7 +56,7 @@ public final class Invoker {
|
|||||||
/**
|
/**
|
||||||
* The list of package prefixes we want the
|
* The list of package prefixes we want the
|
||||||
* {@link MaskingClassLoader} to prevent the parent
|
* {@link MaskingClassLoader} to prevent the parent
|
||||||
* classLoader from loading
|
* class loader from loading
|
||||||
*/
|
*/
|
||||||
static final String[] maskedPackages = new String[]{
|
static final String[] maskedPackages = new String[]{
|
||||||
"com.sun.istack.internal.tools.",
|
"com.sun.istack.internal.tools.",
|
||||||
@ -130,24 +127,6 @@ public final class Invoker {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//find and load tools.jar
|
|
||||||
List<URL> urls = new ArrayList<URL>();
|
|
||||||
findToolsJar(cl, urls);
|
|
||||||
|
|
||||||
if(urls.size() > 0){
|
|
||||||
List<String> mask = new ArrayList<String>(Arrays.asList(maskedPackages));
|
|
||||||
|
|
||||||
// first create a protected area so that we load JAXB/WS 2.1 API
|
|
||||||
// and everything that depends on them inside
|
|
||||||
cl = new MaskingClassLoader(cl,mask);
|
|
||||||
|
|
||||||
// then this classloader loads the API and tools.jar
|
|
||||||
cl = new URLClassLoader(urls.toArray(new URL[urls.size()]), cl);
|
|
||||||
|
|
||||||
// finally load the rest of the RI. The actual class files are loaded from ancestors
|
|
||||||
cl = new ParallelWorldClassLoader(cl,"");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Thread.currentThread().setContextClassLoader(cl);
|
Thread.currentThread().setContextClassLoader(cl);
|
||||||
@ -158,8 +137,6 @@ public final class Invoker {
|
|||||||
Method runMethod = compileTool.getMethod("run",String[].class);
|
Method runMethod = compileTool.getMethod("run",String[].class);
|
||||||
boolean r = (Boolean)runMethod.invoke(tool,new Object[]{args});
|
boolean r = (Boolean)runMethod.invoke(tool,new Object[]{args});
|
||||||
return r ? 0 : 1;
|
return r ? 0 : 1;
|
||||||
} catch (ToolsJarNotFoundException e) {
|
|
||||||
System.err.println(e.getMessage());
|
|
||||||
} catch (InvocationTargetException e) {
|
} catch (InvocationTargetException e) {
|
||||||
throw e.getCause();
|
throw e.getCause();
|
||||||
} catch(ClassNotFoundException e){
|
} catch(ClassNotFoundException e){
|
||||||
@ -167,8 +144,6 @@ public final class Invoker {
|
|||||||
}finally {
|
}finally {
|
||||||
Thread.currentThread().setContextClassLoader(oldcc);
|
Thread.currentThread().setContextClassLoader(oldcc);
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -203,10 +178,10 @@ public final class Invoker {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a classloader that can load JAXB/WS 2.2 API and tools.jar,
|
* Creates a class loader that can load JAXB/WS 2.2 API,
|
||||||
* and then return a classloader that can RI classes, which can see all those APIs and tools.jar.
|
* and then return a class loader that can RI classes, which can see all those APIs.
|
||||||
*/
|
*/
|
||||||
public static ClassLoader createClassLoader(ClassLoader cl) throws ClassNotFoundException, IOException, ToolsJarNotFoundException {
|
public static ClassLoader createClassLoader(ClassLoader cl) throws ClassNotFoundException, IOException {
|
||||||
|
|
||||||
URL[] urls = findIstack22APIs(cl);
|
URL[] urls = findIstack22APIs(cl);
|
||||||
if(urls.length==0)
|
if(urls.length==0)
|
||||||
@ -223,7 +198,7 @@ public final class Invoker {
|
|||||||
// and everything that depends on them inside
|
// and everything that depends on them inside
|
||||||
cl = new MaskingClassLoader(cl,mask);
|
cl = new MaskingClassLoader(cl,mask);
|
||||||
|
|
||||||
// then this classloader loads the API and tools.jar
|
// then this class loader loads the API
|
||||||
cl = new URLClassLoader(urls, cl);
|
cl = new URLClassLoader(urls, cl);
|
||||||
|
|
||||||
// finally load the rest of the RI. The actual class files are loaded from ancestors
|
// finally load the rest of the RI. The actual class files are loaded from ancestors
|
||||||
@ -233,13 +208,13 @@ public final class Invoker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a classloader for loading JAXB/WS 2.2 jar and tools.jar
|
* Creates a class loader for loading JAXB/WS 2.2 jar
|
||||||
*/
|
*/
|
||||||
private static URL[] findIstack22APIs(ClassLoader cl) throws ClassNotFoundException, IOException, ToolsJarNotFoundException {
|
private static URL[] findIstack22APIs(ClassLoader cl) throws ClassNotFoundException, IOException {
|
||||||
List<URL> urls = new ArrayList<URL>();
|
List<URL> urls = new ArrayList<URL>();
|
||||||
|
|
||||||
if(Service.class.getClassLoader()==null) {
|
if(Service.class.getClassLoader()==null) {
|
||||||
// JAX-WS API is loaded from bootstrap classloader
|
// JAX-WS API is loaded from bootstrap class loader
|
||||||
URL res = cl.getResource("javax/xml/ws/EndpointContext.class");
|
URL res = cl.getResource("javax/xml/ws/EndpointContext.class");
|
||||||
if(res==null)
|
if(res==null)
|
||||||
throw new ClassNotFoundException("There's no JAX-WS 2.2 API in the classpath");
|
throw new ClassNotFoundException("There's no JAX-WS 2.2 API in the classpath");
|
||||||
@ -250,28 +225,7 @@ public final class Invoker {
|
|||||||
urls.add(ParallelWorldClassLoader.toJarUrl(res));
|
urls.add(ParallelWorldClassLoader.toJarUrl(res));
|
||||||
}
|
}
|
||||||
|
|
||||||
findToolsJar(cl, urls);
|
|
||||||
|
|
||||||
return urls.toArray(new URL[urls.size()]);
|
return urls.toArray(new URL[urls.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void findToolsJar(ClassLoader cl, List<URL> urls) throws ToolsJarNotFoundException, MalformedURLException {
|
|
||||||
try {
|
|
||||||
Class.forName("com.sun.tools.javac.Main",false,cl);
|
|
||||||
// we can already load them in the parent class loader.
|
|
||||||
// so no need to look for tools.jar.
|
|
||||||
// this happens when we are run inside IDE/Ant, or
|
|
||||||
// in Mac OS.
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
// otherwise try to find tools.jar
|
|
||||||
File jreHome = new File(System.getProperty("java.home"));
|
|
||||||
File toolsJar = new File( jreHome.getParent(), "lib/tools.jar" );
|
|
||||||
|
|
||||||
if (!toolsJar.exists()) {
|
|
||||||
throw new ToolsJarNotFoundException(toolsJar);
|
|
||||||
}
|
|
||||||
urls.add(toolsJar.toURL());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -35,8 +35,7 @@ import com.sun.tools.internal.ws.wscompile.WsgenTool;
|
|||||||
*/
|
*/
|
||||||
public class WsGen {
|
public class WsGen {
|
||||||
/**
|
/**
|
||||||
* CLI entry point. Use {@link Invoker} to
|
* CLI entry point. Use {@link Invoker} to load proper API version
|
||||||
* load tools.jar
|
|
||||||
*/
|
*/
|
||||||
public static void main(String[] args) throws Throwable {
|
public static void main(String[] args) throws Throwable {
|
||||||
System.exit(Invoker.invoke("com.sun.tools.internal.ws.wscompile.WsgenTool", args));
|
System.exit(Invoker.invoke("com.sun.tools.internal.ws.wscompile.WsgenTool", args));
|
||||||
@ -50,7 +49,7 @@ public class WsGen {
|
|||||||
* it doesn't invoke {@link System#exit(int)}. This method
|
* it doesn't invoke {@link System#exit(int)}. This method
|
||||||
* also doesn't play with classloaders. It's the caller's
|
* also doesn't play with classloaders. It's the caller's
|
||||||
* responsibility to set up the classloader to load all jars
|
* responsibility to set up the classloader to load all jars
|
||||||
* needed to run the tool, including <tt>$JAVA_HOME/lib/tools.jar</tt>
|
* needed to run the tool.
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
* 0 if the tool runs successfully.
|
* 0 if the tool runs successfully.
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -35,8 +35,7 @@ import com.sun.tools.internal.ws.wscompile.WsimportTool;
|
|||||||
*/
|
*/
|
||||||
public class WsImport {
|
public class WsImport {
|
||||||
/**
|
/**
|
||||||
* CLI entry point. Use {@link Invoker} to
|
* CLI entry point. Use {@link Invoker} to load proper API version
|
||||||
* load tools.jar
|
|
||||||
*/
|
*/
|
||||||
public static void main(String[] args) throws Throwable {
|
public static void main(String[] args) throws Throwable {
|
||||||
System.exit(Invoker.invoke("com.sun.tools.internal.ws.wscompile.WsimportTool", args));
|
System.exit(Invoker.invoke("com.sun.tools.internal.ws.wscompile.WsimportTool", args));
|
||||||
@ -50,7 +49,7 @@ public class WsImport {
|
|||||||
* it doesn't invoke {@link System#exit(int)}. This method
|
* it doesn't invoke {@link System#exit(int)}. This method
|
||||||
* also doesn't play with classloaders. It's the caller's
|
* also doesn't play with classloaders. It's the caller's
|
||||||
* responsibility to set up the classloader to load all jars
|
* responsibility to set up the classloader to load all jars
|
||||||
* needed to run the tool, including <tt>$JAVA_HOME/lib/tools.jar</tt>
|
* needed to run the tool.
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
* 0 if the tool runs successfully.
|
* 0 if the tool runs successfully.
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -39,40 +39,16 @@ public final class JavacompilerMessages {
|
|||||||
private final static LocalizableMessageFactory messageFactory = new LocalizableMessageFactory("com.sun.tools.internal.ws.resources.javacompiler");
|
private final static LocalizableMessageFactory messageFactory = new LocalizableMessageFactory("com.sun.tools.internal.ws.resources.javacompiler");
|
||||||
private final static Localizer localizer = new Localizer();
|
private final static Localizer localizer = new Localizer();
|
||||||
|
|
||||||
public static Localizable localizableJAVACOMPILER_CLASSPATH_ERROR(Object arg0) {
|
public static Localizable localizableNO_JAVACOMPILER_ERROR() {
|
||||||
return messageFactory.getMessage("javacompiler.classpath.error", arg0);
|
return messageFactory.getMessage("no.javacompiler.error");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {0} is not available in the classpath, requires Sun's JDK version 5.0 or latter.
|
* No system compiler found, check your jdk.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public static String JAVACOMPILER_CLASSPATH_ERROR(Object arg0) {
|
public static String NO_JAVACOMPILER_ERROR() {
|
||||||
return localizer.localize(localizableJAVACOMPILER_CLASSPATH_ERROR(arg0));
|
return localizer.localize(localizableNO_JAVACOMPILER_ERROR());
|
||||||
}
|
|
||||||
|
|
||||||
public static Localizable localizableJAVACOMPILER_NOSUCHMETHOD_ERROR(Object arg0) {
|
|
||||||
return messageFactory.getMessage("javacompiler.nosuchmethod.error", arg0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* There is no such method {0} available, requires Sun's JDK version 5.0 or latter.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public static String JAVACOMPILER_NOSUCHMETHOD_ERROR(Object arg0) {
|
|
||||||
return localizer.localize(localizableJAVACOMPILER_NOSUCHMETHOD_ERROR(arg0));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Localizable localizableJAVACOMPILER_ERROR(Object arg0) {
|
|
||||||
return messageFactory.getMessage("javacompiler.error", arg0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* error : {0}.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public static String JAVACOMPILER_ERROR(Object arg0) {
|
|
||||||
return localizer.localize(localizableJAVACOMPILER_ERROR(arg0));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#
|
#
|
||||||
# Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
|
# Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
#
|
#
|
||||||
# This code is free software; you can redistribute it and/or modify it
|
# This code is free software; you can redistribute it and/or modify it
|
||||||
@ -26,6 +26,4 @@
|
|||||||
#
|
#
|
||||||
# Generic Messages
|
# Generic Messages
|
||||||
#
|
#
|
||||||
javacompiler.classpath.error={0} is not available in the classpath, requires Sun's JDK version 5.0 or latter.
|
no.javacompiler.error=No system compiler found, check your jdk.
|
||||||
javacompiler.nosuchmethod.error=There is no such method {0} available, requires Sun's JDK version 5.0 or latter.
|
|
||||||
javacompiler.error=error : {0}.
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -28,14 +28,13 @@ package com.sun.tools.internal.ws.wscompile;
|
|||||||
import com.sun.istack.internal.tools.ParallelWorldClassLoader;
|
import com.sun.istack.internal.tools.ParallelWorldClassLoader;
|
||||||
import com.sun.tools.internal.ws.resources.JavacompilerMessages;
|
import com.sun.tools.internal.ws.resources.JavacompilerMessages;
|
||||||
|
|
||||||
|
import javax.tools.JavaCompiler;
|
||||||
|
import javax.tools.ToolProvider;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.PrintWriter;
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A helper class to invoke javac.
|
* A helper class to invoke javac.
|
||||||
@ -61,34 +60,17 @@ class JavaCompilerHelper{
|
|||||||
}
|
}
|
||||||
|
|
||||||
static boolean compile(String[] args, OutputStream out, ErrorReceiver receiver){
|
static boolean compile(String[] args, OutputStream out, ErrorReceiver receiver){
|
||||||
ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
|
||||||
try {
|
try {
|
||||||
/* try to use the new compiler */
|
JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
|
||||||
Class comSunToolsJavacMainClass =
|
if (comp == null) {
|
||||||
cl.loadClass("com.sun.tools.javac.Main");
|
receiver.error(JavacompilerMessages.NO_JAVACOMPILER_ERROR(), null);
|
||||||
try {
|
return false;
|
||||||
Method compileMethod =
|
|
||||||
comSunToolsJavacMainClass.getMethod(
|
|
||||||
"compile",
|
|
||||||
compileMethodSignature);
|
|
||||||
Object result =
|
|
||||||
compileMethod.invoke(
|
|
||||||
null, args, new PrintWriter(out));
|
|
||||||
return result instanceof Integer && (Integer) result == 0;
|
|
||||||
} catch (NoSuchMethodException e2) {
|
|
||||||
receiver.error(JavacompilerMessages.JAVACOMPILER_NOSUCHMETHOD_ERROR("getMethod(\"compile\", Class[])"), e2);
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
receiver.error(e);
|
|
||||||
} catch (InvocationTargetException e) {
|
|
||||||
receiver.error(e);
|
|
||||||
}
|
}
|
||||||
} catch (ClassNotFoundException e) {
|
return 0 == comp.run(null, out, out, args);
|
||||||
receiver.error(JavacompilerMessages.JAVACOMPILER_CLASSPATH_ERROR("com.sun.tools.javac.Main"), e);
|
|
||||||
} catch (SecurityException e) {
|
} catch (SecurityException e) {
|
||||||
receiver.error(e);
|
receiver.error(e);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Class[] compileMethodSignature = {String[].class, PrintWriter.class};
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user