org.gradle.initialization.BuildCancellationToken Java Examples

The following examples show how to use org.gradle.initialization.BuildCancellationToken. 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: DaemonBuildActionExecuter.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public <T> T execute(BuildAction<T> action, BuildCancellationToken cancellationToken, ProviderOperationParameters actionParameters) {
    BuildActionParameters parameters = new DefaultBuildActionParameters(new GradleLauncherMetaData(), actionParameters.getStartTime(),
            this.parameters.getEffectiveSystemProperties(), System.getenv(), SystemProperties.getCurrentDir(), actionParameters.getBuildLogLevel());
    try {
        return executer.execute(action, cancellationToken, parameters);
    } catch (ReportedException e) {
        Throwable t = e.getCause();
        while (t != null) {
            if (t instanceof BuildCancelledException) {
                throw new InternalBuildCancelledException(e.getCause());
            }
            t = t.getCause();
        }
        throw new BuildExceptionVersion1(e.getCause());
    }
}
 
Example #2
Source File: SynchronizedToolingImplementationLoader.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public ConsumerConnection create(Distribution distribution, ProgressLoggerFactory progressLoggerFactory, ConnectionParameters connectionParameters, BuildCancellationToken cancellationToken) {
    if (lock.tryLock()) {
        try {
            return delegate.create(distribution, progressLoggerFactory, connectionParameters, cancellationToken);
        } finally {
            lock.unlock();
        }
    }
    ProgressLogger logger = progressLoggerFactory.newOperation(SynchronizedToolingImplementationLoader.class);
    logger.setDescription("Wait for the other thread to finish acquiring the distribution");
    logger.started();
    lock.lock();
    try {
        return delegate.create(distribution, progressLoggerFactory, connectionParameters, cancellationToken);
    } finally {
        lock.unlock();
        logger.completed();
    }
}
 
Example #3
Source File: LazyConsumerActionExecutor.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private ConsumerConnection onStartAction(BuildCancellationToken cancellationToken) {
    lock.lock();
    try {
        if (stopped) {
            throw new IllegalStateException("This connection has been stopped.");
        }
        executing.add(Thread.currentThread());
        if (connection == null) {
            // Hold the lock while creating the connection. Not generally good form.
            // In this instance, blocks other threads from creating the connection at the same time
            connection = implementationLoader.create(distribution, loggingProvider.getProgressLoggerFactory(), connectionParameters, cancellationToken);
        }
        return connection;
    } finally {
        lock.unlock();
    }
}
 
Example #4
Source File: SynchronizedToolingImplementationLoader.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public ConsumerConnection create(Distribution distribution, ProgressLoggerFactory progressLoggerFactory, ConnectionParameters connectionParameters, BuildCancellationToken cancellationToken) {
    if (lock.tryLock()) {
        try {
            return delegate.create(distribution, progressLoggerFactory, connectionParameters, cancellationToken);
        } finally {
            lock.unlock();
        }
    }
    ProgressLogger logger = progressLoggerFactory.newOperation(SynchronizedToolingImplementationLoader.class);
    logger.setDescription("Wait for the other thread to finish acquiring the distribution");
    logger.started();
    lock.lock();
    try {
        return delegate.create(distribution, progressLoggerFactory, connectionParameters, cancellationToken);
    } finally {
        lock.unlock();
        logger.completed();
    }
}
 
Example #5
Source File: LazyConsumerActionExecutor.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private ConsumerConnection onStartAction(BuildCancellationToken cancellationToken) {
    lock.lock();
    try {
        if (stopped) {
            throw new IllegalStateException("This connection has been stopped.");
        }
        executing.add(Thread.currentThread());
        if (connection == null) {
            // Hold the lock while creating the connection. Not generally good form.
            // In this instance, blocks other threads from creating the connection at the same time
            connection = implementationLoader.create(distribution, loggingProvider.getProgressLoggerFactory(), connectionParameters, cancellationToken);
        }
        return connection;
    } finally {
        lock.unlock();
    }
}
 
