Search in sources :

Example 1 with BuildRequestMetaData

use of org.gradle.initialization.BuildRequestMetaData in project gradle by gradle.

the class ContinuousBuildActionExecutor method executeMultipleBuilds.

private BuildActionRunner.Result executeMultipleBuilds(BuildAction action, BuildRequestMetaData requestContext, BuildSessionContext buildSession, BuildCancellationToken cancellationToken, CancellableOperationManager cancellableOperationManager, ContinuousExecutionGate continuousExecutionGate) {
    BuildActionRunner.Result lastResult;
    PendingChangesListener pendingChangesListener = listenerManager.getBroadcaster(PendingChangesListener.class);
    while (true) {
        BuildInputHierarchy buildInputs = new BuildInputHierarchy(caseSensitivity, stat);
        ContinuousBuildTriggerHandler continuousBuildTriggerHandler = new ContinuousBuildTriggerHandler(cancellationToken, continuousExecutionGate, action.getStartParameter().getContinuousBuildQuietPeriod());
        SingleFirePendingChangesListener singleFirePendingChangesListener = new SingleFirePendingChangesListener(pendingChangesListener);
        FileEventCollector fileEventCollector = new FileEventCollector(buildInputs, () -> {
            continuousBuildTriggerHandler.notifyFileChangeArrived();
            singleFirePendingChangesListener.onPendingChanges();
        });
        try {
            fileChangeListeners.addListener(fileEventCollector);
            lastResult = executeBuildAndAccumulateInputs(action, new AccumulateBuildInputsListener(buildInputs), buildSession);
            if (buildInputs.isEmpty()) {
                logger.println().withStyle(StyledTextOutput.Style.Failure).println("Exiting continuous build as Gradle did not detect any file system inputs.");
                return lastResult;
            } else if (!continuousBuildTriggerHandler.hasBeenTriggered() && !fileSystemWatchingInformation.isWatchingAnyLocations()) {
                logger.println().withStyle(StyledTextOutput.Style.Failure).println("Exiting continuous build as Gradle does not watch any file system locations.");
                return lastResult;
            } else {
                cancellableOperationManager.monitorInput(operationToken -> {
                    continuousBuildTriggerHandler.wait(() -> logger.println().println("Waiting for changes to input files..." + determineExitHint(requestContext)));
                    if (!operationToken.isCancellationRequested()) {
                        fileEventCollector.reportChanges(logger);
                    }
                });
            }
        } finally {
            fileChangeListeners.removeListener(fileEventCollector);
        }
        if (cancellationToken.isCancellationRequested()) {
            break;
        } else {
            logger.println("Change detected, executing build...").println();
            resetBuildStartedTime();
        }
    }
    logger.println("Build cancelled.");
    return lastResult;
}
Also used : DefaultCancellableOperationManager(org.gradle.execution.DefaultCancellableOperationManager) BuildRequestMetaData(org.gradle.initialization.BuildRequestMetaData) ExecutorFactory(org.gradle.internal.concurrent.ExecutorFactory) Supplier(java.util.function.Supplier) DeploymentRegistryInternal(org.gradle.deployment.internal.DeploymentRegistryInternal) BuildSessionActionExecutor(org.gradle.internal.session.BuildSessionActionExecutor) WorkInputListeners(org.gradle.internal.execution.WorkInputListeners) ContinuousExecutionGate(org.gradle.deployment.internal.ContinuousExecutionGate) Clock(org.gradle.internal.time.Clock) WorkInputListener(org.gradle.internal.execution.WorkInputListener) DisconnectableInputStream(org.gradle.util.internal.DisconnectableInputStream) PassThruCancellableOperationManager(org.gradle.execution.PassThruCancellableOperationManager) Deployment(org.gradle.deployment.internal.Deployment) CancellableOperationManager(org.gradle.execution.CancellableOperationManager) BuildActionRunner(org.gradle.internal.buildtree.BuildActionRunner) LogLevel(org.gradle.api.logging.LogLevel) BuildCancellationToken(org.gradle.initialization.BuildCancellationToken) ListenerManager(org.gradle.internal.event.ListenerManager) CaseSensitivity(org.gradle.internal.snapshot.CaseSensitivity) Stat(org.gradle.internal.file.Stat) StyledTextOutput(org.gradle.internal.logging.text.StyledTextOutput) FileSystemWatchingInformation(org.gradle.internal.watch.vfs.FileSystemWatchingInformation) DeploymentInternal(org.gradle.deployment.internal.DeploymentInternal) OperatingSystem(org.gradle.internal.os.OperatingSystem) DefaultContinuousExecutionGate(org.gradle.deployment.internal.DefaultContinuousExecutionGate) FileChangeListeners(org.gradle.internal.watch.vfs.FileChangeListeners) PendingChangesListener(org.gradle.deployment.internal.PendingChangesListener) BuildAction(org.gradle.internal.invocation.BuildAction) BuildStartedTime(org.gradle.internal.buildevents.BuildStartedTime) BuildSessionContext(org.gradle.internal.session.BuildSessionContext) StyledTextOutputFactory(org.gradle.internal.logging.text.StyledTextOutputFactory) PendingChangesListener(org.gradle.deployment.internal.PendingChangesListener) BuildActionRunner(org.gradle.internal.buildtree.BuildActionRunner)

