aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Doległo <kamilok1965@interia.pl>2019-04-08 17:22:04 +0200
committerKamil Doległo <kamilok1965@interia.pl>2019-04-08 17:22:04 +0200
commit49800d9c8276ec8851bcc3b181563cd6e0f8f4b9 (patch)
tree16462fc1425e5d53cbc53fcd4d0bacd3435fde5c
parent9975b7209f55edfe7e2f1a48e8d1f8b3c522e71a (diff)
downloaddokka-49800d9c8276ec8851bcc3b181563cd6e0f8f4b9.tar.gz
dokka-49800d9c8276ec8851bcc3b181563cd6e0f8f4b9.tar.bz2
dokka-49800d9c8276ec8851bcc3b181563cd6e0f8f4b9.zip
Implement Gradle Pass Configuration
-rw-r--r--core/build.gradle1
-rw-r--r--core/src/main/kotlin/DokkaBootstrapImpl.kt11
-rw-r--r--integration/build.gradle4
-rw-r--r--integration/src/main/kotlin/org/jetbrains/dokka/configuration.kt23
-rw-r--r--integration/src/main/kotlin/org/jetbrains/dokka/defaultConfiguration.kt12
-rw-r--r--runners/gradle-plugin/build.gradle1
-rw-r--r--runners/gradle-plugin/src/main/kotlin/main.kt227
7 files changed, 188 insertions, 91 deletions
diff --git a/core/build.gradle b/core/build.gradle
index 0008bfd7..4c140df3 100644
--- a/core/build.gradle
+++ b/core/build.gradle
@@ -47,6 +47,7 @@ dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile group: 'org.jetbrains.kotlin', name: 'kotlin-test-junit', version: kotlin_version
testCompile "com.nhaarman:mockito-kotlin-kt1.1:1.5.0"
+ implementation 'com.google.code.gson:gson:2.8.5'
testCompile ideaRT()
} \ No newline at end of file
diff --git a/core/src/main/kotlin/DokkaBootstrapImpl.kt b/core/src/main/kotlin/DokkaBootstrapImpl.kt
index 2077458a..b48b62d4 100644
--- a/core/src/main/kotlin/DokkaBootstrapImpl.kt
+++ b/core/src/main/kotlin/DokkaBootstrapImpl.kt
@@ -1,8 +1,6 @@
package org.jetbrains.dokka
-import com.intellij.openapi.util.Pass
-import kotlinx.serialization.*
-import kotlinx.serialization.json.Json
+import com.google.gson.Gson
import org.jetbrains.dokka.DokkaConfiguration.PackageOptions
import java.util.function.BiConsumer
@@ -41,9 +39,7 @@ class DokkaBootstrapImpl : DokkaBootstrap {
}
lateinit var generator: DokkaGenerator
-
- override fun configure(logger: BiConsumer<String, String>, serializedConfigurationJSON: String)
- = configure(DokkaProxyLogger(logger), Json.parse(DokkaConfigurationImpl.serializer(), serializedConfigurationJSON))
+ val gson = Gson()
fun configure(logger: DokkaLogger, configuration: DokkaConfigurationImpl) = with(configuration) {
@@ -73,5 +69,8 @@ class DokkaBootstrapImpl : DokkaBootstrap {
generator = DokkaGenerator(configurationWithLinks, logger)
}
+ override fun configure(logger: BiConsumer<String, String>, serializedConfigurationJSON: String)
+ = configure(DokkaProxyLogger(logger), gson.fromJson(serializedConfigurationJSON, DokkaConfigurationImpl::class.java))
+
override fun generate() = generator.generate()
}
diff --git a/integration/build.gradle b/integration/build.gradle
index ce95844c..3f4297ee 100644
--- a/integration/build.gradle
+++ b/integration/build.gradle
@@ -3,12 +3,10 @@ buildscript {
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
- classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
}
}
apply plugin: 'kotlin'
-apply plugin: 'kotlinx-serialization'
sourceCompatibility = 1.8
@@ -23,5 +21,5 @@ tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
dependencies {
compileOnly group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib', version: kotlin_for_gradle_runtime_version
compileOnly group: 'org.jetbrains.kotlin', name: 'kotlin-reflect', version: kotlin_for_gradle_runtime_version
- compile "org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.10.0"
+ implementation 'com.google.code.gson:gson:2.8.5'
} \ No newline at end of file
diff --git a/integration/src/main/kotlin/org/jetbrains/dokka/configuration.kt b/integration/src/main/kotlin/org/jetbrains/dokka/configuration.kt
index 717fa477..49481089 100644
--- a/integration/src/main/kotlin/org/jetbrains/dokka/configuration.kt
+++ b/integration/src/main/kotlin/org/jetbrains/dokka/configuration.kt
@@ -1,26 +1,7 @@
package org.jetbrains.dokka
-import kotlinx.serialization.*
-import kotlinx.serialization.internal.StringDescriptor
import java.net.URL
-
-@Serializer(forClass = URL::class)
-object UrlSerializer: KSerializer<URL> {
-
- override val descriptor: SerialDescriptor =
- StringDescriptor.withName("WithCustomDefault")
-
- override fun deserialize(decoder: Decoder): URL {
- return URL(decoder.decodeString())
- }
-
- override fun serialize(encoder: Encoder, obj: URL) {
- encoder.encodeString(obj.toExternalForm())
- }
-}
-
-
enum class Platform(val key: String) {
jvm("jvm"),
js("js"),
@@ -97,8 +78,8 @@ interface DokkaConfiguration {
}
interface ExternalDocumentationLink {
- @Serializable(with = UrlSerializer::class) val url: URL
- @Serializable(with = UrlSerializer::class) val packageListUrl: URL
+ val url: URL
+ val packageListUrl: URL
open class Builder(open var url: URL? = null,
open var packageListUrl: URL? = null) {
diff --git a/integration/src/main/kotlin/org/jetbrains/dokka/defaultConfiguration.kt b/integration/src/main/kotlin/org/jetbrains/dokka/defaultConfiguration.kt
index 615f0215..6d754ebc 100644
--- a/integration/src/main/kotlin/org/jetbrains/dokka/defaultConfiguration.kt
+++ b/integration/src/main/kotlin/org/jetbrains/dokka/defaultConfiguration.kt
@@ -1,10 +1,8 @@
package org.jetbrains.dokka
-import kotlinx.serialization.Serializable
import java.io.File
import java.net.URL
-@Serializable
data class DokkaConfigurationImpl(
override val outputDir: String,
override val format: String,
@@ -14,7 +12,6 @@ data class DokkaConfigurationImpl(
override val passesConfigurations: List<PassConfigurationImpl>
) : DokkaConfiguration
-@Serializable
data class PassConfigurationImpl (
override val moduleName: String,
override val classpath: List<String>,
@@ -41,12 +38,11 @@ data class PassConfigurationImpl (
override val sinceKotlin: String
) : DokkaConfiguration.PassConfiguration
-@Serializable
+
data class SourceRootImpl(
override val path: String
): DokkaConfiguration.SourceRoot
-@Serializable
data class SourceLinkDefinitionImpl(
override val path: String,
override val url: String,
@@ -63,7 +59,6 @@ data class SourceLinkDefinitionImpl(
}
}
-@Serializable
data class PackageOptionsImpl(
override val prefix: String,
override val includeNonPublic: Boolean,
@@ -73,7 +68,6 @@ data class PackageOptionsImpl(
): DokkaConfiguration.PackageOptions
-@Serializable
-data class ExternalDocumentationLinkImpl(@Serializable(with = UrlSerializer::class) override val url: URL,
- @Serializable(with = UrlSerializer::class) override val packageListUrl: URL
+data class ExternalDocumentationLinkImpl(override val url: URL,
+ override val packageListUrl: URL
) : DokkaConfiguration.ExternalDocumentationLink \ No newline at end of file
diff --git a/runners/gradle-plugin/build.gradle b/runners/gradle-plugin/build.gradle
index 1c307588..97a6b697 100644
--- a/runners/gradle-plugin/build.gradle
+++ b/runners/gradle-plugin/build.gradle
@@ -28,6 +28,7 @@ dependencies {
compileOnly gradleApi()
compileOnly localGroovy()
+ implementation 'com.google.code.gson:gson:2.8.5'
}
task sourceJar(type: Jar) {
diff --git a/runners/gradle-plugin/src/main/kotlin/main.kt b/runners/gradle-plugin/src/main/kotlin/main.kt
index ef7bd41f..555dece4 100644
--- a/runners/gradle-plugin/src/main/kotlin/main.kt
+++ b/runners/gradle-plugin/src/main/kotlin/main.kt
@@ -1,13 +1,8 @@
package org.jetbrains.dokka.gradle
+import com.google.gson.GsonBuilder
import groovy.lang.Closure
-import kotlinx.serialization.*
-import kotlinx.serialization.json.Json
-import org.gradle.api.Action
-import org.gradle.api.DefaultTask
-import org.gradle.api.Plugin
-import org.gradle.api.Project
-import org.gradle.api.Task
+import org.gradle.api.*
import org.gradle.api.artifacts.Configuration
import org.gradle.api.file.FileCollection
import org.gradle.api.plugins.JavaBasePlugin
@@ -23,6 +18,7 @@ import org.jetbrains.dokka.gradle.DokkaVersion.version
import java.io.File
import java.io.InputStream
import java.io.Serializable
+import java.net.URL
import java.net.URLClassLoader
import java.util.*
import java.util.concurrent.Callable
@@ -32,6 +28,10 @@ open class DokkaPlugin : Plugin<Project> {
override fun apply(project: Project) {
DokkaVersion.loadFrom(javaClass.getResourceAsStream("/META-INF/gradle-plugins/org.jetbrains.dokka.properties"))
+
+ val passConfiguration= project.container(GradlePassConfigurationImpl::class.java)
+ project.extensions.add("passConfigurations", passConfiguration)
+
project.tasks.create("dokka", DokkaTask::class.java).apply {
dokkaRuntime = project.configurations.create("dokkaRuntime")
moduleName = project.name
@@ -40,6 +40,7 @@ open class DokkaPlugin : Plugin<Project> {
}
}
+
object DokkaVersion {
var version: String? = null
@@ -137,6 +138,25 @@ open class DokkaTask : DefaultTask() {
@Optional @Input
var targets: List<String> = listOf()
+// @Input var passConfigurations: MutableList<GradlePassConfigurationImpl> = arrayListOf()
+
+// fun passConfiguration(action: Action<GradlePassConfigurationImpl>) {
+// val passConfig = GradlePassConfigurationImpl()
+// action.execute(passConfig)
+// passConfigurations.add(passConfig)
+// }
+//
+// fun passConfiguration(closure: Closure<Unit>) {
+// passConfiguration(Action {
+// closure.delegate = it
+// closure.call()
+// })
+// }
+
+// fun passConfiguration(closure: Closure<Unit>) {
+// closure.call()
+// passConfiguration = mutableListOf(PassConfigurationImpl(targets = closure.getProperty("targets") as List<String>))
+// }
private var kotlinTasksConfigurator: () -> List<Any?>? = { defaultKotlinTasks() }
private val kotlinTasks: List<Task> by lazy { extractKotlinCompileTasks() }
@@ -286,7 +306,6 @@ open class DokkaTask : DefaultTask() {
protected open fun collectSuppressedFiles(sourceRoots: List<SourceRoot>): List<String> = emptyList()
- @ImplicitReflectionSerializer
@TaskAction
fun generate() {
if (dokkaRuntime == null){
@@ -314,48 +333,55 @@ open class DokkaTask : DefaultTask() {
val bootstrapInstance = bootstrapClass.constructors.first().newInstance()
val bootstrapProxy: DokkaBootstrap = automagicTypedProxy(javaClass.classLoader, bootstrapInstance)
-
- val configuration = DokkaConfigurationImpl(
- outputDirectory,
- outputFormat,
- true,
- cacheRoot,
- impliedPlatforms,
- listOf(PassConfigurationImpl(
- classpath= fullClasspath.map { it.absolutePath },
- sourceRoots = sourceRoots.map { SourceRootImpl(it.path) },
- samples = samples.filterNotNull().map { project.file(it).absolutePath },
- includes = includes.filterNotNull().map { project.file(it).absolutePath },
- collectInheritedExtensionsFromLibraries = collectInheritedExtensionsFromLibraries,
- perPackageOptions = perPackageOptions.map{PackageOptionsImpl(
- prefix = it.prefix,
- includeNonPublic = it.includeNonPublic,
- reportUndocumented = it.reportUndocumented,
- skipDeprecated = it.skipDeprecated,
- suppress = it.suppress
- )},
- moduleName = moduleName,
- includeNonPublic = includeNonPublic,
- includeRootPackage = false,
- reportUndocumented = reportUndocumented,
- skipEmptyPackages = skipEmptyPackages,
- skipDeprecated = skipDeprecated,
- jdkVersion = jdkVersion,
- languageVersion = languageVersion,
- apiVersion = apiVersion,
- noStdlibLink = noStdlibLink,
- noJdkLink = noJdkLink,
- suppressedFiles = collectSuppressedFiles(sourceRoots),
- sinceKotlin = "1.0",
- analysisPlatform = Platform.DEFAULT,
- targets = targets,
- sourceLinks = mutableListOf(), // TODO: check this line
- externalDocumentationLinks = externalDocumentationLinks.map {
- ExternalDocumentationLinkImpl(it.url, it.packageListUrl)
- }
- )
- )
- )
+ val gson = GsonBuilder().setPrettyPrinting().create()
+
+
+ val configuration = GradleDokkaConfigurationImpl()
+ configuration.outputDir = outputDirectory
+ configuration.format = outputFormat
+ configuration.generateIndexPages = true
+ configuration.cacheRoot = cacheRoot
+ configuration.impliedPlatforms = impliedPlatforms
+ configuration.passesConfigurations =
+ (project.extensions.getByName("passConfigurations") as Iterable<GradlePassConfigurationImpl>)
+ .toList()
+ .map { defaultPassConfiguration(it) }
+
+// listOf(PassConfigurationImpl(
+// classpath= fullClasspath.map { it.absolutePath },
+// sourceRoots = sourceRoots.map { SourceRootImpl(it.path) },
+// samples = samples.filterNotNull().map { project.file(it).absolutePath },
+// includes = includes.filterNotNull().map { project.file(it).absolutePath },
+// collectInheritedExtensionsFromLibraries = collectInheritedExtensionsFromLibraries,
+// perPackageOptions = perPackageOptions.map{PackageOptionsImpl(
+// prefix = it.prefix,
+// includeNonPublic = it.includeNonPublic,
+// reportUndocumented = it.reportUndocumented,
+// skipDeprecated = it.skipDeprecated,
+// suppress = it.suppress
+// )},
+// moduleName = moduleName,
+// includeNonPublic = includeNonPublic,
+// includeRootPackage = false,
+// reportUndocumented = reportUndocumented,
+// skipEmptyPackages = skipEmptyPackages,
+// skipDeprecated = skipDeprecated,
+// jdkVersion = jdkVersion,
+// languageVersion = languageVersion,
+// apiVersion = apiVersion,
+// noStdlibLink = noStdlibLink,
+// noJdkLink = noJdkLink,
+// suppressedFiles = collectSuppressedFiles(sourceRoots),
+// sinceKotlin = "1.0",
+// analysisPlatform = Platform.DEFAULT,
+// targets = emptyList(),
+// sourceLinks = mutableListOf(), // TODO: check this line
+// externalDocumentationLinks = externalDocumentationLinks.map {
+// ExternalDocumentationLinkImpl(it.url, it.packageListUrl)
+// }
+// )
+// )
+// )
bootstrapProxy.configure(
BiConsumer { level, message ->
@@ -365,10 +391,9 @@ open class DokkaTask : DefaultTask() {
"error" -> logger.error(message)
}
},
- Json.stringify(configuration)
+ gson.toJson(configuration)
)
-
bootstrapProxy.generate()
} finally {
@@ -376,6 +401,40 @@ open class DokkaTask : DefaultTask() {
}
}
+ private fun defaultPassConfiguration(passConfig: GradlePassConfigurationImpl): GradlePassConfigurationImpl{
+
+ fun Closure<Unit>.setDelegateAndCall(delegate: Any) {
+ this.delegate = delegate
+ this.call()
+ this.delegate
+ }
+
+ val (tasksClasspath, tasksSourceRoots) = kotlinCompileBasedClasspathAndSourceRoots
+
+ val fullClasspath = tasksClasspath + classpath
+ passConfig.moduleName = moduleName
+ passConfig.classpath = fullClasspath.map { it.absolutePath }
+ passConfig.sourceRoots = sourceRoots.map { SourceRootImpl(it.path) }
+ passConfig.samples = samples.filterNotNull().map { project.file(it).absolutePath }
+ passConfig.includes = includes.filterNotNull().map { project.file(it).absolutePath }
+ passConfig.collectInheritedExtensionsFromLibraries = collectInheritedExtensionsFromLibraries
+
+ passConfig.perPackageOptions = ((passConfig.perPackageOptions as List<Closure<Unit>>).map {
+ it.setDelegateAndCall(GradlePackageOptionsImpl())
+ }) as List<PackageOptionsImpl>
+
+ passConfig.suppressedFiles = collectSuppressedFiles(sourceRoots)
+ passConfig.sourceLinks = ((passConfig.sourceLinks as List<Closure<Unit>>).map {
+ it.setDelegateAndCall(GradleSourceLinkDefinitionImpl())
+ }) as MutableList<GradleSourceLinkDefinitionImpl> // TODO: Parse source links?
+
+ passConfig.externalDocumentationLinks = ((passConfig.externalDocumentationLinks as List<Closure<Unit>>).map {
+ it.setDelegateAndCall(GradleExternalDocumentationLinkImpl())
+ }) as List<ExternalDocumentationLinkImpl>
+
+ return passConfig
+ }
+
private fun collectSourceRoots(): List<SourceRoot> {
val sourceDirs = if (sourceDirs.any()) {
@@ -487,3 +546,67 @@ class PackageOptions : Serializable, DokkaConfiguration.PackageOptions {
override var skipDeprecated: Boolean = false
override var suppress: Boolean = false
}
+
+open class GradlePassConfigurationImpl(@Transient val name: String = ""): DokkaConfiguration.PassConfiguration {
+ override var classpath: List<String> = emptyList()
+ override var moduleName: String = ""
+ override var sourceRoots: List<SourceRootImpl> = emptyList()
+ override var samples: List<String> = emptyList()
+ override var includes: List<String> = emptyList()
+ override var includeNonPublic: Boolean = false
+ override var includeRootPackage: Boolean = false
+ override var reportUndocumented: Boolean = false
+ override var skipEmptyPackages: Boolean = false
+ override var skipDeprecated: Boolean = false
+ override var jdkVersion: Int = 6
+ override var sourceLinks: List<GradleSourceLinkDefinitionImpl> = emptyList()
+ override var perPackageOptions: List<PackageOptionsImpl> = emptyList()
+ override var externalDocumentationLinks: List<ExternalDocumentationLinkImpl> = emptyList()
+ override var languageVersion: String? = null
+ override var apiVersion: String? = null
+ override var noStdlibLink: Boolean = false
+ override var noJdkLink: Boolean = false
+ override var suppressedFiles: List<String> = emptyList()
+ override var collectInheritedExtensionsFromLibraries: Boolean = false
+ override var analysisPlatform: Platform = Platform.DEFAULT
+ override var targets: List<String> = listOf("JVM")
+ override var sinceKotlin: String = "1.0"
+}
+
+class GradleSourceLinkDefinitionImpl : DokkaConfiguration.SourceLinkDefinition {
+ override var path: String = ""
+ override var url: String = ""
+ override var lineSuffix: String? = null
+
+ companion object {
+ fun parseSourceLinkDefinition(srcLink: String): SourceLinkDefinitionImpl {
+ val (path, urlAndLine) = srcLink.split('=')
+ return SourceLinkDefinitionImpl(
+ File(path).canonicalPath,
+ urlAndLine.substringBefore("#"),
+ urlAndLine.substringAfter("#", "").let { if (it.isEmpty()) null else "#$it" })
+ }
+ }
+}
+
+class GradleExternalDocumentationLinkImpl : DokkaConfiguration.ExternalDocumentationLink {
+ override var url: URL = URL("")
+ override var packageListUrl: URL = URL("")
+}
+
+class GradleDokkaConfigurationImpl: DokkaConfiguration {
+ override var outputDir: String = ""
+ override var format: String = "html"
+ override var generateIndexPages: Boolean = false
+ override var cacheRoot: String? = null
+ override var impliedPlatforms: List<String> = emptyList()
+ override var passesConfigurations: List<GradlePassConfigurationImpl> = emptyList()
+}
+
+class GradlePackageOptionsImpl: DokkaConfiguration.PackageOptions {
+ override var prefix: String = ""
+ override val includeNonPublic: Boolean = false
+ override val reportUndocumented: Boolean = true
+ override val skipDeprecated: Boolean = true
+ override val suppress: Boolean = false
+} \ No newline at end of file