Skip to content
This repository has been archived by the owner on Aug 19, 2020. It is now read-only.

Commit

Permalink
Generate compilable accessors for tasks with types in the default pac…
Browse files Browse the repository at this point in the history
…kage

By explicitly importing task types from the default package in
the generated code.

Resolves #1158
  • Loading branch information
bamboo committed Oct 2, 2018
1 parent 2929bf0 commit 3767a97
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,47 @@ class ProjectSchemaAccessorsIntegrationTest : AbstractPluginIntegrationTest() {
)
}

@Test
fun `can access task of default package type`() {

withFolders {

"buildSrc" {

withPrecompiledPlugins()

"src/main/kotlin" {

withFile("CustomTask.kt", """
open class CustomTask : org.gradle.api.DefaultTask()
""")

withFile("plugin.gradle.kts", """
tasks.register<CustomTask>("customTask")
""")
}
}
}

withBuildScript("""
plugins { id("plugin") }
inline fun <reified T> typeOf(value: T) = typeOf<T>()
println("task: " + typeOf(tasks.customTask))
tasks.customTask { println("task{} " + typeOf(this)) }
""")

assertThat(
build("customTask", "-q").output,
containsMultiLineString("""
task: org.gradle.api.tasks.TaskProvider<CustomTask>
task{} CustomTask
""")
)
}

@Test
fun `can access extension of nested type`() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,7 @@ private
fun importsRequiredBy(schemaSubset: ProjectSchema<TypeAccessibility>): List<String> =
defaultPackageTypesIn(
schemaSubset
.extensions
.flatMap { listOf(it.target, it.type) }
.run { extensions.flatMap { listOf(it.target, it.type) } + tasks.map { it.type } }
.filterIsInstance<TypeAccessibility.Accessible>()
.map { it.type }
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ class TypeAccessibilityProviderTest : TestWithClassPath() {
assertTrue(leafs.isEmpty())
}

classNamesFromTypeString("CustomTask").apply {
assertThat(all, hasItems("CustomTask"))
assertThat(leafs, hasItems("CustomTask"))
}

classNamesFromTypeString("java.util.List<String>").apply {
assertThat(all, hasItems("java.util.List"))
assertTrue(leafs.isEmpty())
Expand Down

0 comments on commit 3767a97

Please sign in to comment.