From 1b8030d4b8d4b83e35c91632694fb32fcb58a02d Mon Sep 17 00:00:00 2001 From: "sebastian.sellmair" Date: Wed, 8 Jul 2020 17:09:41 +0200 Subject: Implement PublicationValidation --- build.gradle.kts | 6 +- .../main/kotlin/org/jetbrains/BintrayPublishing.kt | 4 +- .../src/main/kotlin/org/jetbrains/DokkaVersion.kt | 3 + .../kotlin/org/jetbrains/ValidatePublications.kt | 79 ++++++++++++++++++++++ plugins/gfm/build.gradle.kts | 4 ++ plugins/javadoc/build.gradle.kts | 1 - plugins/jekyll/build.gradle.kts | 6 +- plugins/mathjax/build.gradle.kts | 6 +- runners/gradle-plugin/build.gradle.kts | 2 +- 9 files changed, 104 insertions(+), 7 deletions(-) create mode 100644 buildSrc/src/main/kotlin/org/jetbrains/ValidatePublications.kt diff --git a/build.gradle.kts b/build.gradle.kts index ee17ba75..7cc0394f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,3 +1,4 @@ +import org.jetbrains.ValidatePublications import org.jetbrains.configureDokkaVersion import org.jetbrains.kotlin.gradle.tasks.KotlinCompile @@ -45,8 +46,6 @@ subprojects { } } -println("Publication version: $dokka_version") - // Workaround for https://github.com/bintray/gradle-bintray-plugin/issues/267 // Manually disable bintray tasks added to the root project tasks.whenTaskAdded { @@ -54,3 +53,6 @@ tasks.whenTaskAdded { enabled = false } } + +println("Publication version: $dokka_version") +tasks.register("validatePublications") diff --git a/buildSrc/src/main/kotlin/org/jetbrains/BintrayPublishing.kt b/buildSrc/src/main/kotlin/org/jetbrains/BintrayPublishing.kt index c3d21d88..4180c445 100644 --- a/buildSrc/src/main/kotlin/org/jetbrains/BintrayPublishing.kt +++ b/buildSrc/src/main/kotlin/org/jetbrains/BintrayPublishing.kt @@ -10,7 +10,8 @@ fun Project.configureBintrayPublication(vararg publications: String) { extensions.configure("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 name = "dokka" @@ -25,3 +26,4 @@ fun Project.configureBintrayPublication(vararg publications: String) { setPublications(*publications) } } + diff --git a/buildSrc/src/main/kotlin/org/jetbrains/DokkaVersion.kt b/buildSrc/src/main/kotlin/org/jetbrains/DokkaVersion.kt index d5fd3e78..2a5c21a7 100644 --- a/buildSrc/src/main/kotlin/org/jetbrains/DokkaVersion.kt +++ b/buildSrc/src/main/kotlin/org/jetbrains/DokkaVersion.kt @@ -21,3 +21,6 @@ private fun dokkaVersionFromBase(baseVersion: String): String { } return "$baseVersion-$buildNumber" } + +val Project.dokkaVersion: String + get() = configureDokkaVersion() diff --git a/buildSrc/src/main/kotlin/org/jetbrains/ValidatePublications.kt b/buildSrc/src/main/kotlin/org/jetbrains/ValidatePublications.kt new file mode 100644 index 00000000..84c48b96 --- /dev/null +++ b/buildSrc/src/main/kotlin/org/jetbrains/ValidatePublications.kt @@ -0,0 +1,79 @@ +package org.jetbrains + +import com.jfrog.bintray.gradle.BintrayExtension +import org.gradle.api.DefaultTask +import org.gradle.api.GradleException +import org.gradle.api.Project +import org.gradle.api.artifacts.ProjectDependency +import org.gradle.api.publish.PublishingExtension +import org.gradle.api.publish.maven.MavenPublication +import org.gradle.api.tasks.TaskAction +import org.gradle.kotlin.dsl.findByType +import org.gradle.kotlin.dsl.provideDelegate + +open class ValidatePublications : DefaultTask() { + class MissingBintrayPublicationException(project: Project, publication: MavenPublication) : GradleException( + "Project ${project.path} has publication ${publication.name} that is not configured for bintray publication" + ) + + class UnpublishedProjectDependencyException( + project: Project, dependencyProject: Project + ) : GradleException( + "Published project ${project.path} cannot depend on unpublished projed ${dependencyProject.path}" + ) + + + @TaskAction + fun validatePublicationConfiguration() { + @Suppress("LocalVariableName") + project.subprojects.forEach { subProject -> + val publishing = subProject.extensions.findByType() ?: return@forEach + publishing.publications + .filterIsInstance() + .filter { it.version == project.dokkaVersion } + .forEach { publication -> + checkPublicationIsConfiguredForBintray(subProject, publication) + checkProjectDependenciesArePublished(subProject) + } + } + } + + private fun checkPublicationIsConfiguredForBintray(project: Project, publication: MavenPublication) { + val bintrayExtension = project.extensions.findByType() + ?: throw MissingBintrayPublicationException(project, publication) + + val isPublicationConfiguredForBintray = bintrayExtension.publications.orEmpty() + .any { publicationName -> publicationName == publication.name } + + if (!isPublicationConfiguredForBintray) { + throw MissingBintrayPublicationException(project, publication) + } + } + + private fun checkProjectDependenciesArePublished(project: Project) { + (project.configurations.findByName("implementation")?.allDependencies.orEmpty() + + project.configurations.findByName("api")?.allDependencies.orEmpty()) + .filterIsInstance() + .forEach { projectDependency -> + val publishing = projectDependency.dependencyProject.extensions.findByType() + ?: throw UnpublishedProjectDependencyException( + project = project, dependencyProject = projectDependency.dependencyProject + ) + + val isPublished = publishing.publications.filterIsInstance() + .filter { it.version == project.dokkaVersion } + .any() + + if (!isPublished) { + throw UnpublishedProjectDependencyException(project, projectDependency.dependencyProject) + } + } + } + + init { + group = "verification" + project.tasks.named("check") { + dependsOn(this@ValidatePublications) + } + } +} diff --git a/plugins/gfm/build.gradle.kts b/plugins/gfm/build.gradle.kts index 2addd9c9..16b318fb 100644 --- a/plugins/gfm/build.gradle.kts +++ b/plugins/gfm/build.gradle.kts @@ -1,3 +1,5 @@ +import org.jetbrains.configureBintrayPublication + publishing { publications { register("gfmPlugin") { @@ -7,6 +9,8 @@ publishing { } } +configureBintrayPublication("gfmPlugin") + dependencies { compileOnly(project(":plugins:base")) testImplementation(project(":plugins:base")) diff --git a/plugins/javadoc/build.gradle.kts b/plugins/javadoc/build.gradle.kts index 4c5c22b0..ebf79f8f 100644 --- a/plugins/javadoc/build.gradle.kts +++ b/plugins/javadoc/build.gradle.kts @@ -1,5 +1,4 @@ import org.jetbrains.configureBintrayPublication -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile publishing { publications { diff --git a/plugins/jekyll/build.gradle.kts b/plugins/jekyll/build.gradle.kts index a5c10fa0..b47633db 100644 --- a/plugins/jekyll/build.gradle.kts +++ b/plugins/jekyll/build.gradle.kts @@ -1,3 +1,5 @@ +import org.jetbrains.configureBintrayPublication + publishing { publications { register("jekyllPlugin") { @@ -7,7 +9,9 @@ publishing { } } +configureBintrayPublication("jekyllPlugin") + dependencies { compileOnly(project(":plugins:base")) implementation(project(":plugins:gfm")) -} \ No newline at end of file +} diff --git a/plugins/mathjax/build.gradle.kts b/plugins/mathjax/build.gradle.kts index 0e9a16d0..67f4822f 100644 --- a/plugins/mathjax/build.gradle.kts +++ b/plugins/mathjax/build.gradle.kts @@ -1,3 +1,5 @@ +import org.jetbrains.configureBintrayPublication + publishing { publications { register("mathjaxPlugin") { @@ -5,4 +7,6 @@ publishing { from(components["java"]) } } -} \ No newline at end of file +} + +configureBintrayPublication("mathjaxPlugin") diff --git a/runners/gradle-plugin/build.gradle.kts b/runners/gradle-plugin/build.gradle.kts index 77fbe4a7..a8345652 100644 --- a/runners/gradle-plugin/build.gradle.kts +++ b/runners/gradle-plugin/build.gradle.kts @@ -81,4 +81,4 @@ pluginBundle { } } -configureBintrayPublication("dokkaGradlePlugin", "dokkaGradlePluginPluginMarkerMaven") +configureBintrayPublication("dokkaGradlePlugin", "pluginMaven", "dokkaGradlePluginPluginMarkerMaven") -- cgit