Search in sources :

Example 86 with URLClassLoader

use of java.net.URLClassLoader in project intellij-community by JetBrains.

the class RemoteAgentReflectiveProxyFactory method createAgentClassLoader.

@Override
protected ClassLoader createAgentClassLoader(URL[] agentLibraryUrls) throws Exception {
    Set<URL> urls = new HashSet<>();
    urls.addAll(Arrays.asList(agentLibraryUrls));
    return myClassLoaderCache == null ? new URLClassLoader(urls.toArray(new URL[urls.size()]), null) : myClassLoaderCache.getOrCreateClassLoader(urls);
}
Also used : URLClassLoader(java.net.URLClassLoader) URL(java.net.URL) HashSet(com.intellij.util.containers.hash.HashSet)

Example 87 with URLClassLoader

use of java.net.URLClassLoader in project wildfly by wildfly.

the class ServerConfigImplTestCase method setStackConfigFactory.

@BeforeClass
public static void setStackConfigFactory() throws Exception {
    URL url = ServerConfigImplTestCase.class.getResource("util/");
    origTCCL = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(new URLClassLoader(new URL[] { url }));
}
Also used : URLClassLoader(java.net.URLClassLoader) URL(java.net.URL) BeforeClass(org.junit.BeforeClass)

Example 88 with URLClassLoader

use of java.net.URLClassLoader in project android by JetBrains.

the class UnitTest method onlyOneMockableJar.

@Test
public void onlyOneMockableJar() throws Exception {
    URL[] urls = ((URLClassLoader) getClass().getClassLoader()).getURLs();
    int count = 0;
    URL mockableJar = null;
    for (URL u : urls) {
        if (u.toString().contains("mockable-")) {
            count++;
            mockableJar = u;
        }
    }
    assertEquals(1, count);
    assertNotNull(mockableJar);
    assertTrue(mockableJar.toString().contains("mockable-android-22.jar"));
}
Also used : URLClassLoader(java.net.URLClassLoader) URL(java.net.URL) Test(org.junit.Test)

Example 89 with URLClassLoader

use of java.net.URLClassLoader in project intellij-community by JetBrains.

the class InProcessGroovyc method obtainParentLoader.

