use of org.gradle.internal.service.ServiceRegistry in project gradle by gradle.
the class BuildActionsFactory method runBuildWithDaemon.
private Runnable runBuildWithDaemon(StartParameter startParameter, DaemonParameters daemonParameters, ServiceRegistry loggingServices) {
// Create a client that will match based on the daemon startup parameters.
ServiceRegistry clientSharedServices = createGlobalClientServices();
ServiceRegistry clientServices = clientSharedServices.get(DaemonClientFactory.class).createBuildClientServices(loggingServices.get(OutputEventListener.class), daemonParameters, System.in);
DaemonClient client = clientServices.get(DaemonClient.class);
return runBuildAndCloseServices(startParameter, daemonParameters, client, clientSharedServices, clientServices);
}
use of org.gradle.internal.service.ServiceRegistry in project gradle by gradle.
the class TestUtility method createMockProject.
/**
* Creates a mock project with the specified properties.
*
* Note: depth is 0 for a root project. 1 for a root project's subproject, etc.
*/
public static Project createMockProject(JUnit4Mockery context, final String name, final String buildFilePath, final int depth, Project[] subProjectArray, Task[] tasks, String[] defaultTasks) {
final ProjectInternal project = context.mock(ProjectInternal.class, "[project]_" + name + '_' + uniqueNameCounter++);
final ServiceRegistry services = ServiceRegistryBuilder.builder().provider(new Object() {
ProjectTaskLister createTaskLister() {
return new DefaultProjectTaskLister();
}
}).build();
context.checking(new Expectations() {
{
allowing(project).getName();
will(returnValue(name));
allowing(project).getDescription();
will(returnValue(null));
allowing(project).getBuildFile();
will(returnValue(new File(buildFilePath)));
allowing(project).getDepth();
will(returnValue(depth));
allowing(project).getServices();
will(returnValue(services));
}
});
attachSubProjects(context, project, subProjectArray);
attachTasks(context, project, tasks);
assignDefaultTasks(context, project, defaultTasks);
return project;
}
use of org.gradle.internal.service.ServiceRegistry in project gradle by gradle.
the class DefaultGradleLauncherFactory method createChildInstance.
private GradleLauncher createChildInstance(BuildDefinition buildDefinition, GradleLauncher parent, BuildTreeScopeServices buildTreeScopeServices, List<?> servicesToStop) {
ServiceRegistry services = parent.getGradle().getServices();
BuildRequestMetaData requestMetaData = new DefaultBuildRequestMetaData(services.get(BuildClientMetaData.class));
BuildCancellationToken cancellationToken = services.get(BuildCancellationToken.class);
BuildEventConsumer buildEventConsumer = services.get(BuildEventConsumer.class);
return doNewInstance(buildDefinition, parent, cancellationToken, requestMetaData, buildEventConsumer, buildTreeScopeServices, servicesToStop);
}
use of org.gradle.internal.service.ServiceRegistry in project gradle by gradle.
the class ProjectBuilderImpl method createProject.
public Project createProject(String name, File inputProjectDir, File gradleUserHomeDir) {
File projectDir = prepareProjectDir(inputProjectDir);
final File homeDir = new File(projectDir, "gradleHome");
StartParameter startParameter = new StartParameterInternal();
File userHomeDir = gradleUserHomeDir == null ? new File(projectDir, "userHome") : FileUtils.canonicalize(gradleUserHomeDir);
startParameter.setGradleUserHomeDir(userHomeDir);
NativeServices.initialize(userHomeDir);
BuildRequestMetaData buildRequestMetaData = new DefaultBuildRequestMetaData(Time.currentTimeMillis());
CrossBuildSessionScopeServices crossBuildSessionScopeServices = new CrossBuildSessionScopeServices(getGlobalServices(), startParameter);
ServiceRegistry userHomeServices = getUserHomeServices(userHomeDir);
BuildSessionScopeServices buildSessionScopeServices = new BuildSessionScopeServices(userHomeServices, crossBuildSessionScopeServices, startParameter, buildRequestMetaData, ClassPath.EMPTY);
BuildTreeScopeServices buildTreeScopeServices = new BuildTreeScopeServices(buildSessionScopeServices);
ServiceRegistry topLevelRegistry = new TestBuildScopeServices(buildTreeScopeServices, homeDir);
GradleInternal gradle = CLASS_GENERATOR.newInstance(DefaultGradle.class, null, startParameter, topLevelRegistry.get(ServiceRegistryFactory.class));
DefaultProjectDescriptor projectDescriptor = new DefaultProjectDescriptor(null, name, projectDir, new DefaultProjectDescriptorRegistry(), topLevelRegistry.get(FileResolver.class));
ClassLoaderScope baseScope = gradle.getClassLoaderScope();
ClassLoaderScope rootProjectScope = baseScope.createChild("root-project");
ProjectInternal project = topLevelRegistry.get(IProjectFactory.class).createProject(projectDescriptor, null, gradle, rootProjectScope, baseScope);
gradle.setRootProject(project);
gradle.setDefaultProject(project);
// Take a root worker lease, it won't ever be released as ProjectBuilder has no lifecycle
ResourceLockCoordinationService coordinationService = topLevelRegistry.get(ResourceLockCoordinationService.class);
WorkerLeaseService workerLeaseService = topLevelRegistry.get(WorkerLeaseService.class);
coordinationService.withStateLock(DefaultResourceLockCoordinationService.lock(workerLeaseService.getWorkerLease()));
return project;
}
use of org.gradle.internal.service.ServiceRegistry in project gradle by gradle.
the class BuildActionsFactory method runBuildInSingleUseDaemon.
private Runnable runBuildInSingleUseDaemon(StartParameterInternal startParameter, DaemonParameters daemonParameters, ServiceRegistry loggingServices) {
// (SF) this is a workaround until this story is completed. I'm hardcoding setting the idle timeout to be max X mins.
// this way we avoid potential runaway daemons that steal resources on linux and break builds on windows.
// We might leave that in if we decide it's a good idea for an extra safety net.
int maxTimeout = 2 * 60 * 1000;
if (daemonParameters.getIdleTimeout() > maxTimeout) {
daemonParameters.setIdleTimeout(maxTimeout);
}
// end of workaround.
// Create a client that will not match any existing daemons, so it will always startup a new one
ServiceRegistry clientSharedServices = createGlobalClientServices(true);
ServiceRegistry clientServices = clientSharedServices.get(DaemonClientFactory.class).createSingleUseDaemonClientServices(loggingServices.get(OutputEventListener.class), daemonParameters, System.in);
DaemonClient client = clientServices.get(DaemonClient.class);
return runBuildAndCloseServices(startParameter, daemonParameters, client, clientSharedServices, clientServices);
}
Aggregations