Search in sources :

Example 1 with RunnableBuildOperation

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);
}
Also used : TaskOutputFilePropertySpec(org.gradle.api.internal.tasks.TaskOutputFilePropertySpec) BuildOperationContext(org.gradle.internal.operations.BuildOperationContext) FileCollection(org.gradle.api.file.FileCollection) File(java.io.File) RunnableBuildOperation(org.gradle.internal.operations.RunnableBuildOperation) HashSet(java.util.HashSet)

Example 2 with RunnableBuildOperation

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);
            }
        }
    });
}
Also used : BuildOperationContext(org.gradle.internal.operations.BuildOperationContext) BuildOperationRef(org.gradle.internal.operations.BuildOperationRef) MultiCauseException(org.gradle.internal.exceptions.MultiCauseException) DefaultMultiCauseException(org.gradle.internal.exceptions.DefaultMultiCauseException) RunnableBuildOperation(org.gradle.internal.operations.RunnableBuildOperation)

Example 3 with RunnableBuildOperation

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);
        }
    });
}
Also used : BuildOperationContext(org.gradle.internal.operations.BuildOperationContext) RunnableBuildOperation(org.gradle.internal.operations.RunnableBuildOperation) BuildOperationExecutor(org.gradle.internal.operations.BuildOperationExecutor)

Example 4 with RunnableBuildOperation

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");
        }
    });
}
Also used : BuildOperationContext(org.gradle.internal.operations.BuildOperationContext) TextResource(org.gradle.internal.resource.TextResource) TextResourceScriptSource(org.gradle.groovy.scripts.TextResourceScriptSource) File(java.io.File) RunnableBuildOperation(org.gradle.internal.operations.RunnableBuildOperation)

Example 5 with RunnableBuildOperation

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);
    }
}
Also used : BuildOperationContext(org.gradle.internal.operations.BuildOperationContext) Action(org.gradle.api.Action) BuildOperationQueue(org.gradle.internal.operations.BuildOperationQueue) HtmlReportBuilder(org.gradle.reporting.HtmlReportBuilder) IOException(java.io.IOException) IOException(java.io.IOException) GradleException(org.gradle.api.GradleException) HtmlReportBuilder(org.gradle.reporting.HtmlReportBuilder) GradleException(org.gradle.api.GradleException) RunnableBuildOperation(org.gradle.internal.operations.RunnableBuildOperation) File(java.io.File) HtmlReportRenderer(org.gradle.reporting.HtmlReportRenderer)

Aggregations

BuildOperationContext (org.gradle.internal.operations.BuildOperationContext)12 RunnableBuildOperation (org.gradle.internal.operations.RunnableBuildOperation)12 File (java.io.File)8 BuildOperationDescriptor (org.gradle.internal.operations.BuildOperationDescriptor)3 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 List (java.util.List)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Action (org.gradle.api.Action)2 FileCollection (org.gradle.api.file.FileCollection)2 ImmutableList (com.google.common.collect.ImmutableList)1 LinkedHashMultimap (com.google.common.collect.LinkedHashMultimap)1 Multimap (com.google.common.collect.Multimap)1 Queues (com.google.common.collect.Queues)1 Sets (com.google.common.collect.Sets)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 FilenameFilter (java.io.FilenameFilter)1 URI (java.net.URI)1 Collection (java.util.Collection)1