use of org.gradle.internal.classloader.CachingClassLoader in project gradle by gradle.
the class MessageHubBackedObjectConnection method connect.
public void connect() {
ClassLoader methodParamClassLoader;
if (methodParamClassLoaders.size() == 0) {
methodParamClassLoader = getClass().getClassLoader();
} else if (methodParamClassLoaders.size() == 1) {
methodParamClassLoader = CollectionUtils.single(methodParamClassLoaders);
} else {
methodParamClassLoader = new CachingClassLoader(new MultiParentClassLoader(methodParamClassLoaders));
}
MethodArgsSerializer argsSerializer = new DefaultMethodArgsSerializer(paramSerializers, new JavaSerializationBackedMethodArgsSerializer(methodParamClassLoader));
StatefulSerializer<InterHubMessage> serializer = new InterHubMessageSerializer(new TypeSafeSerializer<MethodInvocation>(MethodInvocation.class, new MethodInvocationSerializer(methodParamClassLoader, argsSerializer)));
connection = completion.create(serializer);
hub.addConnection(connection);
hub.noFurtherConnections();
completion = null;
}
use of org.gradle.internal.classloader.CachingClassLoader 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.CachingClassLoader in project gradle by gradle.
the class DefaultClassLoaderScope method buildEffectiveLoaders.
private void buildEffectiveLoaders() {
if (effectiveLocalClassLoader == null) {
boolean hasExports = !export.isEmpty() || exportLoaders != null;
boolean hasLocals = !local.isEmpty();
if (locked) {
if (hasExports && hasLocals) {
effectiveExportClassLoader = buildLockedLoader(id.exportId(), export, exportLoaders);
effectiveLocalClassLoader = buildLockedLoader(id.localId(), effectiveExportClassLoader, local);
} else if (hasLocals) {
classLoaderCache.remove(id.exportId());
effectiveLocalClassLoader = buildLockedLoader(id.localId(), local);
effectiveExportClassLoader = parent.getExportClassLoader();
} else if (hasExports) {
classLoaderCache.remove(id.localId());
effectiveLocalClassLoader = buildLockedLoader(id.exportId(), export, exportLoaders);
effectiveExportClassLoader = effectiveLocalClassLoader;
} else {
classLoaderCache.remove(id.localId());
classLoaderCache.remove(id.exportId());
effectiveLocalClassLoader = parent.getExportClassLoader();
effectiveExportClassLoader = parent.getExportClassLoader();
}
} else {
// creating before locking, have to create the most flexible setup
if (Boolean.getBoolean(STRICT_MODE_PROPERTY)) {
throw new IllegalStateException("Attempt to define scope class loader before scope is locked");
}
exportingClassLoader = buildMultiLoader(id.exportId(), export, exportLoaders);
effectiveExportClassLoader = new CachingClassLoader(exportingClassLoader);
localClassLoader = new MultiParentClassLoader(effectiveExportClassLoader, loader(id.localId(), local));
effectiveLocalClassLoader = new CachingClassLoader(localClassLoader);
}
export = null;
exportLoaders = null;
local = null;
}
}
Aggregations