aboutsummaryrefslogtreecommitdiff
path: root/dokka-runners/dokkatoo/buildSrc/src/main/kotlin/buildsrc/tasks
diff options
context:
space:
mode:
authorAdam <897017+aSemy@users.noreply.github.com>2023-10-20 00:39:12 +1300
committerGitHub <noreply@github.com>2023-10-19 13:39:12 +0200
commit35d15601f2d129a7d3db67dd9e2f4c41c87ef083 (patch)
treef9098cb5b79fc31b4a393347f5cebcf9d87dd139 /dokka-runners/dokkatoo/buildSrc/src/main/kotlin/buildsrc/tasks
parent8016c1face1283952e228aee348487bf0421ab90 (diff)
downloaddokka-35d15601f2d129a7d3db67dd9e2f4c41c87ef083.tar.gz
dokka-35d15601f2d129a7d3db67dd9e2f4c41c87ef083.tar.bz2
dokka-35d15601f2d129a7d3db67dd9e2f4c41c87ef083.zip
Contribute Dokkatoo (#3188)
Diffstat (limited to 'dokka-runners/dokkatoo/buildSrc/src/main/kotlin/buildsrc/tasks')
-rw-r--r--dokka-runners/dokkatoo/buildSrc/src/main/kotlin/buildsrc/tasks/SetupDokkaProjects.kt73
-rw-r--r--dokka-runners/dokkatoo/buildSrc/src/main/kotlin/buildsrc/tasks/UpdateDokkatooExampleProjects.kt49
2 files changed, 122 insertions, 0 deletions
diff --git a/dokka-runners/dokkatoo/buildSrc/src/main/kotlin/buildsrc/tasks/SetupDokkaProjects.kt b/dokka-runners/dokkatoo/buildSrc/src/main/kotlin/buildsrc/tasks/SetupDokkaProjects.kt
new file mode 100644
index 00000000..d473d287
--- /dev/null
+++ b/dokka-runners/dokkatoo/buildSrc/src/main/kotlin/buildsrc/tasks/SetupDokkaProjects.kt
@@ -0,0 +1,73 @@
+package buildsrc.tasks
+
+import buildsrc.settings.DokkaTemplateProjectSettings.DokkaTemplateProjectSpec
+import javax.inject.Inject
+import org.gradle.api.DefaultTask
+import org.gradle.api.NamedDomainObjectContainer
+import org.gradle.api.file.DirectoryProperty
+import org.gradle.api.file.FileCollection
+import org.gradle.api.file.FileSystemOperations
+import org.gradle.api.file.ProjectLayout
+import org.gradle.api.provider.ProviderFactory
+import org.gradle.api.tasks.*
+
+abstract class SetupDokkaProjects @Inject constructor(
+ private val fs: FileSystemOperations,
+ private val layout: ProjectLayout,
+ private val providers: ProviderFactory,
+) : DefaultTask() {
+
+ @get:OutputDirectories
+ val destinationDirs: FileCollection
+ get() = layout.files(
+ destinationBaseDir.map { base ->
+ templateProjects.map { spec -> base.dir(spec.destinationPath) }
+ }
+ )
+
+ @get:Internal // tracked by destinationDirs
+ abstract val destinationBaseDir: DirectoryProperty
+
+ @get:Nested
+ abstract val templateProjects: NamedDomainObjectContainer<DokkaTemplateProjectSpec>
+
+ @get:InputDirectory
+ abstract val dokkaSourceDir: DirectoryProperty
+
+ @get:InputFiles
+ val additionalFiles: FileCollection
+ get() = layout.files(
+ providers.provider {
+ templateProjects.map { it.additionalFiles }
+ }
+ )
+
+ init {
+ group = "dokka examples"
+ }
+
+ @TaskAction
+ internal fun action() {
+ val dokkaSourceDir = dokkaSourceDir.get()
+ val destinationBaseDir = destinationBaseDir.get()
+ val templateProjects = templateProjects.filter { it.destinationPath.isPresent }
+
+ templateProjects.forEach { spec ->
+ fs.sync {
+ with(spec.copySpec)
+
+ from(dokkaSourceDir.dir(spec.sourcePath))
+
+ from(
+ spec.additionalPaths.get().map { additionalPath ->
+ dokkaSourceDir.asFile.resolve(additionalPath)
+ }
+ )
+
+ from(spec.additionalFiles)
+
+ into(destinationBaseDir.dir(spec.destinationPath))
+ }
+ }
+ }
+}
diff --git a/dokka-runners/dokkatoo/buildSrc/src/main/kotlin/buildsrc/tasks/UpdateDokkatooExampleProjects.kt b/dokka-runners/dokkatoo/buildSrc/src/main/kotlin/buildsrc/tasks/UpdateDokkatooExampleProjects.kt
new file mode 100644
index 00000000..7737e098
--- /dev/null
+++ b/dokka-runners/dokkatoo/buildSrc/src/main/kotlin/buildsrc/tasks/UpdateDokkatooExampleProjects.kt
@@ -0,0 +1,49 @@
+package buildsrc.tasks
+
+import buildsrc.settings.DokkatooExampleProjectsSettings.DokkatooExampleProjectSpec
+import javax.inject.Inject
+import org.gradle.api.DefaultTask
+import org.gradle.api.NamedDomainObjectContainer
+import org.gradle.api.model.ObjectFactory
+import org.gradle.api.tasks.CacheableTask
+import org.gradle.api.tasks.Internal
+import org.gradle.api.tasks.Nested
+import org.gradle.api.tasks.TaskAction
+
+/**
+ * Utility for updating the `gradle.properties` of projects used in automated tests.
+ */
+@CacheableTask
+abstract class UpdateDokkatooExampleProjects @Inject constructor(
+ @get:Internal
+ val objects: ObjectFactory
+) : DefaultTask() {
+
+ @get:Nested
+ abstract val exampleProjects: NamedDomainObjectContainer<DokkatooExampleProjectSpec>
+
+ private val taskPath: String = path // renamed for clarity
+
+ @TaskAction
+ fun update() {
+ exampleProjects.forEach { exampleProject ->
+ updateGradleProperties(exampleProject)
+ }
+ }
+
+ private fun updateGradleProperties(exampleProject: DokkatooExampleProjectSpec) {
+
+ val gradlePropertiesContent = exampleProject.gradlePropertiesContent.orNull?.sorted() ?: return
+
+ val content = buildString {
+ appendLine("# DO NOT EDIT - Generated by $taskPath")
+ appendLine()
+
+ gradlePropertiesContent.forEach {
+ appendLine(it)
+ }
+ }
+
+ exampleProject.gradlePropertiesFile.get().asFile.writeText(content)
+ }
+}