Search in sources :

Example 1 with BuildStartedTime

use of org.gradle.internal.buildevents.BuildStartedTime in project gradle by gradle.

the class DefaultGradleLauncherFactory method doNewInstance.

private DefaultGradleLauncher doNewInstance(BuildDefinition buildDefinition, @Nullable GradleLauncher parent, BuildCancellationToken cancellationToken, BuildRequestMetaData requestMetaData, BuildEventConsumer buildEventConsumer, final BuildTreeScopeServices buildTreeScopeServices, List<?> servicesToStop) {
    BuildScopeServices serviceRegistry = new BuildScopeServices(buildTreeScopeServices);
    serviceRegistry.add(BuildDefinition.class, buildDefinition);
    serviceRegistry.add(BuildRequestMetaData.class, requestMetaData);
    serviceRegistry.add(BuildClientMetaData.class, requestMetaData.getClient());
    serviceRegistry.add(BuildEventConsumer.class, buildEventConsumer);
    serviceRegistry.add(BuildCancellationToken.class, cancellationToken);
    serviceRegistry.add(BuildIdentity.class, new DefaultBuildIdentity(buildDefinition, parent == null));
    NestedBuildFactoryImpl nestedBuildFactory = new NestedBuildFactoryImpl(buildTreeScopeServices);
    serviceRegistry.add(NestedBuildFactory.class, nestedBuildFactory);
    StartParameter startParameter = buildDefinition.getStartParameter();
    ListenerManager listenerManager = serviceRegistry.get(ListenerManager.class);
    LoggerProvider loggerProvider = (parent == null) ? buildProgressLogger : LoggerProvider.NO_OP;
    listenerManager.useLogger(new TaskExecutionLogger(serviceRegistry.get(ProgressLoggerFactory.class), loggerProvider));
    if (parent == null) {
        BuildStartedTime buildStartedTime = serviceRegistry.get(BuildStartedTime.class);
        Clock clock = serviceRegistry.get(Clock.class);
        listenerManager.useLogger(new BuildLogger(Logging.getLogger(BuildLogger.class), serviceRegistry.get(StyledTextOutputFactory.class), startParameter, requestMetaData, buildStartedTime, clock));
    }
    listenerManager.addListener(serviceRegistry.get(TaskExecutionStatisticsEventAdapter.class));
    listenerManager.addListener(new TaskExecutionStatisticsReporter(serviceRegistry.get(StyledTextOutputFactory.class)));
    listenerManager.addListener(serviceRegistry.get(ProfileEventAdapter.class));
    if (startParameter.isProfile()) {
        listenerManager.addListener(new ReportGeneratingProfileListener(serviceRegistry.get(StyledTextOutputFactory.class)));
    }
    ScriptUsageLocationReporter usageLocationReporter = new ScriptUsageLocationReporter();
    listenerManager.addListener(usageLocationReporter);
    ShowStacktrace showStacktrace = startParameter.getShowStacktrace();
    switch(showStacktrace) {
        case ALWAYS:
        case ALWAYS_FULL:
            LoggingDeprecatedFeatureHandler.setTraceLoggingEnabled(true);
            break;
        default:
            LoggingDeprecatedFeatureHandler.setTraceLoggingEnabled(false);
    }
    DeprecationLogger.init(usageLocationReporter, startParameter.getWarningMode());
    SettingsLoaderFactory settingsLoaderFactory = serviceRegistry.get(SettingsLoaderFactory.class);
    SettingsLoader settingsLoader = parent != null ? settingsLoaderFactory.forNestedBuild() : settingsLoaderFactory.forTopLevelBuild();
    GradleInternal parentBuild = parent == null ? null : parent.getGradle();
    GradleInternal gradle = serviceRegistry.get(Instantiator.class).newInstance(DefaultGradle.class, parentBuild, startParameter, serviceRegistry.get(ServiceRegistryFactory.class));
    DefaultGradleLauncher gradleLauncher = new DefaultGradleLauncher(gradle, serviceRegistry.get(InitScriptHandler.class), settingsLoader, serviceRegistry.get(BuildLoader.class), serviceRegistry.get(BuildConfigurer.class), serviceRegistry.get(ExceptionAnalyser.class), gradle.getBuildListenerBroadcaster(), listenerManager.getBroadcaster(ModelConfigurationListener.class), listenerManager.getBroadcaster(BuildCompletionListener.class), serviceRegistry.get(BuildOperationExecutor.class), gradle.getServices().get(BuildConfigurationActionExecuter.class), gradle.getServices().get(BuildExecuter.class), serviceRegistry, servicesToStop);
    nestedBuildFactory.setParent(gradleLauncher);
    return gradleLauncher;
}
Also used : ExceptionAnalyser(org.gradle.api.internal.ExceptionAnalyser) TaskExecutionStatisticsReporter(org.gradle.internal.buildevents.TaskExecutionStatisticsReporter) Instantiator(org.gradle.internal.reflect.Instantiator) Clock(org.gradle.internal.time.Clock) GradleInternal(org.gradle.api.internal.GradleInternal) ReportGeneratingProfileListener(org.gradle.profile.ReportGeneratingProfileListener) BuildExecuter(org.gradle.execution.BuildExecuter) LoggerProvider(org.gradle.internal.progress.LoggerProvider) ScriptUsageLocationReporter(org.gradle.internal.featurelifecycle.ScriptUsageLocationReporter) BuildConfigurer(org.gradle.configuration.BuildConfigurer) StartParameter(org.gradle.StartParameter) BuildConfigurationActionExecuter(org.gradle.execution.BuildConfigurationActionExecuter) ProfileEventAdapter(org.gradle.profile.ProfileEventAdapter) BuildScopeServices(org.gradle.internal.service.scopes.BuildScopeServices) TaskExecutionStatisticsEventAdapter(org.gradle.api.internal.tasks.execution.statistics.TaskExecutionStatisticsEventAdapter) ShowStacktrace(org.gradle.api.logging.configuration.ShowStacktrace) BuildOperationExecutor(org.gradle.internal.operations.BuildOperationExecutor) ServiceRegistryFactory(org.gradle.internal.service.scopes.ServiceRegistryFactory) TaskExecutionLogger(org.gradle.internal.buildevents.TaskExecutionLogger) BuildStartedTime(org.gradle.internal.buildevents.BuildStartedTime) BuildLogger(org.gradle.internal.buildevents.BuildLogger) ListenerManager(org.gradle.internal.event.ListenerManager)

