Java Code Examples for org.gradle.initialization.BuildCancellationToken#isCancellationRequested()

The following examples show how to use org.gradle.initialization.BuildCancellationToken#isCancellationRequested() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultBuildController.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public BuildResult<?> getModel(Object target, ModelIdentifier modelIdentifier) throws BuildExceptionVersion1, InternalUnsupportedModelException {
    BuildCancellationToken cancellationToken = gradle.getServices().get(BuildCancellationToken.class);
    if (cancellationToken.isCancellationRequested()) {
        throw new BuildCancelledException(String.format("Could not build '%s' model. Build cancelled.", modelIdentifier.getName()));
    }
    ToolingModelBuilderRegistry modelBuilderRegistry;
    ProjectInternal project;
    boolean isImplicitProject;
    if (target == null) {
        project = gradle.getDefaultProject();
        isImplicitProject = true;
    } else if (target instanceof GradleProjectIdentity) {
        GradleProjectIdentity gradleProject = (GradleProjectIdentity) target;
        project = gradle.getRootProject().project(gradleProject.getPath());
        isImplicitProject = false;
    } else {
        throw new IllegalArgumentException("Don't know how to build models for " + target);
    }
    modelBuilderRegistry = project.getServices().get(ToolingModelBuilderRegistry.class);

    ToolingModelBuilder builder;
    try {
        builder = modelBuilderRegistry.getBuilder(modelIdentifier.getName());
    } catch (UnknownModelException e) {
        throw (InternalUnsupportedModelException) (new InternalUnsupportedModelException()).initCause(e);
    }
    Object model;
    if (builder instanceof ProjectSensitiveToolingModelBuilder) {
        model = ((ProjectSensitiveToolingModelBuilder) builder).buildAll(modelIdentifier.getName(), project, isImplicitProject);
    } else {
        model = builder.buildAll(modelIdentifier.getName(), project);
    }
    return new ProviderBuildResult<Object>(model);
}
 
Example 2
Source File: LazyConsumerActionExecutor.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public <T> T run(ConsumerAction<T> action) throws UnsupportedOperationException, IllegalStateException {
    try {
        BuildCancellationToken cancellationToken = action.getParameters().getCancellationToken();
        if (cancellationToken.isCancellationRequested()) {
            throw new BuildCancelledException("Build cancelled");
        }
        ConsumerConnection connection = onStartAction(cancellationToken);
        return action.run(connection);
    } finally {
        onEndAction();
    }
}
 
Example 3
Source File: DefaultBuildController.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public BuildResult<?> getModel(Object target, ModelIdentifier modelIdentifier) throws BuildExceptionVersion1, InternalUnsupportedModelException {
    BuildCancellationToken cancellationToken = gradle.getServices().get(BuildCancellationToken.class);
    if (cancellationToken.isCancellationRequested()) {
        throw new BuildCancelledException(String.format("Could not build '%s' model. Build cancelled.", modelIdentifier.getName()));
    }
    ToolingModelBuilderRegistry modelBuilderRegistry;
    ProjectInternal project;
    boolean isImplicitProject;
    if (target == null) {
        project = gradle.getDefaultProject();
        isImplicitProject = true;
    } else if (target instanceof GradleProjectIdentity) {
        GradleProjectIdentity gradleProject = (GradleProjectIdentity) target;
        project = gradle.getRootProject().project(gradleProject.getPath());
        isImplicitProject = false;
    } else {
        throw new IllegalArgumentException("Don't know how to build models for " + target);
    }
    modelBuilderRegistry = project.getServices().get(ToolingModelBuilderRegistry.class);

    ToolingModelBuilder builder;
    try {
        builder = modelBuilderRegistry.getBuilder(modelIdentifier.getName());
    } catch (UnknownModelException e) {
        throw (InternalUnsupportedModelException) (new InternalUnsupportedModelException()).initCause(e);
    }
    Object model;
    if (builder instanceof ProjectSensitiveToolingModelBuilder) {
        model = ((ProjectSensitiveToolingModelBuilder) builder).buildAll(modelIdentifier.getName(), project, isImplicitProject);
    } else {
        model = builder.buildAll(modelIdentifier.getName(), project);
    }
    return new ProviderBuildResult<Object>(model);
}
 
