InAndOutDirectoryOperationRequest

public interface InAndOutDirectoryOperationRequest<TaskT extends Task>


Summary

Public methods

abstract void
<ArtifactTypeT extends Artifact.Single<@NonNull Directory> & Artifact.Transformable> toTransform(
    @NonNull ArtifactTypeT type
)

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

abstract @NonNull ArtifactTransformationRequest<@NonNull TaskT>
<ArtifactTypeT extends Artifact.Single<@NonNull Directory> & Artifact.ContainsMany> toTransformMany(
    @NonNull ArtifactTypeT type
)

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

Public methods

toTransform

abstract void <ArtifactTypeT extends Artifact.Single<@NonNull Directory> & Artifact.Transformable> toTransform(
    @NonNull ArtifactTypeT type
)

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

Parameters
@NonNull ArtifactTypeT type

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

abstract @NonNull ArtifactTransformationRequest<@NonNull TaskT> <ArtifactTypeT extends Artifact.Single<@NonNull Directory> & Artifact.ContainsMany> toTransformMany(
    @NonNull ArtifactTypeT type
)

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

Parameters
@NonNull ArtifactTypeT type

The Artifact of the Directory identifying the artifact to transform.

Returns
@NonNull ArtifactTransformationRequest<@NonNull 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)
}