InAndOutDirectoryOperationRequest

Added in 4.2.0

interface InAndOutDirectoryOperationRequest<TaskT : Task>


Operations performed by a Task with a single Directory output.

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

Summary

Public functions

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

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

ArtifactTransformationRequest<TaskT>
<ArtifactTypeT : Artifact.Single<Directory> & Artifact.ContainsMany & Artifact.Transformable> toTransformMany(
    type: ArtifactTypeT
)

Initiates a transform request to a single Artifact.Transformable artifact type that can contain more than one artifact.

Public functions

toTransform

Added in 7.0.0
fun <ArtifactTypeT : Artifact.Single<Directory> & 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.DIRECTORY

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

Let's take a Task transforming an input org.gradle.api.file.Directory into an output:

    abstract class MyTask: DefaultTask() {
@get:InputFiles abstract val inputDir: DirectoryProperty
@get:OutputDirectory abstract val outputDir: DirectoryProperty

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

An ArtifactType defined as follows:

    sealed class ArtifactType<T: FileSystemLocation>(val kind: ArtifactKind) {
object SINGLE_DIR_ARTIFACT:
ArtifactType<Directory>(DIRECTORY), 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)
.wiredWithDirectories(
MyTask::inputDir,
MyTask::outputDir)
.toTransform(ArtifactType.SINGLE_DIR_ARTIFACT)

toTransformMany

Added in 8.4.0
fun <ArtifactTypeT : Artifact.Single<Directory> & Artifact.ContainsMany & Artifact.Transformable> toTransformMany(
    type: ArtifactTypeT
): ArtifactTransformationRequest<TaskT>

Initiates a transform request to a single Artifact.Transformable artifact type that can contain more than one artifact.

Parameters
type: ArtifactTypeT

The Artifact of the Directory identifying the artifact to transform.

Returns
ArtifactTransformationRequest<TaskT>

ArtifactTransformationRequest that will allow processing of individual artifacts located in the input directory.

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

For example, let's take a Task to transform a list of org.gradle.api.file.RegularFile as inputs into a single output:

    abstract class MyTask: DefaultTask() {
@get:InputFiles abstract val inputFolder: DirectoryProperty
@get:OutputFile abstract val outputFolder: DirectoryProperty
@Internal abstract Property<ArtifactTransformationRequest<MyTask>> getTransformationRequest()

@TaskAction fun taskAction() {
transformationRequest.get().submit(
... submit a work item for each input file ...
)
}
}

You then register the task as follows:

    val taskProvider= projects.tasks.register(MyTask::class.java, "combineTask")
val transformationRequest = artifacts.use(taskProvider)
.wiredWithDirectories(
MyTask::inputFolder,
MyTask::outputFolder)
.toTransformMany(SingleArtifact.APK)
taskProvider.configure { task ->
task.getTransformationRequest().set(transformationRequest)
}