Search in sources :

Example 1 with ExecuteBuildAction

use of org.gradle.launcher.cli.ExecuteBuildAction in project gradle by gradle.

the class InProcessGradleExecuter method executeBuild.

private BuildResult executeBuild(GradleInvocation invocation, StandardOutputListener outputListener, StandardOutputListener errorListener, 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...
    StartParameter startParameter = new StartParameter();
    startParameter.setCurrentDir(getWorkingDir());
    startParameter.setShowStacktrace(ShowStacktrace.ALWAYS);
    CommandLineParser parser = new CommandLineParser();
    ParametersConverter parametersConverter = new ParametersConverter();
    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(outputListener, errorListener);
        startMeasurement();
        actionExecuter.execute(action, buildRequestContext, buildActionParameters, GLOBAL_SERVICES);
        return new BuildResult(null, null);
    } catch (ReportedException e) {
        return new BuildResult(null, e.getCause());
    } finally {
        stopMeasurement();
        listenerManager.removeListener(listener);
    }
}
Also used : StartParameter(org.gradle.StartParameter) 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.ExecuteBuildAction) DefaultBuildRequestContext(org.gradle.initialization.DefaultBuildRequestContext) BuildRequestContext(org.gradle.initialization.BuildRequestContext) BuildResult(org.gradle.BuildResult) ParametersConverter(org.gradle.launcher.cli.ParametersConverter) CommandLineParser(org.gradle.cli.CommandLineParser) Map(java.util.Map) HashMap(java.util.HashMap) ExecuteBuildAction(org.gradle.launcher.cli.ExecuteBuildAction) BuildAction(org.gradle.internal.invocation.BuildAction) ListenerManager(org.gradle.internal.event.ListenerManager) ReportedException(org.gradle.initialization.ReportedException)

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 BuildResult (org.gradle.BuildResult)1 StartParameter (org.gradle.StartParameter)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 ListenerManager (org.gradle.internal.event.ListenerManager)1 BuildAction (org.gradle.internal.invocation.BuildAction)1 ExecuteBuildAction (org.gradle.launcher.cli.ExecuteBuildAction)1 Parameters (org.gradle.launcher.cli.Parameters)1 ParametersConverter (org.gradle.launcher.cli.ParametersConverter)1 BuildActionParameters (org.gradle.launcher.exec.BuildActionParameters)1 DefaultBuildActionParameters (org.gradle.launcher.exec.DefaultBuildActionParameters)1