Search in sources :

Example 1 with BuildAction

use of org.gradle.internal.invocation.BuildAction in project gradle by gradle.

the class ProviderConnection method run.

public Object run(InternalBuildAction<?> clientAction, BuildCancellationToken cancellationToken, ProviderOperationParameters providerParameters) {
    List<String> tasks = providerParameters.getTasks();
    SerializedPayload serializedAction = payloadSerializer.serialize(clientAction);
    Parameters params = initParams(providerParameters);
    StartParameter startParameter = new ProviderStartParameterConverter().toStartParameter(providerParameters, params.properties);
    ProgressListenerConfiguration listenerConfig = ProgressListenerConfiguration.from(providerParameters);
    BuildAction action = new ClientProvidedBuildAction(startParameter, serializedAction, tasks != null, listenerConfig.clientSubscriptions);
    return run(action, cancellationToken, listenerConfig, providerParameters, params);
}
Also used : SerializedPayload(org.gradle.tooling.internal.provider.serialization.SerializedPayload) StartParameter(org.gradle.StartParameter) ProviderConnectionParameters(org.gradle.tooling.internal.provider.connection.ProviderConnectionParameters) ProviderOperationParameters(org.gradle.tooling.internal.provider.connection.ProviderOperationParameters) DaemonParameters(org.gradle.launcher.daemon.configuration.DaemonParameters) BuildActionParameters(org.gradle.launcher.exec.BuildActionParameters) BuildLayoutParameters(org.gradle.initialization.BuildLayoutParameters) InternalBuildAction(org.gradle.tooling.internal.protocol.InternalBuildAction) BuildAction(org.gradle.internal.invocation.BuildAction)

Example 2 with BuildAction

use of org.gradle.internal.invocation.BuildAction 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 3 with BuildAction

use of org.gradle.internal.invocation.BuildAction in project gradle by gradle.

the class ProviderConnection method runClientAction.

public Object runClientAction(Object clientAction, BuildCancellationToken cancellationToken, ProviderOperationParameters providerParameters) {
    List<String> tasks = providerParameters.getTasks();
    SerializedPayload serializedAction = payloadSerializer.serialize(clientAction);
    Parameters params = initParams(providerParameters);
    StartParameterInternal startParameter = new ProviderStartParameterConverter().toStartParameter(providerParameters, params.buildLayout, params.properties);
    ProgressListenerConfiguration listenerConfig = ProgressListenerConfiguration.from(providerParameters, consumerVersion);
    BuildAction action = new ClientProvidedBuildAction(startParameter, serializedAction, tasks != null, listenerConfig.clientSubscriptions);
    return run(action, cancellationToken, listenerConfig, listenerConfig.buildEventConsumer, providerParameters, params);
}
Also used : SerializedPayload(org.gradle.tooling.internal.provider.serialization.SerializedPayload) ProviderConnectionParameters(org.gradle.tooling.internal.provider.connection.ProviderConnectionParameters) ProviderOperationParameters(org.gradle.tooling.internal.provider.connection.ProviderOperationParameters) DaemonParameters(org.gradle.launcher.daemon.configuration.DaemonParameters) BuildActionParameters(org.gradle.launcher.exec.BuildActionParameters) ClientProvidedBuildAction(org.gradle.tooling.internal.provider.action.ClientProvidedBuildAction) StartParameterInternal(org.gradle.api.internal.StartParameterInternal) ClientProvidedBuildAction(org.gradle.tooling.internal.provider.action.ClientProvidedBuildAction) BuildAction(org.gradle.internal.invocation.BuildAction)

Example 4 with BuildAction

use of org.gradle.internal.invocation.BuildAction in project gradle by gradle.

the class BuildTreeLifecycleBuildActionExecutor method execute.

