use of org.gradle.initialization.ReportedException in project gradle by gradle.
the class IncludedBuildArtifactBuilder method contextualizeFailure.
private RuntimeException contextualizeFailure(BuildIdentifier buildId, ReportedException e) {
if (e.getCause() instanceof LocationAwareException) {
LocationAwareException lae = (LocationAwareException) e.getCause();
IncludedBuildArtifactException wrappedCause = new IncludedBuildArtifactException("Failed to build artifacts for " + buildId, lae.getCause());
LocationAwareException newLae = new LocationAwareException(wrappedCause, lae.getSourceDisplayName(), lae.getLineNumber());
return new ReportedException(newLae);
}
return e;
}
use of org.gradle.initialization.ReportedException 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));
}
use of org.gradle.initialization.ReportedException in project gradle by gradle.
the class ExecuteBuild method doBuild.
protected void doBuild(final DaemonCommandExecution execution, Build build) {
LOGGER.debug(DaemonMessages.STARTED_BUILD);
LOGGER.debug("Executing build with daemon context: {}", execution.getDaemonContext());
runningStats.buildStarted();
try {
BuildCancellationToken cancellationToken = execution.getDaemonStateControl().getCancellationToken();
BuildRequestContext buildRequestContext = new DefaultBuildRequestContext(build.getBuildRequestMetaData(), cancellationToken, new DaemonConnectionBackedEventConsumer(execution));
if (!build.getParameters().isContinuous()) {
buildRequestContext.getCancellationToken().addCallback(new Runnable() {
@Override
public void run() {
LOGGER.info(DaemonMessages.CANCELED_BUILD);
}
});
}
Object result = actionExecuter.execute(build.getAction(), buildRequestContext, build.getParameters(), contextServices);
execution.setResult(result);
} catch (ReportedException e) {
/*
We have to wrap in a ReportedException so the other side doesn't re-log this exception, because it's already
been logged by the GradleLauncher infrastructure, and that logging has been shipped over to the other side.
This doesn't seem right. Perhaps we should assume on the client side that all “build failures” (opposed to daemon infrastructure failures)
have already been logged and do away with this wrapper.
*/
execution.setException(e);
} finally {
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.ReportedException in project gradle by gradle.
the class ContinuousBuildActionExecuter method executeMultipleBuilds.
private Object executeMultipleBuilds(BuildAction action, BuildRequestContext requestContext, final BuildActionParameters actionParameters, ServiceRegistry buildSessionScopeServices) {
SingleMessageLogger.incubatingFeatureUsed("Continuous build");
BuildCancellationToken cancellationToken = requestContext.getCancellationToken();
final CancellableOperationManager cancellableOperationManager;
if (actionParameters.isInteractive()) {
if (!(System.in instanceof DisconnectableInputStream)) {
System.setIn(new DisconnectableInputStream(System.in));
}
DisconnectableInputStream inputStream = (DisconnectableInputStream) System.in;
cancellableOperationManager = new DefaultCancellableOperationManager(executorFactory.create("cancel signal monitor"), inputStream, cancellationToken);
} else {
cancellableOperationManager = new PassThruCancellableOperationManager(cancellationToken);
}
Object lastResult = null;
int counter = 0;
while (!cancellationToken.isCancellationRequested()) {
if (++counter != 1) {
// reset the time the build started so the total time makes sense
requestContext.getBuildTimeClock().reset();
logger.println("Change detected, executing build...").println();
}
final FileSystemChangeWaiter waiter = changeWaiterFactory.createChangeWaiter(cancellationToken);
try {
try {
lastResult = executeBuildAndAccumulateInputs(action, requestContext, actionParameters, waiter, buildSessionScopeServices);
} catch (ReportedException t) {
lastResult = t;
}
if (!waiter.isWatching()) {
logger.println().withStyle(StyledTextOutput.Style.Failure).println("Exiting continuous build as no executed tasks declared file system inputs.");
if (lastResult instanceof ReportedException) {
throw (ReportedException) lastResult;
}
return lastResult;
} else {
cancellableOperationManager.monitorInput(new Action<BuildCancellationToken>() {
@Override
public void execute(BuildCancellationToken cancellationToken) {
ChangeReporter reporter = new ChangeReporter();
waiter.wait(new Runnable() {
@Override
public void run() {
logger.println().println("Waiting for changes to input files of tasks..." + determineExitHint(actionParameters));
}
}, reporter);
if (!cancellationToken.isCancellationRequested()) {
reporter.reportChanges(logger);
}
}
});
}
} finally {
waiter.stop();
}
}
logger.println("Build cancelled.");
if (lastResult instanceof ReportedException) {
throw (ReportedException) lastResult;
}
return lastResult;
}
use of org.gradle.initialization.ReportedException 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