Search in sources :

Example 1 with InternalBuildAdapter

use of org.gradle.internal.InternalBuildAdapter in project gradle by gradle.

the class DefaultDaemonScanInfo method notifyOnUnhealthy.

@Override
public void notifyOnUnhealthy(final Action<? super String> listener) {
    /*
            The semantics of this method are that the given action should be notified if the
            Daemon is going to be terminated at the end of this build.
            It is not a generic outlet for “expiry events”.

            Ideally, the value given would describe the problem and not be phrased in terms of why we are shutting down,
            but this is a practical compromise born out of piggy backing on the expiration listener mechanism to implement it.
         */
    final AtomicReference<DaemonExpirationListener> daemonExpirationListenerReference = new AtomicReference<DaemonExpirationListener>();
    final DaemonExpirationListener daemonExpirationListener = new DaemonExpirationListener() {

        @Override
        public void onExpirationEvent(DaemonExpirationResult result) {
            if (result.getStatus() == DaemonExpirationStatus.GRACEFUL_EXPIRE) {
                try {
                    listener.execute(result.getReason());
                } finally {
                    // set the reference to null, which says that we're taking care of removing the listener
                    if (daemonExpirationListenerReference.getAndSet(null) != null) {
                        listenerManager.removeListener(this);
                    }
                }
            }
        }
    };
    daemonExpirationListenerReference.set(daemonExpirationListener);
    listenerManager.addListener(daemonExpirationListener);
    final BuildAdapter buildListener = new InternalBuildAdapter() {

        @Override
        public void buildFinished(BuildResult result) {
            DaemonExpirationListener daemonExpirationListener = daemonExpirationListenerReference.getAndSet(null);
            if (daemonExpirationListener != null) {
                listenerManager.removeListener(daemonExpirationListener);
            }
            listenerManager.removeListener(this);
        }
    };
    listenerManager.addListener(buildListener);
}
Also used : BuildResult(org.gradle.BuildResult) AtomicReference(java.util.concurrent.atomic.AtomicReference) BuildAdapter(org.gradle.BuildAdapter) InternalBuildAdapter(org.gradle.internal.InternalBuildAdapter) DaemonExpirationResult(org.gradle.launcher.daemon.server.expiry.DaemonExpirationResult) InternalBuildAdapter(org.gradle.internal.InternalBuildAdapter) DaemonExpirationListener(org.gradle.launcher.daemon.server.expiry.DaemonExpirationListener)

Example 2 with InternalBuildAdapter

use of org.gradle.internal.InternalBuildAdapter in project gradle by gradle.

the class DefaultRootBuildState method run.

@Override
public <T> T run(Function<? super BuildTreeLifecycleController, T> action) {
    if (completed) {
        throw new IllegalStateException("Cannot run more than one action for a build.");
    }
    try {
        RootBuildLifecycleListener buildLifecycleListener = listenerManager.getBroadcaster(RootBuildLifecycleListener.class);
        buildLifecycleListener.afterStart();
        try {
            GradleInternal gradle = getBuildController().getGradle();
            DefaultDeploymentRegistry deploymentRegistry = gradle.getServices().get(DefaultDeploymentRegistry.class);
            gradle.addBuildListener(new InternalBuildAdapter() {

                @Override
                public void buildFinished(BuildResult result) {
                    deploymentRegistry.buildFinished(result);
                }
            });
            return action.apply(buildTreeLifecycleController);
        } finally {
            buildLifecycleListener.beforeComplete();
        }
    } finally {
        completed = true;
    }
}
Also used : GradleInternal(org.gradle.api.internal.GradleInternal) BuildResult(org.gradle.BuildResult) DefaultDeploymentRegistry(org.gradle.deployment.internal.DefaultDeploymentRegistry) RootBuildLifecycleListener(org.gradle.initialization.RootBuildLifecycleListener) InternalBuildAdapter(org.gradle.internal.InternalBuildAdapter)

Example 3 with InternalBuildAdapter

use of org.gradle.internal.InternalBuildAdapter in project gradle by gradle.

the class RootOfNestedBuildTree method run.

@Override
public <T> T run(Function<? super BuildTreeLifecycleController, T> action) {
    final GradleInternal gradle = getBuildController().getGradle();
    ServiceRegistry services = gradle.getServices();
    BuildOperationExecutor executor = services.get(BuildOperationExecutor.class);
    return executor.call(new CallableBuildOperation<T>() {

        @Override
        public T call(BuildOperationContext context) {
            gradle.addBuildListener(new InternalBuildAdapter() {

                @Override
                public void settingsEvaluated(Settings settings) {
                    buildName = settings.getRootProject().getName();
                }
            });
            T result = action.apply(buildTreeLifecycleController);
            context.setResult(new RunNestedBuildBuildOperationType.Result() {
            });
            return result;
        }

        @Override
        public BuildOperationDescriptor.Builder description() {
            return BuildOperationDescriptor.displayName("Run nested build").details(new RunNestedBuildBuildOperationType.Details() {

                @Override
                public String getBuildPath() {
                    return gradle.getIdentityPath().getPath();
                }
            });
        }
    });
}
Also used : BuildOperationContext(org.gradle.internal.operations.BuildOperationContext) GradleInternal(org.gradle.api.internal.GradleInternal) ServiceRegistry(org.gradle.internal.service.ServiceRegistry) InternalBuildAdapter(org.gradle.internal.InternalBuildAdapter) Settings(org.gradle.api.initialization.Settings) BuildOperationExecutor(org.gradle.internal.operations.BuildOperationExecutor)

Example 4 with InternalBuildAdapter

use of org.gradle.internal.InternalBuildAdapter in project gradle by gradle.

the class GradleEnterprisePluginManager method registerMissingPluginWarning.

/**
 * This should never happen due to the auto apply behavior.
 * It's only here as a kind of safeguard or fallback.
 */
public void registerMissingPluginWarning(GradleInternal gradle) {
    if (gradle.isRootBuild()) {
        StartParameter startParameter = gradle.getStartParameter();
        boolean requested = !startParameter.isNoBuildScan() && startParameter.isBuildScan();
        if (requested) {
            gradle.addListener(new InternalBuildAdapter() {

                @Override
                public void settingsEvaluated(@Nonnull Settings settings) {
                    if (!isPresent() && !unsupported) {
                        LOGGER.warn(NO_SCAN_PLUGIN_MSG);
                    }
                }
            });
        }
    }
}
Also used : StartParameter(org.gradle.StartParameter) InternalBuildAdapter(org.gradle.internal.InternalBuildAdapter) Settings(org.gradle.api.initialization.Settings)

Aggregations

InternalBuildAdapter (org.gradle.internal.InternalBuildAdapter)4 BuildResult (org.gradle.BuildResult)2 Settings (org.gradle.api.initialization.Settings)2 GradleInternal (org.gradle.api.internal.GradleInternal)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 BuildAdapter (org.gradle.BuildAdapter)1 StartParameter (org.gradle.StartParameter)1 DefaultDeploymentRegistry (org.gradle.deployment.internal.DefaultDeploymentRegistry)1 RootBuildLifecycleListener (org.gradle.initialization.RootBuildLifecycleListener)1 BuildOperationContext (org.gradle.internal.operations.BuildOperationContext)1 BuildOperationExecutor (org.gradle.internal.operations.BuildOperationExecutor)1 ServiceRegistry (org.gradle.internal.service.ServiceRegistry)1 DaemonExpirationListener (org.gradle.launcher.daemon.server.expiry.DaemonExpirationListener)1 DaemonExpirationResult (org.gradle.launcher.daemon.server.expiry.DaemonExpirationResult)1