Example #6
Source File: ProviderConnection.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public Object run(String modelName, BuildCancellationToken cancellationToken, ProviderOperationParameters providerParameters) {
    List<String> tasks = providerParameters.getTasks();
    if (modelName.equals(ModelIdentifier.NULL_MODEL) && tasks == null) {
        throw new IllegalArgumentException("No model type or tasks specified.");
    }
    Parameters params = initParams(providerParameters);
    Class<?> type = new ModelMapping().getProtocolTypeFromModelName(modelName);
    if (type == InternalBuildEnvironment.class) {
        //we don't really need to launch the daemon to acquire information needed for BuildEnvironment
        if (tasks != null) {
            throw new IllegalArgumentException("Cannot run tasks and fetch the build environment model.");
        }
        return new DefaultBuildEnvironment(
                GradleVersion.current().getVersion(),
                params.daemonParams.getEffectiveJavaHome(),
                params.daemonParams.getEffectiveJvmArgs());
    }

    BuildAction<BuildActionResult> action = new BuildModelAction(modelName, tasks != null);
    return run(action, cancellationToken, providerParameters, params.properties);
}
 
Example #7
Source File: DaemonBuildActionExecuter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public <T> T execute(BuildAction<T> action, BuildCancellationToken cancellationToken, ProviderOperationParameters actionParameters) {
    BuildActionParameters parameters = new DefaultBuildActionParameters(new GradleLauncherMetaData(), actionParameters.getStartTime(),
            this.parameters.getEffectiveSystemProperties(), System.getenv(), SystemProperties.getCurrentDir(), actionParameters.getBuildLogLevel());
    try {
        return executer.execute(action, cancellationToken, parameters);
    } catch (ReportedException e) {
        Throwable t = e.getCause();
        while (t != null) {
            if (t instanceof BuildCancelledException) {
                throw new InternalBuildCancelledException(e.getCause());
            }
            t = t.getCause();
        }
        throw new BuildExceptionVersion1(e.getCause());
    }
}
 
Example #8
Source File: LoggingBridgingBuildActionExecuter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public <T> T execute(BuildAction<T> action, BuildCancellationToken cancellationToken, ProviderOperationParameters actionParameters) {
    LoggingManagerInternal loggingManager = loggingManagerFactory.create();
    if (actionParameters.getStandardOutput() != null) {
        loggingManager.addStandardOutputListener(new StreamBackedStandardOutputListener(actionParameters.getStandardOutput()));
    }
    if (actionParameters.getStandardError() != null) {
        loggingManager.addStandardErrorListener(new StreamBackedStandardOutputListener(actionParameters.getStandardError()));
    }
    ProgressListenerVersion1 progressListener = actionParameters.getProgressListener();
    OutputEventListenerAdapter listener = new OutputEventListenerAdapter(progressListener);
    loggingManager.addOutputEventListener(listener);
    loggingManager.setLevel(actionParameters.getBuildLogLevel());
    loggingManager.start();
    try {
        return executer.execute(action, cancellationToken, actionParameters);
    } finally {
        loggingManager.stop();
    }
}
 
Example #9
Source File: ProviderConnection.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public Object run(String modelName, BuildCancellationToken cancellationToken, ProviderOperationParameters providerParameters) {
    List<String> tasks = providerParameters.getTasks();
    if (modelName.equals(ModelIdentifier.NULL_MODEL) && tasks == null) {
        throw new IllegalArgumentException("No model type or tasks specified.");
    }
    Parameters params = initParams(providerParameters);
    Class<?> type = new ModelMapping().getProtocolTypeFromModelName(modelName);
    if (type == InternalBuildEnvironment.class) {
        //we don't really need to launch the daemon to acquire information needed for BuildEnvironment
        if (tasks != null) {
            throw new IllegalArgumentException("Cannot run tasks and fetch the build environment model.");
        }
        return new DefaultBuildEnvironment(
                GradleVersion.current().getVersion(),
                params.daemonParams.getEffectiveJavaHome(),
                params.daemonParams.getEffectiveJvmArgs());
    }

    BuildAction<BuildActionResult> action = new BuildModelAction(modelName, tasks != null);
    return run(action, cancellationToken, providerParameters, params.properties);
}
 
