Search in sources :

Example 1 with URLClassPath

use of sun.misc.URLClassPath in project intellij-community by JetBrains.

the class GroovycRunner method buildMainLoader.

@Nullable
private static ClassLoader buildMainLoader(String argsPath) {
    Set<URL> bootstrapUrls = new HashSet<URL>();
    try {
        Method method = ClassLoader.class.getDeclaredMethod("getBootstrapClassPath");
        method.setAccessible(true);
        URLClassPath ucp = (URLClassPath) method.invoke(null);
        Collections.addAll(bootstrapUrls, ucp.getURLs());
    } catch (Exception e) {
        e.printStackTrace();
    }
    final List<URL> urls = new ArrayList<URL>();
    try {
        //noinspection IOResourceOpenedButNotSafelyClosed
        BufferedReader reader = new BufferedReader(new FileReader(argsPath));
        String classpath = reader.readLine();
        for (String s : classpath.split(File.pathSeparator)) {
            URL url = new File(s).toURI().toURL();
            if (!bootstrapUrls.contains(url)) {
                urls.add(url);
            }
        }
        reader.close();
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
    final ClassLoader[] ref = new ClassLoader[1];
    new Runnable() {

        public void run() {
            ref[0] = UrlClassLoader.build().urls(urls).useCache().get();
        }
    }.run();
    return ref[0];
}
Also used : URLClassPath(sun.misc.URLClassPath) Method(java.lang.reflect.Method) IOException(java.io.IOException) URL(java.net.URL) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) BufferedReader(java.io.BufferedReader) UrlClassLoader(com.intellij.util.lang.UrlClassLoader) FileReader(java.io.FileReader) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with URLClassPath

use of sun.misc.URLClassPath in project jdk8u_jdk by JetBrains.

the class SystemClassLoaderAction method getBootstrapResource.

/**
     * Find resources from the VM's built-in classloader.
     */
private static URL getBootstrapResource(String name) {
    URLClassPath ucp = getBootstrapClassPath();
    Resource res = ucp.getResource(name);
    return res != null ? res.getURL() : null;
}
Also used : URLClassPath(sun.misc.URLClassPath) Resource(sun.misc.Resource)

Example 3 with URLClassPath

use of sun.misc.URLClassPath in project intellij-community by JetBrains.

the class SystemClassLoaderAction method getBootstrapResource.

/**
     * Find resources from the VM's built-in classloader.
     */
private static URL getBootstrapResource(String name) {
    URLClassPath ucp = getBootstrapClassPath();
    Resource res = ucp.getResource(name);
    return res != null ? res.getURL() : null;
}
Also used : URLClassPath(sun.misc.URLClassPath) Resource(sun.misc.Resource)

Aggregations

URLClassPath (sun.misc.URLClassPath)3 Resource (sun.misc.Resource)2 UrlClassLoader (com.intellij.util.lang.UrlClassLoader)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 URL (java.net.URL)1 Nullable (org.jetbrains.annotations.Nullable)1