From 887e71a7c1fdebbec8c34355a626f09bafc61541 Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Mon, 2 Oct 2017 23:06:01 +0300 Subject: [PATCH] Provide kotlin bootstrap source options --- build.gradle.kts | 12 ++-- buildSrc/src/main/kotlin/Bootstrap.kt | 78 ++++++++++++++++++++++++ buildSrc/src/main/kotlin/dependencies.kt | 2 - gradle.properties | 4 +- 4 files changed, 87 insertions(+), 9 deletions(-) create mode 100644 buildSrc/src/main/kotlin/Bootstrap.kt diff --git a/build.gradle.kts b/build.gradle.kts index 9eae88ae5bb..b3d457e519e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -6,14 +6,16 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile buildscript { + extra["defaultSnapshotVersion"] = "1.1-SNAPSHOT" + + kotlinBootstrapFrom(BootstrapOption.BintrayDev("1.1.50-dev-1451")) + val repos = listOfNotNull( - property("bootstrap.kotlin.repo") as String, - "https://repo.gradle.org/gradle/repo", + bootstrapKotlinRepo, + "https://jcenter.bintray.com/", "https://plugins.gradle.org/m2", "http://repository.jetbrains.com/utils/") - extra["bootstrapKotlinVersion"] = bootstrapKotlinVersion - extra["repos"] = repos extra["versions.shadow"] = "2.0.1" @@ -46,7 +48,7 @@ val configuredJdks: List = } } -val defaultSnapshotVersion = "1.1-SNAPSHOT" +val defaultSnapshotVersion: String by extra val buildNumber by extra(findProperty("build.number")?.toString() ?: defaultSnapshotVersion) val kotlinVersion by extra(findProperty("deployVersion")?.toString() ?: buildNumber) diff --git a/buildSrc/src/main/kotlin/Bootstrap.kt b/buildSrc/src/main/kotlin/Bootstrap.kt new file mode 100644 index 00000000000..5af4e03d868 --- /dev/null +++ b/buildSrc/src/main/kotlin/Bootstrap.kt @@ -0,0 +1,78 @@ +@file:Suppress("unused") // usages in build scripts are not tracked properly + +import org.gradle.api.Project +import org.gradle.kotlin.dsl.* + + +var Project.bootstrapKotlinVersion: String + get() = this.property("bootstrapKotlinVersion") as String + private set(value) { this.extra["bootstrapKotlinVersion"] = value } +var Project.bootstrapKotlinRepo: String? + get() = this.property("bootstrapKotlinRepo") as String? + private set(value) { this.extra["bootstrapKotlinRepo"] = value } + +fun Project.kotlinBootstrapFrom(defaultSource: BootstrapOption) { + val bootstrapVersion = project.findProperty("bootstrap.kotlin.version") as String? + val bootstrapRepo = project.findProperty("bootstrap.kotlin.repo") as String? + val bootstrapTeamCityVersion = project.findProperty("bootstrap.teamcity.kotlin.version") as String? + + val bootstrapSource = when { + project.hasProperty("bootstrap.local") -> BootstrapOption.Local(project.findProperty("bootstrap.local.version") as String?, project.findProperty("bootstrap.local.path") as String?) + bootstrapTeamCityVersion != null -> BootstrapOption.TeamCity(bootstrapTeamCityVersion, onlySuccessBootstrap = false) + bootstrapVersion != null -> BootstrapOption.Custom(kotlinVersion = bootstrapVersion, repo = bootstrapRepo) + else -> defaultSource + } + + bootstrapSource.applyToProject(project) + project.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?) : BootstrapOption() { + override fun applyToProject(project: Project) { + project.bootstrapKotlinVersion = kotlinVersion + project.bootstrapKotlinRepo = repo + } + } + + /** Get bootstrap from kotlin-dev bintray repo, where bootstraps are published */ + class BintrayDev(kotlinVersion: String) : Custom(kotlinVersion, "https://dl.bintray.com/kotlin/kotlin-dev") + + /** Get bootstrap from teamcity maven artifacts of the specified build configuration + * + * [kotlinVersion] build number and the version of maven artifacts + * [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 projectExtId: String? = null, val onlySuccessBootstrap: Boolean = true) : BootstrapOption() { + override fun applyToProject(project: Project) { + val query = if (onlySuccessBootstrap) "status:SUCCESS,tag:bootstrap,pinned:true" else "branch:default:any" + project.bootstrapKotlinRepo = "https://teamcity.jetbrains.com/guestAuth/app/rest/builds/buildType:(id:${projectExtId ?: "Kotlin_dev_Compiler"}),number:$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 + } + } +} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/dependencies.kt b/buildSrc/src/main/kotlin/dependencies.kt index 64c0bf2bdf1..9fc4abd3a65 100644 --- a/buildSrc/src/main/kotlin/dependencies.kt +++ b/buildSrc/src/main/kotlin/dependencies.kt @@ -8,9 +8,7 @@ import org.gradle.api.file.ConfigurableFileCollection import org.gradle.api.plugins.JavaPluginConvention import org.gradle.kotlin.dsl.* import java.io.File -import java.util.* -val Project.bootstrapKotlinVersion: String get() = this.property("bootstrap.kotlin.version") as String fun Project.commonDep(coord: String): String { val parts = coord.split(':') diff --git a/gradle.properties b/gradle.properties index fb97f0a9c87..77fe0a40af5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,6 +3,6 @@ org.gradle.parallel=false org.gradle.configureondemand=false org.gradle.jvmargs=-Xmx1000m -XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled -bootstrap.kotlin.repo=https://dl.bintray.com/kotlin/kotlin-dev -bootstrap.kotlin.version=1.1.50-dev-1451 +#bootstrap.kotlin.repo=https://dl.bintray.com/kotlin/kotlin-dev +#bootstrap.kotlin.version=1.1.50-dev-1451 #signingRequired=true