Example #10
Source File: DockerizedExecHandle.java    From gradle-dockerized-test-plugin with Apache License 2.0 6 votes vote down vote up
public DockerizedExecHandle(DockerizedTestExtension testExtension, String displayName, File directory, String command, List<String> arguments,
                  Map<String, String> environment, StreamsHandler outputHandler, StreamsHandler inputHandler,
                  List<ExecHandleListener> listeners, boolean redirectErrorStream, int timeoutMillis, boolean daemon,
                  Executor executor, BuildCancellationToken buildCancellationToken) {
    this.displayName = displayName;
    this.directory = directory;
    this.command = command;
    this.arguments = arguments;
    this.environment = environment;
    this.outputHandler = outputHandler;
    this.inputHandler = inputHandler;
    this.redirectErrorStream = redirectErrorStream;
    this.timeoutMillis = timeoutMillis;
    this.daemon = daemon;
    this.executor = executor;
    this.lock = new ReentrantLock();
    this.stateChanged = lock.newCondition();
    this.state = ExecHandleState.INIT;
    this.buildCancellationToken = buildCancellationToken;
    this.testExtension = testExtension;
    shutdownHookAction = new ExecHandleShutdownHookAction(this);
    broadcast = new ListenerBroadcast<ExecHandleListener>(ExecHandleListener.class);
    broadcast.addAll(listeners);
}
 
Example #11
Source File: LoggingBridgingBuildActionExecuter.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public <T> T execute(BuildAction<T> action, BuildCancellationToken cancellationToken, ProviderOperationParameters actionParameters) {
    LoggingManagerInternal loggingManager = loggingManagerFactory.create();
    if (actionParameters.getStandardOutput() != null) {
        loggingManager.addStandardOutputListener(new StreamBackedStandardOutputListener(actionParameters.getStandardOutput()));
    }
    if (actionParameters.getStandardError() != null) {
        loggingManager.addStandardErrorListener(new StreamBackedStandardOutputListener(actionParameters.getStandardError()));
    }
    ProgressListenerVersion1 progressListener = actionParameters.getProgressListener();
    OutputEventListenerAdapter listener = new OutputEventListenerAdapter(progressListener);
    loggingManager.addOutputEventListener(listener);
    loggingManager.setLevel(actionParameters.getBuildLogLevel());
    loggingManager.start();
    try {
        return executer.execute(action, cancellationToken, actionParameters);
    } finally {
        loggingManager.stop();
    }
}
 
Example #12
Source File: ExecuteBuild.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
protected void doBuild(DaemonCommandExecution execution, Build build) {
    LOGGER.debug(DaemonMessages.STARTED_BUILD);
    LOGGER.info("Executing build with daemon context: {}", execution.getDaemonContext());
    try {
        BuildCancellationToken cancellationToken = execution.getDaemonStateControl().getCancellationToken();
        Object result = actionExecuter.execute(build.getAction(), cancellationToken, build.getParameters());
        execution.setResult(result);
    } catch (ReportedException e) {
        /*
            We have to wrap in a ReportedException so the other side doesn't re-log this exception, because it's already
            been logged by the GradleLauncher infrastructure, and that logging has been shipped over to the other side.
            
            This doesn't seem right. Perhaps we should assume on the client side that all “build failures” (opposed to daemon infrastructure failures)
            have already been logged and do away with this wrapper.
        */
        execution.setException(e);
    } finally {
        LOGGER.debug(DaemonMessages.FINISHED_BUILD);
    }

    execution.proceed(); // ExecuteBuild should be the last action, but in case we want to decorate the result in the future
}
 
Example #13
Source File: ExecuteBuild.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
protected void doBuild(DaemonCommandExecution execution, Build build) {
    LOGGER.debug(DaemonMessages.STARTED_BUILD);
    LOGGER.info("Executing build with daemon context: {}", execution.getDaemonContext());
    try {
        BuildCancellationToken cancellationToken = execution.getDaemonStateControl().getCancellationToken();
        Object result = actionExecuter.execute(build.getAction(), cancellationToken, build.getParameters());
        execution.setResult(result);
    } catch (ReportedException e) {
        /*
            We have to wrap in a ReportedException so the other side doesn't re-log this exception, because it's already
            been logged by the GradleLauncher infrastructure, and that logging has been shipped over to the other side.
            
            This doesn't seem right. Perhaps we should assume on the client side that all “build failures” (opposed to daemon infrastructure failures)
            have already been logged and do away with this wrapper.
        */
        execution.setException(e);
    } finally {
        LOGGER.debug(DaemonMessages.FINISHED_BUILD);
    }

    execution.proceed(); // ExecuteBuild should be the last action, but in case we want to decorate the result in the future
}
 
