Search in sources :

Example 1 with PayloadSerializer

use of org.gradle.tooling.internal.provider.serialization.PayloadSerializer in project gradle by gradle.

the class ClientProvidedBuildActionRunner method buildResult.

@SuppressWarnings("deprecation")
private BuildActionResult buildResult(Object clientAction, GradleInternal gradle) {
    forceFullConfiguration(gradle);
    DefaultBuildController internalBuildController = new DefaultBuildController(gradle);
    Object model = null;
    Throwable failure = null;
    try {
        if (clientAction instanceof InternalBuildActionVersion2<?>) {
            model = ((InternalBuildActionVersion2) clientAction).execute(internalBuildController);
        } else {
            model = ((org.gradle.tooling.internal.protocol.InternalBuildAction) clientAction).execute(internalBuildController);
        }
    } catch (BuildCancelledException e) {
        failure = new InternalBuildCancelledException(e);
    } catch (RuntimeException e) {
        failure = new InternalBuildActionFailureException(e);
    }
    PayloadSerializer payloadSerializer = getPayloadSerializer(gradle);
    if (failure != null) {
        return new BuildActionResult(null, payloadSerializer.serialize(failure));
    } else {
        return new BuildActionResult(payloadSerializer.serialize(model), null);
    }
}
Also used : PayloadSerializer(org.gradle.tooling.internal.provider.serialization.PayloadSerializer) InternalBuildCancelledException(org.gradle.tooling.internal.protocol.InternalBuildCancelledException) InternalBuildActionFailureException(org.gradle.tooling.internal.protocol.InternalBuildActionFailureException) BuildActionResult(org.gradle.tooling.internal.provider.BuildActionResult) InternalBuildActionVersion2(org.gradle.tooling.internal.protocol.InternalBuildActionVersion2) InternalBuildCancelledException(org.gradle.tooling.internal.protocol.InternalBuildCancelledException) BuildCancelledException(org.gradle.api.BuildCancelledException)

Example 2 with PayloadSerializer

use of org.gradle.tooling.internal.provider.serialization.PayloadSerializer in project gradle by gradle.

the class TestExecutionRequestActionRunner method run.

@Override
public void run(BuildAction action, BuildController buildController) {
    if (!(action instanceof TestExecutionRequestAction)) {
        return;
    }
    GradleInternal gradle = buildController.getGradle();
    try {
        TestExecutionRequestAction testExecutionRequestAction = (TestExecutionRequestAction) action;
        TestExecutionResultEvaluator testExecutionResultEvaluator = new TestExecutionResultEvaluator(testExecutionRequestAction);
        buildOperationListenerManager.addListener(testExecutionResultEvaluator);
        try {
            doRun(testExecutionRequestAction, buildController);
        } finally {
            buildOperationListenerManager.removeListener(testExecutionResultEvaluator);
        }
        testExecutionResultEvaluator.evaluate();
    } catch (RuntimeException rex) {
        Throwable throwable = findRootCause(rex);
        if (throwable instanceof TestExecutionException) {
            // Tunnel the failure through the reporting
            throw new ReportedException(new InternalTestExecutionException("Error while running test(s)", throwable));
        } else {
            throw rex;
        }
    }
    PayloadSerializer payloadSerializer = gradle.getServices().get(PayloadSerializer.class);
    buildController.setResult(new BuildActionResult(payloadSerializer.serialize(null), null));
}
Also used : TestExecutionRequestAction(org.gradle.tooling.internal.provider.TestExecutionRequestAction) GradleInternal(org.gradle.api.internal.GradleInternal) PayloadSerializer(org.gradle.tooling.internal.provider.serialization.PayloadSerializer) TestExecutionException(org.gradle.api.tasks.testing.TestExecutionException) InternalTestExecutionException(org.gradle.tooling.internal.protocol.test.InternalTestExecutionException) BuildActionResult(org.gradle.tooling.internal.provider.BuildActionResult) InternalTestExecutionException(org.gradle.tooling.internal.protocol.test.InternalTestExecutionException) ReportedException(org.gradle.initialization.ReportedException)

Example 3 with PayloadSerializer

use of org.gradle.tooling.internal.provider.serialization.PayloadSerializer in project gradle by gradle.

the class InProcessGradleExecuter method executeBuild.

