aboutsummaryrefslogtreecommitdiff
path: root/build-logic/src/main/kotlin/org/jetbrains/DokkaPublicationChannel.kt
diff options
context:
space:
mode:
authorGoooler <wangzongler@gmail.com>2023-03-13 21:51:31 +0800
committerGitHub <noreply@github.com>2023-03-13 14:51:31 +0100
commit3ea414251d32108dab8b14d41a672e9834824690 (patch)
tree5f7a62f60e3d90ee97989cff8e5d748b180d091b /build-logic/src/main/kotlin/org/jetbrains/DokkaPublicationChannel.kt
parent7a46cd329ac6ccbdb10195310197289947ee4104 (diff)
downloaddokka-3ea414251d32108dab8b14d41a672e9834824690.tar.gz
dokka-3ea414251d32108dab8b14d41a672e9834824690.tar.bz2
dokka-3ea414251d32108dab8b14d41a672e9834824690.zip
Migrate buildSrc to composite build (#2912)
Diffstat (limited to 'build-logic/src/main/kotlin/org/jetbrains/DokkaPublicationChannel.kt')
-rw-r--r--build-logic/src/main/kotlin/org/jetbrains/DokkaPublicationChannel.kt62
1 files changed, 62 insertions, 0 deletions
diff --git a/build-logic/src/main/kotlin/org/jetbrains/DokkaPublicationChannel.kt b/build-logic/src/main/kotlin/org/jetbrains/DokkaPublicationChannel.kt
new file mode 100644
index 00000000..03f607e8
--- /dev/null
+++ b/build-logic/src/main/kotlin/org/jetbrains/DokkaPublicationChannel.kt
@@ -0,0 +1,62 @@
+@file:Suppress("LocalVariableName")
+
+package org.jetbrains
+
+import org.gradle.api.Project
+
+enum class DokkaPublicationChannel {
+ SPACE_DOKKA_DEV,
+ MAVEN_CENTRAL,
+ MAVEN_CENTRAL_SNAPSHOT,
+ GRADLE_PLUGIN_PORTAL;
+
+ val acceptedDokkaVersionTypes: List<DokkaVersionType>
+ get() = when(this) {
+ MAVEN_CENTRAL -> listOf(DokkaVersionType.RELEASE, DokkaVersionType.RC)
+ MAVEN_CENTRAL_SNAPSHOT -> listOf(DokkaVersionType.SNAPSHOT)
+ SPACE_DOKKA_DEV -> listOf(DokkaVersionType.RELEASE, DokkaVersionType.RC, DokkaVersionType.DEV, DokkaVersionType.SNAPSHOT)
+ GRADLE_PLUGIN_PORTAL -> listOf(DokkaVersionType.RELEASE, DokkaVersionType.RC)
+ }
+
+ fun isSpaceRepository() = this == SPACE_DOKKA_DEV
+
+ fun isMavenRepository() = this == MAVEN_CENTRAL || this == MAVEN_CENTRAL_SNAPSHOT
+
+ fun isGradlePluginPortal() = this == GRADLE_PLUGIN_PORTAL
+
+ companion object {
+ fun fromPropertyString(value: String): DokkaPublicationChannel = when (value) {
+ "space-dokka-dev" -> SPACE_DOKKA_DEV
+ "maven-central-release" -> MAVEN_CENTRAL
+ "maven-central-snapshot" -> MAVEN_CENTRAL_SNAPSHOT
+ "gradle-plugin-portal" -> GRADLE_PLUGIN_PORTAL
+ else -> throw IllegalArgumentException("Unknown dokka_publication_channel=$value")
+ }
+ }
+}
+
+val Project.publicationChannels: Set<DokkaPublicationChannel>
+ get() {
+ val publicationChannel = this.properties["dokka_publication_channel"]?.toString()
+ val publicationChannels = this.properties["dokka_publication_channels"]?.toString()
+ if (publicationChannel != null && publicationChannels != null) {
+ throw IllegalArgumentException(
+ "Only one of dokka_publication_channel and dokka_publication_channel*s* can be set. Found: \n" +
+ "dokka_publication_channel=$publicationChannel\n" +
+ "dokka_publication_channels=$publicationChannels"
+ )
+ }
+
+ if (publicationChannel != null) {
+ return setOf(DokkaPublicationChannel.fromPropertyString(publicationChannel))
+ }
+
+ if (publicationChannels != null) {
+ return publicationChannels.split("&").map { channel ->
+ DokkaPublicationChannel.fromPropertyString(channel)
+ }.toSet()
+ }
+
+ return emptySet()
+ }
+