diff options
Diffstat (limited to 'runners/gradle-plugin/src')
2 files changed, 64 insertions, 35 deletions
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 104635dc..f3ce7d6f 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,18 +26,19 @@ import java.io.Serializable class ConfigurationExtractor(private val project: Project) { - fun extractConfiguration(targetName: String, variantNames: List<String>) = if (project.isMultiplatformProject()) { - extractFromMultiPlatform(targetName, variantNames) - } else { - extractFromSinglePlatform(variantNames) - } + 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 @@ -45,9 +46,13 @@ class ConfigurationExtractor(private val project: Project) { } return try { - - PlatformData(null, accumulateClassPaths(variantNames, target), accumulateSourceSets(variantNames, target), getPlatformName(target.platformType)) - } catch(e: NoSuchMethodError){ + PlatformData( + null, + accumulateClassPaths(variantNames, target), + accumulateSourceSets(variantNames, target), + getPlatformName(target.platformType) + ) + } catch (e: NoSuchMethodError) { null } } @@ -56,16 +61,20 @@ class ConfigurationExtractor(private val project: Project) { try { project.extensions.getByType(KotlinMultiplatformExtension::class.java).targets } catch (e: Throwable) { - when (e){ + when (e) { is UnknownDomainObjectException, is NoClassDefFoundError, is ClassNotFoundException -> null else -> throw e } }?.let { - val fixedName = if(targetName.toLowerCase() == "common") "metadata" else targetName.toLowerCase() + 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()) + PlatformData( + fixedName, + accumulateClassPaths(variantNames, target), + accumulateSourceSets(variantNames, target), + target.platformType.toString() + ) } } @@ -77,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 @@ -93,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 } } @@ -136,7 +150,7 @@ 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(), "") } @@ -184,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,20 +224,21 @@ class ConfigurationExtractor(private val project: Project) { if (platform == KotlinPlatformType.androidJvm) KotlinPlatformType.jvm.toString() else platform.toString() private fun accumulateClassPaths(variantNames: List<String>, target: KotlinTarget) = - if(variantNames.isNotEmpty()) + if (variantNames.isNotEmpty()) variantNames.flatMap { getClasspath(target, it) }.distinct() else getClasspath(getMainCompilation(target)) private fun accumulateSourceSets(variantNames: List<String>, target: KotlinTarget) = - if(variantNames.isNotEmpty()) + 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 + 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/configurationImplementations.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/configurationImplementations.kt index 55d110f4..0bf21d57 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 @@ -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 androidVariants: List<String> = emptyList() + @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 { |