Example #14
Source File: DaemonClient.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Executes the given action in the daemon. The action and parameters must be serializable.
 *
 * @param action The action
 * @throws org.gradle.launcher.exec.ReportedException On failure, when the failure has already been logged/reported.
 */
public <T> T execute(BuildAction<T> action, BuildCancellationToken cancellationToken, BuildActionParameters parameters) {
    Object buildId = idGenerator.generateId();
    Build build = new Build(buildId, action, parameters);
    int saneNumberOfAttempts = 100; //is it sane enough?
    for (int i = 1; i < saneNumberOfAttempts; i++) {
        final DaemonClientConnection connection = connector.connect(compatibilitySpec);
        try {
            return (T) executeBuild(build, connection, cancellationToken);
        } catch (DaemonInitialConnectException e) {
            //this exception means that we want to try again.
            LOGGER.info(e.getMessage() + " Trying a different daemon...");
        } finally {
            connection.stop();
        }
    }
    //TODO it would be nice if below includes the errors that were accumulated above.
    throw new NoUsableDaemonFoundException("Unable to find a usable idle daemon. I have connected to "
            + saneNumberOfAttempts + " different daemons but I could not use any of them to run build: " + build + ".");
}
 
Example #15
Source File: DaemonClient.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private Object monitorBuild(Build build, DaemonDiagnostics diagnostics, Connection<Object> connection, BuildCancellationToken cancellationToken) {
    DaemonClientInputForwarder inputForwarder = new DaemonClientInputForwarder(buildStandardInput, connection, executorFactory, idGenerator);
    DaemonCancelForwarder cancelForwarder = new DaemonCancelForwarder(connection, cancellationToken, idGenerator);
    try {
        cancelForwarder.start();
        inputForwarder.start();
        int objectsReceived = 0;

        while (true) {
            Object object = connection.receive();
            LOGGER.trace("Received object #{}, type: {}", objectsReceived++, object == null ? null : object.getClass().getName());

            if (object == null) {
                return handleDaemonDisappearance(build, diagnostics, cancellationToken);
            } else if (object instanceof OutputEvent) {
                outputEventListener.onOutput((OutputEvent) object);
            } else {
                return object;
            }
        }
    } finally {
        // Stop cancelling before sending end-of-input
        CompositeStoppable.stoppable(cancelForwarder, inputForwarder).stop();
    }
}
 
Example #16
Source File: DaemonClient.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private Object monitorBuild(Build build, DaemonDiagnostics diagnostics, Connection<Object> connection, BuildCancellationToken cancellationToken) {
    DaemonClientInputForwarder inputForwarder = new DaemonClientInputForwarder(buildStandardInput, connection, executorFactory, idGenerator);
    DaemonCancelForwarder cancelForwarder = new DaemonCancelForwarder(connection, cancellationToken, idGenerator);
    try {
        cancelForwarder.start();
        inputForwarder.start();
        int objectsReceived = 0;

        while (true) {
            Object object = connection.receive();
            LOGGER.trace("Received object #{}, type: {}", objectsReceived++, object == null ? null : object.getClass().getName());

            if (object == null) {
                return handleDaemonDisappearance(build, diagnostics, cancellationToken);
            } else if (object instanceof OutputEvent) {
                outputEventListener.onOutput((OutputEvent) object);
            } else {
                return object;
            }
        }
    } finally {
        // Stop cancelling before sending end-of-input
        CompositeStoppable.stoppable(cancelForwarder, inputForwarder).stop();
    }
}
 
Example #17
Source File: DaemonClient.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Executes the given action in the daemon. The action and parameters must be serializable.
 *
 * @param action The action
 * @throws org.gradle.launcher.exec.ReportedException On failure, when the failure has already been logged/reported.
 */
