use of org.gradle.internal.operations.RunnableBuildOperation in project gradle by gradle.
the class CleanupStaleOutputsExecuter method execute.
@Override
public void execute(final TaskInternal task, TaskStateInternal state, TaskExecutionContext context) {
final Set<File> filesToDelete = new HashSet<File>();
TaskProperties taskProperties = context.getTaskProperties();
for (TaskOutputFilePropertySpec outputFileSpec : taskProperties.getOutputFileProperties()) {
FileCollection files = outputFileSpec.getPropertyFiles();
for (File file : files) {
if (cleanupRegistry.isOutputOwnedByBuild(file) && !taskOutputFilesRepository.isGeneratedByGradle(file) && file.exists()) {
filesToDelete.add(file);
}
}
}
if (!filesToDelete.isEmpty()) {
taskOutputChangesListener.beforeTaskOutputChanged();
buildOperationExecutor.run(new RunnableBuildOperation() {
@Override
public void run(BuildOperationContext context) {
for (File file : filesToDelete) {
if (file.exists()) {
logger.info("Deleting stale output file: {}", file.getAbsolutePath());
GFileUtils.forceDelete(file);
}
}
}
@Override
public BuildOperationDescriptor.Builder description() {
return BuildOperationDescriptor.displayName(CLEAN_STALE_OUTPUTS_DISPLAY_NAME).progressDisplayName("Cleaning stale outputs");
}
});
}
executer.execute(task, state, context);
}
use of org.gradle.internal.operations.RunnableBuildOperation in project gradle by gradle.
the class ExecuteActionsTaskExecuter method executeAction.
private void executeAction(final String actionDisplayName, final TaskInternal task, final ContextAwareTaskAction action, TaskExecutionContext context) {
action.contextualise(context);
buildOperationExecutor.run(new RunnableBuildOperation() {
@Override
public BuildOperationDescriptor.Builder description() {
return BuildOperationDescriptor.displayName(actionDisplayName + " for " + task.getPath()).name(actionDisplayName);
}
@Override
public void run(BuildOperationContext context) {
BuildOperationRef currentOperation = buildOperationExecutor.getCurrentOperation();
Throwable actionFailure = null;
try {
action.execute(task);
} catch (Throwable t) {
actionFailure = t;
} finally {
action.releaseContext();
}
try {
asyncWorkTracker.waitForCompletion(currentOperation, true);
} catch (Throwable t) {
List<Throwable> failures = Lists.newArrayList();
if (actionFailure != null) {
failures.add(actionFailure);
}
if (t instanceof MultiCauseException) {
failures.addAll(((MultiCauseException) t).getCauses());
} else {
failures.add(t);
}
if (failures.size() > 1) {
throw new MultipleTaskActionFailures("Multiple task action failures occurred:", failures);
} else {
throw UncheckedException.throwAsUncheckedException(failures.get(0));
}
}
if (actionFailure != null) {
throw UncheckedException.throwAsUncheckedException(actionFailure);
}
}
});
}
use of org.gradle.internal.operations.RunnableBuildOperation in project gradle by gradle.
the class RunAsBuildOperationBuildActionRunner method run.
@Override
public void run(final BuildAction action, final BuildController buildController) {
BuildOperationExecutor buildOperationExecutor = buildController.getGradle().getServices().get(BuildOperationExecutor.class);
buildOperationExecutor.run(new RunnableBuildOperation() {
@Override
public void run(BuildOperationContext context) {
delegate.run(action, buildController);
context.setResult(RESULT);
}
@Override
public BuildOperationDescriptor.Builder description() {
return BuildOperationDescriptor.displayName("Run build").details(DETAILS);
}
});
}
use of org.gradle.internal.operations.RunnableBuildOperation in project gradle by gradle.
the class InitScriptHandler method executeScripts.
public void executeScripts(final GradleInternal gradle) {
final List<File> initScripts = gradle.getStartParameter().getAllInitScripts();
if (initScripts.isEmpty()) {
return;
}
buildOperationExecutor.run(new RunnableBuildOperation() {
@Override
public void run(BuildOperationContext context) {
for (File script : initScripts) {
TextResource resource = resourceLoader.loadFile("initialization script", script);
processor.process(new TextResourceScriptSource(resource), gradle);
}
}
@Override
public BuildOperationDescriptor.Builder description() {
return BuildOperationDescriptor.displayName("Run init scripts").progressDisplayName("Running init scripts");
}
});
}
use of org.gradle.internal.operations.RunnableBuildOperation in project gradle by gradle.
the class DefaultTestReport method generateFiles.
private void generateFiles(AllTestResults model, final TestResultsProvider resultsProvider, final File reportDir) {
try {
HtmlReportRenderer htmlRenderer = new HtmlReportRenderer();
buildOperationExecutor.run(new RunnableBuildOperation() {
@Override
public void run(BuildOperationContext context) {
// Clean-up old HTML report directories
GFileUtils.deleteQuietly(new File(reportDir, "packages"));
GFileUtils.deleteQuietly(new File(reportDir, "classes"));
}
@Override
public BuildOperationDescriptor.Builder description() {
return BuildOperationDescriptor.displayName("Delete old HTML results");
}
});
htmlRenderer.render(model, new ReportRenderer<AllTestResults, HtmlReportBuilder>() {
@Override
public void render(final AllTestResults model, final HtmlReportBuilder output) throws IOException {
buildOperationExecutor.runAll(new Action<BuildOperationQueue<HtmlReportFileGenerator<? extends CompositeTestResults>>>() {
@Override
public void execute(BuildOperationQueue<HtmlReportFileGenerator<? extends CompositeTestResults>> queue) {
queue.add(generator("index.html", model, new OverviewPageRenderer(), output));
for (PackageTestResults packageResults : model.getPackages()) {
queue.add(generator(packageResults.getBaseUrl(), packageResults, new PackagePageRenderer(), output));
for (ClassTestResults classResults : packageResults.getClasses()) {
queue.add(generator(classResults.getBaseUrl(), classResults, new ClassPageRenderer(resultsProvider), output));
}
}
}
});
}
}, reportDir);
} catch (Exception e) {
throw new GradleException(String.format("Could not generate test report to '%s'.", reportDir), e);
}
}
Aggregations