Search in sources :

Example 1 with TaskProperties

use of org.gradle.api.internal.tasks.properties.TaskProperties in project gradle by gradle.

the class CleanupStaleOutputsExecuter method cleanupStaleOutputs.

private void cleanupStaleOutputs(TaskExecutionContext context) {
    Set<File> filesToDelete = new HashSet<>();
    TaskProperties properties = context.getTaskProperties();
    for (FilePropertySpec outputFileSpec : properties.getOutputFileProperties()) {
        FileCollection files = outputFileSpec.getPropertyFiles();
        for (File file : files) {
            if (cleanupRegistry.isOutputOwnedByBuild(file) && !outputFilesRepository.isGeneratedByGradle(file) && file.exists()) {
                filesToDelete.add(file);
            }
        }
    }
    if (!filesToDelete.isEmpty()) {
        outputChangeListener.beforeOutputChange(filesToDelete.stream().map(File::getAbsolutePath).collect(Collectors.toList()));
        buildOperationExecutor.run(new RunnableBuildOperation() {

            @Override
            public void run(BuildOperationContext context) throws IOException {
                for (File file : filesToDelete) {
                    if (file.exists()) {
                        logger.info("Deleting stale output file: {}", file.getAbsolutePath());
                        deleter.deleteRecursively(file);
                    }
                }
            }

            @Override
            public BuildOperationDescriptor.Builder description() {
                return BuildOperationDescriptor.displayName(CLEAN_STALE_OUTPUTS_DISPLAY_NAME).progressDisplayName("Cleaning stale outputs");
            }
        });
    }
}
Also used : BuildOperationContext(org.gradle.internal.operations.BuildOperationContext) TaskProperties(org.gradle.api.internal.tasks.properties.TaskProperties) FilePropertySpec(org.gradle.api.internal.tasks.properties.FilePropertySpec) IOException(java.io.IOException) FileCollection(org.gradle.api.file.FileCollection) File(java.io.File) RunnableBuildOperation(org.gradle.internal.operations.RunnableBuildOperation) HashSet(java.util.HashSet)

Example 2 with TaskProperties

use of org.gradle.api.internal.tasks.properties.TaskProperties in project gradle by gradle.

the class TaskExecution method visitRegularInputs.

@Override
public void visitRegularInputs(InputFingerprinter.InputVisitor visitor) {
    TaskProperties taskProperties = context.getTaskProperties();
    ImmutableSortedSet<InputPropertySpec> inputProperties = taskProperties.getInputProperties();
    ImmutableSortedSet<InputFilePropertySpec> inputFileProperties = taskProperties.getInputFileProperties();
    for (InputPropertySpec inputProperty : inputProperties) {
        visitor.visitInputProperty(inputProperty.getPropertyName(), () -> InputParameterUtils.prepareInputParameterValue(inputProperty, task));
    }
    for (InputFilePropertySpec inputFileProperty : inputFileProperties) {
        Object value = inputFileProperty.getValue();
        // SkipWhenEmpty implies incremental.
        // If this file property is empty, then we clean up the previously generated outputs.
        // That means that there is a very close relation between the file property and the output.
        InputFingerprinter.InputPropertyType type = inputFileProperty.isSkipWhenEmpty() ? InputFingerprinter.InputPropertyType.PRIMARY : inputFileProperty.isIncremental() ? InputFingerprinter.InputPropertyType.INCREMENTAL : InputFingerprinter.InputPropertyType.NON_INCREMENTAL;
        String propertyName = inputFileProperty.getPropertyName();
        visitor.visitInputFileProperty(propertyName, type, new InputFingerprinter.FileValueSupplier(value, inputFileProperty.getNormalizer(), inputFileProperty.getDirectorySensitivity(), inputFileProperty.getLineEndingNormalization(), inputFileProperty::getPropertyFiles));
    }
}
Also used : InputPropertySpec(org.gradle.api.internal.tasks.properties.InputPropertySpec) InputFingerprinter(org.gradle.internal.execution.fingerprint.InputFingerprinter) TaskProperties(org.gradle.api.internal.tasks.properties.TaskProperties) InputFilePropertySpec(org.gradle.api.internal.tasks.properties.InputFilePropertySpec)

Aggregations

TaskProperties (org.gradle.api.internal.tasks.properties.TaskProperties)2 File (java.io.File)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 FileCollection (org.gradle.api.file.FileCollection)1 FilePropertySpec (org.gradle.api.internal.tasks.properties.FilePropertySpec)1 InputFilePropertySpec (org.gradle.api.internal.tasks.properties.InputFilePropertySpec)1 InputPropertySpec (org.gradle.api.internal.tasks.properties.InputPropertySpec)1 InputFingerprinter (org.gradle.internal.execution.fingerprint.InputFingerprinter)1 BuildOperationContext (org.gradle.internal.operations.BuildOperationContext)1 RunnableBuildOperation (org.gradle.internal.operations.RunnableBuildOperation)1