Search in sources :

Example 6 with BuildActionParameters

use of org.gradle.launcher.exec.BuildActionParameters 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)

Example 7 with BuildActionParameters

use of org.gradle.launcher.exec.BuildActionParameters in project gradle by gradle.

the class DaemonBuildActionExecuter method execute.

public Object execute(BuildAction action, BuildRequestContext buildRequestContext, ProviderOperationParameters parameters, ServiceRegistry contextServices) {
    boolean continuous = action.getStartParameter() != null && action.getStartParameter().isContinuous() && isNotBuildingModel(action);
    if (continuous && !doesConsumerSupportCancellation(buildRequestContext)) {
        throw new UnsupportedVersionException("Continuous build requires Tooling API client version 2.1 or later.");
    }
    ClassPath classPath = DefaultClassPath.of(parameters.getInjectedPluginClasspath(Collections.<File>emptyList()));
    BuildActionParameters actionParameters = new DefaultBuildActionParameters(daemonParameters.getEffectiveSystemProperties(), daemonParameters.getEnvironmentVariables(), SystemProperties.getInstance().getCurrentDir(), parameters.getBuildLogLevel(), daemonParameters.isEnabled(), continuous, false, classPath);
    try {
        return executer.execute(action, buildRequestContext, actionParameters, contextServices);
    } catch (ReportedException e) {
        Throwable t = e.getCause();
        // Unpack tunnelled test request failure
        if (t instanceof InternalTestExecutionException) {
            throw (InternalTestExecutionException) t;
        }
        while (t != null) {
            if (t instanceof BuildCancelledException) {
                throw new InternalBuildCancelledException(e.getCause());
            }
            t = t.getCause();
        }
        throw new BuildExceptionVersion1(e.getCause());
    }
}
Also used : DefaultClassPath(org.gradle.internal.classpath.DefaultClassPath) ClassPath(org.gradle.internal.classpath.ClassPath) BuildExceptionVersion1(org.gradle.tooling.internal.protocol.BuildExceptionVersion1) DefaultBuildActionParameters(org.gradle.launcher.exec.DefaultBuildActionParameters) DefaultBuildActionParameters(org.gradle.launcher.exec.DefaultBuildActionParameters) BuildActionParameters(org.gradle.launcher.exec.BuildActionParameters) InternalTestExecutionException(org.gradle.tooling.internal.protocol.test.InternalTestExecutionException) File(java.io.File) InternalBuildCancelledException(org.gradle.tooling.internal.protocol.InternalBuildCancelledException) BuildCancelledException(org.gradle.api.BuildCancelledException) UnsupportedVersionException(org.gradle.tooling.UnsupportedVersionException) ReportedException(org.gradle.initialization.ReportedException) InternalBuildCancelledException(org.gradle.tooling.internal.protocol.InternalBuildCancelledException)

Example 8 with BuildActionParameters

use of org.gradle.launcher.exec.BuildActionParameters in project gradle by gradle.

the class DaemonBuildActionExecuter method execute.

@Override
public BuildActionResult execute(BuildAction action, ConnectionOperationParameters parameters, BuildRequestContext buildRequestContext) {
    ProviderOperationParameters operationParameters = parameters.getOperationParameters();
    ClassPath classPath = DefaultClassPath.of(operationParameters.getInjectedPluginClasspath());
    DaemonParameters daemonParameters = parameters.getDaemonParameters();
    BuildActionParameters actionParameters = new DefaultBuildActionParameters(daemonParameters.getEffectiveSystemProperties(), daemonParameters.getEnvironmentVariables(), SystemProperties.getInstance().getCurrentDir(), operationParameters.getBuildLogLevel(), daemonParameters.isEnabled(), classPath);
    return executer.execute(action, actionParameters, buildRequestContext);
}
Also used : DefaultClassPath(org.gradle.internal.classpath.DefaultClassPath) ClassPath(org.gradle.internal.classpath.ClassPath) DefaultBuildActionParameters(org.gradle.launcher.exec.DefaultBuildActionParameters) ProviderOperationParameters(org.gradle.tooling.internal.provider.connection.ProviderOperationParameters) DefaultBuildActionParameters(org.gradle.launcher.exec.DefaultBuildActionParameters) BuildActionParameters(org.gradle.launcher.exec.BuildActionParameters) DaemonParameters(org.gradle.launcher.daemon.configuration.DaemonParameters)

Aggregations

BuildActionParameters (org.gradle.launcher.exec.BuildActionParameters)8 DefaultBuildActionParameters (org.gradle.launcher.exec.DefaultBuildActionParameters)7 BuildRequestContext (org.gradle.initialization.BuildRequestContext)3 DefaultBuildRequestContext (org.gradle.initialization.DefaultBuildRequestContext)3 CompositeStoppable (org.gradle.internal.concurrent.CompositeStoppable)3 Stoppable (org.gradle.internal.concurrent.Stoppable)3 LoggingManagerInternal (org.gradle.internal.logging.LoggingManagerInternal)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 BuildResult (org.gradle.BuildResult)2 StartParameterInternal (org.gradle.api.internal.StartParameterInternal)2 CommandLineParser (org.gradle.cli.CommandLineParser)2 ReportedException (org.gradle.initialization.ReportedException)2 BuildLayoutFactory (org.gradle.initialization.layout.BuildLayoutFactory)2 ClassPath (org.gradle.internal.classpath.ClassPath)2 DefaultClassPath (org.gradle.internal.classpath.DefaultClassPath)2 ListenerManager (org.gradle.internal.event.ListenerManager)2 BuildAction (org.gradle.internal.invocation.BuildAction)2 Parameters (org.gradle.launcher.cli.Parameters)2 ParametersConverter (org.gradle.launcher.cli.ParametersConverter)2