private BuildResult executeBuild(GradleInvocation invocation, OutputStream outputStream, OutputStream errorStream, BuildListenerImpl listener) {
    // Augment the environment for the execution
    System.setIn(connectStdIn());
    processEnvironment.maybeSetProcessDir(getWorkingDir());
    for (Map.Entry<String, String> entry : invocation.environmentVars.entrySet()) {
        processEnvironment.maybeSetEnvironmentVariable(entry.getKey(), entry.getValue());
    }
    Map<String, String> implicitJvmSystemProperties = getImplicitJvmSystemProperties();
    System.getProperties().putAll(implicitJvmSystemProperties);
    // TODO: Reuse more of CommandlineActionFactory
    CommandLineParser parser = new CommandLineParser();
    FileCollectionFactory fileCollectionFactory = TestFiles.fileCollectionFactory();
    ParametersConverter parametersConverter = new ParametersConverter(new BuildLayoutFactory(), fileCollectionFactory);
    parametersConverter.configure(parser);
    Parameters parameters = parametersConverter.convert(parser.parse(getAllArgs()), getWorkingDir());
    BuildActionExecuter<BuildActionParameters, BuildRequestContext> actionExecuter = GLOBAL_SERVICES.get(BuildActionExecuter.class);
    ListenerManager listenerManager = GLOBAL_SERVICES.get(ListenerManager.class);
    listenerManager.addListener(listener);
    try {
        // TODO: Reuse more of BuildActionsFactory
        StartParameterInternal startParameter = parameters.getStartParameter();
        BuildAction action = new ExecuteBuildAction(startParameter);
        BuildActionParameters buildActionParameters = createBuildActionParameters(startParameter);
        BuildRequestContext buildRequestContext = createBuildRequestContext();
        LoggingManagerInternal loggingManager = createLoggingManager(startParameter, outputStream, errorStream);
        loggingManager.start();
        try {
            startMeasurement();
            try {
                BuildActionResult result = actionExecuter.execute(action, buildActionParameters, buildRequestContext);
                if (result.getException() != null) {
                    return new BuildResult(null, result.getException());
                }
                if (result.getFailure() != null) {
                    PayloadSerializer payloadSerializer = new PayloadSerializer(new TestClassLoaderRegistry());
                    return new BuildResult(null, (RuntimeException) payloadSerializer.deserialize(result.getFailure()));
                }
                return new BuildResult(null, null);
            } finally {
                stopMeasurement();
            }
        } finally {
            loggingManager.stop();
        }
    } finally {
        listenerManager.removeListener(listener);
    }
}
Also used : LoggingManagerInternal(org.gradle.internal.logging.LoggingManagerInternal) DefaultBuildActionParameters(org.gradle.launcher.exec.DefaultBuildActionParameters) BuildActionParameters(org.gradle.launcher.exec.BuildActionParameters) Parameters(org.gradle.launcher.cli.Parameters) PayloadSerializer(org.gradle.tooling.internal.provider.serialization.PayloadSerializer) DefaultBuildActionParameters(org.gradle.launcher.exec.DefaultBuildActionParameters) BuildActionParameters(org.gradle.launcher.exec.BuildActionParameters) ExecuteBuildAction(org.gradle.tooling.internal.provider.action.ExecuteBuildAction) Hashing.hashString(org.gradle.internal.hash.Hashing.hashString) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) BuildLayoutFactory(org.gradle.initialization.layout.BuildLayoutFactory) DefaultBuildRequestContext(org.gradle.initialization.DefaultBuildRequestContext) BuildRequestContext(org.gradle.initialization.BuildRequestContext) BuildResult(org.gradle.BuildResult) ParametersConverter(org.gradle.launcher.cli.ParametersConverter) StartParameterInternal(org.gradle.api.internal.StartParameterInternal) BuildActionResult(org.gradle.launcher.exec.BuildActionResult) CommandLineParser(org.gradle.cli.CommandLineParser) SerializeMap(org.gradle.tooling.internal.provider.serialization.SerializeMap) Map(java.util.Map) DeserializeMap(org.gradle.tooling.internal.provider.serialization.DeserializeMap) HashMap(java.util.HashMap) ExecuteBuildAction(org.gradle.tooling.internal.provider.action.ExecuteBuildAction) BuildAction(org.gradle.internal.invocation.BuildAction) FileCollectionFactory(org.gradle.api.internal.file.FileCollectionFactory) ListenerManager(org.gradle.internal.event.ListenerManager)

Example 4 with PayloadSerializer

use of org.gradle.tooling.internal.provider.serialization.PayloadSerializer in project gradle by gradle.

the class ClientProvidedBuildActionRunner method buildResult.