Example 4
Source File: LazyConsumerActionExecutor.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public <T> T run(ConsumerAction<T> action) throws UnsupportedOperationException, IllegalStateException {
    try {
        BuildCancellationToken cancellationToken = action.getParameters().getCancellationToken();
        if (cancellationToken.isCancellationRequested()) {
            throw new BuildCancelledException("Build cancelled");
        }
        ConsumerConnection connection = onStartAction(cancellationToken);
        return action.run(connection);
    } finally {
        onEndAction();
    }
}
 
Example 5
Source File: DaemonClient.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
protected Object executeBuild(Build build, DaemonClientConnection connection, BuildCancellationToken cancellationToken) throws DaemonInitialConnectException {
    Object result;
    try {
        LOGGER.info("Connected to daemon {}. Dispatching request {}.", connection.getDaemon(), build);
        connection.dispatch(build);
        result = connection.receive();
    } catch (StaleDaemonAddressException e) {
        LOGGER.debug("Connected to a stale daemon address.", e);
        //We might fail hard here on the assumption that something weird happened to the daemon.
        //However, since we haven't yet started running the build, we can recover by just trying again...
        throw new DaemonInitialConnectException("Connected to a stale daemon address.", e);
    }
    if (result == null) {
        throw new DaemonInitialConnectException("The first result from the daemon was empty. Most likely the process died immediately after connection.");
    }

    if (result instanceof BuildStarted) {
        DaemonDiagnostics diagnostics = ((BuildStarted) result).getDiagnostics();
        result = monitorBuild(build, diagnostics, connection, cancellationToken);
    }

    LOGGER.info("Received result {} from daemon {}.", result, connection.getDaemon());

    connection.dispatch(new Finished());

    if (result instanceof Failure) {
        // Could potentially distinguish between CommandFailure and DaemonFailure here.
        Throwable failure = ((Failure) result).getValue();
        if (failure instanceof DaemonStoppedException && cancellationToken.isCancellationRequested()) {
            LOGGER.error("Daemon was stopped to handle build cancel request.");
            throw new BuildCancelledException();
        }
        throw UncheckedException.throwAsUncheckedException(failure);
    } else if (result instanceof DaemonUnavailable) {
        throw new DaemonInitialConnectException("The daemon we connected to was unavailable: " + ((DaemonUnavailable) result).getReason());
    } else if (result instanceof Result) {
        return ((Result) result).getValue();
    } else {
        throw invalidResponse(result, build);
    }
}
 
Example 6
Source File: DaemonClient.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
protected Object executeBuild(Build build, DaemonClientConnection connection, BuildCancellationToken cancellationToken) throws DaemonInitialConnectException {
    Object result;
    try {
        LOGGER.info("Connected to daemon {}. Dispatching request {}.", connection.getDaemon(), build);
        connection.dispatch(build);
        result = connection.receive();
    } catch (StaleDaemonAddressException e) {
        LOGGER.debug("Connected to a stale daemon address.", e);
        //We might fail hard here on the assumption that something weird happened to the daemon.
        //However, since we haven't yet started running the build, we can recover by just trying again...
        throw new DaemonInitialConnectException("Connected to a stale daemon address.", e);
    }
    if (result == null) {
        throw new DaemonInitialConnectException("The first result from the daemon was empty. Most likely the process died immediately after connection.");
    }

    if (result instanceof BuildStarted) {
        DaemonDiagnostics diagnostics = ((BuildStarted) result).getDiagnostics();
        result = monitorBuild(build, diagnostics, connection, cancellationToken);
    }

    LOGGER.info("Received result {} from daemon {}.", result, connection.getDaemon());

    connection.dispatch(new Finished());

    if (result instanceof Failure) {
        // Could potentially distinguish between CommandFailure and DaemonFailure here.
        Throwable failure = ((Failure) result).getValue();
        if (failure instanceof DaemonStoppedException && cancellationToken.isCancellationRequested()) {
            LOGGER.error("Daemon was stopped to handle build cancel request.");
            throw new BuildCancelledException();
        }
        throw UncheckedException.throwAsUncheckedException(failure);
    } else if (result instanceof DaemonUnavailable) {
        throw new DaemonInitialConnectException("The daemon we connected to was unavailable: " + ((DaemonUnavailable) result).getReason());
    } else if (result instanceof Result) {
        return ((Result) result).getValue();
    } else {
        throw invalidResponse(result, build);
    }
}