feat(jdk8): move files to new folder to avoid resources compiled.
This commit is contained in:
@@ -0,0 +1,324 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2013, 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.istack.internal.tools;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.Authenticator;
|
||||
import java.net.Authenticator.RequestorType;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.PasswordAuthentication;
|
||||
import java.net.URL;
|
||||
import java.net.URLDecoder;
|
||||
import java.net.URLEncoder;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Pattern;
|
||||
import org.xml.sax.Locator;
|
||||
import org.xml.sax.helpers.LocatorImpl;
|
||||
|
||||
/**
|
||||
* @author Vivek Pandey
|
||||
* @author Lukas Jungmann
|
||||
*/
|
||||
public class DefaultAuthenticator extends Authenticator {
|
||||
|
||||
private static DefaultAuthenticator instance;
|
||||
private static Authenticator systemAuthenticator = getCurrentAuthenticator();
|
||||
private String proxyUser;
|
||||
private String proxyPasswd;
|
||||
private final List<AuthInfo> authInfo = new ArrayList<AuthInfo>();
|
||||
private static int counter = 0;
|
||||
|
||||
DefaultAuthenticator() {
|
||||
//try undocumented but often used properties
|
||||
if (System.getProperty("http.proxyUser") != null) {
|
||||
proxyUser = System.getProperty("http.proxyUser");
|
||||
} else {
|
||||
proxyUser = System.getProperty("proxyUser");
|
||||
}
|
||||
if (System.getProperty("http.proxyPassword") != null) {
|
||||
proxyPasswd = System.getProperty("http.proxyPassword");
|
||||
} else {
|
||||
proxyPasswd = System.getProperty("proxyPassword");
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized DefaultAuthenticator getAuthenticator() {
|
||||
if (instance == null) {
|
||||
instance = new DefaultAuthenticator();
|
||||
Authenticator.setDefault(instance);
|
||||
}
|
||||
counter++;
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static synchronized void reset() {
|
||||
--counter;
|
||||
if (instance != null && counter == 0) {
|
||||
Authenticator.setDefault(systemAuthenticator);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PasswordAuthentication getPasswordAuthentication() {
|
||||
//If user sets proxy user and passwd and the RequestType is from proxy server then create
|
||||
// PasswordAuthentication using proxyUser and proxyPasswd;
|
||||
if ((getRequestorType() == RequestorType.PROXY) && proxyUser != null && proxyPasswd != null) {
|
||||
return new PasswordAuthentication(proxyUser, proxyPasswd.toCharArray());
|
||||
}
|
||||
for (AuthInfo auth : authInfo) {
|
||||
if (auth.matchingHost(getRequestingURL())) {
|
||||
return new PasswordAuthentication(auth.getUser(), auth.getPassword().toCharArray());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Proxy authorization string in form of username:password.
|
||||
*
|
||||
* @param proxyAuth
|
||||
*/
|
||||
public void setProxyAuth(String proxyAuth) {
|
||||
if (proxyAuth == null) {
|
||||
this.proxyUser = null;
|
||||
this.proxyPasswd = null;
|
||||
} else {
|
||||
int i = proxyAuth.indexOf(':');
|
||||
if (i < 0) {
|
||||
this.proxyUser = proxyAuth;
|
||||
this.proxyPasswd = "";
|
||||
} else if (i == 0) {
|
||||
this.proxyUser = "";
|
||||
this.proxyPasswd = proxyAuth.substring(1);
|
||||
} else {
|
||||
this.proxyUser = proxyAuth.substring(0, i);
|
||||
this.proxyPasswd = proxyAuth.substring(i + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setAuth(File f, Receiver l) {
|
||||
Receiver listener = l == null ? new DefaultRImpl() : l;
|
||||
BufferedReader in = null;
|
||||
FileInputStream fi = null;
|
||||
InputStreamReader is = null;
|
||||
try {
|
||||
String text;
|
||||
LocatorImpl locator = new LocatorImpl();
|
||||
locator.setSystemId(f.getAbsolutePath());
|
||||
try {
|
||||
fi = new FileInputStream(f);
|
||||
is = new InputStreamReader(fi, "UTF-8");
|
||||
in = new BufferedReader(is);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
listener.onError(e, locator);
|
||||
return;
|
||||
} catch (FileNotFoundException e) {
|
||||
listener.onError(e, locator);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
int lineno = 1;
|
||||
locator.setSystemId(f.getCanonicalPath());
|
||||
while ((text = in.readLine()) != null) {
|
||||
locator.setLineNumber(lineno++);
|
||||
//ignore empty lines and treat those starting with '#' as comments
|
||||
if ("".equals(text.trim()) || text.startsWith("#")) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
AuthInfo ai = parseLine(text);
|
||||
authInfo.add(ai);
|
||||
} catch (Exception e) {
|
||||
listener.onParsingError(text, locator);
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
listener.onError(e, locator);
|
||||
Logger.getLogger(DefaultAuthenticator.class.getName()).log(Level.SEVERE, e.getMessage(), e);
|
||||
}
|
||||
} finally {
|
||||
try {
|
||||
if (in != null) {
|
||||
in.close();
|
||||
}
|
||||
if (is != null) {
|
||||
is.close();
|
||||
}
|
||||
if (fi != null) {
|
||||
fi.close();
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(DefaultAuthenticator.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private AuthInfo parseLine(String text) throws Exception {
|
||||
URL url;
|
||||
try {
|
||||
url = new URL(text);
|
||||
} catch (MalformedURLException mue) {
|
||||
//possible cause of this can be that password contains
|
||||
//character which has to be encoded in URL,
|
||||
//such as '@', ')', '#' and few others
|
||||
//so try to recreate the URL with encoded string
|
||||
//between 2nd ':' and last '@'
|
||||
int i = text.indexOf(':', text.indexOf(':') + 1) + 1;
|
||||
int j = text.lastIndexOf('@');
|
||||
String encodedUrl =
|
||||
text.substring(0, i)
|
||||
+ URLEncoder.encode(text.substring(i, j), "UTF-8")
|
||||
+ text.substring(j);
|
||||
url = new URL(encodedUrl);
|
||||
}
|
||||
|
||||
String authinfo = url.getUserInfo();
|
||||
|
||||
if (authinfo != null) {
|
||||
int i = authinfo.indexOf(':');
|
||||
|
||||
if (i >= 0) {
|
||||
String user = authinfo.substring(0, i);
|
||||
String password = authinfo.substring(i + 1);
|
||||
return new AuthInfo(
|
||||
new URL(url.getProtocol(), url.getHost(), url.getPort(), url.getFile()),
|
||||
user, URLDecoder.decode(password, "UTF-8"));
|
||||
}
|
||||
}
|
||||
throw new Exception();
|
||||
}
|
||||
|
||||
static Authenticator getCurrentAuthenticator() {
|
||||
final Field f = getTheAuthenticator();
|
||||
if (f == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
AccessController.doPrivileged(new PrivilegedAction<Void>() {
|
||||
@Override
|
||||
public Void run() {
|
||||
f.setAccessible(true);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
return (Authenticator) f.get(null);
|
||||
} catch (Exception ex) {
|
||||
return null;
|
||||
} finally {
|
||||
AccessController.doPrivileged(new PrivilegedAction<Void>() {
|
||||
@Override
|
||||
public Void run() {
|
||||
f.setAccessible(false);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static Field getTheAuthenticator() {
|
||||
try {
|
||||
return Authenticator.class.getDeclaredField("theAuthenticator");
|
||||
} catch (Exception ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static interface Receiver {
|
||||
|
||||
void onParsingError(String line, Locator loc);
|
||||
|
||||
void onError(Exception e, Locator loc);
|
||||
}
|
||||
|
||||
private static class DefaultRImpl implements Receiver {
|
||||
|
||||
@Override
|
||||
public void onParsingError(String line, Locator loc) {
|
||||
System.err.println(getLocationString(loc) + ": " + line);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Exception e, Locator loc) {
|
||||
System.err.println(getLocationString(loc) + ": " + e.getMessage());
|
||||
Logger.getLogger(DefaultAuthenticator.class.getName()).log(Level.SEVERE, e.getMessage(), e);
|
||||
}
|
||||
|
||||
private String getLocationString(Locator l) {
|
||||
return "[" + l.getSystemId() + "#" + l.getLineNumber() + "]";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents authorization information needed by
|
||||
* {@link DefaultAuthenticator} to authenticate access to remote resources.
|
||||
*
|
||||
* @author Vivek Pandey
|
||||
* @author Lukas Jungmann
|
||||
*/
|
||||
final static class AuthInfo {
|
||||
|
||||
private final String user;
|
||||
private final String password;
|
||||
private final Pattern urlPattern;
|
||||
|
||||
public AuthInfo(URL url, String user, String password) {
|
||||
String u = url.toExternalForm().replaceFirst("\\?", "\\\\?");
|
||||
this.urlPattern = Pattern.compile(u.replace("*", ".*"), Pattern.CASE_INSENSITIVE);
|
||||
this.user = user;
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if the requesting host and port are associated with this
|
||||
* {@link AuthInfo}
|
||||
*/
|
||||
public boolean matchingHost(URL requestingURL) {
|
||||
return urlPattern.matcher(requestingURL.toExternalForm()).matches();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* 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.istack.internal.tools;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* {@link ClassLoader} that masks a specified set of classes
|
||||
* from its parent class loader.
|
||||
*
|
||||
* <p>
|
||||
* This code is used to create an isolated environment.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public class MaskingClassLoader extends ClassLoader {
|
||||
|
||||
private final String[] masks;
|
||||
|
||||
public MaskingClassLoader(String... masks) {
|
||||
this.masks = masks;
|
||||
}
|
||||
|
||||
public MaskingClassLoader(Collection<String> masks) {
|
||||
this(masks.toArray(new String[masks.size()]));
|
||||
}
|
||||
|
||||
public MaskingClassLoader(ClassLoader parent, String... masks) {
|
||||
super(parent);
|
||||
this.masks = masks;
|
||||
}
|
||||
|
||||
public MaskingClassLoader(ClassLoader parent, Collection<String> masks) {
|
||||
this(parent, masks.toArray(new String[masks.size()]));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected synchronized Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
|
||||
for (String mask : masks) {
|
||||
if(name.startsWith(mask))
|
||||
throw new ClassNotFoundException();
|
||||
}
|
||||
|
||||
return super.loadClass(name, resolve);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,217 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2013, 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.istack.internal.tools;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.Closeable;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.JarURLConnection;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URLConnection;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* Load classes/resources from a side folder, so that
|
||||
* classes of the same package can live in a single jar file.
|
||||
*
|
||||
* <p>
|
||||
* For example, with the following jar file:
|
||||
* <pre>
|
||||
* /
|
||||
* +- foo
|
||||
* +- X.class
|
||||
* +- bar
|
||||
* +- X.class
|
||||
* </pre>
|
||||
* <p>
|
||||
* {@link ParallelWorldClassLoader}("foo/") would load <tt>X.class<tt> from
|
||||
* <tt>/foo/X.class</tt> (note that X is defined in the root package, not
|
||||
* <tt>foo.X</tt>.
|
||||
*
|
||||
* <p>
|
||||
* This can be combined with {@link MaskingClassLoader} to mask classes which are loaded by the parent
|
||||
* class loader so that the child class loader
|
||||
* classes living in different folders are loaded
|
||||
* before the parent class loader loads classes living the jar file publicly
|
||||
* visible
|
||||
* For example, with the following jar file:
|
||||
* <pre>
|
||||
* /
|
||||
* +- foo
|
||||
* +- X.class
|
||||
* +- bar
|
||||
* +-foo
|
||||
* +- X.class
|
||||
* </pre>
|
||||
* <p>
|
||||
* {@link ParallelWorldClassLoader}(MaskingClassLoader.class.getClassLoader()) would load <tt>foo.X.class<tt> from
|
||||
* <tt>/bar/foo.X.class</tt> not the <tt>foo.X.class<tt> in the publicly visible place in the jar file, thus
|
||||
* masking the parent classLoader from loading the class from <tt>foo.X.class<tt>
|
||||
* (note that X is defined in the package foo, not
|
||||
* <tt>bar.foo.X</tt>.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public class ParallelWorldClassLoader extends ClassLoader implements Closeable {
|
||||
|
||||
/**
|
||||
* Strings like "prefix/", "abc/", or "" to indicate
|
||||
* classes should be loaded normally.
|
||||
*/
|
||||
private final String prefix;
|
||||
private final Set<JarFile> jars;
|
||||
|
||||
public ParallelWorldClassLoader(ClassLoader parent,String prefix) {
|
||||
super(parent);
|
||||
this.prefix = prefix;
|
||||
jars = Collections.synchronizedSet(new HashSet<JarFile>());
|
||||
}
|
||||
|
||||
protected Class findClass(String name) throws ClassNotFoundException {
|
||||
|
||||
StringBuffer sb = new StringBuffer(name.length()+prefix.length()+6);
|
||||
sb.append(prefix).append(name.replace('.','/')).append(".class");
|
||||
|
||||
URL u = getParent().getResource(sb.toString());
|
||||
if (u == null) {
|
||||
throw new ClassNotFoundException(name);
|
||||
}
|
||||
|
||||
InputStream is = null;
|
||||
URLConnection con = null;
|
||||
|
||||
try {
|
||||
con = u.openConnection();
|
||||
is = con.getInputStream();
|
||||
} catch (IOException ioe) {
|
||||
throw new ClassNotFoundException(name);
|
||||
}
|
||||
|
||||
if (is==null)
|
||||
throw new ClassNotFoundException(name);
|
||||
|
||||
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();
|
||||
int packIndex = name.lastIndexOf('.');
|
||||
if (packIndex != -1) {
|
||||
String pkgname = name.substring(0, packIndex);
|
||||
// Check if package already loaded.
|
||||
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 {
|
||||
if (con != null && con instanceof JarURLConnection) {
|
||||
jars.add(((JarURLConnection) con).getJarFile());
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
//ignore
|
||||
}
|
||||
if (is != null) {
|
||||
try {
|
||||
is.close();
|
||||
} catch (IOException ioe) {
|
||||
//ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected URL findResource(String name) {
|
||||
URL u = getParent().getResource(prefix + name);
|
||||
if (u != null) {
|
||||
try {
|
||||
jars.add(new JarFile(new File(toJarUrl(u).toURI())));
|
||||
} catch (URISyntaxException ex) {
|
||||
Logger.getLogger(ParallelWorldClassLoader.class.getName()).log(Level.WARNING, null, ex);
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(ParallelWorldClassLoader.class.getName()).log(Level.WARNING, null, ex);
|
||||
} catch (ClassNotFoundException ex) {
|
||||
//ignore - not a jar
|
||||
}
|
||||
}
|
||||
return u;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Enumeration<URL> findResources(String name) throws IOException {
|
||||
Enumeration<URL> en = getParent().getResources(prefix + name);
|
||||
while (en.hasMoreElements()) {
|
||||
try {
|
||||
jars.add(new JarFile(new File(toJarUrl(en.nextElement()).toURI())));
|
||||
} catch (URISyntaxException ex) {
|
||||
//should not happen
|
||||
Logger.getLogger(ParallelWorldClassLoader.class.getName()).log(Level.WARNING, null, ex);
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(ParallelWorldClassLoader.class.getName()).log(Level.WARNING, null, ex);
|
||||
} catch (ClassNotFoundException ex) {
|
||||
//ignore - not a jar
|
||||
}
|
||||
}
|
||||
return en;
|
||||
}
|
||||
|
||||
public synchronized void close() throws IOException {
|
||||
for (JarFile jar : jars) {
|
||||
jar.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Given the URL inside jar, returns the URL to the jar itself.
|
||||
*/
|
||||
public static URL toJarUrl(URL res) throws ClassNotFoundException, MalformedURLException {
|
||||
String url = res.toExternalForm();
|
||||
if(!url.startsWith("jar:"))
|
||||
throw new ClassNotFoundException("Loaded outside a jar "+url);
|
||||
url = url.substring(4); // cut off jar:
|
||||
url = url.substring(0,url.lastIndexOf('!')); // cut off everything after '!'
|
||||
url = url.replaceAll(" ", "%20"); // support white spaces in path
|
||||
return new URL(url);
|
||||
}
|
||||
}
|
||||
102
jdkSrc/jdk8/com/sun/istack/internal/tools/SecureLoader.java
Normal file
102
jdkSrc/jdk8/com/sun/istack/internal/tools/SecureLoader.java
Normal file
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* 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.istack.internal.tools;
|
||||
|
||||
/**
|
||||
* Class defined for safe calls of getClassLoader methods of any kind (context/system/class
|
||||
* classloader. This MUST be package private and defined in every package which
|
||||
* uses such invocations.
|
||||
* @author snajper
|
||||
*/
|
||||
class SecureLoader {
|
||||
|
||||
static ClassLoader getContextClassLoader() {
|
||||
if (System.getSecurityManager() == null) {
|
||||
return Thread.currentThread().getContextClassLoader();
|
||||
} else {
|
||||
return (ClassLoader) java.security.AccessController.doPrivileged(
|
||||
new java.security.PrivilegedAction() {
|
||||
public java.lang.Object run() {
|
||||
return Thread.currentThread().getContextClassLoader();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
static ClassLoader getClassClassLoader(final Class c) {
|
||||
if (System.getSecurityManager() == null) {
|
||||
return c.getClassLoader();
|
||||
} else {
|
||||
return (ClassLoader) java.security.AccessController.doPrivileged(
|
||||
new java.security.PrivilegedAction() {
|
||||
public java.lang.Object run() {
|
||||
return c.getClassLoader();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
static ClassLoader getSystemClassLoader() {
|
||||
if (System.getSecurityManager() == null) {
|
||||
return ClassLoader.getSystemClassLoader();
|
||||
} else {
|
||||
return (ClassLoader) java.security.AccessController.doPrivileged(
|
||||
new java.security.PrivilegedAction() {
|
||||
public java.lang.Object run() {
|
||||
return ClassLoader.getSystemClassLoader();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
static ClassLoader getParentClassLoader(final ClassLoader cl) {
|
||||
if (System.getSecurityManager() == null) {
|
||||
return cl.getParent();
|
||||
} else {
|
||||
return (ClassLoader) java.security.AccessController.doPrivileged(
|
||||
new java.security.PrivilegedAction() {
|
||||
public java.lang.Object run() {
|
||||
return cl.getParent();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
static void setContextClassLoader(final ClassLoader cl) {
|
||||
if (System.getSecurityManager() == null) {
|
||||
Thread.currentThread().setContextClassLoader(cl);
|
||||
} else {
|
||||
java.security.AccessController.doPrivileged(
|
||||
new java.security.PrivilegedAction() {
|
||||
public java.lang.Object run() {
|
||||
Thread.currentThread().setContextClassLoader(cl);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
32
jdkSrc/jdk8/com/sun/istack/internal/tools/package-info.java
Normal file
32
jdkSrc/jdk8/com/sun/istack/internal/tools/package-info.java
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* istack-commons tool time utilities.
|
||||
*
|
||||
* <p>
|
||||
* This includes code that relies on APT, javac, etc.
|
||||
*/
|
||||
package com.sun.istack.internal.tools;
|
||||
Reference in New Issue
Block a user