diff options
Diffstat (limited to 'runners')
9 files changed, 170 insertions, 153 deletions
diff --git a/runners/cli/src/main/kotlin/cli/main.kt b/runners/cli/src/main/kotlin/cli/main.kt index 52815e75..55601b21 100644 --- a/runners/cli/src/main/kotlin/cli/main.kt +++ b/runners/cli/src/main/kotlin/cli/main.kt @@ -1,6 +1,7 @@ package org.jetbrains.dokka import org.jetbrains.dokka.DokkaConfiguration.ExternalDocumentationLink +import org.jetbrains.dokka.Utilities.defaultLinks import java.io.File import java.net.MalformedURLException import java.net.URL @@ -261,10 +262,11 @@ object MainKt { return configuration } + fun GlobalArguments.addDefaultLinks() = passesConfigurations.forEach { it.externalDocumentationLinks += it.defaultLinks() } + @JvmStatic fun main(args: Array<String>) { - val configuration = createConfiguration(args) - + val configuration = createConfiguration(args).apply { addDefaultLinks() } if (configuration.format.toLowerCase() == "javadoc") startWithToolsJar(configuration) else diff --git a/runners/gradle-integration-tests/src/test/kotlin/org/jetbrains/dokka/gradle/MultiplatformProjectTest.kt b/runners/gradle-integration-tests/src/test/kotlin/org/jetbrains/dokka/gradle/MultiplatformProjectTest.kt index 3e61d79e..6ab9fd52 100644 --- a/runners/gradle-integration-tests/src/test/kotlin/org/jetbrains/dokka/gradle/MultiplatformProjectTest.kt +++ b/runners/gradle-integration-tests/src/test/kotlin/org/jetbrains/dokka/gradle/MultiplatformProjectTest.kt @@ -40,8 +40,8 @@ class MultiplatformProjectTest : AbstractDokkaGradleTest() { checkNoUnresolvedLinks(docsOutput) } - @Test fun `test kotlin 1_3_30 and gradle 4_7`() { - doTest("4.7", "1.3.30") + @Test fun `test kotlin 1_3_30 and gradle 4_9`() { + doTest("4.9", "1.3.30") } @Test fun `test kotlin 1_3_40 and gradle 4_10_3`() { diff --git a/runners/gradle-integration-tests/testData/typeSafeConfiguration/build.gradle b/runners/gradle-integration-tests/testData/typeSafeConfiguration/build.gradle index 8688ae41..444d2ab3 100644 --- a/runners/gradle-integration-tests/testData/typeSafeConfiguration/build.gradle +++ b/runners/gradle-integration-tests/testData/typeSafeConfiguration/build.gradle @@ -52,11 +52,12 @@ def configureDokkaTypeSafely(DokkaTask dokka) { sourceRoot.path = "some String" } }) - externalDocumentationLink(new Action<GradleExternalDocumentationLinkImpl>() { + externalDocumentationLink(new Action<GradleExternalDocumentationLinkImpl.Builder>() { @Override - void execute(GradleExternalDocumentationLinkImpl link) { - link.url = uri("some URI").toURL() - link.packageListUrl = uri("some URI").toURL() + void execute(GradleExternalDocumentationLinkImpl.Builder builder) { + builder.url = uri("some URI").toURL() + builder.packageListUrl = uri("some URI").toURL() + builder.build() } }) kotlinTasks(new Callable<List<Object>>() { diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/ConfigurationExtractor.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/ConfigurationExtractor.kt index c66998d9..39672b9a 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/ConfigurationExtractor.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/ConfigurationExtractor.kt @@ -26,12 +26,19 @@ import java.io.Serializable class ConfigurationExtractor(private val project: Project) { - fun extractFromSinglePlatform(variantName: String? = null): PlatformData? { + fun extractConfiguration(targetName: String, variantNames: List<String>) = + if (project.isMultiplatformProject()) { + extractFromMultiPlatform(targetName, variantNames) + } else { + extractFromSinglePlatform(variantNames) + } + + private fun extractFromSinglePlatform(variantNames: List<String>): PlatformData? { val target: KotlinTarget try { target = project.extensions.getByType(KotlinSingleTargetExtension::class.java).target } catch (e: Throwable) { - when (e){ + when (e) { is UnknownDomainObjectException, is NoClassDefFoundError, is ClassNotFoundException -> return null else -> throw e @@ -39,34 +46,38 @@ class ConfigurationExtractor(private val project: Project) { } return try { - PlatformData(null, getClasspath(target, variantName), getSourceSet(target, variantName), getPlatformName(target.platformType)) - } catch(e: NoSuchMethodError){ + PlatformData( + null, + accumulateClassPaths(variantNames, target), + accumulateSourceSets(variantNames, target), + getPlatformName(target.platformType) + ) + } catch (e: NoSuchMethodError) { null } } - fun extractFromMultiPlatform(): List<PlatformData>? { - val targets: NamedDomainObjectCollection<KotlinTarget> + private fun extractFromMultiPlatform(targetName: String, variantNames: List<String>): PlatformData? = try { - targets = project.extensions.getByType(KotlinMultiplatformExtension::class.java).targets + project.extensions.getByType(KotlinMultiplatformExtension::class.java).targets } catch (e: Throwable) { - when (e){ + when (e) { is UnknownDomainObjectException, is NoClassDefFoundError, is ClassNotFoundException -> - return null + null else -> throw e } + }?.let { + val fixedName = if (targetName.toLowerCase() == "common") "metadata" else targetName.toLowerCase() + it.find { target -> target.name.toLowerCase() == fixedName }?.let { target -> + PlatformData( + fixedName, + accumulateClassPaths(variantNames, target), + accumulateSourceSets(variantNames, target), + target.platformType.toString() + ) + } } - val commonTargetPlatformData = targets.find { it.platformType == KotlinPlatformType.common }?.let { - PlatformData("common", getClasspath(it), getSourceSet(it), "common") - } - val config = targets.filter { it.platformType != KotlinPlatformType.common }.map { - PlatformData(it.name, getClasspath(it), getSourceSet(it), it.platformType.toString()) - } - - return (config + commonTargetPlatformData).filterNotNull() - } - fun extractFromJavaPlugin(): PlatformData? = project.convention.findPlugin(JavaPluginConvention::class.java) ?.run { sourceSets.findByName(SourceSet.MAIN_SOURCE_SET_NAME)?.allSource?.srcDirs } @@ -75,10 +86,15 @@ class ConfigurationExtractor(private val project: Project) { fun extractFromKotlinTasks(kotlinTasks: List<Task>): PlatformData? = try { kotlinTasks.map { extractFromKotlinTask(it) }.let { platformDataList -> - PlatformData(null, platformDataList.flatMap { it.classpath }, platformDataList.flatMap { it.sourceRoots }, "") + PlatformData( + null, + platformDataList.flatMap { it.classpath }, + platformDataList.flatMap { it.sourceRoots }, + "" + ) } } catch (e: Throwable) { - when (e){ + when (e) { is UnknownDomainObjectException, is NoClassDefFoundError, is ClassNotFoundException -> extractFromKotlinTasksTheHardWay(kotlinTasks) else -> throw e @@ -91,7 +107,7 @@ class ConfigurationExtractor(private val project: Project) { .compilations .find { it.compileKotlinTask == task } } catch (e: Throwable) { - when (e){ + when (e) { is UnknownDomainObjectException, is NoClassDefFoundError, is ClassNotFoundException -> project.extensions.getByType(KotlinMultiplatformExtension::class.java).targets .firstNotNullResult { target -> target.compilations.find { it.compileKotlinTask == task } } @@ -134,25 +150,22 @@ class ConfigurationExtractor(private val project: Project) { } catch (e: ResolveException) { mutableListOf() } - classpath.addAll (project.files(allClasspath).toList()) + classpath.addAll(project.files(allClasspath).toList()) return PlatformData(null, classpath, allSourceRoots.toList(), "") } - private fun getSourceSet(target: KotlinTarget, variantName: String? = null): List<File> = - if(variantName != null) + private fun getSourceSet(target: KotlinTarget, variantName: String): List<File> = + if (target.isAndroidTarget()) getSourceSet(getCompilation(target, variantName)) else getSourceSet(getMainCompilation(target)) - private fun getClasspath(target: KotlinTarget, variantName: String? = null): List<File> = if (target.isAndroidTarget()) { - if(variantName != null) + private fun getClasspath(target: KotlinTarget, variantName: String): List<File> = + if (target.isAndroidTarget()) getClasspathFromAndroidTask(getCompilation(target, variantName)) else - getClasspathFromAndroidTask(getMainCompilation(target)) - } else { - getClasspath(getMainCompilation(target)) - } + getClasspath(getMainCompilation(target)) private fun getSourceSet(compilation: KotlinCompilation<*>?): List<File> = compilation ?.allKotlinSourceSets @@ -185,7 +198,7 @@ class ConfigurationExtractor(private val project: Project) { private fun getVariants(project: Project): Set<BaseVariant> { val androidExtension = project.extensions.getByName("android") - val baseVariants = when (androidExtension) { + val baseVariants = when (androidExtension) { is AppExtension -> androidExtension.applicationVariants.toSet() is LibraryExtension -> { androidExtension.libraryVariants.toSet() + @@ -210,8 +223,26 @@ class ConfigurationExtractor(private val project: Project) { private fun getPlatformName(platform: KotlinPlatformType): String = if (platform == KotlinPlatformType.androidJvm) KotlinPlatformType.jvm.toString() else platform.toString() - data class PlatformData(val name: String?, - val classpath: List<File>, - val sourceRoots: List<File>, - val platform: String) : Serializable + private fun accumulateClassPaths(variantNames: List<String>, target: KotlinTarget) = + if (variantNames.isNotEmpty()) { + variantNames.flatMap { getClasspath(target, it) }.distinct() + } else { + if (target.isAndroidTarget()) + getClasspathFromAndroidTask(getMainCompilation(target)) + else + getClasspath(getMainCompilation(target)) + } + + private fun accumulateSourceSets(variantNames: List<String>, target: KotlinTarget) = + if (variantNames.isNotEmpty()) + variantNames.flatMap { getSourceSet(target, it) }.distinct() + else + getSourceSet(getMainCompilation(target)) + + data class PlatformData( + val name: String?, + val classpath: List<File>, + val sourceRoots: List<File>, + val platform: String + ) : Serializable }
\ No newline at end of file diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaTask.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaTask.kt index 5153ae1c..bafe657e 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaTask.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaTask.kt @@ -8,13 +8,13 @@ import org.gradle.api.internal.plugins.DslObject import org.gradle.api.plugins.JavaBasePlugin import org.gradle.api.tasks.* import org.jetbrains.dokka.DokkaBootstrap -import org.jetbrains.dokka.DokkaConfiguration import org.jetbrains.dokka.DokkaConfiguration.ExternalDocumentationLink.Builder import org.jetbrains.dokka.DokkaConfiguration.SourceRoot import org.jetbrains.dokka.Platform import org.jetbrains.dokka.ReflectDsl import org.jetbrains.dokka.ReflectDsl.isNotInstance import org.jetbrains.dokka.gradle.ConfigurationExtractor.PlatformData +import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType import java.io.File import java.net.URLClassLoader import java.util.concurrent.Callable @@ -53,6 +53,9 @@ open class DokkaTask : DefaultTask() { var dokkaRuntime: Configuration? = null @Input + var subProjects: List<String> = emptyList() + + @Input var impliedPlatforms: MutableList<String> = arrayListOf() @Optional @@ -72,31 +75,18 @@ open class DokkaTask : DefaultTask() { // Configure Dokka with closure in Gradle Kotlin DSL fun configuration(action: Action<in GradlePassConfigurationImpl>) = action.execute(configuration) - private var externalDocumentationLinks: MutableList<DokkaConfiguration.ExternalDocumentationLink> = mutableListOf() - private val kotlinTasks: List<Task> by lazy { extractKotlinCompileTasks(configuration.collectKotlinTasks ?: { defaultKotlinTasks() }) } private val configExtractor = ConfigurationExtractor(project) @Input - var subProjects: List<String> = emptyList() - - @Input var disableAutoconfiguration: Boolean = false private var outputDiagnosticInfo: Boolean = false // Workaround for Gradle, which fires some methods (like collectConfigurations()) multiple times in its lifecycle - private fun tryResolveFatJar(configuration: Configuration?): Set<File> { - return try { - configuration!!.resolve() - } catch (e: Exception) { - project.parent?.let { tryResolveFatJar(configuration) } ?: throw e - } - } - private fun loadFatJar() { if (ClassloaderContainer.fatJarClassLoader == null) { - val jars = tryResolveFatJar(dokkaRuntime).toList() + val jars = dokkaRuntime!!.resolve().toList() ClassloaderContainer.fatJarClassLoader = URLClassLoader(jars.map { it.toURI().toURL() }.toTypedArray(), ClassLoader.getSystemClassLoader().parent) } } @@ -124,7 +114,7 @@ open class DokkaTask : DefaultTask() { private fun Iterable<File>.toSourceRoots(): List<GradleSourceRootImpl> = this.filter { it.exists() }.map { GradleSourceRootImpl().apply { path = it.path } } private fun Iterable<String>.toProjects(): List<Project> = project.subprojects.toList().filter { this.contains(it.name) } - private fun collectSuppressedFiles(sourceRoots: List<SourceRoot>) = + protected open fun collectSuppressedFiles(sourceRoots: List<SourceRoot>) = if(project.isAndroidProject()) { val generatedRoot = project.buildDir.resolve("generated").absoluteFile sourceRoots @@ -153,7 +143,7 @@ open class DokkaTask : DefaultTask() { val globalConfig = multiplatform.toList().find { it.name.toLowerCase() == GLOBAL_PLATFORM_NAME } val passConfigurationList = collectConfigurations() - .map { defaultPassConfiguration(globalConfig, it) } + .map { defaultPassConfiguration(it, globalConfig) } val configuration = GradleDokkaConfigurationImpl() configuration.outputDir = outputDirectory @@ -163,6 +153,11 @@ open class DokkaTask : DefaultTask() { configuration.impliedPlatforms = impliedPlatforms configuration.passesConfigurations = passConfigurationList + if(passConfigurationList.isEmpty() || passConfigurationList == listOf(globalConfig)) { + println("No pass configurations for generation detected!") + return + } + bootstrapProxy.configure( BiConsumer { level, message -> when (level) { @@ -181,38 +176,15 @@ open class DokkaTask : DefaultTask() { } } - private fun collectConfigurations(): List<GradlePassConfigurationImpl> = - if (this.isMultiplatformProject()) collectFromMultiPlatform() else collectFromSinglePlatform() - - private fun collectFromMultiPlatform(): List<GradlePassConfigurationImpl> { - val userConfig = multiplatform - .filterNot { it.name.toLowerCase() == GLOBAL_PLATFORM_NAME } - .map { - if (it.collectKotlinTasks != null) { - configExtractor.extractFromKotlinTasks(extractKotlinCompileTasks(it.collectKotlinTasks!!)) - ?.let { platformData -> mergeUserConfigurationAndPlatformData(it, platformData) } ?: it - } else { - it - } - } - - if (disableAutoconfiguration) return userConfig - - val baseConfig = mergeUserAndAutoConfigurations( - userConfig, - configExtractor.extractFromMultiPlatform().orEmpty() - ) + protected open fun collectConfigurations() = + if (this.isMultiplatformProject()) collectMultiplatform() else listOf(collectSinglePlatform(configuration)) - return if (subProjects.isNotEmpty()) - subProjects.toProjects().fold(baseConfig) { list, subProject -> - mergeUserAndAutoConfigurations(list, ConfigurationExtractor(subProject).extractFromMultiPlatform().orEmpty()) - } - else - baseConfig - } + protected open fun collectMultiplatform() = multiplatform + .filterNot { it.name.toLowerCase() == GLOBAL_PLATFORM_NAME } + .map { collectSinglePlatform(it) } - private fun collectFromSinglePlatform(): List<GradlePassConfigurationImpl> { - val userConfig = configuration.let { + protected open fun collectSinglePlatform(config: GradlePassConfigurationImpl): GradlePassConfigurationImpl { + val userConfig = config.let { if (it.collectKotlinTasks != null) { configExtractor.extractFromKotlinTasks(extractKotlinCompileTasks(it.collectKotlinTasks!!)) ?.let { platformData -> mergeUserConfigurationAndPlatformData(it, platformData) } ?: it @@ -221,21 +193,27 @@ open class DokkaTask : DefaultTask() { } } - if (disableAutoconfiguration) return listOf(userConfig) + if (disableAutoconfiguration) return userConfig - val extractedConfig = configExtractor.extractFromSinglePlatform(userConfig.androidVariant) - val baseConfig = if (extractedConfig != null) - listOf(mergeUserConfigurationAndPlatformData(userConfig, extractedConfig)) - else - collectFromSinglePlatformOldPlugin() + val baseConfig = configExtractor.extractConfiguration(userConfig.name, userConfig.androidVariants) + ?.let { mergeUserConfigurationAndPlatformData(userConfig, it) } + ?: if (this.isMultiplatformProject()) { + if (outputDiagnosticInfo) + logger.warn("Could not find target with name: ${userConfig.name} in Kotlin Gradle Plugin, " + + "using only user provided configuration for this target") + userConfig + } else { + logger.warn("Could not find target with name: ${userConfig.name} in Kotlin Gradle Plugin") + collectFromSinglePlatformOldPlugin() + } return if (subProjects.isNotEmpty()) { try { - subProjects.toProjects().fold(baseConfig) { list, subProject -> - listOf(mergeUserConfigurationAndPlatformData( - list.first(), - ConfigurationExtractor(subProject).extractFromSinglePlatform()!! - )) + subProjects.toProjects().fold(baseConfig) { config, subProject -> + mergeUserConfigurationAndPlatformData( + config, + ConfigurationExtractor(subProject).extractConfiguration(config.name, config.androidVariants)!! + ) } } catch(e: NullPointerException) { logger.warn("Cannot extract sources from subProjects. Do you have the Kotlin plugin in version 1.3.30+ " + @@ -247,41 +225,14 @@ open class DokkaTask : DefaultTask() { } } - private fun collectFromSinglePlatformOldPlugin(): List<GradlePassConfigurationImpl> { - val kotlinTasks = configExtractor.extractFromKotlinTasks(kotlinTasks) - return if (kotlinTasks != null) { - listOf(mergeUserConfigurationAndPlatformData(configuration, kotlinTasks)) - } else { - val javaPlugin = configExtractor.extractFromJavaPlugin() - if (javaPlugin != null) - listOf(mergeUserConfigurationAndPlatformData(configuration, javaPlugin)) else listOf(configuration) - } - } - - private fun mergeUserAndAutoConfigurations(userConfigurations: List<GradlePassConfigurationImpl>, - autoConfigurations: List<PlatformData>): List<GradlePassConfigurationImpl> { - val merged: MutableList<GradlePassConfigurationImpl> = mutableListOf() - merged.addAll( - userConfigurations.map { userConfig -> - val autoConfig = autoConfigurations.find { autoConfig -> autoConfig.name == userConfig.name } - if (autoConfig != null) { - mergeUserConfigurationAndPlatformData(userConfig, autoConfig) - } else { - if(outputDiagnosticInfo) { - logger.warn( - "Could not find platform with name: ${userConfig.name} in Kotlin Gradle Plugin, " + - "using only user provided configuration for this platform" - ) - } - userConfig - } - } - ) - return merged.toList() - } + protected open fun collectFromSinglePlatformOldPlugin() = + configExtractor.extractFromKotlinTasks(kotlinTasks) + ?.let { mergeUserConfigurationAndPlatformData(configuration, it) } + ?: configExtractor.extractFromJavaPlugin() + ?.let { mergeUserConfigurationAndPlatformData(configuration, it) } + ?: configuration - private fun mergeUserConfigurationAndPlatformData(userConfig: GradlePassConfigurationImpl, - autoConfig: PlatformData): GradlePassConfigurationImpl = + protected open fun mergeUserConfigurationAndPlatformData(userConfig: GradlePassConfigurationImpl, autoConfig: PlatformData) = userConfig.copy().apply { sourceRoots.addAll(userConfig.sourceRoots.union(autoConfig.sourceRoots.toSourceRoots()).distinct()) classpath = userConfig.classpath.union(autoConfig.classpath.map { it.absolutePath }).distinct() @@ -289,7 +240,10 @@ open class DokkaTask : DefaultTask() { platform = autoConfig.platform } - private fun defaultPassConfiguration(globalConfig: GradlePassConfigurationImpl?, config: GradlePassConfigurationImpl): GradlePassConfigurationImpl { + protected open fun defaultPassConfiguration( + config: GradlePassConfigurationImpl, + globalConfig: GradlePassConfigurationImpl? + ): GradlePassConfigurationImpl { if (config.moduleName == "") { config.moduleName = project.name } @@ -304,7 +258,6 @@ open class DokkaTask : DefaultTask() { if (project.isAndroidProject() && !config.noAndroidSdkLink) { // TODO: introduce Android as a separate Dokka platform? config.externalDocumentationLinks.add(ANDROID_REFERENCE_URL) } - config.externalDocumentationLinks.addAll(externalDocumentationLinks) if (config.platform != null && config.platform.toString().isNotEmpty()) { config.analysisPlatform = dokkaPlatformFromString(config.platform.toString()) } @@ -319,7 +272,8 @@ open class DokkaTask : DefaultTask() { } private fun dokkaPlatformFromString(platform: String) = when (platform.toLowerCase()) { - "androidjvm", "android" -> Platform.jvm + KotlinPlatformType.androidJvm.toString().toLowerCase(), "androidjvm", "android" -> Platform.jvm + "metadata" -> Platform.common else -> Platform.fromString(platform) } diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/configurationImplementations.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/configurationImplementations.kt index 767bf4f4..65afad04 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/configurationImplementations.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/configurationImplementations.kt @@ -33,7 +33,7 @@ open class GradlePassConfigurationImpl(@Transient val name: String = ""): PassCo @Input override var includeNonPublic: Boolean = false @Input override var includeRootPackage: Boolean = false @Input override var reportUndocumented: Boolean = false - @Input override var skipEmptyPackages: Boolean = false + @Input override var skipEmptyPackages: Boolean = true @Input override var skipDeprecated: Boolean = false @Input override var jdkVersion: Int = 6 @Input override var sourceLinks: MutableList<SourceLinkDefinition> = mutableListOf() @@ -51,7 +51,7 @@ open class GradlePassConfigurationImpl(@Transient val name: String = ""): PassCo @Input override var targets: List<String> = emptyList() @Input @Optional override var sinceKotlin: String? = null @Transient var collectKotlinTasks: (() -> List<Any?>?)? = null - @Input @Optional @Transient var androidVariant: String? = null + @Input @Transient var androidVariants: List<String> = emptyList() fun kotlinTasks(taskSupplier: Callable<List<Any>>) { collectKotlinTasks = { taskSupplier.call() } @@ -95,14 +95,14 @@ open class GradlePassConfigurationImpl(@Transient val name: String = ""): PassCo } fun externalDocumentationLink(c: Closure<Unit>) { - val link = ConfigureUtil.configure(c, GradleExternalDocumentationLinkImpl()) - externalDocumentationLinks.add(link) + val builder = ConfigureUtil.configure(c, GradleExternalDocumentationLinkImpl.Builder()) + externalDocumentationLinks.add(builder.build()) } - fun externalDocumentationLink(action: Action<in GradleExternalDocumentationLinkImpl>) { - val link = GradleExternalDocumentationLinkImpl() - action.execute(link) - externalDocumentationLinks.add(link) + fun externalDocumentationLink(action: Action<in GradleExternalDocumentationLinkImpl.Builder>) { + val builder = GradleExternalDocumentationLinkImpl.Builder() + action.execute(builder) + externalDocumentationLinks.add(builder.build()) } } @@ -112,9 +112,23 @@ class GradleSourceLinkDefinitionImpl : SourceLinkDefinition, Serializable { override var lineSuffix: String? = null } -class GradleExternalDocumentationLinkImpl : ExternalDocumentationLink, Serializable { - override var url: URL = URL("http://") - override var packageListUrl: URL = URL("http://") +class GradleExternalDocumentationLinkImpl( + override val url: URL, + override val packageListUrl: URL +): ExternalDocumentationLink, Serializable { + open class Builder(open var url: URL? = null, + open var packageListUrl: URL? = null) { + + constructor(root: String, packageList: String? = null) : this(URL(root), packageList?.let { URL(it) }) + + fun build(): ExternalDocumentationLink = + if (packageListUrl != null && url != null) + GradleExternalDocumentationLinkImpl(url!!, packageListUrl!!) + else if (url != null) + GradleExternalDocumentationLinkImpl(url!!, URL(url!!, "package-list")) + else + throw IllegalArgumentException("url or url && packageListUrl must not be null for external documentation link") + } } class GradleDokkaConfigurationImpl: DokkaConfiguration { @@ -129,8 +143,8 @@ class GradleDokkaConfigurationImpl: DokkaConfiguration { class GradlePackageOptionsImpl: PackageOptions, Serializable { override var prefix: String = "" override var includeNonPublic: Boolean = false - override var reportUndocumented: Boolean = true - override var skipDeprecated: Boolean = true + override var reportUndocumented: Boolean = false + override var skipDeprecated: Boolean = false override var suppress: Boolean = false } diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/main.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/main.kt index 6f8d55e4..7ed29c58 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/main.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/main.kt @@ -27,7 +27,7 @@ open class DokkaPlugin : Plugin<Project> { defaultDependencies{ dependencies -> dependencies.add(project.dependencies.create("org.jetbrains.dokka:dokka-fatjar:${DokkaVersion.version}")) } } - private fun addTasks(project: Project, runtimeConfiguration: Configuration, taskClass: Class<out DokkaTask>) { + protected open fun addTasks(project: Project, runtimeConfiguration: Configuration, taskClass: Class<out DokkaTask>) { if(GradleVersion.current() >= GradleVersion.version("4.10")) { project.tasks.register(taskName, taskClass) } else { diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/utils.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/utils.kt index d70b0499..31892e8e 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/utils.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/utils.kt @@ -2,6 +2,7 @@ package org.jetbrains.dokka.gradle import org.gradle.api.Project import org.gradle.api.UnknownDomainObjectException +import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType import org.jetbrains.kotlin.gradle.plugin.KotlinTarget @@ -15,5 +16,16 @@ fun Project.isAndroidProject() = try { false } +fun Project.isMultiplatformProject() = try { + project.extensions.getByType(KotlinMultiplatformExtension::class.java) + true +} catch(e: UnknownDomainObjectException) { + false +} catch (e: NoClassDefFoundError){ + false +} catch(e: ClassNotFoundException) { + false +} + fun KotlinTarget.isAndroidTarget() = this.platformType == KotlinPlatformType.androidJvm fun DokkaTask.isMultiplatformProject() = this.multiplatform.isNotEmpty()
\ No newline at end of file diff --git a/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt b/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt index fb11ecac..1cbe39f3 100644 --- a/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt +++ b/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt @@ -11,6 +11,7 @@ import org.apache.maven.project.MavenProjectHelper import org.codehaus.plexus.archiver.Archiver import org.codehaus.plexus.archiver.jar.JarArchiver import org.jetbrains.dokka.* +import org.jetbrains.dokka.Utilities.defaultLinks import java.io.File import java.net.URL @@ -183,6 +184,8 @@ abstract class AbstractDokkaMojo : AbstractMojo() { includeRootPackage = includeRootPackage ) + passConfiguration.externalDocumentationLinks += passConfiguration.defaultLinks() + val configuration = DokkaConfigurationImpl( outputDir = getOutDir(), format = getOutFormat(), |