Search in sources :

Example 1 with CachingClassLoader

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;
}
Also used : MultiParentClassLoader(org.gradle.internal.classloader.MultiParentClassLoader) MultiParentClassLoader(org.gradle.internal.classloader.MultiParentClassLoader) CachingClassLoader(org.gradle.internal.classloader.CachingClassLoader) MethodInvocation(org.gradle.internal.dispatch.MethodInvocation) CachingClassLoader(org.gradle.internal.classloader.CachingClassLoader) InterHubMessage(org.gradle.internal.remote.internal.hub.protocol.InterHubMessage)

Example 2 with CachingClassLoader

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()));
}
Also used : VisitableURLClassLoader(org.gradle.internal.classloader.VisitableURLClassLoader) FilteringClassLoader(org.gradle.internal.classloader.FilteringClassLoader) MultiParentClassLoader(org.gradle.internal.classloader.MultiParentClassLoader) FilteringClassLoader(org.gradle.internal.classloader.FilteringClassLoader) VisitableURLClassLoader(org.gradle.internal.classloader.VisitableURLClassLoader) MultiParentClassLoader(org.gradle.internal.classloader.MultiParentClassLoader) CachingClassLoader(org.gradle.internal.classloader.CachingClassLoader) CachingClassLoader(org.gradle.internal.classloader.CachingClassLoader)

Example 3 with CachingClassLoader

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;
    }
}
Also used : MultiParentClassLoader(org.gradle.internal.classloader.MultiParentClassLoader) CachingClassLoader(org.gradle.internal.classloader.CachingClassLoader)

Aggregations

CachingClassLoader (org.gradle.internal.classloader.CachingClassLoader)3 MultiParentClassLoader (org.gradle.internal.classloader.MultiParentClassLoader)3 FilteringClassLoader (org.gradle.internal.classloader.FilteringClassLoader)1 VisitableURLClassLoader (org.gradle.internal.classloader.VisitableURLClassLoader)1 MethodInvocation (org.gradle.internal.dispatch.MethodInvocation)1 InterHubMessage (org.gradle.internal.remote.internal.hub.protocol.InterHubMessage)1