Search in sources :

Example 1 with ClassPath

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

the class BuildSourceBuilder method buildAndCreateClassLoader.

public ClassLoaderScope buildAndCreateClassLoader(StartParameter startParameter) {
    ClassPath classpath = createBuildSourceClasspath(startParameter);
    ClassLoaderScope childScope = classLoaderScope.createChild(startParameter.getCurrentDir().getAbsolutePath());
    childScope.export(cachedClasspathTransformer.transform(classpath));
    childScope.lock();
    return childScope;
}
Also used : DefaultClassPath(org.gradle.internal.classpath.DefaultClassPath) ClassPath(org.gradle.internal.classpath.ClassPath) ClassLoaderScope(org.gradle.api.internal.initialization.ClassLoaderScope)

Example 2 with ClassPath

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

the class DefaultDaemonStarter method startDaemon.

public DaemonStartupInfo startDaemon() {
    String daemonUid = UUID.randomUUID().toString();
    GradleInstallation gradleInstallation = CurrentGradleInstallation.get();
    ModuleRegistry registry = new DefaultModuleRegistry(gradleInstallation);
    ClassPath classpath;
    List<File> searchClassPath;
    if (gradleInstallation == null) {
        // When not running from a Gradle distro, need runtime impl for launcher plus the search path to look for other modules
        classpath = new DefaultClassPath();
        for (Module module : registry.getModule("gradle-launcher").getAllRequiredModules()) {
            classpath = classpath.plus(module.getClasspath());
        }
        searchClassPath = registry.getAdditionalClassPath().getAsFiles();
    } else {
        // When running from a Gradle distro, only need launcher jar. The daemon can find everything from there.
        classpath = registry.getModule("gradle-launcher").getImplementationClasspath();
        searchClassPath = Collections.emptyList();
    }
    if (classpath.isEmpty()) {
        throw new IllegalStateException("Unable to construct a bootstrap classpath when starting the daemon");
    }
    versionValidator.validate(daemonParameters);
    List<String> daemonArgs = new ArrayList<String>();
    daemonArgs.add(daemonParameters.getEffectiveJvm().getJavaExecutable().getAbsolutePath());
    List<String> daemonOpts = daemonParameters.getEffectiveJvmArgs();
    daemonArgs.addAll(daemonOpts);
    daemonArgs.add("-cp");
    daemonArgs.add(CollectionUtils.join(File.pathSeparator, classpath.getAsFiles()));
    if (Boolean.getBoolean("org.gradle.daemon.debug")) {
        daemonArgs.add("-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005");
    }
    LOGGER.debug("Using daemon args: {}", daemonArgs);
    daemonArgs.add(GradleDaemon.class.getName());
    // Version isn't used, except by a human looking at the output of jps.
    daemonArgs.add(GradleVersion.current().getVersion());
    // Serialize configuration to daemon via the process' stdin
    StreamByteBuffer buffer = new StreamByteBuffer();
    FlushableEncoder encoder = new KryoBackedEncoder(new EncodedStream.EncodedOutput(buffer.getOutputStream()));
    try {
        encoder.writeString(daemonParameters.getGradleUserHomeDir().getAbsolutePath());
        encoder.writeString(daemonDir.getBaseDir().getAbsolutePath());
        encoder.writeSmallInt(daemonParameters.getIdleTimeout());
        encoder.writeSmallInt(daemonParameters.getPeriodicCheckInterval());
        encoder.writeString(daemonUid);
        encoder.writeSmallInt(daemonOpts.size());
        for (String daemonOpt : daemonOpts) {
            encoder.writeString(daemonOpt);
        }
        encoder.writeSmallInt(searchClassPath.size());
        for (File file : searchClassPath) {
            encoder.writeString(file.getAbsolutePath());
        }
        encoder.flush();
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
    InputStream stdInput = buffer.getInputStream();
    return startProcess(daemonArgs, daemonDir.getVersionedDir(), stdInput);
}
Also used : DefaultClassPath(org.gradle.internal.classpath.DefaultClassPath) ClassPath(org.gradle.internal.classpath.ClassPath) FlushableEncoder(org.gradle.internal.serialize.FlushableEncoder) EncodedStream(org.gradle.process.internal.streams.EncodedStream) InputStream(java.io.InputStream) ModuleRegistry(org.gradle.api.internal.classpath.ModuleRegistry) DefaultModuleRegistry(org.gradle.api.internal.classpath.DefaultModuleRegistry) ArrayList(java.util.ArrayList) StreamByteBuffer(org.gradle.internal.io.StreamByteBuffer) UncheckedIOException(org.gradle.api.UncheckedIOException) KryoBackedEncoder(org.gradle.internal.serialize.kryo.KryoBackedEncoder) UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) CurrentGradleInstallation(org.gradle.internal.installation.CurrentGradleInstallation) GradleInstallation(org.gradle.internal.installation.GradleInstallation) DefaultModuleRegistry(org.gradle.api.internal.classpath.DefaultModuleRegistry) GradleDaemon(org.gradle.launcher.daemon.bootstrap.GradleDaemon) Module(org.gradle.api.internal.classpath.Module) File(java.io.File) DefaultClassPath(org.gradle.internal.classpath.DefaultClassPath)

