Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Configuring Custom Dokka Plugin #3870

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions docs/topics/dokka-migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ options according to your project setup:
customAssets.set(listOf("logo.png"))
footerMessage.set("(c) Your Company")
}
pluginConfiguration<YourCustomPlugin, YourCustomPluginConfiguration> {
stringProperty.set("bar")
booleanProperty.set(true)
fileListProperty.set(files("foo.txt", "bar.txt"))
}
}
```

Expand All @@ -120,10 +125,19 @@ options according to your project setup:
remoteLineSuffix.set("#L")
}
}
pluginsConfiguration.html {
customStyleSheets.from("styles.css")
customAssets.from("logo.png")
footerMessage.set("(c) Your Company")
pluginsConfiguration {
html {
customStyleSheets.from("styles.css")
customAssets.from("logo.png")
footerMessage.set("(c) Your Company")
}
pluginParameters("your.package.YourCustomPluginConfiguration") {
property("stringProperty", "bar")
property("booleanProperty", true)
files("fileListProperty") {
from("foo.txt", "bar.txt")
}
}
}
}
```
Expand Down Expand Up @@ -416,4 +430,4 @@ DGP v2 now supports Gradle build cache and configuration cache, improving build

* Explore more [DGP v2 project examples](https://github.com/Kotlin/dokka/tree/master/examples/gradle-v2).
* [Get started with Dokka](dokka-get-started.md).
* [Learn more about Dokka plugins](dokka-plugins.md).
* [Learn more about Dokka plugins](dokka-plugins.md).
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import kotlinx.serialization.json.JsonArray
import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.JsonPrimitive
import org.gradle.api.Project
import org.gradle.api.file.ConfigurableFileCollection
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.file.RegularFileProperty
Expand Down Expand Up @@ -56,17 +57,15 @@ abstract class DokkaPluginParametersBuilder
@DokkaInternalApi
constructor(
name: String,
@get:Input
override val pluginFqn: String,

@Internal
@get:Internal
internal val objects: ObjectFactory,
) : DokkaPluginParametersBaseSpec(name, pluginFqn) {
@get:Internal
internal val project: Project,
) : DokkaPluginParametersBaseSpec(name, name) {

@get:Nested
internal val properties = PluginConfigValue.Properties(objects.mapProperty())

@Internal
override fun jsonEncode(): String = properties.convertToJson().toString()

companion object {
Expand All @@ -83,17 +82,15 @@ constructor(
is PluginConfigValue.Properties ->
JsonObject(values.get().mapValues { (_, value) -> value.convertToJson() })

is PluginConfigValue.Values ->
JsonArray(values.get().map { it.convertToJson() })
is PluginConfigValue.Values -> JsonArray(values.get().map { it.convertToJson() })
}

/** Creates a [JsonPrimitive] from the given [File]. */
private fun File?.convertToJson(): JsonPrimitive =
JsonPrimitive(this?.canonicalFile?.invariantSeparatorsPath)
private fun File?.convertToJson(): JsonPrimitive = JsonPrimitive(this?.canonicalFile?.invariantSeparatorsPath)
}
}


//region File System Properties
fun DokkaPluginParametersBuilder.files(
propertyName: String,
filesConfig: ConfigurableFileCollection.() -> Unit
Expand All @@ -103,6 +100,25 @@ fun DokkaPluginParametersBuilder.files(
properties.values.put(propertyName, PluginConfigValue.FilesValue(files))
}

fun DokkaPluginParametersBuilder.file(
propertyName: String,
file: Any,
) {
val fileProperty = objects.fileProperty()
fileProperty.set(project.file(file))
properties.values.put(propertyName, PluginConfigValue.FileValue(fileProperty))
}

fun DokkaPluginParametersBuilder.directory(
propertyName: String,
directory: Any,
) {
val directoryProperty = objects.directoryProperty()
directoryProperty.set(project.file(directory))
properties.values.put(propertyName, PluginConfigValue.DirectoryValue(directoryProperty))
}
//endregion

//region Primitive Properties
fun DokkaPluginParametersBuilder.property(propertyName: String, value: String) {
properties.values.put(propertyName, PluginConfigValue(value))
Expand Down Expand Up @@ -169,6 +185,18 @@ fun PluginConfigValue.Values.add(value: Provider<Boolean>) =
//endregion


//region Map Properties
fun DokkaPluginParametersBuilder.propertiesMap(
propertyName: String,
build: PluginConfigValue.Properties.() -> Unit
) {
val values = PluginConfigValue.Properties(objects.mapProperty())
values.build()
properties.values.put(propertyName, values)
}
//endregion


sealed class PluginConfigValue {

/** An input file */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import org.gradle.kotlin.dsl.registerBinding
import org.gradle.kotlin.dsl.withType
import org.jetbrains.dokka.gradle.engine.plugins.DokkaHtmlPluginParameters
import org.jetbrains.dokka.gradle.engine.plugins.DokkaHtmlPluginParameters.Companion.DOKKA_HTML_PARAMETERS_NAME
import org.jetbrains.dokka.gradle.engine.plugins.DokkaPluginParametersBuilder
import org.jetbrains.dokka.gradle.engine.plugins.DokkaVersioningPluginParameters
import org.jetbrains.dokka.gradle.engine.plugins.DokkaVersioningPluginParameters.Companion.DOKKA_VERSIONING_PLUGIN_PARAMETERS_NAME
import org.jetbrains.dokka.gradle.internal.DokkaInternalApi
Expand All @@ -35,12 +36,19 @@ constructor(
HtmlModuleAggregationCheck(archives, providers)

override fun DokkaFormatPluginContext.configure() {
registerCustomPluginConfigurationHelper()
registerDokkaBasePluginConfiguration()
registerDokkaVersioningPlugin()
configureHtmlUrlLogging()
configureModuleAggregation()
}

private fun DokkaFormatPluginContext.registerCustomPluginConfigurationHelper() {
with(dokkaExtension.pluginsConfiguration) {
registerBinding(DokkaPluginParametersBuilder::class, DokkaPluginParametersBuilder::class)
}
}

private fun DokkaFormatPluginContext.registerDokkaBasePluginConfiguration() {
with(dokkaExtension.pluginsConfiguration) {
registerBinding(DokkaHtmlPluginParameters::class, DokkaHtmlPluginParameters::class)
Expand Down