Example 2 with BuildRequestMetaData

use of org.gradle.initialization.BuildRequestMetaData in project gradle by gradle.

the class DefaultNestedBuildTree method run.

@Override
public <T> T run(Function<? super BuildTreeLifecycleController, T> buildAction) {
    StartParameterInternal startParameter = buildDefinition.getStartParameter();
    BuildRequestMetaData buildRequestMetaData = new DefaultBuildRequestMetaData(Time.currentTimeMillis());
    BuildSessionState session = new BuildSessionState(userHomeDirServiceRegistry, crossBuildSessionState, startParameter, buildRequestMetaData, ClassPath.EMPTY, buildCancellationToken, buildRequestMetaData.getClient(), new NoOpBuildEventConsumer());
    try {
        session.getServices().get(BuildLayoutValidator.class).validate(startParameter);
        BuildTreeModelControllerServices.Supplier modelServices = session.getServices().get(BuildTreeModelControllerServices.class).servicesForNestedBuildTree(startParameter);
        BuildTreeState buildTree = new BuildTreeState(session.getServices(), modelServices);
        try {
            RootOfNestedBuildTree rootBuild = new RootOfNestedBuildTree(buildDefinition, buildIdentifier, identityPath, owner, buildTree);
            rootBuild.attach();
            return rootBuild.run(buildAction);
        } finally {
            buildTree.close();
        }
    } finally {
        session.close();
    }
}
Also used : NoOpBuildEventConsumer(org.gradle.initialization.NoOpBuildEventConsumer) BuildRequestMetaData(org.gradle.initialization.BuildRequestMetaData) DefaultBuildRequestMetaData(org.gradle.initialization.DefaultBuildRequestMetaData) BuildLayoutValidator(org.gradle.internal.build.BuildLayoutValidator) BuildTreeModelControllerServices(org.gradle.internal.buildtree.BuildTreeModelControllerServices) DefaultBuildRequestMetaData(org.gradle.initialization.DefaultBuildRequestMetaData) CrossBuildSessionState(org.gradle.internal.session.CrossBuildSessionState) BuildSessionState(org.gradle.internal.session.BuildSessionState) StartParameterInternal(org.gradle.api.internal.StartParameterInternal) BuildTreeState(org.gradle.internal.buildtree.BuildTreeState)

Example 3 with BuildRequestMetaData

use of org.gradle.initialization.BuildRequestMetaData in project gradle by gradle.

the class ProjectBuilderImpl method createProject.

