public ClassPathSnapshot snapshot(ClassPath classPath) { List<String> visitedFilePaths = new LinkedList<String>(); Set<File> visitedDirs = new LinkedHashSet<File>(); byte[] combinedHash = new byte[0]; List<File> cpFiles = classPath.getAsFiles(); combinedHash = hash( visitedFilePaths, visitedDirs, combinedHash, cpFiles.toArray(new File[cpFiles.size()])); return new ClassPathSnapshotImpl(visitedFilePaths, combinedHash); }
public DefaultIsolatedAntBuilder( ClassPathRegistry classPathRegistry, ClassLoaderFactory classLoaderFactory) { this.classPathRegistry = classPathRegistry; this.classLoaderFactory = classLoaderFactory; this.libClasspath = new DefaultClassPath(); GroovySystemLoaderFactory groovySystemLoaderFactory = new GroovySystemLoaderFactory(); this.classLoaderCache = new ClassPathToClassLoaderCache(groovySystemLoaderFactory); List<File> antClasspath = Lists.newArrayList(classPathRegistry.getClassPath("ANT").getAsFiles()); // Need tools.jar for compile tasks File toolsJar = Jvm.current().getToolsJar(); if (toolsJar != null) { antClasspath.add(toolsJar); } antLoader = classLoaderFactory.createIsolatedClassLoader(new DefaultClassPath(antClasspath)); FilteringClassLoader loggingLoader = new FilteringClassLoader(getClass().getClassLoader()); loggingLoader.allowPackage("org.slf4j"); loggingLoader.allowPackage("org.apache.commons.logging"); loggingLoader.allowPackage("org.apache.log4j"); loggingLoader.allowClass(Logger.class); loggingLoader.allowClass(LogLevel.class); this.baseAntLoader = new CachingClassLoader(new MultiParentClassLoader(antLoader, loggingLoader)); // Need gradle core to pick up ant logging adapter, AntBuilder and such ClassPath gradleCoreUrls = classPathRegistry.getClassPath("GRADLE_CORE"); gradleCoreUrls = gradleCoreUrls.plus(classPathRegistry.getClassPath("GROOVY")); // Need Transformer (part of AntBuilder API) from base services gradleCoreUrls = gradleCoreUrls.plus(classPathRegistry.getClassPath("GRADLE_BASE_SERVICES")); this.antAdapterLoader = new URLClassLoader(gradleCoreUrls.getAsURLArray(), baseAntLoader); gradleApiGroovyLoader = groovySystemLoaderFactory.forClassLoader(this.getClass().getClassLoader()); antAdapterGroovyLoader = groovySystemLoaderFactory.forClassLoader(antAdapterLoader); // register finalizer for the root builder only! FINALIZERS.add(new Finalizer(this, FINALIZER_REFQUEUE)); }
public ClassPath findClassPath(String name) { if (name.equals("WORKER_PROCESS")) { // TODO - split out a logging project and use its classpath, instead of hardcoding logging // dependencies here ClassPath classpath = new DefaultClassPath(); classpath = classpath.plus( moduleRegistry.getModule("gradle-base-services").getImplementationClasspath()); classpath = classpath.plus(moduleRegistry.getModule("gradle-core").getImplementationClasspath()); classpath = classpath.plus(moduleRegistry.getModule("gradle-cli").getImplementationClasspath()); classpath = classpath.plus(moduleRegistry.getModule("gradle-native").getImplementationClasspath()); classpath = classpath.plus(moduleRegistry.getModule("gradle-messaging").getImplementationClasspath()); classpath = classpath.plus(moduleRegistry.getExternalModule("slf4j-api").getClasspath()); classpath = classpath.plus(moduleRegistry.getExternalModule("logback-classic").getClasspath()); classpath = classpath.plus(moduleRegistry.getExternalModule("logback-core").getClasspath()); classpath = classpath.plus(moduleRegistry.getExternalModule("jul-to-slf4j").getClasspath()); classpath = classpath.plus(moduleRegistry.getExternalModule("guava-jdk5").getClasspath()); return classpath; } if (name.equals("WORKER_MAIN")) { synchronized (lock) { if (workerClassPath == null) { workerClassPathCache = cacheRepository.cache("workerMain").withInitializer(new CacheInitializer()).open(); workerClassPath = new DefaultClassPath(jarFile(workerClassPathCache)); } LOGGER.debug("Using worker process classpath: {}", workerClassPath); return workerClassPath; } } return null; }
public ClassLoader createIsolatedClassLoader(ClassPath classPath) { return doCreateIsolatedClassLoader(classPath.getAsURLs()); }
@Override public List<? extends File> getPluginClasspath() { return classpath.getAsFiles(); }
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("-Xdebug"); daemonArgs.add("-Xrunjdwp: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 ByteArrayOutputStream serializedConfig = new ByteArrayOutputStream(); FlushableEncoder encoder = new KryoBackedEncoder(new EncodedStream.EncodedOutput(serializedConfig)); try { encoder.writeString(daemonParameters.getGradleUserHomeDir().getAbsolutePath()); encoder.writeString(daemonDir.getBaseDir().getAbsolutePath()); encoder.writeSmallInt(daemonParameters.getIdleTimeout()); 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); } ByteArrayInputStream stdInput = new ByteArrayInputStream(serializedConfig.toByteArray()); DaemonStartupInfo daemonInfo = startProcess(daemonArgs, daemonDir.getVersionedDir(), stdInput); listener.daemonStarted(daemonInfo); return daemonInfo; }