Rename implement to expectedBy in Gradle, deprecate the old name

Issue #KT-20618 Fixed

(cherry picked from commit 6e0d378)
This commit is contained in:
Sergey Igushkin
2017-10-04 20:24:42 +03:00
parent aff689afba
commit ff687131b1
4 changed files with 49 additions and 10 deletions
@@ -20,6 +20,7 @@ import org.gradle.api.logging.LogLevel
import com.intellij.openapi.util.io.FileUtil
import org.jetbrains.kotlin.gradle.plugin.CopyClassesToJavaOutputStatus
import org.jetbrains.kotlin.gradle.tasks.USING_INCREMENTAL_COMPILATION_MESSAGE
import org.jetbrains.kotlin.gradle.plugin.IMPLEMENT_CONFIG_WARNING
import org.jetbrains.kotlin.gradle.util.*
import org.junit.Test
import java.io.File
@@ -406,6 +407,26 @@ class KotlinGradleIT: BaseGradleIT() {
}
}
@Test
fun testDeprecatedImplementWarning() {
val project = Project("multiplatformProject", GRADLE_VERSION)
val warningText = IMPLEMENT_CONFIG_WARNING
project.build("build") {
assertSuccessful()
assertNotContains(warningText)
}
project.projectDir.walk().filter { it.name == "build.gradle" }.forEach { buildGradle ->
buildGradle.modify { it.replace("expectedBy", "implement") }
}
project.build("build") {
assertSuccessful()
assertContains(warningText)
}
}
@Test
fun testFreeCompilerArgs() {
val project = Project("kotlinProject", GRADLE_VERSION)
@@ -1,5 +1,5 @@
apply plugin: 'kotlin-platform-js'
dependencies {
implement project(":lib")
expectedBy project(":lib")
}
@@ -1,6 +1,6 @@
apply plugin: 'kotlin-platform-jvm'
dependencies {
implement project(":lib")
expectedBy project(":lib")
compile 'com.google.guava:guava:20.0'
}
@@ -35,6 +35,8 @@ open class KotlinPlatformCommonPlugin : KotlinPlatformPluginBase("common") {
}
}
const val IMPLEMENT_CONFIG_WARNING = "The 'implement' configuration is deprecated and will be removed. Use 'expectedBy' instead."
open class KotlinPlatformImplementationPluginBase(platformName: String) : KotlinPlatformPluginBase(platformName) {
private val commonProjects = arrayListOf<Project>()
private val platformKotlinTasksBySourceSetName = hashMapOf<String, AbstractKotlinCompile<*>>()
@@ -47,13 +49,29 @@ open class KotlinPlatformImplementationPluginBase(platformName: String) : Kotlin
project.tasks.filterIsInstance<AbstractKotlinCompile<*>>().associateByTo(platformKotlinTasksBySourceSetName) { it.sourceSetName }
val implementConfig = project.configurations.create("implement")
implementConfig.isTransitive = false
implementConfig.dependencies.whenObjectAdded { dep ->
if (dep is ProjectDependency) {
addCommonProject(dep.dependencyProject, project)
val expectedByConfig = project.configurations.create("expectedBy").apply {
extendsFrom(implementConfig)
}
listOf(implementConfig, expectedByConfig).forEach { config ->
config.isTransitive = false
config.dependencies.whenObjectAdded { dep ->
if (dep is ProjectDependency) {
addCommonProject(dep.dependencyProject, project)
}
else {
throw GradleException("$project '${config.name}' dependency is not a project: $dep")
}
}
else {
throw GradleException("$project `implement` dependency is not a project: $dep")
}
var implementDeprecationWarningShown = false
implementConfig.dependencies.whenObjectAdded {
if (!implementDeprecationWarningShown) {
implementDeprecationWarningShown = true
project.logger.kotlinWarn(IMPLEMENT_CONFIG_WARNING)
}
}
}
@@ -61,12 +79,12 @@ open class KotlinPlatformImplementationPluginBase(platformName: String) : Kotlin
private fun addCommonProject(commonProject: Project, platformProject: Project) {
commonProjects.add(commonProject)
if (commonProjects.size > 1) {
throw GradleException("Platform project $platformProject implements more than one common project: ${commonProjects.joinToString()}")
throw GradleException("Platform project $platformProject is expected by more than one common project: ${commonProjects.joinToString()}")
}
commonProject.whenEvaluated {
if ((!commonProject.plugins.hasPlugin(KotlinPlatformCommonPlugin::class.java))) {
throw GradleException("Platform project $platformProject implements non-common project $commonProject (`apply plugin 'kotlin-platform-kotlin'`)")
throw GradleException("Platform project $platformProject is expected by non-common project $commonProject (`apply plugin 'kotlin-platform-kotlin'`)")
}
commonProject.sourceSets.all { commonSourceSet ->