Example 3 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, 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);
}
Also used : ClassPath(org.gradle.internal.classpath.ClassPath) VisitableURLClassLoader(org.gradle.internal.classloader.VisitableURLClassLoader) FilteringClassLoader(org.gradle.internal.classloader.FilteringClassLoader)

Example 4 with ClassPath

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

the class DynamicModulesClassPathProvider method findClassPath.

public ClassPath findClassPath(String name) {
    if (name.equals("GRADLE_EXTENSIONS")) {
        Set<Module> coreModules = allRequiredModulesOf("gradle-core");
        ClassPath classpath = ClassPath.EMPTY;
        for (String moduleName : GRADLE_EXTENSION_MODULES) {
            Set<Module> extensionModules = allRequiredModulesOf(moduleName);
            classpath = plusExtensionModules(classpath, extensionModules, coreModules);
        }
        for (String moduleName : GRADLE_OPTIONAL_EXTENSION_MODULES) {
            Set<Module> optionalExtensionModules = allRequiredModulesOfOptional(moduleName);
            classpath = plusExtensionModules(classpath, optionalExtensionModules, coreModules);
        }
        for (Module pluginModule : pluginModuleRegistry.getApiModules()) {
            classpath = classpath.plus(pluginModule.getClasspath());
        }
        for (Module pluginModule : pluginModuleRegistry.getImplementationModules()) {
            classpath = classpath.plus(pluginModule.getClasspath());
        }
        return classpath;
    }
    return null;
}
Also used : ClassPath(org.gradle.internal.classpath.ClassPath) Module(org.gradle.api.internal.classpath.Module)

Example 5 with ClassPath

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

the class DefaultVersionedPlayRunAdapter method getBuildLink.

@Override
public Object getBuildLink(final ClassLoader classLoader, final Reloader reloader, final File projectPath, final File applicationJar, final Iterable<File> changingClasspath, final File assetsJar, final Iterable<File> assetsDirs) throws ClassNotFoundException {
    final ClassLoader assetsClassLoader = createAssetsClassLoader(assetsJar, assetsDirs, classLoader);
    final Class<? extends Throwable> playExceptionClass = Cast.uncheckedCast(classLoader.loadClass(PLAY_EXCEPTION_CLASSNAME));
    return Proxy.newProxyInstance(classLoader, new Class<?>[] { getBuildLinkClass(classLoader) }, new InvocationHandler() {

        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
            if (method.getName().equals("projectPath")) {
                return projectPath;
            } else if (method.getName().equals("reload")) {
                Reloader.Result result = reloader.requireUpToDate();
                // We can't close replaced loaders immediately, because their classes may be used during shutdown,
                // after the return of the reload() call that caused the loader to be swapped out.
                // We have no way of knowing when the loader is actually done with, so we use the request after the request
                // that triggered the reload as the trigger point to close the replaced loader.
                closeOldLoaders();
                if (result.changed) {
                    ClassPath classpath = new DefaultClassPath(applicationJar).plus(new DefaultClassPath(changingClasspath));
                    URLClassLoader currentClassLoader = new URLClassLoader(classpath.getAsURLArray(), assetsClassLoader);
                    storeClassLoader(currentClassLoader);
                    return currentClassLoader;
                } else {
                    Throwable failure = result.failure;
                    if (failure == null) {
                        return null;
                    } else {
                        try {
                            return DirectInstantiator.instantiate(playExceptionClass, "Gradle Build Failure", failure.getMessage(), failure);
                        } catch (Exception e) {
                            LOGGER.warn("Could not translate " + failure + " to " + PLAY_EXCEPTION_CLASSNAME, e);
                            return failure;
                        }
                    }
                }
            } else if (method.getName().equals("settings")) {
                return new HashMap<String, String>();
            }
            // TODO: all methods
            return null;
        }
    });
}
Also used : DefaultClassPath(org.gradle.internal.classpath.DefaultClassPath) ClassPath(org.gradle.internal.classpath.ClassPath) Method(java.lang.reflect.Method) ScalaMethod(org.gradle.scala.internal.reflect.ScalaMethod) InvocationHandler(java.lang.reflect.InvocationHandler) UncheckedException(org.gradle.internal.UncheckedException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) DefaultClassPath(org.gradle.internal.classpath.DefaultClassPath)

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