@Override
public BuildActionRunner.Result execute(BuildAction action, BuildSessionContext buildSession) {
    BuildActionRunner.Result result = null;
    try {
        buildLayoutValidator.validate(action.getStartParameter());
        BuildActionModelRequirements actionRequirements;
        if (action instanceof BuildModelAction && action.isCreateModel()) {
            BuildModelAction buildModelAction = (BuildModelAction) action;
            actionRequirements = new QueryModelRequirements(action.getStartParameter(), action.isRunTasks(), buildModelAction.getModelName());
        } else if (action instanceof ClientProvidedBuildAction) {
            actionRequirements = new RunActionRequirements(action.getStartParameter(), action.isRunTasks());
        } else if (action instanceof ClientProvidedPhasedAction) {
            actionRequirements = new RunPhasedActionRequirements(action.getStartParameter(), action.isRunTasks());
        } else {
            actionRequirements = new RunTasksRequirements(action.getStartParameter());
        }
        BuildTreeModelControllerServices.Supplier modelServices = buildTreeModelControllerServices.servicesForBuildTree(actionRequirements);
        BuildTreeState buildTree = new BuildTreeState(buildSession.getServices(), modelServices);
        try {
            result = buildTree.run(context -> context.execute(action));
        } finally {
            buildTree.close();
        }
    } catch (Throwable t) {
        if (result == null) {
            // whereas console failure logging based on the _thrown exception_ happens up outside session scope. It would be better to refactor so that a result can be returned from here
            throw UncheckedException.throwAsUncheckedException(t);
        } else {
            // whereas console failure logging based on the _thrown exception_ happens up outside session scope. It would be better to refactor so that a result can be returned from here
            throw UncheckedException.throwAsUncheckedException(result.addFailure(t).getBuildFailure());
        }
    }
    return result;
}
Also used : BuildActionRunner(org.gradle.internal.buildtree.BuildActionRunner) BuildTreeState(org.gradle.internal.buildtree.BuildTreeState) BuildActionModelRequirements(org.gradle.internal.buildtree.BuildActionModelRequirements) ClientProvidedBuildAction(org.gradle.tooling.internal.provider.action.ClientProvidedBuildAction) BuildTreeModelControllerServices(org.gradle.internal.buildtree.BuildTreeModelControllerServices) ClientProvidedPhasedAction(org.gradle.tooling.internal.provider.action.ClientProvidedPhasedAction) BuildSessionActionExecutor(org.gradle.internal.session.BuildSessionActionExecutor) UncheckedException(org.gradle.internal.UncheckedException) RunTasksRequirements(org.gradle.internal.buildtree.RunTasksRequirements) BuildAction(org.gradle.internal.invocation.BuildAction) BuildSessionContext(org.gradle.internal.session.BuildSessionContext) BuildModelAction(org.gradle.tooling.internal.provider.action.BuildModelAction) BuildLayoutValidator(org.gradle.internal.build.BuildLayoutValidator) ClientProvidedPhasedAction(org.gradle.tooling.internal.provider.action.ClientProvidedPhasedAction) BuildActionModelRequirements(org.gradle.internal.buildtree.BuildActionModelRequirements) BuildTreeState(org.gradle.internal.buildtree.BuildTreeState) BuildActionRunner(org.gradle.internal.buildtree.BuildActionRunner) ClientProvidedBuildAction(org.gradle.tooling.internal.provider.action.ClientProvidedBuildAction) BuildTreeModelControllerServices(org.gradle.internal.buildtree.BuildTreeModelControllerServices) RunTasksRequirements(org.gradle.internal.buildtree.RunTasksRequirements) BuildModelAction(org.gradle.tooling.internal.provider.action.BuildModelAction)

Example 5 with BuildAction

use of org.gradle.internal.invocation.BuildAction in project gradle by gradle.

the class InProcessGradleExecuter method executeBuild.