public <T> T execute(BuildAction<T> action, BuildCancellationToken cancellationToken, BuildActionParameters parameters) {
    Object buildId = idGenerator.generateId();
    Build build = new Build(buildId, action, parameters);
    int saneNumberOfAttempts = 100; //is it sane enough?
    for (int i = 1; i < saneNumberOfAttempts; i++) {
        final DaemonClientConnection connection = connector.connect(compatibilitySpec);
        try {
            return (T) executeBuild(build, connection, cancellationToken);
        } catch (DaemonInitialConnectException e) {
            //this exception means that we want to try again.
            LOGGER.info(e.getMessage() + " Trying a different daemon...");
        } finally {
            connection.stop();
        }
    }
    //TODO it would be nice if below includes the errors that were accumulated above.
    throw new NoUsableDaemonFoundException("Unable to find a usable idle daemon. I have connected to "
            + saneNumberOfAttempts + " different daemons but I could not use any of them to run build: " + build + ".");
}
 
Example #18
Source File: NonCancellableConsumerConnectionAdapter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private Runnable handleCancellationPreOperation(BuildCancellationToken cancellationToken) {
    Runnable callback = new Runnable() {
        public void run() {
            LOGGER.info("Note: Version of Gradle provider does not support cancellation. Upgrade your Gradle build.");
        }
    };
    cancellationToken.addCallback(callback);
    return callback;
}
 
Example #19
Source File: ProviderConnection.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private Object run(BuildAction<? extends BuildActionResult> action, BuildCancellationToken cancellationToken, ProviderOperationParameters operationParameters, Map<String, String> properties) {
    BuildActionExecuter<ProviderOperationParameters> executer = createExecuter(operationParameters);
    ConfiguringBuildAction<BuildActionResult> configuringAction = new ConfiguringBuildAction<BuildActionResult>(operationParameters, action, properties);
    BuildActionResult result = executer.execute(configuringAction, cancellationToken, operationParameters);
    if (result.failure != null) {
        throw (RuntimeException) payloadSerializer.deserialize(result.failure);
    }
    return payloadSerializer.deserialize(result.result);
}
 
Example #20
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 #21
Source File: NonCancellableConsumerConnectionAdapter.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private Runnable handleCancellationPreOperation(BuildCancellationToken cancellationToken) {
    Runnable callback = new Runnable() {
        public void run() {
            LOGGER.info("Note: Version of Gradle provider does not support cancellation. Upgrade your Gradle build.");
        }
    };
    cancellationToken.addCallback(callback);
    return callback;
}
 
Example #22
Source File: DefaultToolingImplementationLoader.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private ClassLoader createImplementationClassLoader(Distribution distribution, ProgressLoggerFactory progressLoggerFactory, File userHomeDir, BuildCancellationToken cancellationToken) {
    ClassPath implementationClasspath = distribution.getToolingImplementationClasspath(progressLoggerFactory, userHomeDir, cancellationToken);
    LOGGER.debug("Using tooling provider classpath: {}", implementationClasspath);
    // On IBM JVM 5, ClassLoader.getResources() uses a combination of findResources() and getParent() and traverses the hierarchy rather than just calling getResources()
    // Wrap our real classloader in one that hides the parent.
    // TODO - move this into FilteringClassLoader
    MultiParentClassLoader parentObfuscatingClassLoader = new MultiParentClassLoader(classLoader);
    FilteringClassLoader filteringClassLoader = new FilteringClassLoader(parentObfuscatingClassLoader);
    filteringClassLoader.allowPackage("org.gradle.tooling.internal.protocol");
    return new MutableURLClassLoader(filteringClassLoader, implementationClasspath.getAsURLArray());
}
 
Example #23
Source File: CachingToolingImplementationLoader.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ConsumerConnection create(Distribution distribution, ProgressLoggerFactory progressLoggerFactory, ConnectionParameters connectionParameters, BuildCancellationToken cancellationToken) {
    ClassPath classpath = distribution.getToolingImplementationClasspath(progressLoggerFactory, connectionParameters.getGradleUserHomeDir(), cancellationToken);

    ConsumerConnection connection = connections.get(classpath);
    if (connection == null) {
        connection = loader.create(distribution, progressLoggerFactory, connectionParameters, cancellationToken);
        connections.put(classpath, connection);
    }

    return connection;
}
 
