InAndOutDirectoryOperationRequest

interface InAndOutDirectoryOperationRequest<TaskT : Task?>


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?> toTransformMany(
    type: ArtifactTypeT?
)

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

Public functions

toTransform

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::inputFile,
MyTask::outputFile)
.toTransform(ArtifactType.SINGLE_DIR_ARTIFACT)

toTransformMany

fun <ArtifactTypeT : Artifact.Single<Directory?>? & Artifact.ContainsMany?> 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)
.wiredWith(
MyTask::inputFolder,
MyTask::outputFolder)
.toTransformMany(ArtifactType.APK)
taskProvider.configure { task ->
task.getTransformationRequest().set(transformationRequest)
}