From 3b9aac067a3aae6af34f4fdbf9f8e22f76f42d6e Mon Sep 17 00:00:00 2001 From: Pavel Kirpichenkov Date: Wed, 18 Jan 2023 12:29:58 +0200 Subject: [PATCH] Mark API for direct access to declared project properties with opt-in KT-55891 --- .../jetbrains/kotlin/gradle/plugin/PropertiesProvider.kt | 6 ++++++ .../gradle/plugin/mpp/internal/deprecationDiagnostics.kt | 2 ++ 2 files changed, 8 insertions(+) diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/PropertiesProvider.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/PropertiesProvider.kt index e51ef7df74b..bb9cdc19c81 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/PropertiesProvider.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/PropertiesProvider.kt @@ -45,12 +45,14 @@ import org.jetbrains.kotlin.gradle.utils.SingleWarningPerBuild import org.jetbrains.kotlin.konan.target.KonanTarget import org.jetbrains.kotlin.konan.target.presetName import org.jetbrains.kotlin.statistics.metrics.StringMetrics +import org.jetbrains.kotlin.tooling.core.UnsafeApi import org.jetbrains.kotlin.util.capitalizeDecapitalize.toLowerCaseAsciiOnly import org.jetbrains.kotlin.util.capitalizeDecapitalize.toUpperCaseAsciiOnly import org.jetbrains.kotlin.util.prefixIfNot import java.io.File import java.util.* +@OptIn(UnsafeApi::class) internal class PropertiesProvider private constructor(private val project: Project) { private val localProperties: Properties by lazy { Properties().apply { @@ -526,7 +528,11 @@ internal class PropertiesProvider private constructor(private val project: Proje * Looks up the property in the following sources with decreasing priority: * 1. Project properties (-P, gradle.properties, etc...) * 2. `local.properties` + * + * Please prefer using dedicated properties for proper defaults handling. + * Use this API only if you specifically need declared project properties disregarding defaults. */ + @UnsafeApi internal fun property(propName: String): String? = if (project.hasProperty(propName)) { project.property(propName) as? String diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/internal/deprecationDiagnostics.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/internal/deprecationDiagnostics.kt index 2bb274b7472..c4a91c8d147 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/internal/deprecationDiagnostics.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/internal/deprecationDiagnostics.kt @@ -19,6 +19,7 @@ import org.jetbrains.kotlin.gradle.utils.SingleWarningPerBuild import org.jetbrains.kotlin.gradle.utils.hasSyncErrors import org.jetbrains.kotlin.gradle.utils.runProjectConfigurationHealthCheckWhenEvaluated import org.jetbrains.kotlin.konan.target.KonanTarget +import org.jetbrains.kotlin.tooling.core.UnsafeApi internal fun checkAndReportDeprecatedNativeTargets(project: Project) { project.runProjectConfigurationHealthCheckWhenEvaluated { @@ -41,6 +42,7 @@ internal fun checkAndReportDeprecatedMppProperties(project: Project) { if (projectProperties.ignoreHmppDeprecationWarnings == true) return val warnings = deprecatedMppProperties.mapNotNull { propertyName -> + @OptIn(UnsafeApi::class) projectProperties.property(propertyName)?.let { getMppDeprecationWarningMessageForProperty(propertyName) } }