Skip to content

Commit 4de9676

Browse files
committed
Make includeExtensions an extension function
1 parent 4573e68 commit 4de9676

File tree

1 file changed

+12
-29
lines changed

1 file changed

+12
-29
lines changed

src/main/kotlin/myaa/subkt/tasks/muxtask.kt

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ interface Filterable {
4141
val id: Long
4242
}
4343

44+
/**
45+
* Filter files by file extension. Case-insensitive.
46+
*/
47+
fun PatternFilterable.includeExtensions(vararg extensions: String) {
48+
include { it.file.extension.toLowerCase() in extensions }
49+
}
50+
4451
/**
4552
* Task to mux a set of files into a single Matroska container using mkvmerge.
4653
*
@@ -502,37 +509,13 @@ open class Mux : PropertyTask() {
502509
val sync = getSync(delay, stretch)
503510
}
504511

505-
/**
506-
* Represents a set of files to attach, added using [attach].
507-
*/
508-
inner class ConfigurableAttachment(
509-
/**
510-
* The backing [ConfigurableFileTree] instance, for more fine-grained
511-
* control of the attached files.
512-
*/
513-
val fileTree: ConfigurableFileTree
514-
)
515-
: PatternFilterable by fileTree, Iterable<File> by fileTree {
516-
/**
517-
* Filter files by file extension. Case-insensitive.
518-
*/
519-
fun includeExtensions(vararg extensions: String) {
520-
fileTree.include { it.file.extension.toLowerCase() in extensions }
521-
}
522-
523-
/**
524-
* Specifies base directory for this file tree using the given path.
525-
*/
526-
fun from(dir: Any) = fileTree.from(dir)
527-
}
528-
529-
private val _attachments = project.objects.listProperty<ConfigurableAttachment>()
512+
private val _attachments = project.objects.listProperty<FileCollection>()
530513

531514
/**
532515
* The files to attach, added via [attach].
533516
*/
534517
@get:InputFiles
535-
val attachmentsProperty: Provider<List<ConfigurableAttachment>> = _attachments
518+
val attachmentsProperty: Provider<List<FileCollection>> = _attachments
536519

537520
private val _files = project.objects.listProperty<MuxFile>().apply { finalizeValueOnRead() }
538521

@@ -754,12 +737,12 @@ open class Mux : PropertyTask() {
754737
* @param action A closure operating on a [ConfigurableAttachment] instance,
755738
* allowing you to filter what files to include.
756739
*/
757-
fun attach(vararg dirs: Any, action: ConfigurableAttachment.() -> Unit = {}):
758-
Provider<List<ConfigurableAttachment>> {
740+
fun attach(vararg dirs: Any, action: ConfigurableFileTree.() -> Unit = {}):
741+
Provider<List<ConfigurableFileTree>> {
759742
_inputFiles.from(dirs)
760743
return project.providers.provider {
761744
project.files(dirs).map { dir ->
762-
ConfigurableAttachment(project.fileTree(dir)).apply(action)
745+
project.fileTree(dir).apply(action)
763746
}
764747
}.also { _attachments.addAll(it) }
765748
}

0 commit comments

Comments
 (0)