-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
e705a36
commit 43df58a
Showing
26 changed files
with
323 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
## Description | ||
|
||
Contains a plugin for Gradle integration tests applying different fixes | ||
for test that are using Android Gradle plugin. |
52 changes: 52 additions & 0 deletions
52
libraries/tools/gradle/android-test-fixes/build.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
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 | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
.../src/main/kotlin/org/jetbrains/kotlin/gradle/test/fixes/android/AndroidTestFixesPlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...xes/src/main/kotlin/org/jetbrains/kotlin/gradle/test/fixes/android/TestFixesProperties.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
.../src/main/kotlin/org/jetbrains/kotlin/gradle/test/fixes/android/fixes/debugKeystoreFix.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* 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 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") { | ||
extensions.configure<AppExtension> { | ||
logger.info("Reconfiguring Android debug keystore") | ||
buildTypes.named("debug") { | ||
it.signingConfig?.storeFile = file(testFixesProperties.androidDebugKeystoreLocation) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
...in-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/testbase/androidFixes.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
@file:OptIn(kotlin.io.path.ExperimentalPathApi::class) | ||
/* | ||
* 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.testbase | ||
|
||
import org.jetbrains.kotlin.gradle.util.modify | ||
import java.io.File | ||
import java.nio.file.Path | ||
import java.nio.file.Paths | ||
import kotlin.io.path.exists | ||
|
||
internal fun Path.applyAndroidTestFixes() { | ||
// Path relative to the current gradle module project dir | ||
val keystoreFile = Paths.get("src/test/resources/common/debug.keystore") | ||
assert(keystoreFile.exists()) { | ||
"Common 'debug.keystore' file does not exists in ${keystoreFile.toAbsolutePath()} location!" | ||
} | ||
resolve("gradle.properties").append( | ||
""" | ||
|test.fixes.android.debugKeystore=${keystoreFile.toAbsolutePath().toString().normalizePath()} | ||
| | ||
""".trimMargin() | ||
) | ||
|
||
val pathFile = toFile() | ||
|
||
pathFile.walkTopDown() | ||
.filter { it.name == "build.gradle" || it.name == "build.gradle.kts" } | ||
.forEach { file -> | ||
when (file.name) { | ||
"build.gradle" -> file.updateBuildGradle() | ||
"build.gradle.kts" -> file.updateBuildGradleKts() | ||
} | ||
} | ||
} | ||
|
||
private fun File.updateBuildGradle() { | ||
modify { | ||
if (it.contains("plugins {")) { | ||
""" | ||
|${it.substringBefore("plugins {")} | ||
|plugins { | ||
| id "org.jetbrains.kotlin.test.fixes.android" | ||
|${it.substringAfter("plugins {")} | ||
""".trimMargin() | ||
} else if (it.contains("apply plugin:")) { | ||
it.modifyBuildScript().run { | ||
""" | ||
|${substringBefore("apply plugin:")} | ||
|apply plugin: 'org.jetbrains.kotlin.test.fixes.android' | ||
|apply plugin:${substringAfter("apply plugin:")} | ||
""".trimMargin() | ||
} | ||
} else { | ||
it.modifyBuildScript() | ||
} | ||
} | ||
} | ||
|
||
private fun String.modifyBuildScript(isKts: Boolean = false): String = | ||
if (contains("buildscript {") && | ||
contains("classpath") | ||
) { | ||
val kotlinVersionStr = if (isKts) "${'$'}{property(\"test_fixes_version\")}" else "${'$'}test_fixes_version" | ||
""" | ||
|${substringBefore("classpath")} | ||
|classpath("org.jetbrains.kotlin:android-test-fixes:$kotlinVersionStr") | ||
|classpath${substringAfter("classpath")} | ||
""".trimMargin() | ||
} else { | ||
this | ||
} | ||
|
||
|
||
private fun File.updateBuildGradleKts() { | ||
modify { | ||
if (it.contains("plugins {")) { | ||
""" | ||
|${it.substringBefore("plugins {")} | ||
|plugins { | ||
| id("org.jetbrains.kotlin.test.fixes.android") | ||
|${it.substringAfter("plugins {")} | ||
""".trimMargin() | ||
} else if (it.contains("apply(plugin")) { | ||
it.modifyBuildScript(true).run { | ||
""" | ||
|${substringBefore("apply(plugin")} | ||
|apply(plugin = "org.jetbrains.kotlin.test.fixes.android") | ||
|apply(plugin${substringAfter("apply(plugin")} | ||
""".trimMargin() | ||
} | ||
} else { | ||
it.modifyBuildScript(true) | ||
} | ||
} | ||
} | ||
|
||
private fun String.normalizePath() = replace("\\", "/") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+2.06 KB
...ies/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/common/debug.keystore
Binary file not shown.
12 changes: 12 additions & 0 deletions
12
...sources/testProject/instantExecutionWithIncludedBuildPlugin/includedBuild/settings.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
pluginManagement { | ||
repositories { | ||
mavenLocal() | ||
mavenCentral() | ||
gradlePluginPortal() | ||
} | ||
|
||
plugins { | ||
id "org.jetbrains.kotlin.jvm" version "$kotlin_version" | ||
id "org.jetbrains.kotlin.test.fixes.android" version "$test_fixes_version" | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...n-integration-tests/src/test/resources/testProject/js-composite-build/lib/settings.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
pluginManagement { | ||
repositories { | ||
mavenLocal() | ||
mavenCentral() | ||
google() | ||
gradlePluginPortal() | ||
} | ||
|
||
plugins { | ||
id "org.jetbrains.kotlin.js" version "$kotlin_version" | ||
id "org.jetbrains.kotlin.test.fixes.android" version "$test_fixes_version" | ||
} | ||
} | ||
|
||
rootProject.name = "lib2" |
7 changes: 6 additions & 1 deletion
7
...ts/src/test/resources/testProject/kotlinPluginDepsInBuildSrc/buildSrc/settings.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
pluginManagement { | ||
repositories { | ||
mavenCentral() | ||
mavenLocal() | ||
mavenCentral() | ||
} | ||
|
||
val test_fixes_version: String by settings | ||
plugins { | ||
id("org.jetbrains.kotlin.test.fixes.android") version test_fixes_version | ||
} | ||
} |
Oops, something went wrong.