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);
}
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 }));
}
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"));
}
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;
}
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;
}
Aggregations