InAndOutFileOperationRequest

interface InAndOutFileOperationRequest


Operations performed by a Task with a single RegularFile or Directory output.

Task is consuming existing version of the target SingleArtifact and producing a new version.

Summary

Public functions

Unit
<ArtifactTypeT : Artifact.Single<RegularFile> & Artifact.Transformable> toTransform(
    type: ArtifactTypeT
)

Initiates a transform request to a single Artifact.Transformable artifact type.

Public functions

toTransform

fun <ArtifactTypeT : Artifact.Single<RegularFile> & Artifact.Transformable> toTransform(
    type: ArtifactTypeT
): Unit

Initiates a transform request to a single Artifact.Transformable artifact type.

Parameters
type: ArtifactTypeT

The Artifact identifying the artifact to transform. The Artifact's Artifact.kind must be Artifact.FILE.

The artifact type must be Artifact.Single and Artifact.Transformable.

As an example, let's take a Task transforming an input org.gradle.api.file.RegularFile into an output:

    abstract class MyTask: DefaultTask() {
@get:InputFile abstract val inputFile: RegularFileProperty
@get:OutputFile abstract val outputFile: RegularFileProperty

@TaskAction fun taskAction() {
... read inputFile and write outputFile ...
}
}

An ArtifactType defined as follows :

    sealed class ArtifactType<T: FileSystemLocation>(val kind: ArtifactKind) {
object SINGLE_FILE_ARTIFACT:
ArtifactType<RegularFile>(FILE), Single, Transformable
}

You can register a transform to the collection of org.gradle.api.file.RegularFile.

    val taskProvider= projects.tasks.register(MyTask::class.java, "transformTask")
artifacts.use(taskProvider)
.wiredWithFiles(
MyTask::inputFile,
MyTask::outputFile)
.toTransform(ArtifactType.SINGLE_FILE_ARTIFACT)