use of org.gradle.internal.classloader.VisitableURLClassLoader in project gradle by gradle.
the class DefaultToolingImplementationLoader method createImplementationClassLoader.
private ClassLoader createImplementationClassLoader(Distribution distribution, ProgressLoggerFactory progressLoggerFactory, InternalBuildProgressListener progressListener, File userHomeDir, BuildCancellationToken cancellationToken) {
ClassPath implementationClasspath = distribution.getToolingImplementationClasspath(progressLoggerFactory, progressListener, userHomeDir, cancellationToken);
LOGGER.debug("Using tooling provider classpath: {}", implementationClasspath);
FilteringClassLoader.Spec filterSpec = new FilteringClassLoader.Spec();
filterSpec.allowPackage("org.gradle.tooling.internal.protocol");
FilteringClassLoader filteringClassLoader = new FilteringClassLoader(classLoader, filterSpec);
return new VisitableURLClassLoader(filteringClassLoader, implementationClasspath);
}
use of org.gradle.internal.classloader.VisitableURLClassLoader in project gradle by gradle.
the class InProcessWorkerFactory method createWorkerClassLoader.
private ClassLoader createWorkerClassLoader(ClassLoader actionClasspathLoader, Iterable<String> sharedPackages, Class<? extends WorkerAction> actionClass) {
FilteringClassLoader.Spec actionFilterSpec = new FilteringClassLoader.Spec();
for (String packageName : sharedPackages) {
actionFilterSpec.allowPackage(packageName);
}
ClassLoader actionFilteredClasspathLoader = classLoaderFactory.createFilteringClassLoader(actionClasspathLoader, actionFilterSpec);
FilteringClassLoader.Spec gradleApiFilterSpec = new FilteringClassLoader.Spec();
// Logging
gradleApiFilterSpec.allowPackage("org.slf4j");
gradleApiFilterSpec.allowClass(Logger.class);
gradleApiFilterSpec.allowClass(LogLevel.class);
// Native
gradleApiFilterSpec.allowPackage("org.gradle.internal.nativeintegration");
gradleApiFilterSpec.allowPackage("org.gradle.internal.nativeplatform");
gradleApiFilterSpec.allowPackage("net.rubygrapefruit.platform");
// TODO:pm Add Gradle API and a way to opt out of it (for compiler workers)
ClassLoader gradleApiLoader = classLoaderFactory.createFilteringClassLoader(actionClass.getClassLoader(), gradleApiFilterSpec);
ClassLoader actionAndGradleApiLoader = new CachingClassLoader(new MultiParentClassLoader(gradleApiLoader, actionFilteredClasspathLoader));
return new VisitableURLClassLoader(actionAndGradleApiLoader, ClasspathUtil.getClasspath(actionClass.getClassLoader()));
}
use of org.gradle.internal.classloader.VisitableURLClassLoader in project gradle by gradle.
the class DefaultPayloadClassLoaderRegistry method getClassLoader.
private ClassLoader getClassLoader(ClassLoaderDetails details) {
ClassLoader classLoader = cache.getClassLoader(details, detailsToClassLoader);
if (details.spec instanceof ClientOwnedClassLoaderSpec) {
ClientOwnedClassLoaderSpec spec = (ClientOwnedClassLoaderSpec) details.spec;
VisitableURLClassLoader urlClassLoader = (VisitableURLClassLoader) classLoader;
Set<URL> currentClassPath = ImmutableSet.copyOf(urlClassLoader.getURLs());
for (URL url : spec.getClasspath()) {
if (!currentClassPath.contains(url)) {
JavaReflectionUtil.method(URLClassLoader.class, Void.class, "addURL", URL.class).invoke(urlClassLoader, url);
}
}
}
return classLoader;
}
use of org.gradle.internal.classloader.VisitableURLClassLoader in project gradle by gradle.
the class ProcessBootstrap method runNoExit.
private void runNoExit(String mainClassName, String[] args) throws Exception {
ClassPathRegistry classPathRegistry = new DefaultClassPathRegistry(new DefaultClassPathProvider(new DefaultModuleRegistry(CurrentGradleInstallation.get())));
ClassLoaderFactory classLoaderFactory = new DefaultClassLoaderFactory();
ClassPath antClasspath = classPathRegistry.getClassPath("ANT");
ClassPath runtimeClasspath = classPathRegistry.getClassPath("GRADLE_RUNTIME");
ClassLoader antClassLoader = classLoaderFactory.createIsolatedClassLoader(antClasspath);
ClassLoader runtimeClassLoader = new VisitableURLClassLoader(antClassLoader, runtimeClasspath);
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(runtimeClassLoader);
try {
Class<?> mainClass = runtimeClassLoader.loadClass(mainClassName);
Object entryPoint = mainClass.newInstance();
Method mainMethod = mainClass.getMethod("run", String[].class);
mainMethod.invoke(entryPoint, new Object[] { args });
} finally {
Thread.currentThread().setContextClassLoader(oldClassLoader);
ClassLoaderUtils.tryClose(runtimeClassLoader);
ClassLoaderUtils.tryClose(antClassLoader);
}
}
Aggregations