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);
}
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;
}
}
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();
}
});
}
});
}
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);
}
}
});
}
}
}
Aggregations