public ProjectInternal createProject(String name, File inputProjectDir, File gradleUserHomeDir) {
    final File projectDir = prepareProjectDir(inputProjectDir);
    File userHomeDir = gradleUserHomeDir == null ? new File(projectDir, "userHome") : FileUtils.canonicalize(gradleUserHomeDir);
    StartParameterInternal startParameter = new StartParameterInternal();
    startParameter.setGradleUserHomeDir(userHomeDir);
    NativeServices.initializeOnDaemon(userHomeDir);
    final ServiceRegistry globalServices = getGlobalServices();
    BuildRequestMetaData buildRequestMetaData = new DefaultBuildRequestMetaData(Time.currentTimeMillis());
    CrossBuildSessionState crossBuildSessionState = new CrossBuildSessionState(globalServices, startParameter);
    GradleUserHomeScopeServiceRegistry userHomeServices = userHomeServicesOf(globalServices);
    BuildSessionState buildSessionState = new BuildSessionState(userHomeServices, crossBuildSessionState, startParameter, buildRequestMetaData, ClassPath.EMPTY, new DefaultBuildCancellationToken(), buildRequestMetaData.getClient(), new NoOpBuildEventConsumer());
    BuildTreeModelControllerServices.Supplier modelServices = buildSessionState.getServices().get(BuildTreeModelControllerServices.class).servicesForBuildTree(new RunTasksRequirements(startParameter));
    BuildTreeState buildTreeState = new BuildTreeState(buildSessionState.getServices(), modelServices);
    TestRootBuild build = new TestRootBuild(projectDir, startParameter, buildTreeState);
    BuildScopeServices buildServices = build.getBuildServices();
    buildServices.get(BuildStateRegistry.class).attachRootBuild(build);
    // Take a root worker lease; this won't ever be released as ProjectBuilder has no lifecycle
    ResourceLockCoordinationService coordinationService = buildServices.get(ResourceLockCoordinationService.class);
    WorkerLeaseService workerLeaseService = buildServices.get(WorkerLeaseService.class);
    WorkerLeaseRegistry.WorkerLeaseCompletion workerLease = workerLeaseService.maybeStartWorker();
    GradleInternal gradle = build.getMutableModel();
    gradle.setIncludedBuilds(Collections.emptyList());
    ProjectDescriptorRegistry projectDescriptorRegistry = buildServices.get(ProjectDescriptorRegistry.class);
    DefaultProjectDescriptor projectDescriptor = new DefaultProjectDescriptor(null, name, projectDir, projectDescriptorRegistry, buildServices.get(FileResolver.class));
    projectDescriptorRegistry.addProject(projectDescriptor);
    ClassLoaderScope baseScope = gradle.getClassLoaderScope();
    ClassLoaderScope rootProjectScope = baseScope.createChild("root-project");
    ProjectStateRegistry projectStateRegistry = buildServices.get(ProjectStateRegistry.class);
    ProjectState projectState = projectStateRegistry.registerProject(build, projectDescriptor);
    projectState.createMutableModel(rootProjectScope, baseScope);
    ProjectInternal project = projectState.getMutableModel();
    gradle.setRootProject(project);
    gradle.setDefaultProject(project);
    // Lock root project; this won't ever be released as ProjectBuilder has no lifecycle
    coordinationService.withStateLock(DefaultResourceLockCoordinationService.lock(project.getOwner().getAccessLock()));
    project.getExtensions().getExtraProperties().set("ProjectBuilder.stoppable", stoppable((Stoppable) workerLeaseService::runAsIsolatedTask, (Stoppable) workerLease::leaseFinish, buildServices, buildTreeState, buildSessionState, crossBuildSessionState));
    return project;
}
Also used : BuildRequestMetaData(org.gradle.initialization.BuildRequestMetaData) DefaultBuildRequestMetaData(org.gradle.initialization.DefaultBuildRequestMetaData) WorkerLeaseRegistry(org.gradle.internal.work.WorkerLeaseRegistry) GradleUserHomeScopeServiceRegistry(org.gradle.internal.service.scopes.GradleUserHomeScopeServiceRegistry) GradleInternal(org.gradle.api.internal.GradleInternal) BuildTreeModelControllerServices(org.gradle.internal.buildtree.BuildTreeModelControllerServices) RunTasksRequirements(org.gradle.internal.buildtree.RunTasksRequirements) ResourceLockCoordinationService(org.gradle.internal.resources.ResourceLockCoordinationService) DefaultResourceLockCoordinationService(org.gradle.internal.resources.DefaultResourceLockCoordinationService) FileResolver(org.gradle.api.internal.file.FileResolver) WorkerLeaseService(org.gradle.internal.work.WorkerLeaseService) CrossBuildSessionState(org.gradle.internal.session.CrossBuildSessionState) BuildStateRegistry(org.gradle.internal.build.BuildStateRegistry) ClassLoaderScope(org.gradle.api.internal.initialization.ClassLoaderScope) DefaultBuildRequestMetaData(org.gradle.initialization.DefaultBuildRequestMetaData) CrossBuildSessionState(org.gradle.internal.session.CrossBuildSessionState) BuildSessionState(org.gradle.internal.session.BuildSessionState) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) BuildScopeServices(org.gradle.internal.service.scopes.BuildScopeServices) Stoppable(org.gradle.internal.concurrent.Stoppable) BuildTreeState(org.gradle.internal.buildtree.BuildTreeState) DefaultProjectDescriptor(org.gradle.initialization.DefaultProjectDescriptor) NoOpBuildEventConsumer(org.gradle.initialization.NoOpBuildEventConsumer) ProjectDescriptorRegistry(org.gradle.initialization.ProjectDescriptorRegistry) DefaultBuildCancellationToken(org.gradle.initialization.DefaultBuildCancellationToken) StartParameterInternal(org.gradle.api.internal.StartParameterInternal) ProjectState(org.gradle.api.internal.project.ProjectState) GradleUserHomeScopeServiceRegistry(org.gradle.internal.service.scopes.GradleUserHomeScopeServiceRegistry) LoggingServiceRegistry(org.gradle.internal.logging.services.LoggingServiceRegistry) ServiceRegistry(org.gradle.internal.service.ServiceRegistry) ProjectStateRegistry(org.gradle.api.internal.project.ProjectStateRegistry) File(java.io.File)