Example 2 with BuildStartedTime

use of org.gradle.internal.buildevents.BuildStartedTime in project gradle by gradle.

the class ContinuousBuildActionExecuter method executeMultipleBuilds.

private Object executeMultipleBuilds(BuildAction action, BuildRequestContext requestContext, final BuildActionParameters actionParameters, final ServiceRegistry buildSessionScopeServices, CancellableOperationManager cancellableOperationManager, ContinuousExecutionGate continuousExecutionGate) {
    BuildCancellationToken cancellationToken = requestContext.getCancellationToken();
    BuildStartedTime buildStartedTime = buildSessionScopeServices.get(BuildStartedTime.class);
    Clock clock = buildSessionScopeServices.get(Clock.class);
    Object lastResult;
    while (true) {
        PendingChangesListener pendingChangesListener = buildSessionScopeServices.get(ListenerManager.class).getBroadcaster(PendingChangesListener.class);
        final FileSystemChangeWaiter waiter = changeWaiterFactory.createChangeWaiter(new SingleFirePendingChangesListener(pendingChangesListener), cancellationToken, continuousExecutionGate);
        try {
            try {
                lastResult = executeBuildAndAccumulateInputs(action, requestContext, actionParameters, waiter, buildSessionScopeServices);
            } catch (ReportedException t) {
                lastResult = t;
            }
            if (!waiter.isWatching()) {
                logger.println().withStyle(StyledTextOutput.Style.Failure).println("Exiting continuous build as no executed tasks declared file system inputs.");
                if (lastResult instanceof ReportedException) {
                    throw (ReportedException) lastResult;
                }
                return lastResult;
            } else {
                cancellableOperationManager.monitorInput(new Action<BuildCancellationToken>() {

                    @Override
                    public void execute(BuildCancellationToken cancellationToken) {
                        FileWatcherEventListener reporter = new DefaultFileWatcherEventListener();
                        waiter.wait(new Runnable() {

                            @Override
                            public void run() {
                                logger.println().println("Waiting for changes to input files of tasks..." + determineExitHint(actionParameters));
                            }
                        }, reporter);
                        if (!cancellationToken.isCancellationRequested()) {
                            reporter.reportChanges(logger);
                        }
                    }
                });
            }
        } finally {
            waiter.stop();
        }
        if (cancellationToken.isCancellationRequested()) {
            break;
        } else {
            logger.println("Change detected, executing build...").println();
            buildStartedTime.reset(clock.getCurrentTime());
        }
    }
    logger.println("Build cancelled.");
    if (lastResult instanceof ReportedException) {
        throw (ReportedException) lastResult;
    }
    return lastResult;
}
Also used : FileWatcherEventListener(org.gradle.internal.filewatch.FileWatcherEventListener) DefaultFileWatcherEventListener(org.gradle.internal.filewatch.DefaultFileWatcherEventListener) DefaultFileWatcherEventListener(org.gradle.internal.filewatch.DefaultFileWatcherEventListener) Clock(org.gradle.internal.time.Clock) SingleFirePendingChangesListener(org.gradle.internal.filewatch.SingleFirePendingChangesListener) PendingChangesListener(org.gradle.internal.filewatch.PendingChangesListener) SingleFirePendingChangesListener(org.gradle.internal.filewatch.SingleFirePendingChangesListener) FileSystemChangeWaiter(org.gradle.internal.filewatch.FileSystemChangeWaiter) BuildCancellationToken(org.gradle.initialization.BuildCancellationToken) BuildStartedTime(org.gradle.internal.buildevents.BuildStartedTime) ListenerManager(org.gradle.internal.event.ListenerManager) ReportedException(org.gradle.initialization.ReportedException)

