Pin AGP 'debug.keystore' in the repo.

This change adds shared 'debug.keystore' into the repository and
sets all the tests to use it.

Fixes issue when keystore was created by AGP 7+, but then consumed in
the test using lower versions of AGP.

^KT-45745 In Progress
This commit is contained in:
Yahor Berdnikau
2021-12-01 22:28:04 +01:00
committed by Space
parent 782b4f64be
commit 59ec10eb9c
26 changed files with 349 additions and 10 deletions
@@ -0,0 +1,4 @@
## Description
Contains a plugin for Gradle integration tests applying different fixes
for test that are using Android Gradle plugin.
@@ -0,0 +1,56 @@
import plugins.KotlinBuildPublishingPlugin
plugins {
id("java-gradle-plugin")
id("gradle-plugin-common-configuration")
id("com.gradle.plugin-publish")
}
repositories {
google()
}
dependencies {
compileOnly(gradleKotlinDsl())
compileOnly("com.android.tools.build:gradle:3.4.0")
compileOnly("com.android.tools.build:gradle-api:3.4.0")
compileOnly("com.android.tools.build:builder:3.4.0")
compileOnly("com.android.tools.build:builder-model:3.4.0")
}
configure<GradlePluginDevelopmentExtension> {
isAutomatedPublishing = false
}
gradlePlugin {
(plugins) {
create("android-test-fixes") {
id = "org.jetbrains.kotlin.test.fixes.android"
implementationClass = "org.jetbrains.kotlin.gradle.test.fixes.android.AndroidTestFixesPlugin"
}
}
}
pluginBundle {
(plugins) {
named("android-test-fixes") {
id = "org.jetbrains.kotlin.test.fixes.android"
displayName = "AndroidTestFixes"
}
}
}
publishPluginMarkers()
// Disable releasing for this plugin
// It is not intended to be released publicly
tasks.withType<PublishToMavenRepository>()
.configureEach {
if (name.endsWith("PublicationTo${KotlinBuildPublishingPlugin.REPOSITORY_NAME}Repository")) {
enabled = false
}
}
tasks.named("publishPlugins") {
enabled = false
}
@@ -0,0 +1,17 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.gradle.test.fixes.android
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.jetbrains.kotlin.gradle.test.fixes.android.fixes.applyDebugKeystoreFix
class AndroidTestFixesPlugin : Plugin<Project> {
override fun apply(target: Project) {
val testFixesProperties = TestFixesProperties(target)
target.applyDebugKeystoreFix(testFixesProperties)
}
}
@@ -0,0 +1,22 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.gradle.test.fixes.android
import org.gradle.api.Project
internal class TestFixesProperties(
private val project: Project
) {
val androidDebugKeystoreLocation: String
get() = project.findProperty(ANDROID_DEBUG_KEYSTORE_LOCATION) as String? ?: throw IllegalArgumentException(
"$ANDROID_DEBUG_KEYSTORE_LOCATION property was not found in 'gradle.properties'."
)
companion object {
private const val PROP_PREFIX = "test.fixes."
private const val ANDROID_DEBUG_KEYSTORE_LOCATION = "${PROP_PREFIX}android.debugKeystore"
}
}
@@ -0,0 +1,40 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.gradle.test.fixes.android.fixes
import com.android.build.gradle.AppExtension
import com.android.build.gradle.BaseExtension
import com.android.build.gradle.TestExtension
import org.gradle.api.Action
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
import org.jetbrains.kotlin.gradle.test.fixes.android.TestFixesProperties
/**
* AGP 7+ creates a keystore that is not compatible with lover versions of AGP,
* but could consume keystores created by them.
*
* With this fix 'debug.keystore' could be checked in into the repo and shared
* between test executions.
*/
internal fun Project.applyDebugKeystoreFix(
testFixesProperties: TestFixesProperties
) {
plugins.withId("com.android.application", fix<AppExtension>(testFixesProperties))
plugins.withId("com.android.test", fix<TestExtension>(testFixesProperties))
}
private inline fun <reified AndroidExtension : BaseExtension> Project.fix(
testFixesProperties: TestFixesProperties
): Action<Plugin<*>> = Action {
extensions.configure<AndroidExtension> {
logger.info("Reconfiguring Android debug keystore")
buildTypes.named("debug") {
it.signingConfig?.storeFile = file(testFixesProperties.androidDebugKeystoreLocation)
}
}
}