[Build, IGS] Implement InternalGradleSetupSettingsPlugin

#KTI-1223 In Progress
This commit is contained in:
Alexander.Likhachev
2023-05-03 20:29:10 +02:00
committed by Space Team
parent f04f1d18c4
commit ea38cfebf2
@@ -7,8 +7,36 @@ package org.jetbrains.kotlin.build
import org.gradle.api.Plugin
import org.gradle.api.initialization.Settings
import org.gradle.api.plugins.ExtensionAware
import org.gradle.kotlin.dsl.extra
import java.net.URL
import kotlin.concurrent.thread
private const val DOMAIN_NAME = "kotlin-build-properties.labs.jb.gg"
private const val SETUP_JSON_URL = "https://$DOMAIN_NAME/setup.json"
abstract class InternalGradleSetupSettingsPlugin : Plugin<Settings> {
override fun apply(target: Settings) {
val isTeamCityBuild = (target as? ExtensionAware)?.extra?.has("teamcity") == true || System.getenv("TEAMCITY_VERSION") != null
if (isTeamCityBuild) return
val rootDir = target.rootDir
// invoke this logic in a separate thread to not pause the build
// the properties will be configured for the future builds
thread {
try {
val modifier = LocalPropertiesModifier(rootDir.resolve("local.properties"))
val consentManager = ConsentManager(modifier)
val initialDecision = consentManager.getUserDecision()
if (initialDecision == false) return@thread // user has opted out
val connection = URL(SETUP_JSON_URL).run { openConnection().apply { connectTimeout = 300 } }
val setupFile = connection.getInputStream().buffered().use {
parseSetupFile(it)
}
if (initialDecision == null && !consentManager.askForConsent()) return@thread
modifier.applySetup(setupFile)
} catch (_: Throwable) {
// no-op
}
}
}
}