Search in sources :

Example 26 with ClassPath

use of org.gradle.internal.classpath.ClassPath in project gradle by gradle.

the class DefaultToolingImplementationLoader method createImplementationClassLoader.

private ClassLoader createImplementationClassLoader(Distribution distribution, ProgressLoggerFactory progressLoggerFactory, InternalBuildProgressListener progressListener, ConnectionParameters connectionParameters, BuildCancellationToken cancellationToken) {
    ClassPath implementationClasspath = distribution.getToolingImplementationClasspath(progressLoggerFactory, progressListener, connectionParameters, cancellationToken);
    LOGGER.debug("Using tooling provider classpath: {}", implementationClasspath);
    FilteringClassLoader.Spec filterSpec = new FilteringClassLoader.Spec();
    filterSpec.allowPackage("org.gradle.tooling.internal.protocol");
    filterSpec.allowClass(JavaVersion.class);
    FilteringClassLoader filteringClassLoader = new FilteringClassLoader(classLoader, filterSpec);
    return new VisitableURLClassLoader("tooling-implementation-loader", filteringClassLoader, implementationClasspath);
}
Also used : ClassPath(org.gradle.internal.classpath.ClassPath) VisitableURLClassLoader(org.gradle.internal.classloader.VisitableURLClassLoader) FilteringClassLoader(org.gradle.internal.classloader.FilteringClassLoader)

Example 27 with ClassPath

use of org.gradle.internal.classpath.ClassPath in project gradle by gradle.

the class WorkerProcessClassPathProvider method findClassPath.

@Override
public ClassPath findClassPath(String name) {
    if (name.equals("WORKER_MAIN")) {
        synchronized (lock) {
            if (workerClassPath == null) {
                PersistentCache workerClassPathCache = cacheRepository.cache("workerMain").withLockOptions(LockOptionsBuilder.mode(FileLockManager.LockMode.Exclusive)).withInitializer(new CacheInitializer()).open();
                try {
                    workerClassPath = DefaultClassPath.of(jarFile(workerClassPathCache));
                } finally {
                    workerClassPathCache.close();
                }
            }
            LOGGER.debug("Using worker process classpath: {}", workerClassPath);
            return workerClassPath;
        }
    }
    // Gradle core plus worker implementation classes
    if (name.equals("CORE_WORKER_RUNTIME")) {
        ClassPath classpath = ClassPath.EMPTY;
        classpath = classpath.plus(moduleRegistry.getModule("gradle-core").getAllRequiredModulesClasspath());
        // If a real Gradle installation is used, the following modules will be force-loaded anyway by gradle-core through the getClassPath("GRADLE_EXTENSIONS") call in the DefaultClassLoaderRegistry constructor
        // See also: DynamicModulesClassPathProvider.GRADLE_EXTENSION_MODULES
        classpath = classpath.plus(moduleRegistry.getModule("gradle-dependency-management").getAllRequiredModulesClasspath());
        classpath = classpath.plus(moduleRegistry.getModule("gradle-plugin-use").getAllRequiredModulesClasspath());
        classpath = classpath.plus(moduleRegistry.getModule("gradle-workers").getAllRequiredModulesClasspath());
        return classpath;
    }
    // Just the minimal stuff necessary for the worker infrastructure
    if (name.equals("MINIMUM_WORKER_RUNTIME")) {
        ClassPath classpath = ClassPath.EMPTY;
        for (String module : RUNTIME_MODULES) {
            classpath = classpath.plus(moduleRegistry.getModule(module).getImplementationClasspath());
        }
        for (String externalModule : RUNTIME_EXTERNAL_MODULES) {
            classpath = classpath.plus(moduleRegistry.getExternalModule(externalModule).getImplementationClasspath());
        }
        classpath = optimizeForClassloading(classpath);
        return classpath;
    }
    return null;
}
Also used : DefaultClassPath(org.gradle.internal.classpath.DefaultClassPath) ClassPath(org.gradle.internal.classpath.ClassPath) PersistentCache(org.gradle.cache.PersistentCache)

Example 28 with ClassPath

use of org.gradle.internal.classpath.ClassPath in project gradle by gradle.