Example #24
Source File: DistributionFactory.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ClassPath getToolingImplementationClasspath(ProgressLoggerFactory progressLoggerFactory, File userHomeDir, BuildCancellationToken cancellationToken) {
    ProgressLogger progressLogger = progressLoggerFactory.newOperation(DistributionFactory.class);
    progressLogger.setDescription("Validate distribution");
    progressLogger.started();
    try {
        return getToolingImpl();
    } finally {
        progressLogger.completed();
    }
}
 
Example #25
Source File: DefaultConnection.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * This is used by consumers 2.1-rc-1 and later.
 */
public <T> BuildResult<T> run(InternalBuildAction<T> action, InternalCancellationToken cancellationToken, BuildParameters operationParameters)
        throws BuildExceptionVersion1, InternalUnsupportedBuildArgumentException, IllegalStateException {
    validateCanRun();
    ProviderOperationParameters providerParameters = toProviderParameters(operationParameters);
    BuildCancellationToken buildCancellationToken = new InternalCancellationTokenAdapter(cancellationToken);
    Object results = connection.run(action, buildCancellationToken, providerParameters);
    return new ProviderBuildResult<T>((T) results);
}
 
Example #26
Source File: DefaultConnection.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * This is used by consumers 2.1-rc-1 and later
 */
public BuildResult<?> getModel(ModelIdentifier modelIdentifier, InternalCancellationToken cancellationToken, BuildParameters operationParameters) throws BuildExceptionVersion1, InternalUnsupportedModelException, InternalUnsupportedBuildArgumentException, IllegalStateException {
    validateCanRun();
    ProviderOperationParameters providerParameters = toProviderParameters(operationParameters);
    BuildCancellationToken buildCancellationToken = new InternalCancellationTokenAdapter(cancellationToken);
    Object result = connection.run(modelIdentifier.getName(), buildCancellationToken, providerParameters);
    return new ProviderBuildResult<Object>(result);
}
 
Example #27
Source File: ProviderConnection.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private Object run(BuildAction<? extends BuildActionResult> action, BuildCancellationToken cancellationToken, ProviderOperationParameters operationParameters, Map<String, String> properties) {
    BuildActionExecuter<ProviderOperationParameters> executer = createExecuter(operationParameters);
    ConfiguringBuildAction<BuildActionResult> configuringAction = new ConfiguringBuildAction<BuildActionResult>(operationParameters, action, properties);
    BuildActionResult result = executer.execute(configuringAction, cancellationToken, operationParameters);
    if (result.failure != null) {
        throw (RuntimeException) payloadSerializer.deserialize(result.failure);
    }
    return payloadSerializer.deserialize(result.result);
}
 
Example #28
Source File: DaemonCancelForwarder.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public DaemonCancelForwarder(final Dispatch<? super Cancel> dispatch, BuildCancellationToken cancellationToken, final IdGenerator<?> idGenerator) {
    this.cancellationToken = cancellationToken;
    cancellationCallback = new Runnable() {
        public void run() {
            LOGGER.info("Request daemon to cancel build...");
            dispatch.dispatch(new Cancel(idGenerator.generateId()));
        }
    };
}
 
Example #29
Source File: SingleUseDaemonClient.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public <T> T execute(BuildAction<T> action, BuildCancellationToken cancellationToken, BuildActionParameters parameters) {
    LOGGER.lifecycle("{} Please consider using the daemon: {}.", MESSAGE, documentationRegistry.getDocumentationFor("gradle_daemon"));
    Build build = new BuildAndStop(getIdGenerator().generateId(), action, parameters);

    DaemonClientConnection daemonConnection = getConnector().startDaemon(ExplainingSpecs.<DaemonContext>satisfyAll());

    return (T) executeBuild(build, daemonConnection, cancellationToken);
}
 
Example #30
Source File: DaemonClient.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private Result handleDaemonDisappearance(Build build, DaemonDiagnostics diagnostics, BuildCancellationToken cancellationToken) {
    //we can try sending something to the daemon and try out if he is really dead or use jps
    //if he's really dead we should deregister it if it is not already deregistered.
    //if the daemon is not dead we might continue receiving from him (and try to find the bug in messaging infrastructure)
    LOGGER.error("The message received from the daemon indicates that the daemon has disappeared."
                 + "\nBuild request sent: " + build
                 + "\nAttempting to read last messages from the daemon log...");

    LOGGER.error(diagnostics.describe());
    throw new DaemonDisappearedException();
}