Skip to content

Commit

Permalink
Preserve fileTree(mapOf(...)) behaviour for backward compatibility
Browse files Browse the repository at this point in the history
See #11335
  • Loading branch information
bamboo committed Nov 12, 2019
1 parent 4adbee6 commit 0490823
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
Expand Up @@ -4,6 +4,7 @@ import org.gradle.test.fixtures.file.LeaksFileHandles

import org.gradle.kotlin.dsl.fixtures.AbstractKotlinIntegrationTest
import org.gradle.kotlin.dsl.fixtures.containsMultiLineString
import org.gradle.kotlin.dsl.fixtures.equalToMultiLineString

import org.hamcrest.CoreMatchers.allOf
import org.hamcrest.CoreMatchers.containsString
Expand Down Expand Up @@ -212,4 +213,39 @@ class KotlinBuildScriptIntegrationTest : AbstractKotlinIntegrationTest() {
""")
)
}

@Test
fun `can create fileTree from map for backward compatibility`() {

val fileTreeFromMap = """
fileTree(mapOf("dir" to ".", "include" to listOf("*.txt")))
.map { it.name }
.joinToString()
"""

withFile("foo.txt")

val initScript = withFile("init.gradle.kts", """
println("INIT: " + $fileTreeFromMap)
""")

withSettings("""
println("SETTINGS: " + $fileTreeFromMap)
""")

withBuildScript("""
task("test") {
doLast { println("PROJECT: " + $fileTreeFromMap) }
}
""")

assertThat(
build("test", "-q", "-I", initScript.absolutePath).output.trim(),
equalToMultiLineString("""
INIT: foo.txt
SETTINGS: foo.txt
PROJECT: foo.txt
""".replaceIndent())
)
}
}
Expand Up @@ -81,7 +81,11 @@ open class DefaultKotlinScript internal constructor(
fileOperations.configurableFiles(paths).also(configuration::execute)

override fun fileTree(baseDir: Any): ConfigurableFileTree =
fileOperations.fileTree(baseDir)
@Suppress("unchecked_cast")
when (baseDir) {
is Map<*, *> -> fileOperations.fileTree(baseDir as Map<String, *>)
else -> fileOperations.fileTree(baseDir)
}

override fun fileTree(baseDir: Any, configuration: Action<ConfigurableFileTree>): ConfigurableFileTree =
fileOperations.fileTree(baseDir).also(configuration::execute)
Expand Down

0 comments on commit 0490823

Please sign in to comment.