private BuildResult executeBuild(GradleInvocation invocation, final StandardOutputListener outputListener, 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);
    resetTempDirLocation();
    // TODO: Fix tests that rely on this being set before we process arguments like this...
    StartParameterInternal startParameter = new StartParameterInternal();
    startParameter.setCurrentDir(getWorkingDir());
    // TODO: Reuse more of CommandlineActionFactory
    CommandLineParser parser = new CommandLineParser();
    BuildLayoutFactory buildLayoutFactory = new BuildLayoutFactory();
    ParametersConverter parametersConverter = new ParametersConverter(buildLayoutFactory);
    parametersConverter.configure(parser);
    final Parameters parameters = new Parameters(startParameter);
    parametersConverter.convert(parser.parse(getAllArgs()), parameters);
    BuildActionExecuter<BuildActionParameters> actionExecuter = GLOBAL_SERVICES.get(BuildActionExecuter.class);
    ListenerManager listenerManager = GLOBAL_SERVICES.get(ListenerManager.class);
    listenerManager.addListener(listener);
    try {
        // TODO: Reuse more of BuildActionsFactory
        BuildAction action = new ExecuteBuildAction(startParameter);
        BuildActionParameters buildActionParameters = createBuildActionParameters(startParameter);
        BuildRequestContext buildRequestContext = createBuildRequestContext();
        LoggingManagerInternal loggingManager = createLoggingManager(startParameter, outputListener);
        loggingManager.start();
        try {
            startMeasurement();
            try {
                actionExecuter.execute(action, buildRequestContext, buildActionParameters, GLOBAL_SERVICES);
            } finally {
                stopMeasurement();
            }
        } finally {
            loggingManager.stop();
        }
        return new BuildResult(null, null);
    } catch (ReportedException e) {
        return new BuildResult(null, e.getCause());
    } finally {
        listenerManager.removeListener(listener);
    }
}
Also used : LoggingManagerInternal(org.gradle.internal.logging.LoggingManagerInternal) Parameters(org.gradle.launcher.cli.Parameters) DefaultBuildActionParameters(org.gradle.launcher.exec.DefaultBuildActionParameters) BuildActionParameters(org.gradle.launcher.exec.BuildActionParameters) DefaultBuildActionParameters(org.gradle.launcher.exec.DefaultBuildActionParameters) BuildActionParameters(org.gradle.launcher.exec.BuildActionParameters) ExecuteBuildAction(org.gradle.launcher.cli.action.ExecuteBuildAction) Matchers.containsString(org.hamcrest.Matchers.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) CommandLineParser(org.gradle.cli.CommandLineParser) Map(java.util.Map) HashMap(java.util.HashMap) ExecuteBuildAction(org.gradle.launcher.cli.action.ExecuteBuildAction) BuildAction(org.gradle.internal.invocation.BuildAction) ListenerManager(org.gradle.internal.event.ListenerManager) ReportedException(org.gradle.initialization.ReportedException)

Aggregations

BuildAction (org.gradle.internal.invocation.BuildAction)8 BuildActionParameters (org.gradle.launcher.exec.BuildActionParameters)6 StartParameterInternal (org.gradle.api.internal.StartParameterInternal)5 DaemonParameters (org.gradle.launcher.daemon.configuration.DaemonParameters)4 ClientProvidedBuildAction (org.gradle.tooling.internal.provider.action.ClientProvidedBuildAction)4 ProviderConnectionParameters (org.gradle.tooling.internal.provider.connection.ProviderConnectionParameters)4 ProviderOperationParameters (org.gradle.tooling.internal.provider.connection.ProviderOperationParameters)4 ListenerManager (org.gradle.internal.event.ListenerManager)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 BuildResult (org.gradle.BuildResult)2 CommandLineParser (org.gradle.cli.CommandLineParser)2 BuildRequestContext (org.gradle.initialization.BuildRequestContext)2 DefaultBuildRequestContext (org.gradle.initialization.DefaultBuildRequestContext)2 BuildLayoutFactory (org.gradle.initialization.layout.BuildLayoutFactory)2 BuildActionRunner (org.gradle.internal.buildtree.BuildActionRunner)2 LoggingManagerInternal (org.gradle.internal.logging.LoggingManagerInternal)2 BuildSessionActionExecutor (org.gradle.internal.session.BuildSessionActionExecutor)2 SerializedPayload (org.gradle.tooling.internal.provider.serialization.SerializedPayload)2 Supplier (java.util.function.Supplier)1