From 37d12bed40edc226d96d0e1a4b28a24583ece94f Mon Sep 17 00:00:00 2001 From: "sebastian.sellmair" Date: Wed, 22 Jul 2020 11:12:16 +0200 Subject: DokkaConfiguration: Use `Set` instead of `List` when collections are expected to be distinct --- core/src/main/kotlin/configuration.kt | 20 ++++++++---------- core/src/main/kotlin/defaultConfiguration.kt | 24 ++++++++-------------- core/src/main/kotlin/utilities/json.kt | 18 ---------------- .../kotlin/utilities/DokkaConfigurationJsonTest.kt | 10 ++++----- 4 files changed, 21 insertions(+), 51 deletions(-) (limited to 'core/src') diff --git a/core/src/main/kotlin/configuration.kt b/core/src/main/kotlin/configuration.kt index 67c55861..b26b93a4 100644 --- a/core/src/main/kotlin/configuration.kt +++ b/core/src/main/kotlin/configuration.kt @@ -79,39 +79,35 @@ interface DokkaConfiguration : Serializable { val failOnWarning: Boolean val sourceSets: List val modules: List - val pluginsClasspath: List + val pluginsClasspath: Set val pluginsConfiguration: Map interface DokkaSourceSet : Serializable { val sourceSetID: DokkaSourceSetID val displayName: String val moduleDisplayName: String - val classpath: List - val sourceRoots: List + val classpath: Set + val sourceRoots: Set val dependentSourceSets: Set - val samples: List - val includes: List + val samples: Set + val includes: Set val includeNonPublic: Boolean val includeRootPackage: Boolean val reportUndocumented: Boolean val skipEmptyPackages: Boolean val skipDeprecated: Boolean val jdkVersion: Int - val sourceLinks: List + val sourceLinks: Set val perPackageOptions: List - val externalDocumentationLinks: List + val externalDocumentationLinks: Set val languageVersion: String? val apiVersion: String? val noStdlibLink: Boolean val noJdkLink: Boolean - val suppressedFiles: List + val suppressedFiles: Set val analysisPlatform: Platform } - interface SourceRoot : Serializable { - val directory: File - } - interface SourceLinkDefinition : Serializable { val path: String val url: String diff --git a/core/src/main/kotlin/defaultConfiguration.kt b/core/src/main/kotlin/defaultConfiguration.kt index 384ce392..1b79ec61 100644 --- a/core/src/main/kotlin/defaultConfiguration.kt +++ b/core/src/main/kotlin/defaultConfiguration.kt @@ -3,15 +3,13 @@ package org.jetbrains.dokka import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet import java.io.File import java.net.URL -import kotlin.reflect.full.memberProperties -import kotlin.reflect.full.primaryConstructor data class DokkaConfigurationImpl( override val outputDir: File = DokkaDefaults.outputDir, override val cacheRoot: File? = DokkaDefaults.cacheRoot, override val offlineMode: Boolean = DokkaDefaults.offlineMode, override val sourceSets: List = emptyList(), - override val pluginsClasspath: List = emptyList(), + override val pluginsClasspath: Set = emptySet(), override val pluginsConfiguration: Map = emptyMap(), override val modules: List = emptyList(), override val failOnWarning: Boolean = DokkaDefaults.failOnWarning @@ -22,25 +20,25 @@ data class DokkaSourceSetImpl( override val moduleDisplayName: String, override val displayName: String = DokkaDefaults.sourceSetDisplayName, override val sourceSetID: DokkaSourceSetID, - override val classpath: List = emptyList(), - override val sourceRoots: List, + override val classpath: Set = emptySet(), + override val sourceRoots: Set = emptySet(), override val dependentSourceSets: Set = emptySet(), - override val samples: List = emptyList(), - override val includes: List = emptyList(), + override val samples: Set = emptySet(), + override val includes: Set = emptySet(), override val includeNonPublic: Boolean = DokkaDefaults.includeNonPublic, override val includeRootPackage: Boolean = DokkaDefaults.includeRootPackage, override val reportUndocumented: Boolean = DokkaDefaults.reportUndocumented, override val skipEmptyPackages: Boolean = DokkaDefaults.skipEmptyPackages, override val skipDeprecated: Boolean = DokkaDefaults.skipDeprecated, override val jdkVersion: Int = DokkaDefaults.jdkVersion, - override val sourceLinks: List = emptyList(), + override val sourceLinks: Set = emptySet(), override val perPackageOptions: List = emptyList(), - override var externalDocumentationLinks: List = emptyList(), + override var externalDocumentationLinks: Set = emptySet(), override val languageVersion: String? = null, override val apiVersion: String? = null, override val noStdlibLink: Boolean = DokkaDefaults.noStdlibLink, override val noJdkLink: Boolean = DokkaDefaults.noJdkLink, - override val suppressedFiles: List = emptyList(), + override val suppressedFiles: Set = emptySet(), override val analysisPlatform: Platform = DokkaDefaults.analysisPlatform ) : DokkaSourceSet @@ -50,12 +48,6 @@ data class DokkaModuleDescriptionImpl( override val docFile: File ) : DokkaConfiguration.DokkaModuleDescription -data class SourceRootImpl( - override val directory: File -) : DokkaConfiguration.SourceRoot { - constructor(directoryPath: String) : this(File(directoryPath)) -} - data class SourceLinkDefinitionImpl( override val path: String, override val url: String, diff --git a/core/src/main/kotlin/utilities/json.kt b/core/src/main/kotlin/utilities/json.kt index feac2b23..211037d6 100644 --- a/core/src/main/kotlin/utilities/json.kt +++ b/core/src/main/kotlin/utilities/json.kt @@ -1,26 +1,18 @@ package org.jetbrains.dokka.utilities import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.JsonParser -import com.fasterxml.jackson.databind.DeserializationContext import com.fasterxml.jackson.databind.DeserializationFeature import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.deser.std.StdScalarDeserializer import com.fasterxml.jackson.databind.module.SimpleModule import com.fasterxml.jackson.databind.ser.std.StdScalarSerializer import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import org.jetbrains.dokka.DokkaConfiguration.SourceRoot -import org.jetbrains.dokka.SourceRootImpl import java.io.File import com.fasterxml.jackson.core.type.TypeReference as JacksonTypeReference private val objectMapper = run { val module = SimpleModule().apply { addSerializer(FileSerializer) - addSerializer(SourceRoot::class.java, SourceRootSerializer) - addDeserializer(SourceRootImpl::class.java, SourceRootImplDeserializer) - addDeserializer(SourceRoot::class.java, SourceRootImplDeserializer) } jacksonObjectMapper() .registerModule(module) @@ -53,13 +45,3 @@ private object FileSerializer : StdScalarSerializer(File::class.java) { g.writeString(value.path) } } - -private object SourceRootSerializer : StdScalarSerializer(SourceRoot::class.java) { - override fun serialize(value: SourceRoot, g: JsonGenerator, provider: SerializerProvider) { - g.writeString(value.directory.path) - } -} - -private object SourceRootImplDeserializer : StdScalarDeserializer(SourceRootImpl::class.java) { - override fun deserialize(p: JsonParser, ctxt: DeserializationContext): SourceRootImpl = SourceRootImpl(File(p.text)) -} diff --git a/core/src/test/kotlin/utilities/DokkaConfigurationJsonTest.kt b/core/src/test/kotlin/utilities/DokkaConfigurationJsonTest.kt index 35755f50..e8135f96 100644 --- a/core/src/test/kotlin/utilities/DokkaConfigurationJsonTest.kt +++ b/core/src/test/kotlin/utilities/DokkaConfigurationJsonTest.kt @@ -10,11 +10,11 @@ class DokkaConfigurationJsonTest { fun `simple configuration toJsonString then parseJson`() { val configuration = DokkaConfigurationImpl( outputDir = File("customOutputDir"), - pluginsClasspath = listOf(File("plugins/customPlugin.jar")), + pluginsClasspath = setOf(File("plugins/customPlugin.jar")), sourceSets = listOf( DokkaSourceSetImpl( moduleDisplayName = "customModuleDisplayName", - sourceRoots = listOf(SourceRootImpl(File("customSourceRoot"))), + sourceRoots = setOf(File("customSourceRoot")), sourceSetID = DokkaSourceSetID("customModuleName", "customSourceSetName") ) ) @@ -49,13 +49,13 @@ class DokkaConfigurationJsonTest { assertEquals( DokkaConfigurationImpl( outputDir = File("customOutputDir"), - pluginsClasspath = listOf(File("plugins/customPlugin.jar")), + pluginsClasspath = setOf(File("plugins/customPlugin.jar")), sourceSets = listOf( DokkaSourceSetImpl( moduleDisplayName = "customModuleDisplayName", - sourceRoots = listOf(SourceRootImpl(File("customSourceRoot"))), + sourceRoots = setOf(File("customSourceRoot")), sourceSetID = DokkaSourceSetID("customModuleName", "customSourceSetName"), - classpath = listOf(File("classpath/custom1.jar"), File("classpath/custom2.jar")) + classpath = setOf(File("classpath/custom1.jar"), File("classpath/custom2.jar")) ) ) ), -- cgit