[Gradle] Fix warnings in AndroidSubplugin.kt
^KT-56904 In Progress
This commit is contained in:
committed by
Space Team
parent
5dcc853df3
commit
969e1957d2
+25
-15
@@ -7,9 +7,6 @@
|
|||||||
package org.jetbrains.kotlin.gradle.internal
|
package org.jetbrains.kotlin.gradle.internal
|
||||||
|
|
||||||
import com.android.build.gradle.BaseExtension
|
import com.android.build.gradle.BaseExtension
|
||||||
import com.android.build.gradle.api.AndroidSourceSet
|
|
||||||
import com.android.build.gradle.api.BaseVariant
|
|
||||||
import com.android.build.gradle.api.TestVariant
|
|
||||||
import com.android.build.gradle.internal.variant.TestVariantData
|
import com.android.build.gradle.internal.variant.TestVariantData
|
||||||
import org.gradle.api.Plugin
|
import org.gradle.api.Plugin
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
@@ -21,6 +18,7 @@ import org.jetbrains.kotlin.gradle.model.builder.KotlinAndroidExtensionModelBuil
|
|||||||
import org.jetbrains.kotlin.gradle.plugin.*
|
import org.jetbrains.kotlin.gradle.plugin.*
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJvmAndroidCompilation
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJvmAndroidCompilation
|
||||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||||
|
import org.jetbrains.kotlin.gradle.utils.*
|
||||||
import org.w3c.dom.Document
|
import org.w3c.dom.Document
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.concurrent.Callable
|
import java.util.concurrent.Callable
|
||||||
@@ -82,17 +80,23 @@ class AndroidSubplugin : KotlinCompilerPluginSupportPlugin {
|
|||||||
val androidExtensionsExtension = project.extensions.getByType(AndroidExtensionsExtension::class.java)
|
val androidExtensionsExtension = project.extensions.getByType(AndroidExtensionsExtension::class.java)
|
||||||
|
|
||||||
if (androidExtensionsExtension.isExperimental) {
|
if (androidExtensionsExtension.isExperimental) {
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
return applyExperimental(
|
return applyExperimental(
|
||||||
kotlinCompilation.compileKotlinTaskProvider, androidExtension, androidExtensionsExtension,
|
kotlinCompilation.compileTaskProvider as TaskProvider<KotlinCompile>,
|
||||||
project, kotlinCompilation.androidVariant
|
androidExtension,
|
||||||
|
androidExtensionsExtension,
|
||||||
|
project,
|
||||||
|
kotlinCompilation.androidVariant
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
val sourceSets = androidExtension.sourceSets
|
val sourceSets = androidExtension.sourceSets
|
||||||
|
|
||||||
val pluginOptions = arrayListOf<SubpluginOption>()
|
val pluginOptions = arrayListOf<SubpluginOption>()
|
||||||
pluginOptions += SubpluginOption("features",
|
pluginOptions += SubpluginOption(
|
||||||
AndroidExtensionsFeature.parseFeatures(androidExtensionsExtension.features).joinToString(",") { it.featureName })
|
"features",
|
||||||
|
AndroidExtensionsFeature.parseFeatures(androidExtensionsExtension.features).joinToString(",") { it.featureName }
|
||||||
|
)
|
||||||
|
|
||||||
val mainSourceSet = sourceSets.getByName("main")
|
val mainSourceSet = sourceSets.getByName("main")
|
||||||
val manifestFile = mainSourceSet.manifest.srcFile
|
val manifestFile = mainSourceSet.manifest.srcFile
|
||||||
@@ -104,7 +108,7 @@ class AndroidSubplugin : KotlinCompilerPluginSupportPlugin {
|
|||||||
}
|
}
|
||||||
pluginOptions += SubpluginOption("package", applicationPackage)
|
pluginOptions += SubpluginOption("package", applicationPackage)
|
||||||
|
|
||||||
fun addVariant(sourceSet: AndroidSourceSet) {
|
fun addVariant(@Suppress("TYPEALIAS_EXPANSION_DEPRECATION") sourceSet: DeprecatedAndroidSourceSet) {
|
||||||
val optionValue = lazy {
|
val optionValue = lazy {
|
||||||
sourceSet.name + ';' + sourceSet.res.srcDirs.joinToString(";") { it.absolutePath }
|
sourceSet.name + ';' + sourceSet.res.srcDirs.joinToString(";") { it.absolutePath }
|
||||||
}
|
}
|
||||||
@@ -115,7 +119,8 @@ class AndroidSubplugin : KotlinCompilerPluginSupportPlugin {
|
|||||||
FilesSubpluginOption("resDirs", project.files(Callable { sourceSet.res.srcDirs }))
|
FilesSubpluginOption("resDirs", project.files(Callable { sourceSet.res.srcDirs }))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
kotlinCompilation.compileKotlinTaskProvider.configure {
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
(kotlinCompilation.compileTaskProvider as TaskProvider<KotlinCompile>).configure {
|
||||||
it.androidLayoutResourceFiles.from(
|
it.androidLayoutResourceFiles.from(
|
||||||
sourceSet.res.getSourceDirectoryTrees().layoutDirectories
|
sourceSet.res.getSourceDirectoryTrees().layoutDirectories
|
||||||
)
|
)
|
||||||
@@ -212,16 +217,21 @@ class AndroidSubplugin : KotlinCompilerPluginSupportPlugin {
|
|||||||
return project.provider { wrapPluginOptions(pluginOptions, "configuration") }
|
return project.provider { wrapPluginOptions(pluginOptions, "configuration") }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("TYPEALIAS_EXPANSION_DEPRECATION")
|
||||||
private fun getVariantComponentNames(flavorData: Any?): VariantComponentNames? = when (flavorData) {
|
private fun getVariantComponentNames(flavorData: Any?): VariantComponentNames? = when (flavorData) {
|
||||||
is TestVariantData -> getVariantComponentNames(flavorData.testedVariantData)
|
is TestVariantData -> getVariantComponentNames(flavorData.testedVariantData)
|
||||||
is TestVariant -> getVariantComponentNames(flavorData.testedVariant)
|
is DeprecatedAndroidTestVariant -> getVariantComponentNames(flavorData.testedVariant)
|
||||||
is BaseVariant -> VariantComponentNames(flavorData.name, flavorData.flavorName, flavorData.buildType.name)
|
is DeprecatedAndroidBaseVariant -> VariantComponentNames(flavorData.name, flavorData.flavorName, flavorData.buildType.name)
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
|
|
||||||
private data class VariantComponentNames(val variantName: String, val flavorName: String, val buildTypeName: String)
|
private data class VariantComponentNames(val variantName: String, val flavorName: String, val buildTypeName: String)
|
||||||
|
|
||||||
private fun getApplicationPackage(androidExtension: BaseExtension, project: Project, mainSourceSet: AndroidSourceSet): String {
|
private fun getApplicationPackage(
|
||||||
|
androidExtension: BaseExtension,
|
||||||
|
project: Project,
|
||||||
|
@Suppress("TYPEALIAS_EXPANSION_DEPRECATION") mainSourceSet: DeprecatedAndroidSourceSet
|
||||||
|
): String {
|
||||||
val manifestFile = mainSourceSet.manifest.srcFile
|
val manifestFile = mainSourceSet.manifest.srcFile
|
||||||
val applicationPackage = getApplicationPackage(androidExtension, manifestFile)
|
val applicationPackage = getApplicationPackage(androidExtension, manifestFile)
|
||||||
|
|
||||||
@@ -265,10 +275,10 @@ class AndroidSubplugin : KotlinCompilerPluginSupportPlugin {
|
|||||||
|
|
||||||
// Didn't find the namespace getter, or it was not set. Try parsing the
|
// Didn't find the namespace getter, or it was not set. Try parsing the
|
||||||
// manifest to find the "package" attribute from there.
|
// manifest to find the "package" attribute from there.
|
||||||
try {
|
return try {
|
||||||
return manifestFile.parseXml().documentElement.getAttribute("package")
|
manifestFile.parseXml().documentElement.getAttribute("package")
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
return null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user