private BuildActionResult buildResult(InternalBuildAction<?> clientAction, GradleInternal gradle, boolean isRunTasks) {
    if (!isRunTasks) {
        forceFullConfiguration(gradle);
    }
    InternalBuildController internalBuildController = new DefaultBuildController(gradle);
    Object model = null;
    Throwable failure = null;
    try {
        model = clientAction.execute(internalBuildController);
    } catch (BuildCancelledException e) {
        failure = new InternalBuildCancelledException(e);
    } catch (RuntimeException e) {
        failure = new InternalBuildActionFailureException(e);
    }
    PayloadSerializer payloadSerializer = getPayloadSerializer(gradle);
    if (failure != null) {
        return new BuildActionResult(null, payloadSerializer.serialize(failure));
    } else {
        return new BuildActionResult(payloadSerializer.serialize(model), null);
    }
}
Also used : InternalBuildController(org.gradle.tooling.internal.protocol.InternalBuildController) PayloadSerializer(org.gradle.tooling.internal.provider.serialization.PayloadSerializer) InternalBuildActionFailureException(org.gradle.tooling.internal.protocol.InternalBuildActionFailureException) BuildActionResult(org.gradle.tooling.internal.provider.BuildActionResult) InternalBuildCancelledException(org.gradle.tooling.internal.protocol.InternalBuildCancelledException) BuildCancelledException(org.gradle.api.BuildCancelledException) InternalBuildCancelledException(org.gradle.tooling.internal.protocol.InternalBuildCancelledException)

Example 5 with PayloadSerializer

use of org.gradle.tooling.internal.provider.serialization.PayloadSerializer in project gradle by gradle.

the class ClientProvidedBuildActionRunner method run.

@Override
public void run(BuildAction action, final BuildController buildController) {
    if (!(action instanceof ClientProvidedBuildAction)) {
        return;
    }
    final GradleInternal gradle = buildController.getGradle();
    gradle.getStartParameter().setConfigureOnDemand(false);
    ClientProvidedBuildAction clientProvidedBuildAction = (ClientProvidedBuildAction) action;
    PayloadSerializer payloadSerializer = getPayloadSerializer(gradle);
    final Object clientAction = payloadSerializer.deserialize(clientProvidedBuildAction.getAction());
    gradle.addBuildListener(new BuildAdapter() {

        @Override
        public void buildFinished(BuildResult result) {
            if (result.getFailure() == null) {
                buildController.setResult(buildResult(clientAction, gradle));
            }
        }
    });
    if (clientProvidedBuildAction.isRunTasks()) {
        buildController.run();
    } else {
        buildController.configure();
    }
}
Also used : GradleInternal(org.gradle.api.internal.GradleInternal) BuildResult(org.gradle.BuildResult) PayloadSerializer(org.gradle.tooling.internal.provider.serialization.PayloadSerializer) ClientProvidedBuildAction(org.gradle.tooling.internal.provider.ClientProvidedBuildAction) BuildAdapter(org.gradle.BuildAdapter)

Aggregations

PayloadSerializer (org.gradle.tooling.internal.provider.serialization.PayloadSerializer)5 BuildActionResult (org.gradle.tooling.internal.provider.BuildActionResult)3 BuildResult (org.gradle.BuildResult)2 BuildCancelledException (org.gradle.api.BuildCancelledException)2 GradleInternal (org.gradle.api.internal.GradleInternal)2 InternalBuildActionFailureException (org.gradle.tooling.internal.protocol.InternalBuildActionFailureException)2 InternalBuildCancelledException (org.gradle.tooling.internal.protocol.InternalBuildCancelledException)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 BuildAdapter (org.gradle.BuildAdapter)1 StartParameterInternal (org.gradle.api.internal.StartParameterInternal)1 FileCollectionFactory (org.gradle.api.internal.file.FileCollectionFactory)1 TestExecutionException (org.gradle.api.tasks.testing.TestExecutionException)1 CommandLineParser (org.gradle.cli.CommandLineParser)1 BuildRequestContext (org.gradle.initialization.BuildRequestContext)1 DefaultBuildRequestContext (org.gradle.initialization.DefaultBuildRequestContext)1 ReportedException (org.gradle.initialization.ReportedException)1 BuildLayoutFactory (org.gradle.initialization.layout.BuildLayoutFactory)1 ListenerManager (org.gradle.internal.event.ListenerManager)1 Hashing.hashString (org.gradle.internal.hash.Hashing.hashString)1