diff options
author | sebastian.sellmair <sebastian.sellmair@jetbrains.com> | 2020-07-08 17:09:41 +0200 |
---|---|---|
committer | Sebastian Sellmair <34319766+sellmair@users.noreply.github.com> | 2020-07-09 09:24:52 +0200 |
commit | 1b8030d4b8d4b83e35c91632694fb32fcb58a02d (patch) | |
tree | b266352658c943159065f5bde252a7a63b99a9aa /buildSrc/src/main | |
parent | 4ba7ec9facb26c5ae0b0dd434e07c4af728f277a (diff) | |
download | dokka-1b8030d4b8d4b83e35c91632694fb32fcb58a02d.tar.gz dokka-1b8030d4b8d4b83e35c91632694fb32fcb58a02d.tar.bz2 dokka-1b8030d4b8d4b83e35c91632694fb32fcb58a02d.zip |
Implement PublicationValidation
Diffstat (limited to 'buildSrc/src/main')
3 files changed, 85 insertions, 1 deletions
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<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 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<PublishingExtension>() ?: return@forEach + publishing.publications + .filterIsInstance<MavenPublication>() + .filter { it.version == project.dokkaVersion } + .forEach { publication -> + checkPublicationIsConfiguredForBintray(subProject, publication) + checkProjectDependenciesArePublished(subProject) + } + } + } + + private fun checkPublicationIsConfiguredForBintray(project: Project, publication: MavenPublication) { + val bintrayExtension = project.extensions.findByType<BintrayExtension>() + ?: 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<ProjectDependency>() + .forEach { projectDependency -> + val publishing = projectDependency.dependencyProject.extensions.findByType<PublishingExtension>() + ?: throw UnpublishedProjectDependencyException( + project = project, dependencyProject = projectDependency.dependencyProject + ) + + val isPublished = publishing.publications.filterIsInstance<MavenPublication>() + .filter { it.version == project.dokkaVersion } + .any() + + if (!isPublished) { + throw UnpublishedProjectDependencyException(project, projectDependency.dependencyProject) + } + } + } + + init { + group = "verification" + project.tasks.named("check") { + dependsOn(this@ValidatePublications) + } + } +} |