Import new Gradle coroutines DSL setting into Kotlin facet
This commit is contained in:
@@ -82,7 +82,7 @@ enum class CoroutineSupport(
|
||||
}
|
||||
|
||||
fun byCompilerArgument(argument: String): CoroutineSupport {
|
||||
return CoroutineSupport.values().find { it.compilerArgument == argument } ?: DEFAULT
|
||||
return CoroutineSupport.values().find { it.compilerArgument.equals(argument, ignoreCase = true) } ?: DEFAULT
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,11 +26,13 @@ import java.lang.Exception
|
||||
interface KotlinGradleModel : Serializable {
|
||||
val implements: String?
|
||||
val serializedCompilerArguments: List<String>?
|
||||
val coroutines: String?
|
||||
}
|
||||
|
||||
class KotlinGradleModelImpl(
|
||||
override val implements: String?,
|
||||
override val serializedCompilerArguments: List<String>?
|
||||
override val serializedCompilerArguments: List<String>?,
|
||||
override val coroutines: String?
|
||||
) : KotlinGradleModel
|
||||
|
||||
class KotlinGradleModelBuilder : ModelBuilderService {
|
||||
@@ -65,6 +67,23 @@ class KotlinGradleModelBuilder : ModelBuilderService {
|
||||
}
|
||||
}
|
||||
|
||||
private fun getCoroutines(project: Project): String? {
|
||||
val kotlinExtension = project.extensions.findByName("kotlin") ?: return null
|
||||
val experimentalExtension = try {
|
||||
kotlinExtension.javaClass.getMethod("getExperimental").invoke(kotlinExtension)
|
||||
}
|
||||
catch(e: NoSuchMethodException) {
|
||||
return null
|
||||
}
|
||||
|
||||
return try {
|
||||
experimentalExtension.javaClass.getMethod("getCoroutines").invoke(experimentalExtension)?.toString()
|
||||
}
|
||||
catch(e: NoSuchMethodException) {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
override fun buildAll(modelName: String?, project: Project) =
|
||||
KotlinGradleModelImpl(getImplements(project), getCompilerArguments(project))
|
||||
KotlinGradleModelImpl(getImplements(project), getCompilerArguments(project), getCoroutines(project))
|
||||
}
|
||||
|
||||
+2
@@ -34,6 +34,7 @@ import org.jetbrains.plugins.gradle.service.project.AbstractProjectResolverExten
|
||||
import org.jetbrains.plugins.gradle.service.project.GradleProjectResolverUtil.getModuleId
|
||||
|
||||
var DataNode<ModuleData>.serializedCompilerArguments by UserDataProperty(Key.create<List<String>>("SERIALIZED_COMPILER_ARGUMENTS"))
|
||||
var DataNode<ModuleData>.coroutines by UserDataProperty(Key.create<String>("KOTLIN_COROUTINES"))
|
||||
|
||||
class KotlinGradleProjectResolverExtension : AbstractProjectResolverExtension() {
|
||||
override fun getToolingExtensionsClasses(): Set<Class<out Any>> {
|
||||
@@ -60,6 +61,7 @@ class KotlinGradleProjectResolverExtension : AbstractProjectResolverExtension()
|
||||
}
|
||||
|
||||
ideModule.serializedCompilerArguments = gradleModel.serializedCompilerArguments
|
||||
ideModule.coroutines = gradleModel.coroutines
|
||||
|
||||
super.populateModuleDependencies(gradleModule, ideModule, ideProject)
|
||||
}
|
||||
|
||||
+5
-5
@@ -115,7 +115,8 @@ private fun configureFacetByGradleModule(
|
||||
?: return null
|
||||
val platformKind = detectPlatformByPlugin(moduleNode) ?: detectPlatformByLibrary(moduleNode)
|
||||
|
||||
val coroutinesProperty = findKotlinCoroutinesProperty(ideModule.project)
|
||||
val coroutinesProperty = CoroutineSupport.byCompilerArgument(
|
||||
moduleNode.coroutines ?: findKotlinCoroutinesProperty(ideModule.project))
|
||||
|
||||
val kotlinFacet = ideModule.getOrCreateFacet(modelsProvider, false)
|
||||
kotlinFacet.configureFacet(compilerVersion, coroutinesProperty, platformKind, modelsProvider)
|
||||
@@ -127,14 +128,13 @@ private fun configureFacetByGradleModule(
|
||||
|
||||
private val gradlePropertyFiles = listOf("local.properties", "gradle.properties")
|
||||
|
||||
private fun findKotlinCoroutinesProperty(project: Project): CoroutineSupport {
|
||||
private fun findKotlinCoroutinesProperty(project: Project): String {
|
||||
for (propertyFileName in gradlePropertyFiles) {
|
||||
val propertyFile = project.baseDir.findChild(propertyFileName) ?: continue
|
||||
val properties = Properties()
|
||||
properties.load(propertyFile.inputStream)
|
||||
val coroutinesProperty = properties.getProperty("kotlin.coroutines") ?: continue
|
||||
return CoroutineSupport.byCompilerArgument(coroutinesProperty)
|
||||
properties.getProperty("kotlin.coroutines")?.let { return it }
|
||||
}
|
||||
|
||||
return CoroutineSupport.DEFAULT
|
||||
return CoroutineSupport.DEFAULT.compilerArgument
|
||||
}
|
||||
Reference in New Issue
Block a user