Search in sources :

Example 21 with ClassPath

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

the class CachingToolingImplementationLoader method create.

@Override
public ConsumerConnection create(Distribution distribution, ProgressLoggerFactory progressLoggerFactory, InternalBuildProgressListener progressListener, ConnectionParameters connectionParameters, BuildCancellationToken cancellationToken) {
    ClassPath classpath = distribution.getToolingImplementationClasspath(progressLoggerFactory, progressListener, connectionParameters, cancellationToken);
    ConsumerConnection connection = connections.get(classpath);
    if (connection == null) {
        connection = loader.create(distribution, progressLoggerFactory, progressListener, connectionParameters, cancellationToken);
        connections.put(classpath, connection);
    }
    return connection;
}
Also used : ClassPath(org.gradle.internal.classpath.ClassPath) ConsumerConnection(org.gradle.tooling.internal.consumer.connection.ConsumerConnection)

Example 22 with ClassPath

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

the class ProcessBootstrap method runNoExit.

private static 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("ant-loader", antClasspath);
    ClassLoader runtimeClassLoader = new VisitableURLClassLoader("ant-and-gradle-loader", antClassLoader, runtimeClasspath);
    ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(runtimeClassLoader);
    try {
        Class<?> mainClass = runtimeClassLoader.loadClass(mainClassName);
        Object entryPoint = mainClass.getConstructor().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);
    }
}
Also used : DefaultClassLoaderFactory(org.gradle.internal.classloader.DefaultClassLoaderFactory) ClassPath(org.gradle.internal.classpath.ClassPath) ClassLoaderFactory(org.gradle.internal.classloader.ClassLoaderFactory) DefaultClassLoaderFactory(org.gradle.internal.classloader.DefaultClassLoaderFactory) VisitableURLClassLoader(org.gradle.internal.classloader.VisitableURLClassLoader) DefaultClassPathProvider(org.gradle.api.internal.DefaultClassPathProvider) Method(java.lang.reflect.Method) ClassPathRegistry(org.gradle.api.internal.ClassPathRegistry) DefaultClassPathRegistry(org.gradle.api.internal.DefaultClassPathRegistry) DefaultModuleRegistry(org.gradle.api.internal.classpath.DefaultModuleRegistry) DefaultClassPathRegistry(org.gradle.api.internal.DefaultClassPathRegistry) VisitableURLClassLoader(org.gradle.internal.classloader.VisitableURLClassLoader)

Example 23 with ClassPath

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

the class DefaultPluginRequestApplicator method exportBuildLogicClassPathTo.

private void exportBuildLogicClassPathTo(ClassLoaderScope classLoaderScope, ClassPath classPath) {
    ClassPath cachedClassPath = cachedClasspathTransformer.transform(classPath, BuildLogic);
    classLoaderScope.export(cachedClassPath);
}
Also used : ClassPath(org.gradle.internal.classpath.ClassPath)

Example 24 with ClassPath

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

the class DefaultDaemonStarter method startDaemon.

@Override
public DaemonStartupInfo startDaemon(boolean singleUse) {
    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 = registry.getModule("gradle-launcher").getAllRequiredModulesClasspath();
        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.addAll(getPriorityArgs(daemonParameters.getPriority()));
    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.writeBoolean(singleUse);
        encoder.writeString(daemonUid);
        encoder.writeSmallInt(daemonParameters.getPriority().ordinal());
        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(), daemonParameters.getGradleUserHomeDir().getAbsoluteFile(), stdInput);
}
Also used : ClassPath(org.gradle.internal.classpath.ClassPath) FlushableEncoder(org.gradle.internal.serialize.FlushableEncoder) EncodedStream(org.gradle.internal.stream.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) File(java.io.File)

Example 25 with ClassPath

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

the class DaemonBuildActionExecuter method execute.

@Override
public BuildActionResult execute(BuildAction action, ConnectionOperationParameters parameters, BuildRequestContext buildRequestContext) {
    ProviderOperationParameters operationParameters = parameters.getOperationParameters();
    ClassPath classPath = DefaultClassPath.of(operationParameters.getInjectedPluginClasspath());
    DaemonParameters daemonParameters = parameters.getDaemonParameters();
    BuildActionParameters actionParameters = new DefaultBuildActionParameters(daemonParameters.getEffectiveSystemProperties(), daemonParameters.getEnvironmentVariables(), SystemProperties.getInstance().getCurrentDir(), operationParameters.getBuildLogLevel(), daemonParameters.isEnabled(), classPath);
    return executer.execute(action, actionParameters, buildRequestContext);
}
Also used : DefaultClassPath(org.gradle.internal.classpath.DefaultClassPath) ClassPath(org.gradle.internal.classpath.ClassPath) DefaultBuildActionParameters(org.gradle.launcher.exec.DefaultBuildActionParameters) ProviderOperationParameters(org.gradle.tooling.internal.provider.connection.ProviderOperationParameters) DefaultBuildActionParameters(org.gradle.launcher.exec.DefaultBuildActionParameters) BuildActionParameters(org.gradle.launcher.exec.BuildActionParameters) DaemonParameters(org.gradle.launcher.daemon.configuration.DaemonParameters)

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