From 512f7b323171491d662ec58d3bc54f6230f327e0 Mon Sep 17 00:00:00 2001 From: "nataliya.valtman" Date: Mon, 10 Oct 2022 18:31:13 +0200 Subject: [PATCH] Add property validation for single file report #KT-54335 Fixed #KT-54356 Fixed --- .../jetbrains/kotlin/gradle/BuildReportsIT.kt | 32 ++++++++++++++++--- .../gradle/plugin/PropertiesProvider.kt | 8 ++--- .../kotlin/gradle/report/configureReporing.kt | 15 +++++---- 3 files changed, 41 insertions(+), 14 deletions(-) diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/BuildReportsIT.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/BuildReportsIT.kt index ad2b903e99a..7efc7e10f82 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/BuildReportsIT.kt +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/BuildReportsIT.kt @@ -12,10 +12,7 @@ import org.jetbrains.kotlin.gradle.report.BuildReportType import org.jetbrains.kotlin.gradle.testbase.* import org.junit.jupiter.api.DisplayName import java.io.ObjectInputStream -import kotlin.io.path.exists -import kotlin.io.path.listDirectoryEntries -import kotlin.io.path.name -import kotlin.io.path.notExists +import kotlin.io.path.* import kotlin.test.assertEquals import kotlin.test.assertNotNull import kotlin.test.assertTrue @@ -97,6 +94,33 @@ class BuildReportsIT : KGPBaseTest() { } } + @DisplayName("validation") + @GradleTest + fun testSingleBuildMetricsFileValidation(gradleVersion: GradleVersion) { + project("simpleProject", gradleVersion) { + buildAndFail( + "compileKotlin", "-Pkotlin.build.report.output=SINGLE_FILE", + ) { + assertOutputContains("Can't configure single file report: 'kotlin.build.report.single_file' property is mandatory") + } + } + } + + @DisplayName("deprecated property") + @GradleTest + fun testDeprecatedAndNewSingleBuildMetricsFile(gradleVersion: GradleVersion) { + project("simpleProject", gradleVersion) { + val newMetricsPath = projectPath.resolve("metrics.bin") + val deprecatedMetricsPath = projectPath.resolve("deprecated_metrics.bin") + build( + "compileKotlin", "-Pkotlin.build.report.single_file=${newMetricsPath.pathString}", + "-Pkotlin.internal.single.build.metrics.file=${deprecatedMetricsPath.pathString}" + ) + assertTrue { deprecatedMetricsPath.exists() } + assertTrue { newMetricsPath.notExists() } + } + } + @DisplayName("smoke") @GradleTest fun testSingleBuildMetricsFileSmoke(gradleVersion: GradleVersion) { 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 bc592c06a93..44280f3337e 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 @@ -59,7 +59,7 @@ internal class PropertiesProvider private constructor(private val project: Proje get() = this.property("kotlin.internal.single.build.metrics.file")?.let { File(it) } val buildReportSingleFile: File? - get() = this.property("kotlin.build.report.single_file")?.let { File(it) } + get() = this.property(PropertyNames.KOTLIN_BUILD_REPORT_SINGLE_FILE)?.let { File(it) } @Deprecated(message = "Please use kotlin.build.report.output instead ") val buildReportEnabled: Boolean @@ -86,10 +86,8 @@ internal class PropertiesProvider private constructor(private val project: Proje val buildReportFileOutputDir: File? get() = this.property("kotlin.build.report.file.output_dir")?.let { File(it) } - val buildReportHttpUrlProperty = "kotlin.build.report.http.url" - val buildReportHttpUrl: String? - get() = this.property(buildReportHttpUrlProperty) + get() = this.property(PropertyNames.KOTLIN_BUILD_REPORT_HTTP_URL) val buildReportHttpUser: String? get() = this.property("kotlin.build.report.http.user") @@ -515,6 +513,8 @@ internal class PropertiesProvider private constructor(private val project: Proje const val KOTLIN_MPP_ENABLE_PLATFORM_INTEGER_COMMONIZATION = "kotlin.mpp.enablePlatformIntegerCommonization" const val KOTLIN_ABI_SNAPSHOT = "kotlin.incremental.classpath.snapshot.enabled" const val KOTLIN_JS_KARMA_BROWSERS = "kotlin.js.browser.karma.browsers" + const val KOTLIN_BUILD_REPORT_SINGLE_FILE = "kotlin.build.report.single_file" + const val KOTLIN_BUILD_REPORT_HTTP_URL = "kotlin.build.report.http.url" } companion object { diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/report/configureReporing.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/report/configureReporing.kt index 271c449f855..aa132b2f851 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/report/configureReporing.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/report/configureReporing.kt @@ -7,6 +7,8 @@ package org.jetbrains.kotlin.gradle.report import org.gradle.api.Project import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider +import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_BUILD_REPORT_SINGLE_FILE +import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_BUILD_REPORT_HTTP_URL internal fun reportingSettings(rootProject: Project): ReportingSettings { val properties = PropertiesProvider(rootProject) @@ -29,7 +31,7 @@ internal fun reportingSettings(rootProject: Project): ReportingSettings { val httpReportSettings = if (buildReportOutputTypes.contains(BuildReportType.HTTP)) { val url = properties.buildReportHttpUrl - ?: throw IllegalStateException("Can't configure http report: '${properties.buildReportHttpUrlProperty}' property is mandatory") + ?: throw IllegalStateException("Can't configure http report: '$KOTLIN_BUILD_REPORT_HTTP_URL' property is mandatory") val password = properties.buildReportHttpPassword val user = properties.buildReportHttpUser HttpReportSettings(url, password, user, properties.buildReportHttpVerboseEnvironment) @@ -43,13 +45,14 @@ internal fun reportingSettings(rootProject: Project): ReportingSettings { null } + val singleOutputFile = if (buildReportOutputTypes.contains(BuildReportType.SINGLE_FILE)) { + properties.buildReportSingleFile + ?: throw IllegalStateException("Can't configure single file report: '$KOTLIN_BUILD_REPORT_SINGLE_FILE' property is mandatory") + } else null + //temporary solution. support old property val oldSingleBuildMetric = properties.singleBuildMetricsFile?.also { buildReportOutputTypes.add(BuildReportType.SINGLE_FILE) } - val singleOutputFile = if (buildReportOutputTypes.contains(BuildReportType.SINGLE_FILE)) { - properties.buildReportSingleFile ?: oldSingleBuildMetric - } else null - return ReportingSettings( buildReportMode = buildReportMode, buildReportLabel = properties.buildReportLabel, @@ -57,7 +60,7 @@ internal fun reportingSettings(rootProject: Project): ReportingSettings { httpReportSettings = httpReportSettings, buildScanReportSettings = buildScanSettings, buildReportOutputs = buildReportOutputTypes, - singleOutputFile = singleOutputFile, + singleOutputFile = singleOutputFile ?: oldSingleBuildMetric, ) }