diff options
Diffstat (limited to 'integration/src/main/kotlin/org/jetbrains')
-rw-r--r-- | integration/src/main/kotlin/org/jetbrains/dokka/configuration.kt | 53 | ||||
-rw-r--r-- | integration/src/main/kotlin/org/jetbrains/dokka/defaultConfiguration.kt | 79 |
2 files changed, 101 insertions, 31 deletions
diff --git a/integration/src/main/kotlin/org/jetbrains/dokka/configuration.kt b/integration/src/main/kotlin/org/jetbrains/dokka/configuration.kt index 12efd252..717fa477 100644 --- a/integration/src/main/kotlin/org/jetbrains/dokka/configuration.kt +++ b/integration/src/main/kotlin/org/jetbrains/dokka/configuration.kt @@ -1,22 +1,26 @@ package org.jetbrains.dokka -import ru.yole.jkid.CustomSerializer -import ru.yole.jkid.ValueSerializer -import ru.yole.jkid.deserialization.JKidException -import java.io.Serializable +import kotlinx.serialization.* +import kotlinx.serialization.internal.StringDescriptor import java.net.URL -class UrlSerializer : ValueSerializer<URL?> { - override fun fromJsonValue(jsonValue: Any?): URL? { - if (jsonValue !is String?) - throw JKidException("Expected string representation of URL, got: $jsonValue") - return jsonValue?.let { URL(jsonValue) } +@Serializer(forClass = URL::class) +object UrlSerializer: KSerializer<URL> { + + override val descriptor: SerialDescriptor = + StringDescriptor.withName("WithCustomDefault") + + override fun deserialize(decoder: Decoder): URL { + return URL(decoder.decodeString()) } - override fun toJsonValue(value: URL?): Any? = value?.toExternalForm() + override fun serialize(encoder: Encoder, obj: URL) { + encoder.encodeString(obj.toExternalForm()) + } } + enum class Platform(val key: String) { jvm("jvm"), js("js"), @@ -93,8 +97,8 @@ interface DokkaConfiguration { } interface ExternalDocumentationLink { - @CustomSerializer(UrlSerializer::class) val url: URL - @CustomSerializer(UrlSerializer::class) val packageListUrl: URL + @Serializable(with = UrlSerializer::class) val url: URL + @Serializable(with = UrlSerializer::class) val packageListUrl: URL open class Builder(open var url: URL? = null, open var packageListUrl: URL? = null) { @@ -102,25 +106,12 @@ interface DokkaConfiguration { constructor(root: String, packageList: String? = null) : this(URL(root), packageList?.let { URL(it) }) fun build(): DokkaConfiguration.ExternalDocumentationLink = - if (packageListUrl != null && url != null) - ExternalDocumentationLinkImpl(url!!, packageListUrl!!) - else if (url != null) - ExternalDocumentationLinkImpl(url!!, URL(url!!, "package-list")) - else - throw IllegalArgumentException("url or url && packageListUrl must not be null for external documentation link") + if (packageListUrl != null && url != null) + ExternalDocumentationLinkImpl(url!!, packageListUrl!!) + else if (url != null) + ExternalDocumentationLinkImpl(url!!, URL(url!!, "package-list")) + else + throw IllegalArgumentException("url or url && packageListUrl must not be null for external documentation link") } } } - -data class SerializeOnlyDokkaConfiguration( - override val outputDir: String, - override val format: String, - override val generateIndexPages: Boolean, - override val cacheRoot: String?, - override val impliedPlatforms: List<String>, - override val passesConfigurations: List<DokkaConfiguration.PassConfiguration> -) : DokkaConfiguration - - -data class ExternalDocumentationLinkImpl(@CustomSerializer(UrlSerializer::class) override val url: URL, - @CustomSerializer(UrlSerializer::class) override val packageListUrl: URL) : Serializable, DokkaConfiguration.ExternalDocumentationLink
\ No newline at end of file diff --git a/integration/src/main/kotlin/org/jetbrains/dokka/defaultConfiguration.kt b/integration/src/main/kotlin/org/jetbrains/dokka/defaultConfiguration.kt new file mode 100644 index 00000000..615f0215 --- /dev/null +++ b/integration/src/main/kotlin/org/jetbrains/dokka/defaultConfiguration.kt @@ -0,0 +1,79 @@ +package org.jetbrains.dokka + +import kotlinx.serialization.Serializable +import java.io.File +import java.net.URL + +@Serializable +data class DokkaConfigurationImpl( + override val outputDir: String, + override val format: String, + override val generateIndexPages: Boolean, + override val cacheRoot: String?, + override val impliedPlatforms: List<String>, + override val passesConfigurations: List<PassConfigurationImpl> +) : DokkaConfiguration + +@Serializable +data class PassConfigurationImpl ( + override val moduleName: String, + override val classpath: List<String>, + override val sourceRoots: List<SourceRootImpl>, + override val samples: List<String>, + override val includes: List<String>, + override val includeNonPublic: Boolean, + override val includeRootPackage: Boolean, + override val reportUndocumented: Boolean, + override val skipEmptyPackages: Boolean, + override val skipDeprecated: Boolean, + override val jdkVersion: Int, + override val sourceLinks: List<SourceLinkDefinitionImpl>, + override val perPackageOptions: List<PackageOptionsImpl>, + override var externalDocumentationLinks: List<ExternalDocumentationLinkImpl>, + override val languageVersion: String?, + override val apiVersion: String?, + override val noStdlibLink: Boolean, + override val noJdkLink: Boolean, + override val suppressedFiles: List<String>, + override val collectInheritedExtensionsFromLibraries: Boolean, + override val analysisPlatform: Platform, + override val targets: List<String>, + override val sinceKotlin: String +) : DokkaConfiguration.PassConfiguration + +@Serializable +data class SourceRootImpl( + override val path: String +): DokkaConfiguration.SourceRoot + +@Serializable +data class SourceLinkDefinitionImpl( + override val path: String, + override val url: String, + override val lineSuffix: String? +): DokkaConfiguration.SourceLinkDefinition { + companion object { + fun parseSourceLinkDefinition(srcLink: String): SourceLinkDefinitionImpl { + val (path, urlAndLine) = srcLink.split('=') + return SourceLinkDefinitionImpl( + File(path).canonicalPath, + urlAndLine.substringBefore("#"), + urlAndLine.substringAfter("#", "").let { if (it.isEmpty()) null else "#$it" }) + } + } +} + +@Serializable +data class PackageOptionsImpl( + override val prefix: String, + override val includeNonPublic: Boolean, + override val reportUndocumented: Boolean, + override val skipDeprecated: Boolean, + override val suppress: Boolean +): DokkaConfiguration.PackageOptions + + +@Serializable +data class ExternalDocumentationLinkImpl(@Serializable(with = UrlSerializer::class) override val url: URL, + @Serializable(with = UrlSerializer::class) override val packageListUrl: URL +) : DokkaConfiguration.ExternalDocumentationLink
\ No newline at end of file |