add cleanup dependencies tasks for buildSrc

change embedded kotlin version to bootstrap for buildSrc
This commit is contained in:
nataliya.valtman
2020-01-29 14:27:02 +03:00
parent ea7b5827ab
commit 8a8536f8ae
13 changed files with 181 additions and 194 deletions
+1 -1
View File
@@ -4,7 +4,7 @@ plugins {
}
group = "org.jetbrains.kotlin"
version = "0.0.12"
version = "0.0.13"
repositories {
mavenCentral()
+114
View File
@@ -0,0 +1,114 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
import org.gradle.api.Project
import java.net.URI
var Project.bootstrapKotlinVersion: String
get() = property("bootstrapKotlinVersion") as String
private set(value) {
extensions.extraProperties.set("bootstrapKotlinVersion", value)
}
var Project.bootstrapKotlinRepo: String?
get() = property("bootstrapKotlinRepo") as String?
private set(value) {
extensions.extraProperties.set("bootstrapKotlinRepo", value)
}
val Project.internalKotlinRepo: String?
get() = "https://teamcity.jetbrains.com/guestAuth/app/rest/builds/buildType:(id:Kotlin_KotlinPublic_Compiler),number:$bootstrapKotlinVersion," +
"branch:default:any/artifacts/content/internal/repo"
fun Project.kotlinBootstrapFrom(defaultSource: BootstrapOption) {
val customVersion = findProperty("bootstrap.custom.kotlin.version") as String?
val customRepo = findProperty("bootstrap.custom.kotlin.repo") as String?
val teamCityVersion = findProperty("bootstrap.teamcity.kotlin.version") as String?
val teamCityBuild = findProperty("bootstrap.teamcity.build.number") as String?
val teamCityProject = findProperty("bootstrap.teamcity.project") as String?
val bootstrapSource = when {
hasProperty("bootstrap.local") -> BootstrapOption.Local(
findProperty("bootstrap.local.version") as String?,
findProperty("bootstrap.local.path") as String?
)
teamCityVersion != null -> BootstrapOption.TeamCity(
teamCityVersion,
teamCityBuild,
projectExtId = teamCityProject,
onlySuccessBootstrap = false
)
customVersion != null -> BootstrapOption.Custom(kotlinVersion = customVersion, repo = customRepo)
else -> defaultSource
}
bootstrapSource.applyToProject(this)
logger.lifecycle("Using kotlin bootstrap version $bootstrapKotlinVersion from repo $bootstrapKotlinRepo")
}
sealed class BootstrapOption {
abstract fun applyToProject(project: Project)
/** Manual repository and version specification.
*
* If [repo] is not specified the default buildscript and project repositories are used
*/
open class Custom(val kotlinVersion: String, val repo: String?, val cacheRedirector: Boolean = false) : BootstrapOption() {
override fun applyToProject(project: Project) {
project.bootstrapKotlinVersion = kotlinVersion
project.bootstrapKotlinRepo = if (cacheRedirector)
repo?.let { URI(it) }?.let { "https://cache-redirector.jetbrains.com/${it.host}/${it.path}" }
else
repo
}
}
/** Get bootstrap from kotlin-dev bintray repo */
class BintrayDev(kotlinVersion: String, cacheRedirector: Boolean = false) :
Custom(kotlinVersion, "https://dl.bintray.com/kotlin/kotlin-dev", cacheRedirector)
/** Get bootstrap from kotlin-bootstrap bintray repo, where bootstraps are published */
class BintrayBootstrap(kotlinVersion: String, cacheRedirector: Boolean = false) :
Custom(kotlinVersion, "https://dl.bintray.com/kotlin/kotlin-bootstrap", cacheRedirector)
/** Get bootstrap from teamcity maven artifacts of the specified build configuration
*
* [kotlinVersion] the version of maven artifacts
* [buildNumber] build number of a teamcity build, by default the same as [kotlinVersion],
* [projectExtId] extId of a teamcity build configuration, by default "Kotlin_dev_Compiler",
* [onlySuccessBootstrap] allow artifacts only from success builds of the default branch tagged with 'bootstrap' tag
*/
class TeamCity(
val kotlinVersion: String,
val buildNumber: String? = null,
val projectExtId: String? = null,
val onlySuccessBootstrap: Boolean = true,
val teamcityUrl: String = "https://teamcity.jetbrains.com"
) : BootstrapOption() {
override fun applyToProject(project: Project) {
val query = if (onlySuccessBootstrap) "status:SUCCESS,tag:bootstrap,pinned:true" else "branch:default:any"
project.bootstrapKotlinRepo = "$teamcityUrl/guestAuth/app/rest/builds/buildType:(id:${projectExtId
?: "Kotlin_dev_Compiler"}),number:${buildNumber ?: kotlinVersion},$query/artifacts/content/maven/"
project.bootstrapKotlinVersion = kotlinVersion
}
}
/**
* Use previously published local artifacts from the build/repo maven repository
*
* [kotlinVersion] version of artifacts, by default the snapshot version of project is used
* [localPath] the path to local repository, if specified it is resolved with respect or project dir
*/
class Local(val kotlinVersion: String? = null, val localPath: String? = null) : BootstrapOption() {
override fun applyToProject(project: Project) {
val repoPath = if (localPath != null)
project.projectDir.resolve(localPath).canonicalFile
else
project.buildDir.resolve("repo")
project.bootstrapKotlinRepo = repoPath.toURI().toString()
project.bootstrapKotlinVersion = kotlinVersion ?: project.property("defaultSnapshotVersion") as String
}
}
}
@@ -19,16 +19,24 @@ class KotlinBuildProperties(
private val propertiesProvider: PropertiesProvider
) {
private val localProperties: Properties = Properties()
private val rootProperties: Properties = Properties()
init {
val localPropertiesFile = propertiesProvider.rootProjectDir.resolve("local.properties")
if (localPropertiesFile.isFile) {
localPropertiesFile.reader().use(localProperties::load)
loadPropertyFile("local.properties", localProperties)
loadPropertyFile("gradle.properties", rootProperties)
}
private fun loadPropertyFile(fileName: String, propertiesDestination: Properties) {
val propertiesFile = propertiesProvider.rootProjectDir.resolve(fileName)
if (propertiesFile.isFile) {
propertiesFile.reader().use(propertiesDestination::load)
}
}
private operator fun get(key: String): Any? = localProperties.getProperty(key) ?: propertiesProvider.getProperty(key)
private fun getLocalOrRoot(key: String): Any? = get(key) ?: rootProperties.getProperty(key)
private fun getBoolean(key: String, default: Boolean = false): Boolean =
this[key]?.toString()?.trim()?.toBoolean() ?: default
@@ -96,6 +104,10 @@ class KotlinBuildProperties(
val buildCacheUser: String? = get("kotlin.build.cache.user") as String?
val buildCachePassword: String? = get("kotlin.build.cache.password") as String?
val kotlinBootstrapVersion: String? = getLocalOrRoot("bootstrap.kotlin.version") as String?
val defaultSnapshotVersion: String? = getLocalOrRoot("defaultSnapshotVersion") as String?
}
private const val extensionName = "kotlinBuildProperties"