From 22700d015f552429af2806c767d716bf8613178c Mon Sep 17 00:00:00 2001 From: Paul Merlin Date: Sat, 15 Sep 2018 15:46:28 +0200 Subject: Add type safe counterparts to Closure taking methods on DokkaTask Signed-off-by: Paul Merlin --- .../testData/typeSafeConfiguration/build.gradle | 31 +++++++++++++ runners/gradle-plugin/src/main/kotlin/main.kt | 53 +++++++++++++++++----- 2 files changed, 72 insertions(+), 12 deletions(-) diff --git a/runners/gradle-integration-tests/testData/typeSafeConfiguration/build.gradle b/runners/gradle-integration-tests/testData/typeSafeConfiguration/build.gradle index b5b09ff9..6cab34c8 100644 --- a/runners/gradle-integration-tests/testData/typeSafeConfiguration/build.gradle +++ b/runners/gradle-integration-tests/testData/typeSafeConfiguration/build.gradle @@ -46,6 +46,37 @@ def configureDokkaTypeSafely(Project project) { cacheRoot = null as String languageVersion = null as String apiVersion = null as String + kotlinTasks(new Callable>() { + @Override + List call() { + return defaultKotlinTasks() + } + }) + linkMapping(new Action() { + @Override + void execute(LinkMapping mapping) { + mapping.dir = "some String" + mapping.url = "some String" + } + }) + sourceRoot(new Action() { + @Override + void execute(SourceRoot sourceRoot) { + sourceRoot.path = "some String" + } + }) + packageOptions(new Action() { + @Override + void execute(PackageOptions packageOptions) { + packageOptions.prefix = "some String" + } + }) + externalDocumentationLink(new Action() { + @Override + void execute(DokkaConfiguration.ExternalDocumentationLink.Builder builder) { + builder.url = uri("some URI").toURL() + } + }) } } } diff --git a/runners/gradle-plugin/src/main/kotlin/main.kt b/runners/gradle-plugin/src/main/kotlin/main.kt index d3a341e0..9130a329 100644 --- a/runners/gradle-plugin/src/main/kotlin/main.kt +++ b/runners/gradle-plugin/src/main/kotlin/main.kt @@ -1,6 +1,7 @@ package org.jetbrains.dokka.gradle import groovy.lang.Closure +import org.gradle.api.Action import org.gradle.api.DefaultTask import org.gradle.api.Plugin import org.gradle.api.Project @@ -147,14 +148,17 @@ open class DokkaTask : DefaultTask() { private var kotlinTasksConfigurator: () -> List? = { defaultKotlinTasks() } private val kotlinTasks: List by lazy { extractKotlinCompileTasks() } + fun kotlinTasks(taskSupplier: Callable>) { + kotlinTasksConfigurator = { taskSupplier.call() } + } + fun kotlinTasks(closure: Closure) { kotlinTasksConfigurator = { closure.call() as? List } } - fun linkMapping(closure: Closure) { + fun linkMapping(action: Action) { val mapping = LinkMapping() - closure.delegate = mapping - closure.call() + action.execute(mapping) if (mapping.path.isEmpty()) { throw IllegalArgumentException("Link mapping should have dir") @@ -166,27 +170,52 @@ open class DokkaTask : DefaultTask() { linkMappings.add(mapping) } - fun sourceRoot(closure: Closure) { + fun linkMapping(closure: Closure) { + linkMapping(Action { mapping -> + closure.delegate = mapping + closure.call() + }) + } + + fun sourceRoot(action: Action) { val sourceRoot = SourceRoot() - closure.delegate = sourceRoot - closure.call() + action.execute(sourceRoot) sourceRoots.add(sourceRoot) } - fun packageOptions(closure: Closure) { + fun sourceRoot(closure: Closure) { + sourceRoot(Action { sourceRoot -> + closure.delegate = sourceRoot + closure.call() + }) + } + + fun packageOptions(action: Action) { val packageOptions = PackageOptions() - closure.delegate = packageOptions - closure.call() + action.execute(packageOptions) perPackageOptions.add(packageOptions) } - fun externalDocumentationLink(closure: Closure) { + fun packageOptions(closure: Closure) { + packageOptions(Action { packageOptions -> + closure.delegate = packageOptions + closure.call() + }) + } + + fun externalDocumentationLink(action: Action) { val builder = DokkaConfiguration.ExternalDocumentationLink.Builder() - closure.delegate = builder - closure.call() + action.execute(builder) externalDocumentationLinks.add(builder.build()) } + fun externalDocumentationLink(closure: Closure) { + externalDocumentationLink(Action { builder -> + closure.delegate = builder + closure.call() + }) + } + fun tryResolveFatJar(project: Project): File { return try { val dependency = project.buildscript.dependencies.create(dokkaFatJar) -- cgit