use of org.gradle.initialization.BuildRequestContext in project gradle by gradle.
the class ProviderConnection method run.
private Object run(BuildAction action, BuildCancellationToken cancellationToken, ProgressListenerConfiguration progressListenerConfiguration, ProviderOperationParameters providerParameters, Parameters parameters) {
try {
BuildActionExecuter<ProviderOperationParameters> executer = createExecuter(providerParameters, parameters);
BuildRequestContext buildRequestContext = new DefaultBuildRequestContext(new DefaultBuildRequestMetaData(providerParameters.getStartTime()), cancellationToken, progressListenerConfiguration.buildEventConsumer);
BuildActionResult result = (BuildActionResult) executer.execute(action, buildRequestContext, providerParameters, sharedServices);
if (result.failure != null) {
throw (RuntimeException) payloadSerializer.deserialize(result.failure);
}
return payloadSerializer.deserialize(result.result);
} finally {
progressListenerConfiguration.failsafeWrapper.rethrowErrors();
}
}
use of org.gradle.initialization.BuildRequestContext 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);
}
}
use of org.gradle.initialization.BuildRequestContext in project gradle by gradle.
the class ExecuteBuild method doBuild.
@Override
protected void doBuild(final DaemonCommandExecution execution, Build build) {
LOGGER.debug(DaemonMessages.STARTED_BUILD);
LOGGER.debug("Executing build with daemon context: {}", execution.getDaemonContext());
runningStats.buildStarted();
DaemonConnectionBackedEventConsumer buildEventConsumer = new DaemonConnectionBackedEventConsumer(execution);
try {
BuildCancellationToken cancellationToken = execution.getDaemonStateControl().getCancellationToken();
BuildRequestContext buildRequestContext = new DefaultBuildRequestContext(build.getBuildRequestMetaData(), cancellationToken, buildEventConsumer);
if (!build.getAction().getStartParameter().isContinuous()) {
buildRequestContext.getCancellationToken().addCallback(new Runnable() {
@Override
public void run() {
LOGGER.info(DaemonMessages.CANCELED_BUILD);
}
});
}
BuildActionResult result = actionExecuter.execute(build.getAction(), build.getParameters(), buildRequestContext);
execution.setResult(result);
} finally {
buildEventConsumer.waitForFinish();
runningStats.buildFinished();
LOGGER.debug(DaemonMessages.FINISHED_BUILD);
}
// ExecuteBuild should be the last action, but in case we want to decorate the result in the future
execution.proceed();
}
use of org.gradle.initialization.BuildRequestContext in project gradle by gradle.
the class ProviderConnection method createExecuter.
private BuildActionExecuter<ConnectionOperationParameters, BuildRequestContext> createExecuter(ProviderOperationParameters operationParameters, Parameters params) {
LoggingManagerInternal loggingManager;
BuildActionExecuter<BuildActionParameters, BuildRequestContext> executer;
InputStream standardInput = operationParameters.getStandardInput();
if (standardInput == null) {
standardInput = SafeStreams.emptyInput();
}
if (Boolean.TRUE.equals(operationParameters.isEmbedded())) {
loggingManager = sharedServices.getFactory(LoggingManagerInternal.class).create();
loggingManager.captureSystemSources();
executer = new StdInSwapExecuter(standardInput, embeddedExecutor);
} else {
LoggingServiceRegistry loggingServices = LoggingServiceRegistry.newNestedLogging();
loggingManager = loggingServices.getFactory(LoggingManagerInternal.class).create();
ServiceRegistry clientServices = daemonClientFactory.createBuildClientServices(loggingServices.get(OutputEventListener.class), params.daemonParams, standardInput);
executer = clientServices.get(DaemonClient.class);
}
return new LoggingBridgingBuildActionExecuter(new DaemonBuildActionExecuter(executer), loggingManager);
}
use of org.gradle.initialization.BuildRequestContext 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);
}
}
Aggregations