diff --git a/repo/gradle-settings-conventions/internal-gradle-setup/src/main/kotlin/InternalGradleSetupSettingsPlugin.kt b/repo/gradle-settings-conventions/internal-gradle-setup/src/main/kotlin/InternalGradleSetupSettingsPlugin.kt index 67de83114ee..4d5041ea828 100644 --- a/repo/gradle-settings-conventions/internal-gradle-setup/src/main/kotlin/InternalGradleSetupSettingsPlugin.kt +++ b/repo/gradle-settings-conventions/internal-gradle-setup/src/main/kotlin/InternalGradleSetupSettingsPlugin.kt @@ -7,18 +7,26 @@ package org.jetbrains.kotlin.build import org.gradle.api.Plugin import org.gradle.api.initialization.Settings +import org.gradle.api.logging.Logging import org.gradle.api.plugins.ExtensionAware import org.gradle.kotlin.dsl.extra +import java.net.SocketTimeoutException import java.net.URL +import java.net.UnknownHostException 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 { + private val log = Logging.getLogger(javaClass) + override fun apply(target: Settings) { val isTeamCityBuild = (target as? ExtensionAware)?.extra?.has("teamcity") == true || System.getenv("TEAMCITY_VERSION") != null - if (isTeamCityBuild) return + if (isTeamCityBuild) { + log.info("TeamCity build detected. Skipping automatic local.properties configuration") + 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 @@ -27,15 +35,26 @@ abstract class InternalGradleSetupSettingsPlugin : Plugin { val modifier = LocalPropertiesModifier(rootDir.resolve("local.properties")) val consentManager = ConsentManager(modifier) val initialDecision = consentManager.getUserDecision() - if (initialDecision == false) return@thread // user has opted out + if (initialDecision == false) { + log.debug("Skipping automatic local.properties configuration as you've opted out") + return@thread + } 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 + if (initialDecision == null && !consentManager.askForConsent()) { + log.debug("Skipping automatic local.properties configuration as the consent wasn't given") + return@thread + } modifier.applySetup(setupFile) - } catch (_: Throwable) { - // no-op + log.info("Automatic local.properties setup has been applied.") + } catch (e: UnknownHostException) { + log.debug("Cannot connect to the internal properties storage", e) + } catch (e: SocketTimeoutException) { + log.debug("Cannot connect to the internal properties storage", e) + } catch (e: Throwable) { + log.warn("Something went wrong during the automatic local.properties setup attempt", e) } } }