diff options
Diffstat (limited to 'buildSrc/src/main')
3 files changed, 101 insertions, 7 deletions
diff --git a/buildSrc/src/main/kotlin/org/jetbrains/DokkaPublicationChannel.kt b/buildSrc/src/main/kotlin/org/jetbrains/DokkaPublicationChannel.kt new file mode 100644 index 00000000..05593b40 --- /dev/null +++ b/buildSrc/src/main/kotlin/org/jetbrains/DokkaPublicationChannel.kt @@ -0,0 +1,33 @@ +package org.jetbrains + +import org.gradle.api.GradleException +import org.gradle.api.Project +import org.gradle.kotlin.dsl.provideDelegate +import org.jetbrains.DokkaPublicationChannel.* + +internal enum class DokkaPublicationChannel { + SpaceDokkaDev, + BintrayKotlinDev, + BintrayKotlinEap, + BintrayKotlinDokka; + + val isSpaceRepository get() = this == SpaceDokkaDev + + val isBintrayRepository + get() = when (this) { + SpaceDokkaDev -> false + BintrayKotlinDev, BintrayKotlinEap, BintrayKotlinDokka -> true + } +} + +internal val Project.publicationChannel: DokkaPublicationChannel + get() { + val dokka_publication_channel: String by this + return when (dokka_publication_channel) { + "space-dokka-dev" -> SpaceDokkaDev + "bintray-kotlin-dev" -> BintrayKotlinDev + "bintray-kotlin-eap" -> BintrayKotlinEap + "bintray-kotlin-dokka" -> BintrayKotlinDokka + else -> throw GradleException("Unknown dokka_publication_channel=$dokka_publication_channel") + } + } diff --git a/buildSrc/src/main/kotlin/org/jetbrains/ValidatePublications.kt b/buildSrc/src/main/kotlin/org/jetbrains/ValidatePublications.kt index 84c48b96..317e5152 100644 --- a/buildSrc/src/main/kotlin/org/jetbrains/ValidatePublications.kt +++ b/buildSrc/src/main/kotlin/org/jetbrains/ValidatePublications.kt @@ -32,7 +32,9 @@ open class ValidatePublications : DefaultTask() { .filterIsInstance<MavenPublication>() .filter { it.version == project.dokkaVersion } .forEach { publication -> - checkPublicationIsConfiguredForBintray(subProject, publication) + if (project.publicationChannel.isBintrayRepository) { + checkPublicationIsConfiguredForBintray(subProject, publication) + } checkProjectDependenciesArePublished(subProject) } } diff --git a/buildSrc/src/main/kotlin/org/jetbrains/publication.kt b/buildSrc/src/main/kotlin/org/jetbrains/publication.kt index 289bd117..36fd6286 100644 --- a/buildSrc/src/main/kotlin/org/jetbrains/publication.kt +++ b/buildSrc/src/main/kotlin/org/jetbrains/publication.kt @@ -1,3 +1,5 @@ +@file:Suppress("UNUSED_VARIABLE") + package org.jetbrains import com.github.jengelman.gradle.plugins.shadow.ShadowExtension @@ -5,7 +7,10 @@ import com.jfrog.bintray.gradle.BintrayExtension import org.gradle.api.Project import org.gradle.api.publish.PublishingExtension import org.gradle.api.publish.maven.MavenPublication +import org.gradle.api.publish.maven.tasks.PublishToMavenRepository import org.gradle.kotlin.dsl.* +import org.jetbrains.DokkaPublicationChannel.* +import java.net.URI class DokkaPublicationBuilder { enum class Component { @@ -16,6 +21,7 @@ class DokkaPublicationBuilder { var component: Component = Component.Java } + fun Project.registerDokkaArtifactPublication(publicationName: String, configure: DokkaPublicationBuilder.() -> Unit) { configure<PublishingExtension> { publications { @@ -32,30 +38,83 @@ fun Project.registerDokkaArtifactPublication(publicationName: String, configure: } } } + configureBintrayPublicationIfNecessary(publicationName) + configureSpacePublicationIfNecessary(publicationName) + createDokkaPublishTaskIfNecessary() +} + +fun Project.configureSpacePublicationIfNecessary(vararg publications: String) { + if (publicationChannel.isSpaceRepository) { + configure<PublishingExtension> { + repositories { + /* already registered */ + findByName(SpaceDokkaDev.name)?.let { return@repositories } + maven { + name = SpaceDokkaDev.name + url = URI.create("https://maven.pkg.jetbrains.space/kotlin/p/dokka/dev") + credentials { + username = System.getenv("SPACE_PACKAGES_USER") + password = System.getenv("SPACE_PACKAGES_SECRET") + } + } + } + } + } - configureBintrayPublication(publicationName) + whenEvaluated { + tasks.withType<PublishToMavenRepository> { + val isSpaceRepository = this.repository.name == SpaceDokkaDev.name + if (!isSpaceRepository) return@withType + this.isEnabled = this.isEnabled && publication.name in publications + if (!this.isEnabled) { + this.group = "disabled" + } + } + } } -fun Project.configureBintrayPublication(vararg publications: String) { - val dokka_version: String by this - val dokka_publication_channel: String by this +fun Project.createDokkaPublishTaskIfNecessary() { + tasks.maybeCreate("dokkaPublish").run { + if (publicationChannel.isSpaceRepository) { + dependsOn(tasks.named("publish")) + } + if (publicationChannel.isBintrayRepository) { + dependsOn(tasks.named("bintrayUpload")) + } + } +} + +fun Project.configureBintrayPublicationIfNecessary(vararg publications: String) { + if (publicationChannel.isBintrayRepository) { + configureBintrayPublication(*publications) + } +} + +private fun Project.configureBintrayPublication(vararg publications: String) { extensions.configure<BintrayExtension>("bintray") { user = System.getenv("BINTRAY_USER") key = System.getenv("BINTRAY_KEY") dryRun = System.getenv("BINTRAY_DRY_RUN") == "true" || project.properties["bintray_dry_run"] == "true" pkg = PackageConfig().apply { - repo = dokka_publication_channel + repo = when (publicationChannel) { + SpaceDokkaDev -> throw IllegalStateException("$SpaceDokkaDev is not a bintray repository") + BintrayKotlinDev -> "kotlin-dev" + BintrayKotlinEap -> "kotlin-eap" + BintrayKotlinDokka -> "dokka" + } name = "dokka" userOrg = "kotlin" desc = "Dokka, the Kotlin documentation tool" vcsUrl = "https://github.com/kotlin/dokka.git" setLicenses("Apache-2.0") version = VersionConfig().apply { - name = dokka_version + name = dokkaVersion } } setPublications(*publications) } } + + |