use of org.gradle.internal.classpath.ClassPath in project gradle by gradle.
the class ProcessBootstrap method runNoExit.
private 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(antClasspath);
ClassLoader runtimeClassLoader = new VisitableURLClassLoader(antClassLoader, runtimeClasspath);
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(runtimeClassLoader);
try {
Class<?> mainClass = runtimeClassLoader.loadClass(mainClassName);
Object entryPoint = mainClass.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);
}
}
use of org.gradle.internal.classpath.ClassPath in project gradle by gradle.
the class CachingToolingImplementationLoader method create.
public ConsumerConnection create(Distribution distribution, ProgressLoggerFactory progressLoggerFactory, InternalBuildProgressListener progressListener, ConnectionParameters connectionParameters, BuildCancellationToken cancellationToken) {
ClassPath classpath = distribution.getToolingImplementationClasspath(progressLoggerFactory, progressListener, connectionParameters.getGradleUserHomeDir(), cancellationToken);
ConsumerConnection connection = connections.get(classpath);
if (connection == null) {
connection = loader.create(distribution, progressLoggerFactory, progressListener, connectionParameters, cancellationToken);
connections.put(classpath, connection);
}
return connection;
}
use of org.gradle.internal.classpath.ClassPath in project gradle by gradle.
the class BuildSourceBuilder method buildAndCreateClassLoader.
public ClassLoaderScope buildAndCreateClassLoader(GradleInternal gradle, File rootDir, StartParameter containingBuildParameters) {
File buildSrcDir = new File(rootDir, DefaultSettings.DEFAULT_BUILD_SRC_DIR);
ClassPath classpath = createBuildSourceClasspath(gradle, buildSrcDir, containingBuildParameters);
return classLoaderScope.createChild(buildSrcDir.getAbsolutePath()).export(classpath).lock();
}
use of org.gradle.internal.classpath.ClassPath in project gradle by gradle.
the class BuildSourceBuilder method createBuildSourceClasspath.
private ClassPath createBuildSourceClasspath(final GradleInternal gradle, File buildSrcDir, final StartParameter containingBuildParameters) {
if (!buildSrcDir.isDirectory()) {
LOGGER.debug("Gradle source dir does not exist. We leave.");
return ClassPath.EMPTY;
}
final StartParameter buildSrcStartParameter = containingBuildParameters.newBuild();
buildSrcStartParameter.setCurrentDir(buildSrcDir);
buildSrcStartParameter.setProjectProperties(containingBuildParameters.getProjectProperties());
buildSrcStartParameter.setSearchUpwards(false);
buildSrcStartParameter.setProfile(containingBuildParameters.isProfile());
final BuildDefinition buildDefinition = BuildDefinition.fromStartParameterForBuild(buildSrcStartParameter, buildSrcDir, DefaultPluginRequests.EMPTY);
assert buildSrcStartParameter.getBuildFile() == null;
return buildOperationExecutor.call(new CallableBuildOperation<ClassPath>() {
@Override
public ClassPath call(BuildOperationContext context) {
ClassPath classPath = buildBuildSrc(buildDefinition);
context.setResult(BUILD_BUILDSRC_RESULT);
return classPath;
}
@Override
public BuildOperationDescriptor.Builder description() {
return BuildOperationDescriptor.displayName("Build buildSrc").progressDisplayName("Building buildSrc").details(new BuildBuildSrcBuildOperationType.Details() {
@Override
public String getBuildPath() {
return gradle.getIdentityPath().toString();
}
});
}
});
}
use of org.gradle.internal.classpath.ClassPath in project gradle by gradle.
the class ApplicationClassesInSystemClassLoaderWorkerImplementationFactory method prepareJavaCommand.
@Override
public void prepareJavaCommand(Object workerId, String displayName, DefaultWorkerProcessBuilder processBuilder, List<URL> implementationClassPath, Address serverAddress, JavaExecHandleBuilder execSpec, boolean publishProcessInfo) {
Collection<File> applicationClasspath = processBuilder.getApplicationClasspath();
LogLevel logLevel = processBuilder.getLogLevel();
Set<String> sharedPackages = processBuilder.getSharedPackages();
Object requestedSecurityManager = execSpec.getSystemProperties().get("java.security.manager");
ClassPath workerMainClassPath = classPathRegistry.getClassPath("WORKER_MAIN");
execSpec.setMain("worker." + GradleWorkerMain.class.getName());
boolean useOptionsFile = shouldUseOptionsFile(execSpec);
if (useOptionsFile) {
// Use an options file to pass across application classpath
File optionsFile = temporaryFileProvider.createTemporaryFile("gradle-worker-classpath", "txt");
List<String> jvmArgs = writeOptionsFile(workerMainClassPath.getAsFiles(), applicationClasspath, optionsFile);
execSpec.jvmArgs(jvmArgs);
} else {
// Use a dummy security manager, which hacks the application classpath into the system ClassLoader
execSpec.classpath(workerMainClassPath.getAsFiles());
execSpec.systemProperty("java.security.manager", "worker." + BootstrapSecurityManager.class.getName());
}
// Serialize configuration for the worker process to it stdin
StreamByteBuffer buffer = new StreamByteBuffer();
try {
DataOutputStream outstr = new DataOutputStream(new EncodedStream.EncodedOutput(buffer.getOutputStream()));
if (!useOptionsFile) {
// Serialize the application classpath, this is consumed by BootstrapSecurityManager
outstr.writeInt(applicationClasspath.size());
for (File file : applicationClasspath) {
outstr.writeUTF(file.getAbsolutePath());
}
// Serialize the actual security manager type, this is consumed by BootstrapSecurityManager
outstr.writeUTF(requestedSecurityManager == null ? "" : requestedSecurityManager.toString());
}
// Serialize the shared packages, this is consumed by GradleWorkerMain
outstr.writeInt(sharedPackages.size());
for (String str : sharedPackages) {
outstr.writeUTF(str);
}
// Serialize the worker implementation classpath, this is consumed by GradleWorkerMain
outstr.writeInt(implementationClassPath.size());
for (URL entry : implementationClassPath) {
outstr.writeUTF(entry.toString());
}
// Serialize the worker config, this is consumed by SystemApplicationClassLoaderWorker
OutputStreamBackedEncoder encoder = new OutputStreamBackedEncoder(outstr);
encoder.writeSmallInt(logLevel.ordinal());
encoder.writeBoolean(publishProcessInfo);
encoder.writeString(gradleUserHomeDir.getAbsolutePath());
new MultiChoiceAddressSerializer().write(encoder, (MultiChoiceAddress) serverAddress);
// Serialize the worker, this is consumed by SystemApplicationClassLoaderWorker
ActionExecutionWorker worker = new ActionExecutionWorker(processBuilder.getWorker(), workerId, displayName, gradleUserHomeDir);
byte[] serializedWorker = GUtil.serialize(worker);
encoder.writeBinary(serializedWorker);
encoder.flush();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
execSpec.setStandardInput(buffer.getInputStream());
}
Aggregations