Search in sources :

Example 1 with DefaultClassPath

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

the class DynamicModulesClassPathProvider method findClassPath.

public ClassPath findClassPath(String name) {
    if (name.equals("GRADLE_EXTENSIONS")) {
        Set<Module> coreModules = moduleRegistry.getModule("gradle-core").getAllRequiredModules();
        ClassPath classpath = new DefaultClassPath();
        for (String moduleName : Arrays.asList("gradle-workers", "gradle-dependency-management", "gradle-plugin-use")) {
            for (Module module : moduleRegistry.getModule(moduleName).getAllRequiredModules()) {
                if (!coreModules.contains(module)) {
                    classpath = classpath.plus(module.getClasspath());
                }
            }
        }
        for (Module pluginModule : pluginModuleRegistry.getPluginModules()) {
            classpath = classpath.plus(pluginModule.getClasspath());
        }
        return classpath;
    }
    return null;
}
Also used : DefaultClassPath(org.gradle.internal.classpath.DefaultClassPath) ClassPath(org.gradle.internal.classpath.ClassPath) Module(org.gradle.api.internal.classpath.Module) DefaultClassPath(org.gradle.internal.classpath.DefaultClassPath)

Example 2 with DefaultClassPath

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

the class DefaultClassPathProvider method findClassPath.

public ClassPath findClassPath(String name) {
    if (name.equals("GRADLE_RUNTIME")) {
        ClassPath classpath = new DefaultClassPath();
        for (Module module : moduleRegistry.getModule("gradle-launcher").getAllRequiredModules()) {
            classpath = classpath.plus(module.getClasspath());
        }
        return classpath;
    }
    if (name.equals("GRADLE_INSTALLATION_BEACON")) {
        return moduleRegistry.getModule("gradle-installation-beacon").getImplementationClasspath();
    }
    if (name.equals("COMMONS_CLI")) {
        return moduleRegistry.getExternalModule("commons-cli").getClasspath();
    }
    if (name.equals("ANT")) {
        ClassPath classpath = new DefaultClassPath();
        classpath = classpath.plus(moduleRegistry.getExternalModule("ant").getClasspath());
        classpath = classpath.plus(moduleRegistry.getExternalModule("ant-launcher").getClasspath());
        return classpath;
    }
    return null;
}
Also used : DefaultClassPath(org.gradle.internal.classpath.DefaultClassPath) ClassPath(org.gradle.internal.classpath.ClassPath) Module(org.gradle.api.internal.classpath.Module) DefaultClassPath(org.gradle.internal.classpath.DefaultClassPath)

Example 3 with DefaultClassPath

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

the class AbstractJettyRunTask method start.

@TaskAction
protected void start() {
    ClassLoader originalClassloader = Server.class.getClassLoader();
    List<File> additionalClasspath = new ArrayList<File>();
    for (File additionalRuntimeJar : getAdditionalRuntimeJars()) {
        additionalClasspath.add(additionalRuntimeJar);
    }
    URLClassLoader jettyClassloader = new URLClassLoader(new DefaultClassPath(additionalClasspath).getAsURLArray(), originalClassloader);
    try {
        Thread.currentThread().setContextClassLoader(jettyClassloader);
        startJetty();
    } finally {
        Thread.currentThread().setContextClassLoader(originalClassloader);
    }
}
Also used : URLClassLoader(java.net.URLClassLoader) ArrayList(java.util.ArrayList) URLClassLoader(java.net.URLClassLoader) File(java.io.File) InputFile(org.gradle.api.tasks.InputFile) DefaultClassPath(org.gradle.internal.classpath.DefaultClassPath) TaskAction(org.gradle.api.tasks.TaskAction)

Example 4 with DefaultClassPath

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

the class PlayWorkerServer method run.

private void run() {
    ClassLoaderUtils.disableUrlConnectionCaching();
    final Thread thread = Thread.currentThread();
    final ClassLoader previousContextClassLoader = thread.getContextClassLoader();
    final ClassLoader classLoader = new URLClassLoader(new DefaultClassPath(runSpec.getClasspath()).getAsURLArray(), null);
    thread.setContextClassLoader(classLoader);
    try {
        Object buildDocHandler = runAdapter.getBuildDocHandler(classLoader, runSpec.getClasspath());
        Object buildLink = runAdapter.getBuildLink(classLoader, runSpec.getProjectPath(), runSpec.getApplicationJar(), runSpec.getChangingClasspath(), runSpec.getAssetsJar(), runSpec.getAssetsDirs());
        runAdapter.runDevHttpServer(classLoader, classLoader, buildLink, buildDocHandler, runSpec.getHttpPort());
    } catch (Exception e) {
        throw UncheckedException.throwAsUncheckedException(e);
    } finally {
        thread.setContextClassLoader(previousContextClassLoader);
    }
}
Also used : URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) UncheckedException(org.gradle.internal.UncheckedException) DefaultClassPath(org.gradle.internal.classpath.DefaultClassPath)

Example 5 with DefaultClassPath

use of org.gradle.internal.classpath.DefaultClassPath 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)

Aggregations

DefaultClassPath (org.gradle.internal.classpath.DefaultClassPath)15 File (java.io.File)8 ClassPath (org.gradle.internal.classpath.ClassPath)5 IOException (java.io.IOException)4 URLClassLoader (java.net.URLClassLoader)4 UncheckedIOException (org.gradle.api.UncheckedIOException)4 Module (org.gradle.api.internal.classpath.Module)3 TaskAction (org.gradle.api.tasks.TaskAction)3 ArrayList (java.util.ArrayList)2 UncheckedException (org.gradle.internal.UncheckedException)2 LoggingManagerInternal (org.gradle.internal.logging.LoggingManagerInternal)2 Daemon (org.gradle.launcher.daemon.server.Daemon)2 DaemonServices (org.gradle.launcher.daemon.server.DaemonServices)2 DaemonExpirationStrategy (org.gradle.launcher.daemon.server.expiry.DaemonExpirationStrategy)2 GroovyClassLoader (groovy.lang.GroovyClassLoader)1 BufferedOutputStream (java.io.BufferedOutputStream)1 EOFException (java.io.EOFException)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1