Aggregations

BuildRequestMetaData (org.gradle.initialization.BuildRequestMetaData)3 StartParameterInternal (org.gradle.api.internal.StartParameterInternal)2 DefaultBuildRequestMetaData (org.gradle.initialization.DefaultBuildRequestMetaData)2 NoOpBuildEventConsumer (org.gradle.initialization.NoOpBuildEventConsumer)2 BuildTreeModelControllerServices (org.gradle.internal.buildtree.BuildTreeModelControllerServices)2 BuildTreeState (org.gradle.internal.buildtree.BuildTreeState)2 BuildSessionState (org.gradle.internal.session.BuildSessionState)2 CrossBuildSessionState (org.gradle.internal.session.CrossBuildSessionState)2 File (java.io.File)1 Supplier (java.util.function.Supplier)1 GradleInternal (org.gradle.api.internal.GradleInternal)1 FileResolver (org.gradle.api.internal.file.FileResolver)1 ClassLoaderScope (org.gradle.api.internal.initialization.ClassLoaderScope)1 ProjectInternal (org.gradle.api.internal.project.ProjectInternal)1 ProjectState (org.gradle.api.internal.project.ProjectState)1 ProjectStateRegistry (org.gradle.api.internal.project.ProjectStateRegistry)1 LogLevel (org.gradle.api.logging.LogLevel)1 ContinuousExecutionGate (org.gradle.deployment.internal.ContinuousExecutionGate)1 DefaultContinuousExecutionGate (org.gradle.deployment.internal.DefaultContinuousExecutionGate)1 Deployment (org.gradle.deployment.internal.Deployment)1