diff options
Diffstat (limited to 'core/src/main/kotlin/Kotlin')
-rw-r--r-- | core/src/main/kotlin/Kotlin/DocumentationBuilder.kt | 9 | ||||
-rw-r--r-- | core/src/main/kotlin/Kotlin/ExternalDocumentationLinkResolver.kt | 10 |
2 files changed, 12 insertions, 7 deletions
diff --git a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt index c258ef2c..824d74bb 100644 --- a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt +++ b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt @@ -29,6 +29,7 @@ import org.jetbrains.kotlin.resolve.source.getPsi import org.jetbrains.kotlin.types.* import org.jetbrains.kotlin.types.typeUtil.isSubtypeOf import org.jetbrains.kotlin.types.typeUtil.supertypes +import java.nio.file.Path import java.nio.file.Paths import com.google.inject.name.Named as GuiceNamed @@ -47,7 +48,7 @@ class DocumentationOptions(val outputDir: String, perPackageOptions: List<PackageOptions> = emptyList(), externalDocumentationLinks: List<ExternalDocumentationLink> = emptyList(), noStdlibLink: Boolean, - val cacheRoot: String = Paths.get(System.getProperty("user.home"), ".cache", "dokka").toString()) { + cacheRoot: String? = null) { init { if (perPackageOptions.any { it.prefix == "" }) throw IllegalArgumentException("Please do not register packageOptions with all match pattern, use global settings instead") @@ -67,6 +68,12 @@ class DocumentationOptions(val outputDir: String, } val externalDocumentationLinks = defaultLinks + externalDocumentationLinks + + val cacheRoot: Path? = when { + cacheRoot == "default" -> Paths.get(System.getProperty("user.home"), ".cache", "dokka") + cacheRoot != null -> Paths.get(cacheRoot) + else -> null + } } private fun isExtensionForExternalClass(extensionFunctionDescriptor: DeclarationDescriptor, diff --git a/core/src/main/kotlin/Kotlin/ExternalDocumentationLinkResolver.kt b/core/src/main/kotlin/Kotlin/ExternalDocumentationLinkResolver.kt index bdf426e0..84d83c73 100644 --- a/core/src/main/kotlin/Kotlin/ExternalDocumentationLinkResolver.kt +++ b/core/src/main/kotlin/Kotlin/ExternalDocumentationLinkResolver.kt @@ -17,7 +17,6 @@ import java.io.ByteArrayOutputStream import java.io.PrintWriter import java.net.URL import java.nio.file.Path -import java.nio.file.Paths import java.security.MessageDigest fun ByteArray.toHexString() = this.joinToString(separator = "") { "%02x".format(it) } @@ -33,8 +32,7 @@ class ExternalDocumentationLinkResolver @Inject constructor( class ExternalDocumentationRoot(val rootUrl: URL, val resolver: InboundExternalLinkResolutionService, val locations: Map<String, String>) - // TODO: Make configurable - val cacheDir: Path = Paths.get(options.cacheRoot, "packageListCache").apply { createDirectories() } + val cacheDir: Path? = options.cacheRoot?.resolve("packageListCache")?.apply { createDirectories() } val cachedProtocols = setOf("http", "https", "ftp") @@ -43,11 +41,11 @@ class ExternalDocumentationLinkResolver @Inject constructor( val packageListUrl = link.packageListUrl val needsCache = packageListUrl.protocol in cachedProtocols - val packageListStream = if (needsCache) { - val text = packageListUrl.toExternalForm() + val packageListStream = if (cacheDir != null && needsCache) { + val packageListLink = packageListUrl.toExternalForm() val digest = MessageDigest.getInstance("SHA-256") - val hash = digest.digest(text.toByteArray(Charsets.UTF_8)).toHexString() + val hash = digest.digest(packageListLink.toByteArray(Charsets.UTF_8)).toHexString() val cacheEntry = cacheDir.resolve(hash) if (cacheEntry.exists()) { |