aboutsummaryrefslogtreecommitdiff
path: root/dokka-runners/dokkatoo/buildSrc/src/main/kotlin/buildsrc/tasks/SetupDokkaProjects.kt
blob: d473d28741ff51adb6473e6cd3906f2e01f0d2c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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))
      }
    }
  }
}