the class WorkerProcessClassPathProvider method optimizeForClassloading.

private static ClassPath optimizeForClassloading(ClassPath classpath) {
    ClassPath optimizedForLoading = ClassPath.EMPTY;
    List<File> optimizedFiles = Lists.newArrayListWithCapacity(WORKER_OPTIMIZED_LOADING_ORDER.length);
    List<File> remainder = Lists.newArrayList(classpath.getAsFiles());
    for (String module : WORKER_OPTIMIZED_LOADING_ORDER) {
        Iterator<File> asFiles = remainder.iterator();
        while (asFiles.hasNext()) {
            File file = asFiles.next();
            if (file.getName().startsWith(module)) {
                optimizedFiles.add(file);
                asFiles.remove();
            }
        }
        if (remainder.isEmpty()) {
            break;
        }
    }
    classpath = optimizedForLoading.plus(optimizedFiles).plus(remainder);
    return classpath;
}
Also used : DefaultClassPath(org.gradle.internal.classpath.DefaultClassPath) ClassPath(org.gradle.internal.classpath.ClassPath) File(java.io.File)

Example 29 with ClassPath

use of org.gradle.internal.classpath.ClassPath in project gradle by gradle.

the class DefaultDependenciesAccessors method executeWork.

private void executeWork(UnitOfWork work) {
    ExecutionEngine.Result result = engine.createRequest(work).execute();
    ExecutionResult er = result.getExecutionResult().get();
    GeneratedAccessors accessors = (GeneratedAccessors) er.getOutput();
    ClassPath generatedClasses = DefaultClassPath.of(accessors.classesDir);
    sources = sources.plus(DefaultClassPath.of(accessors.sourcesDir));
    classes = classes.plus(generatedClasses);
    classLoaderScope.export(generatedClasses);
}
Also used : DefaultClassPath(org.gradle.internal.classpath.DefaultClassPath) ClassPath(org.gradle.internal.classpath.ClassPath) ExecutionEngine(org.gradle.internal.execution.ExecutionEngine) ExecutionResult(org.gradle.internal.execution.ExecutionResult)

Example 30 with ClassPath

use of org.gradle.internal.classpath.ClassPath in project gradle by gradle.

the class DependencyClassPathProvider method localGroovy.

private ClassPath localGroovy() {
    Set<String> groovyModules = ImmutableSet.of("groovy-ant", "groovy-astbuilder", "groovy-console", "groovy-datetime", "groovy-dateutil", "groovy-groovydoc", "groovy-json", "groovy-nio", "groovy-sql", "groovy-templates", "groovy-test", "groovy-xml", "javaparser-core");
    ClassPath groovy = moduleRegistry.getExternalModule("groovy").getClasspath();
    for (String groovyModule : groovyModules) {
        groovy = groovy.plus(moduleRegistry.getExternalModule(groovyModule).getClasspath());
    }
    return groovy;
}
Also used : ClassPath(org.gradle.internal.classpath.ClassPath)

Aggregations

ClassPath (org.gradle.internal.classpath.ClassPath)32 DefaultClassPath (org.gradle.internal.classpath.DefaultClassPath)13 File (java.io.File)10 IOException (java.io.IOException)6 VisitableURLClassLoader (org.gradle.internal.classloader.VisitableURLClassLoader)5 Method (java.lang.reflect.Method)3 URLClassLoader (java.net.URLClassLoader)3 ArrayList (java.util.ArrayList)3 UncheckedIOException (org.gradle.api.UncheckedIOException)3 DefaultModuleRegistry (org.gradle.api.internal.classpath.DefaultModuleRegistry)3 Module (org.gradle.api.internal.classpath.Module)3 StreamByteBuffer (org.gradle.internal.io.StreamByteBuffer)3 InputStream (java.io.InputStream)2 InvocationHandler (java.lang.reflect.InvocationHandler)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 URL (java.net.URL)2 BuildActionParameters (org.gradle.launcher.exec.BuildActionParameters)2 DefaultBuildActionParameters (org.gradle.launcher.exec.DefaultBuildActionParameters)2 Lists (com.google.common.collect.Lists)1 Closure (groovy.lang.Closure)1