gradle-plugin: Throw exceptions on deprecated property/task access

This commit is contained in:
Ilya Matveev
2017-09-08 11:19:38 +03:00
committed by ilmat192
parent 5e1866f262
commit d324585d5c
4 changed files with 79 additions and 14 deletions
@@ -16,6 +16,7 @@
package org.jetbrains.kotlin.gradle.plugin
import org.gradle.api.DefaultTask
import org.gradle.api.Named
import org.gradle.api.Project
import org.gradle.api.file.FileCollection
@@ -110,13 +111,37 @@ open class KonanInteropConfig(
// Child tasks ------------------------------------------------------------
// TODO: Remove dummy tasks and properties in 0.5
val generateStubsTask: KonanInteropTask
get() = throw NotImplementedError("This property is not supported now. Use interopProcessingTask instead.")
val compileStubsTask: KonanCompileTask
get() = throw NotImplementedError("This property is not supported now. Use interopProcessingTask instead.")
val compileStubsConfig: KonanCompileConfig
get() = throw NotImplementedError("This property is not supported now.")
open class DummyTask: DefaultTask() {
var replacementName: String = ""
@TaskAction
fun doAction(): Unit = throw NotImplementedError("This task is not supported now. Use $replacementName instead.")
}
// Task to process the library and generate stubs
val interopProcessingTask: KonanInteropTask = project.tasks.create(
"process${name.capitalize()}Interop",
KonanInteropTask::class.java) {
it.init(name)
it.group = BasePlugin.BUILD_GROUP
it.description = "Generates stubs for the Kotlin/Native interop '$name'"
it.description = "Generates a klib for the Kotlin/Native interop '$name'"
}
init {
val dummyGenerateStubsTask = project.tasks.create(
"gen${name.capitalize()}InteropStubs",
DummyTask::class.java) { it.replacementName = interopProcessingTask.name }
val dummyCompileStubsTask = project.tasks.create(
"compile${name.capitalize()}InteropStubs",
DummyTask::class.java) { it.replacementName = interopProcessingTask.name }
}
// DSL methods ------------------------------------------------------------
@@ -193,6 +193,14 @@ class KonanProject {
return ":compileKonan${artifactName.capitalize()}"
}
String defaultArtifactConfig() {
return artifactConfig(DEFAULT_ARTIFACT_NAME)
}
String artifactConfig(String artifactName) {
return "konanArtifacts['$artifactName']"
}
/** Creates a project with default build and source files. */
static KonanProject create(File projectDir) {
return createEmpty(projectDir) {
@@ -273,7 +281,7 @@ class KonanInteropProject extends KonanProject {
}
""".stripIndent()
)
interopTasks = [defaultStubGenerationTask()]
interopTasks = [defaultInteropProcessingTask()]
compilationTasks = [defaultCompilationTask(), ":compileKonan", ":build"]
return result
}
@@ -308,14 +316,22 @@ class KonanInteropProject extends KonanProject {
addSetting("konanInterop", interopName, parameter, value)
}
String defaultStubGenerationTask() {
return stubGenerationTask(DEFAULT_INTEROP_NAME)
String defaultInteropProcessingTask() {
return interopProcessingTask(DEFAULT_INTEROP_NAME)
}
String stubGenerationTask(String interopName) {
String interopProcessingTask(String interopName) {
return ":process${interopName.capitalize()}Interop"
}
String defaultInteropConfig() {
return interopConfig(DEFAULT_INTEROP_NAME)
}
String interopConfig(String interopName) {
return "konanInterop[$interopName]"
}
/** Creates a project with default build, source and def files. */
static KonanInteropProject create(File projectDir) {
return createEmpty(projectDir) {
@@ -1,10 +1,6 @@
package org.jetbrains.kotlin.gradle.plugin.test
import org.gradle.testkit.runner.TaskOutcome
import org.junit.Rule
import org.junit.rules.TemporaryFolder
import spock.lang.Specification
class PathSpecification extends BaseKonanSpecification {
@@ -39,7 +35,7 @@ class PathSpecification extends BaseKonanSpecification {
def result = project.createRunner().withArguments('build').buildAndFail()
then:
result.task(project.defaultStubGenerationTask()).outcome == TaskOutcome.FAILED
result.task(project.defaultInteropProcessingTask()).outcome == TaskOutcome.FAILED
}
}
@@ -1,10 +1,7 @@
package org.jetbrains.kotlin.gradle.plugin.test
import org.gradle.testkit.runner.BuildResult
import org.gradle.testkit.runner.TaskOutcome
import org.junit.Rule
import org.junit.rules.TemporaryFolder
import spock.lang.Specification
class TaskSpecification extends BaseKonanSpecification {
@@ -91,4 +88,35 @@ class TaskSpecification extends BaseKonanSpecification {
result.output.findAll(~/BACKEND:\s+\d+\s+msec/).size() == 1
result.output.findAll(~/LINK_STAGE:\s+\d+\s+msec/).size() == 1
}
BuildResult failOnPropertyAccess(String property) {
def project = KonanInteropProject.createEmpty(projectDirectory)
project.buildFile.append("""
task testTask(type: DefaultTask) {
doLast {
println(${project.defaultInteropConfig()}.$property)
}
}
""".stripIndent())
return project.createRunner().withArguments("testTask").buildAndFail()
}
BuildResult failOnTaskAccess(String task) {
def project = KonanInteropProject.createEmpty(projectDirectory)
project.buildFile.append("""
task testTask(type: DefaultTask) {
dependsOn $task
}
""".stripIndent())
return project.createRunner().withArguments("testTask").buildAndFail()
}
def 'Deprecated properties/tasks should generate exceptions'() {
expect:
failOnPropertyAccess("generateStubsTask")
failOnPropertyAccess("compileStubsTask")
failOnPropertyAccess("compileStubsConfig")
failOnTaskAccess("gen${KonanInteropProject.DEFAULT_INTEROP_NAME.capitalize()}InteropStubs")
failOnTaskAccess("compile${KonanInteropProject.DEFAULT_INTEROP_NAME.capitalize()}InteropStubs")
}
}