Aggregations

BuildStartedTime (org.gradle.internal.buildevents.BuildStartedTime)2 ListenerManager (org.gradle.internal.event.ListenerManager)2 Clock (org.gradle.internal.time.Clock)2 StartParameter (org.gradle.StartParameter)1 ExceptionAnalyser (org.gradle.api.internal.ExceptionAnalyser)1 GradleInternal (org.gradle.api.internal.GradleInternal)1 TaskExecutionStatisticsEventAdapter (org.gradle.api.internal.tasks.execution.statistics.TaskExecutionStatisticsEventAdapter)1 ShowStacktrace (org.gradle.api.logging.configuration.ShowStacktrace)1 BuildConfigurer (org.gradle.configuration.BuildConfigurer)1 BuildConfigurationActionExecuter (org.gradle.execution.BuildConfigurationActionExecuter)1 BuildExecuter (org.gradle.execution.BuildExecuter)1 BuildCancellationToken (org.gradle.initialization.BuildCancellationToken)1 ReportedException (org.gradle.initialization.ReportedException)1 BuildLogger (org.gradle.internal.buildevents.BuildLogger)1 TaskExecutionLogger (org.gradle.internal.buildevents.TaskExecutionLogger)1 TaskExecutionStatisticsReporter (org.gradle.internal.buildevents.TaskExecutionStatisticsReporter)1 ScriptUsageLocationReporter (org.gradle.internal.featurelifecycle.ScriptUsageLocationReporter)1 DefaultFileWatcherEventListener (org.gradle.internal.filewatch.DefaultFileWatcherEventListener)1 FileSystemChangeWaiter (org.gradle.internal.filewatch.FileSystemChangeWaiter)1 FileWatcherEventListener (org.gradle.internal.filewatch.FileWatcherEventListener)1