@Nullable
private static ClassLoader obtainParentLoader(Collection<String> compilationClassPath) throws MalformedURLException {
    if (!"true".equals(System.getProperty("groovyc.reuse.compiler.classes", "true"))) {
        return null;
    }
    List<String> groovyJars = ContainerUtil.findAll(compilationClassPath, s -> {
        String fileName = StringUtil.getShortName(s, '/');
        return GROOVY_ALL_JAR_PATTERN.matcher(fileName).matches() || GROOVY_JAR_PATTERN.matcher(fileName).matches();
    });
    LOG.debug("Groovy jars: " + groovyJars);
    if (groovyJars.size() != 1 || !GROOVY_ALL_JAR_PATTERN.matcher(groovyJars.get(0)).matches()) {
        // avoid complications caused by caching classes from several groovy versions in classpath
        return null;
    }
    String groovyAll = groovyJars.get(0);
    Pair<String, ClassLoader> pair = SoftReference.dereference(ourParentLoaderCache);
    if (pair != null && pair.first.equals(groovyAll)) {
        return pair.second;
    }
    final ClassDependencyLoader checkWellFormed = new ClassDependencyLoader() {

        @Override
        protected void loadClassDependencies(Class aClass) throws ClassNotFoundException {
            if (!isCompilerCoreClass(aClass.getName()) || !(aClass.getClassLoader() instanceof UrlClassLoader)) {
                super.loadClassDependencies(aClass);
            }
        }

        private boolean isCompilerCoreClass(String name) {
            if (name.startsWith("groovyjarjar")) {
                return true;
            }
            if (name.startsWith("org.codehaus.groovy.")) {
                String tail = name.substring("org.codehaus.groovy.".length());
                if (tail.startsWith("ast") || tail.startsWith("classgen") || tail.startsWith("tools.javac") || tail.startsWith("antlr") || tail.startsWith("vmplugin") || tail.startsWith("reflection") || tail.startsWith("control")) {
                    return true;
                }
                if (tail.startsWith("runtime") && name.contains("GroovyMethods")) {
                    return true;
                }
            }
            return false;
        }
    };
    UrlClassLoader groovyAllLoader = UrlClassLoader.build().urls(toUrls(ContainerUtil.concat(GroovyBuilder.getGroovyRtRoots(), Collections.singletonList(groovyAll)))).allowLock().useCache(ourLoaderCachePool, new UrlClassLoader.CachingCondition() {

        @Override
        public boolean shouldCacheData(@NotNull URL url) {
            return true;
        }
    }).get();
    ClassLoader wrapper = new URLClassLoader(new URL[0], groovyAllLoader) {

        @Override
        protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
            if (name.startsWith("groovy.grape.")) {
                // grape depends on Ivy which is not included in this class loader
                throw new ClassNotFoundException(name);
            }
            try {
                return checkWellFormed.loadDependencies(super.loadClass(name, resolve));
            } catch (NoClassDefFoundError e) {
                // For this to happen we should throw ClassNotFoundException
                throw new ClassNotFoundException(name, e);
            }
        }
    };
    ourParentLoaderCache = new SoftReference<>(Pair.create(groovyAll, wrapper));
    return wrapper;
}
Also used : NotNull(org.jetbrains.annotations.NotNull) URL(java.net.URL) URLClassLoader(java.net.URLClassLoader) UrlClassLoader(com.intellij.util.lang.UrlClassLoader) URLClassLoader(java.net.URLClassLoader) ClassDependencyLoader(org.jetbrains.groovy.compiler.rt.ClassDependencyLoader) UrlClassLoader(com.intellij.util.lang.UrlClassLoader) Nullable(org.jetbrains.annotations.Nullable)

Example 90 with URLClassLoader

use of java.net.URLClassLoader in project gerrit by GerritCodeReview.

the class RulesCache method createMachine.

private PrologMachineCopy createMachine(Project.NameKey project, ObjectId rulesId) throws CompileException {
    //
    if (rulesDir != null) {
        Path jarPath = rulesDir.resolve("rules-" + rulesId.getName() + ".jar");
        if (Files.isRegularFile(jarPath)) {
            URL[] cp = new URL[] { toURL(jarPath) };
            return save(newEmptyMachine(new URLClassLoader(cp, systemLoader)));
        }
    }
    // Dynamically consult the rules into the machine's internal database.
    //
    String rules = read(project, rulesId);
    PrologMachineCopy pmc = consultRules("rules.pl", new StringReader(rules));
    if (pmc == null) {
        throw new CompileException("Cannot consult rules of " + project);
    }
    return pmc;
}
Also used : Path(java.nio.file.Path) URLClassLoader(java.net.URLClassLoader) StringReader(java.io.StringReader) CompileException(com.googlecode.prolog_cafe.exceptions.CompileException) PrologMachineCopy(com.googlecode.prolog_cafe.lang.PrologMachineCopy) URL(java.net.URL)

Aggregations

URLClassLoader (java.net.URLClassLoader)1351 URL (java.net.URL)872 File (java.io.File)514 Test (org.junit.Test)317 IOException (java.io.IOException)256 ArrayList (java.util.ArrayList)202 MalformedURLException (java.net.MalformedURLException)186 Method (java.lang.reflect.Method)177 InvocationTargetException (java.lang.reflect.InvocationTargetException)68 JarFile (java.util.jar.JarFile)54 InputStream (java.io.InputStream)50 HashSet (java.util.HashSet)49 HashMap (java.util.HashMap)44 URISyntaxException (java.net.URISyntaxException)41 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)35 Path (java.nio.file.Path)33 QuickTest (com.hazelcast.test.annotation.QuickTest)32 Test (org.junit.jupiter.api.Test)28 URI (java.net.URI)27 List (java.util.List)27