[Gradle][KT-53342] M/A SSLv2: Only change Manifest location when it was not previously changed

This commit is contained in:
sebastian.sellmair
2022-08-05 09:45:51 +02:00
committed by Space
parent 60c90d6065
commit f1a54dfeba
2 changed files with 32 additions and 3 deletions
@@ -6,14 +6,28 @@
package org.jetbrains.kotlin.gradle.plugin.sources.android.configurator
import com.android.build.gradle.api.AndroidSourceSet
import org.gradle.api.logging.Logging
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinAndroidTarget
internal object MultiplatformLayoutV2DefaultManifestLocationConfigurator : KotlinAndroidSourceSetConfigurator {
private const val DEFAULT_FILE_NAME = "AndroidManifest.xml"
private val logger = Logging.getLogger(javaClass)
override fun configure(target: KotlinAndroidTarget, kotlinSourceSet: KotlinSourceSet, androidSourceSet: AndroidSourceSet) {
/* Default can only be set when the entity is created 'fresh'. Changes here in afterEvaluate might overwrite user setup */
if (!target.project.state.executed) {
androidSourceSet.manifest.srcFile("src/${kotlinSourceSet.name}/AndroidManifest.xml")
val defaultManifestLocation = target.project.file("src/${androidSourceSet.name}/$DEFAULT_FILE_NAME")
if (androidSourceSet.manifest.srcFile != defaultManifestLocation) {
logger.debug(
"""
${androidSourceSet.name}: Default Manifest location was already changed
Expected: $defaultManifestLocation, Found: ${androidSourceSet.manifest.srcFile}
""".trimIndent()
)
return
}
val newManifestLocation = target.project.file("src/${kotlinSourceSet.name}/$DEFAULT_FILE_NAME")
androidSourceSet.manifest.srcFile(newManifestLocation)
logger.debug("${androidSourceSet.name}: Changed default Manifest location to $newManifestLocation")
}
}
@@ -244,6 +244,21 @@ class MultiplatformAndroidSourceSetLayoutV2Test {
assertEquals(project.file("custom.xml"), android.sourceSets.main.manifest.srcFile)
}
@Test
fun `test - main - default Manifest location - already changed by user - does not get overwritten`() {
/* First: Change manifest location to something non-default */
val customManifestFile = project.file("src/main/CustomAndroidManifest.xml")
android.sourceSets.main.manifest.srcFile(customManifestFile)
/* Then: Setup Kotlin/Android target */
kotlin.android()
assertEquals(
customManifestFile, android.sourceSets.main.manifest.srcFile,
"Expected location of Manifest file to retain user configuration."
)
}
@Test
fun `test - defaultKotlinSourceSetName - is determined for all compilations`() {
kotlin.android()