diff options
-rw-r--r-- | core/src/main/kotlin/DokkaBootstrapImpl.kt | 3 | ||||
-rw-r--r-- | core/src/main/kotlin/Generation/configurationImpl.kt | 3 | ||||
-rw-r--r-- | core/src/main/kotlin/Kotlin/DocumentationBuilder.kt | 9 | ||||
-rw-r--r-- | core/src/main/kotlin/Kotlin/ExternalDocumentationLinkResolver.kt | 10 | ||||
-rw-r--r-- | core/src/test/kotlin/TestAPI.kt | 3 | ||||
-rw-r--r-- | integration/src/main/kotlin/org/jetbrains/dokka/configuration.kt | 4 | ||||
-rw-r--r-- | runners/ant/src/main/kotlin/ant/dokka.kt | 5 | ||||
-rw-r--r-- | runners/cli/src/main/kotlin/cli/main.kt | 8 | ||||
-rw-r--r-- | runners/gradle-plugin/src/main/kotlin/main.kt | 5 | ||||
-rw-r--r-- | runners/maven-plugin/src/main/kotlin/DokkaMojo.kt | 6 |
10 files changed, 40 insertions, 16 deletions
diff --git a/core/src/main/kotlin/DokkaBootstrapImpl.kt b/core/src/main/kotlin/DokkaBootstrapImpl.kt index 593c6db1..b4af636a 100644 --- a/core/src/main/kotlin/DokkaBootstrapImpl.kt +++ b/core/src/main/kotlin/DokkaBootstrapImpl.kt @@ -63,7 +63,8 @@ class DokkaBootstrapImpl : DokkaBootstrap { impliedPlatforms, perPackageOptions, externalDocumentationLinks, - noStdlibLink + noStdlibLink, + cacheRoot ) ) } diff --git a/core/src/main/kotlin/Generation/configurationImpl.kt b/core/src/main/kotlin/Generation/configurationImpl.kt index cdc9752d..9b4013ad 100644 --- a/core/src/main/kotlin/Generation/configurationImpl.kt +++ b/core/src/main/kotlin/Generation/configurationImpl.kt @@ -52,4 +52,5 @@ data class DokkaConfigurationImpl(override val moduleName: String, override val impliedPlatforms: List<String>, override val perPackageOptions: List<PackageOptionsImpl>, override val externalDocumentationLinks: List<ExternalDocumentationLinkImpl>, - override val noStdlibLink: Boolean) : DokkaConfiguration
\ No newline at end of file + override val noStdlibLink: Boolean, + override val cacheRoot: String?) : DokkaConfiguration
\ No newline at end of file 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()) { diff --git a/core/src/test/kotlin/TestAPI.kt b/core/src/test/kotlin/TestAPI.kt index 2d937679..e11274ea 100644 --- a/core/src/test/kotlin/TestAPI.kt +++ b/core/src/test/kotlin/TestAPI.kt @@ -33,7 +33,8 @@ fun verifyModel(vararg roots: ContentRoot, includeRootPackage = true, sourceLinks = listOf<SourceLinkDefinition>(), generateIndexPages = false, - noStdlibLink = true) + noStdlibLink = true, + cacheRoot = "default") appendDocumentation(documentation, *roots, withJdk = withJdk, diff --git a/integration/src/main/kotlin/org/jetbrains/dokka/configuration.kt b/integration/src/main/kotlin/org/jetbrains/dokka/configuration.kt index f9846a9e..b28f0713 100644 --- a/integration/src/main/kotlin/org/jetbrains/dokka/configuration.kt +++ b/integration/src/main/kotlin/org/jetbrains/dokka/configuration.kt @@ -37,6 +37,7 @@ interface DokkaConfiguration { val perPackageOptions: List<PackageOptions> val externalDocumentationLinks: List<DokkaConfiguration.ExternalDocumentationLink> val noStdlibLink: Boolean + val cacheRoot: String? interface SourceRoot { val path: String @@ -94,7 +95,8 @@ data class SerializeOnlyDokkaConfiguration(override val moduleName: String, override val impliedPlatforms: List<String>, override val perPackageOptions: List<DokkaConfiguration.PackageOptions>, override val externalDocumentationLinks: List<DokkaConfiguration.ExternalDocumentationLink>, - override val noStdlibLink: Boolean) : DokkaConfiguration + override val noStdlibLink: Boolean, + override val cacheRoot: String?) : DokkaConfiguration data class ExternalDocumentationLinkImpl(@CustomSerializer(UrlSerializer::class) override val url: URL, diff --git a/runners/ant/src/main/kotlin/ant/dokka.kt b/runners/ant/src/main/kotlin/ant/dokka.kt index 964c77a5..fb70aefd 100644 --- a/runners/ant/src/main/kotlin/ant/dokka.kt +++ b/runners/ant/src/main/kotlin/ant/dokka.kt @@ -42,6 +42,8 @@ class DokkaAntTask: Task() { var skipDeprecated: Boolean = false + var cacheRoot: String? = null + val compileClasspath: Path by lazy { Path(getProject()) } val sourcePath: Path by lazy { Path(getProject()) } val samplesPath: Path by lazy { Path(getProject()) } @@ -122,7 +124,8 @@ class DokkaAntTask: Task() { impliedPlatforms = impliedPlatforms.split(','), perPackageOptions = antPackageOptions, externalDocumentationLinks = antExternalDocumentationLinks.map { it.build() }, - noStdlibLink = noStdlibLink + noStdlibLink = noStdlibLink, + cacheRoot = cacheRoot ) ) generator.generate() diff --git a/runners/cli/src/main/kotlin/cli/main.kt b/runners/cli/src/main/kotlin/cli/main.kt index 9a852b5a..70336b9e 100644 --- a/runners/cli/src/main/kotlin/cli/main.kt +++ b/runners/cli/src/main/kotlin/cli/main.kt @@ -58,8 +58,11 @@ class DokkaArguments { @set:Argument(value = "links", description = "External documentation links in format url^packageListUrl^^url2...") var links: String = "" - @set: Argument(value = "noStdlibLink", description = "Disable documentation link to stdlib") + @set:Argument(value = "noStdlibLink", description = "Disable documentation link to stdlib") var noStdlibLink: Boolean = false + + @set:Argument(value = "cacheRoot", description = "Path to cache folder, or 'default' to use ~/.cache/dokka, if not provided caching is disabled") + var cacheRoot: String? = null } @@ -112,7 +115,8 @@ object MainKt { perPackageOptions = parsePerPackageOptions(arguments.packageOptions), jdkVersion = arguments.jdkVersion, externalDocumentationLinks = parseLinks(arguments.links), - noStdlibLink = arguments.noStdlibLink + noStdlibLink = arguments.noStdlibLink, + cacheRoot = arguments.cacheRoot ) val generator = DokkaGenerator( diff --git a/runners/gradle-plugin/src/main/kotlin/main.kt b/runners/gradle-plugin/src/main/kotlin/main.kt index afd1f762..ad5f3038 100644 --- a/runners/gradle-plugin/src/main/kotlin/main.kt +++ b/runners/gradle-plugin/src/main/kotlin/main.kt @@ -89,6 +89,8 @@ open class DokkaTask : DefaultTask() { @Input var noStdlibLink: Boolean = false + @Input var cacheRoot: String? = null + protected open val sdkProvider: SdkProvider? = null fun linkMapping(closure: Closure<Any?>) { @@ -197,7 +199,8 @@ open class DokkaTask : DefaultTask() { impliedPlatforms, perPackageOptions, externalDocumentationLinks, - noStdlibLink) + noStdlibLink, + cacheRoot) bootstrapProxy.configure( diff --git a/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt b/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt index fc358a90..345de523 100644 --- a/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt +++ b/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt @@ -102,6 +102,9 @@ abstract class AbstractDokkaMojo : AbstractMojo() { @Parameter(defaultValue = "false") var noStdlibLink: Boolean = false + @Parameter + var cacheRoot: String? = null + protected abstract fun getOutDir(): String protected abstract fun getOutFormat(): String @@ -127,7 +130,8 @@ abstract class AbstractDokkaMojo : AbstractMojo() { impliedPlatforms = impliedPlatforms, perPackageOptions = perPackageOptions, externalDocumentationLinks = externalDocumentationLinks.map { it.build() }, - noStdlibLink = noStdlibLink + noStdlibLink = noStdlibLink, + cacheRoot = cacheRoot ) ) |