aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaweł Marks <pmarks@virtuslab.com>2019-11-14 15:18:56 +0100
committerBłażej Kardyś <bkardys@virtuslab.com>2019-11-25 16:24:16 +0100
commitdac6ba2a589aa1e8a9f4a9c7af32026be77776b3 (patch)
treef7be54609c482f0a0e5b021db38410c0dee8a82f
parentd3bd543f569656e66112e584ad86af95ae7ea000 (diff)
downloaddokka-dac6ba2a589aa1e8a9f4a9c7af32026be77776b3.tar.gz
dokka-dac6ba2a589aa1e8a9f4a9c7af32026be77776b3.tar.bz2
dokka-dac6ba2a589aa1e8a9f4a9c7af32026be77776b3.zip
First plugin draft
-rw-r--r--core/src/main/kotlin/DokkaGenerator.kt14
-rw-r--r--core/src/main/kotlin/plugability/DokkaContext.kt27
-rw-r--r--core/src/main/kotlin/plugability/DokkaPlugin.kt6
-rw-r--r--integration/src/main/kotlin/org/jetbrains/dokka/configuration.kt2
-rw-r--r--integration/src/main/kotlin/org/jetbrains/dokka/defaultConfiguration.kt3
-rw-r--r--runners/ant/src/main/kotlin/ant/dokka.kt1
-rw-r--r--runners/cli/src/main/kotlin/cli/main.kt2
-rw-r--r--runners/fatjar/build.gradle28
-rw-r--r--runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaTask.kt19
-rw-r--r--runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/configurationImplementations.kt1
-rw-r--r--runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/main.kt11
11 files changed, 103 insertions, 11 deletions
diff --git a/core/src/main/kotlin/DokkaGenerator.kt b/core/src/main/kotlin/DokkaGenerator.kt
index 11f583b3..a522ea40 100644
--- a/core/src/main/kotlin/DokkaGenerator.kt
+++ b/core/src/main/kotlin/DokkaGenerator.kt
@@ -2,11 +2,11 @@ package org.jetbrains.dokka
import org.jetbrains.dokka.Model.Module
import org.jetbrains.dokka.Model.transformers.DocumentationNodesMerger
-//import org.jetbrains.dokka.Utilities.genericPretty
import org.jetbrains.dokka.Utilities.pretty
import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.pages.MarkdownToContentConverter
import org.jetbrains.dokka.pages.PlatformData
+import org.jetbrains.dokka.plugability.DokkaContext
import org.jetbrains.dokka.renderers.FileWriter
import org.jetbrains.dokka.renderers.HtmlRenderer
import org.jetbrains.dokka.resolvers.DefaultLocationProvider
@@ -23,6 +23,18 @@ class DokkaGenerator(
private val logger: DokkaLogger
) {
fun generate(): Unit {
+
+ logger.info("Initializing plugins")
+ val context = DokkaContext.from(configuration.pluginsClasspath)
+ context.pluginNames.also { names ->
+ logger.info("Loaded plugins: $names")
+ names.groupingBy { it }.eachCount().filter { it.value > 1 }.forEach {
+ logger.warn("Duplicate plugin name: ${it.key}. It will make debugging much harder.")
+ }
+ }
+
+
+
configuration.passesConfigurations.map { pass ->
AnalysisEnvironment(DokkaMessageCollector(logger), pass.analysisPlatform).run {
if (analysisPlatform == Platform.jvm) {
diff --git a/core/src/main/kotlin/plugability/DokkaContext.kt b/core/src/main/kotlin/plugability/DokkaContext.kt
new file mode 100644
index 00000000..7da4d9a7
--- /dev/null
+++ b/core/src/main/kotlin/plugability/DokkaContext.kt
@@ -0,0 +1,27 @@
+package org.jetbrains.dokka.plugability
+
+import java.io.File
+import java.net.URLClassLoader
+import java.util.*
+
+
+class DokkaContext private constructor() {
+ private val plugins = mutableListOf<DokkaPlugin>()
+
+ val pluginNames: List<String>
+ get() = plugins.map { it.name }
+
+ private fun install(plugin: DokkaPlugin) {
+ plugins += plugin
+ plugin.install(this)
+ }
+
+ companion object {
+ fun from(pluginsClasspath: Iterable<File>) = DokkaContext().apply {
+ pluginsClasspath.map { it.relativeTo(File(".").absoluteFile).toURI().toURL() }
+ .toTypedArray()
+ .let { ServiceLoader.load(DokkaPlugin::class.java, URLClassLoader(it, this.javaClass.classLoader)) }
+ .forEach { install(it) }
+ }
+ }
+} \ No newline at end of file
diff --git a/core/src/main/kotlin/plugability/DokkaPlugin.kt b/core/src/main/kotlin/plugability/DokkaPlugin.kt
new file mode 100644
index 00000000..2654bcee
--- /dev/null
+++ b/core/src/main/kotlin/plugability/DokkaPlugin.kt
@@ -0,0 +1,6 @@
+package org.jetbrains.dokka.plugability
+
+interface DokkaPlugin {
+ val name: String
+ fun install(context: DokkaContext)
+} \ 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 6eae9701..8c6d35e8 100644
--- a/integration/src/main/kotlin/org/jetbrains/dokka/configuration.kt
+++ b/integration/src/main/kotlin/org/jetbrains/dokka/configuration.kt
@@ -1,5 +1,6 @@
package org.jetbrains.dokka
+import java.io.File
import java.net.URL
enum class Platform(val key: String) {
@@ -30,6 +31,7 @@ interface DokkaConfiguration {
val cacheRoot: String?
val passesConfigurations: List<PassConfiguration>
val impliedPlatforms: List<String>
+ var pluginsClasspath: List<File>
interface PassConfiguration {
val moduleName: String
diff --git a/integration/src/main/kotlin/org/jetbrains/dokka/defaultConfiguration.kt b/integration/src/main/kotlin/org/jetbrains/dokka/defaultConfiguration.kt
index 78112904..6c797fcd 100644
--- a/integration/src/main/kotlin/org/jetbrains/dokka/defaultConfiguration.kt
+++ b/integration/src/main/kotlin/org/jetbrains/dokka/defaultConfiguration.kt
@@ -9,7 +9,8 @@ data class DokkaConfigurationImpl(
override val generateIndexPages: Boolean,
override val cacheRoot: String?,
override val impliedPlatforms: List<String>,
- override val passesConfigurations: List<PassConfigurationImpl>
+ override val passesConfigurations: List<PassConfigurationImpl>,
+ override var pluginsClasspath: List<File>
) : DokkaConfiguration
data class PassConfigurationImpl (
diff --git a/runners/ant/src/main/kotlin/ant/dokka.kt b/runners/ant/src/main/kotlin/ant/dokka.kt
index 3ecc7b94..038bfca9 100644
--- a/runners/ant/src/main/kotlin/ant/dokka.kt
+++ b/runners/ant/src/main/kotlin/ant/dokka.kt
@@ -153,6 +153,7 @@ class DokkaAntTask: Task(), DokkaConfiguration {
override var cacheRoot: String? = null
override val passesConfigurations: MutableList<AntPassConfig> = mutableListOf()
+ override var pluginsClasspath: List<File> = mutableListOf()
fun createPassConfig() = AntPassConfig(this).apply { passesConfigurations.add(this) }
fun createImpliedPlatform(): TextProperty = TextProperty().apply { buildImpliedPlatforms.add(this) }
diff --git a/runners/cli/src/main/kotlin/cli/main.kt b/runners/cli/src/main/kotlin/cli/main.kt
index 52815e75..32ce762d 100644
--- a/runners/cli/src/main/kotlin/cli/main.kt
+++ b/runners/cli/src/main/kotlin/cli/main.kt
@@ -35,6 +35,8 @@ open class GlobalArguments(parser: DokkaArgumentsParser) : DokkaConfiguration {
) {
Arguments(parser)
}
+
+ override var pluginsClasspath: List<File> = emptyList()
}
class Arguments(val parser: DokkaArgumentsParser) : DokkaConfiguration.PassConfiguration {
diff --git a/runners/fatjar/build.gradle b/runners/fatjar/build.gradle
index 4ce0416c..1da23841 100644
--- a/runners/fatjar/build.gradle
+++ b/runners/fatjar/build.gradle
@@ -1,5 +1,6 @@
import com.github.jengelman.gradle.plugins.shadow.transformers.ServiceFileTransformer
import org.jetbrains.PluginXmlTransformer
+import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
apply plugin: 'java'
apply plugin: 'com.github.johnrengelman.shadow'
@@ -18,7 +19,28 @@ jar {
shadowJar {
baseName = 'dokka-fatjar'
classifier = ''
+ configurations {
+ exclude compileOnly
+ }
+
+ transform(ServiceFileTransformer)
+ transform(PluginXmlTransformer)
+
+ exclude 'colorScheme/**'
+ exclude 'fileTemplates/**'
+ exclude 'inspectionDescriptions/**'
+ exclude 'intentionDescriptions/**'
+
+ exclude 'src/**'
+
+ relocate('kotlin.reflect.full', 'kotlin.reflect')
+}
+
+task apiShadow(type: ShadowJar) {
+ baseName = 'dokka-fatapi'
+ classifier = ''
+ configurations = [project.configurations.compile]
configurations {
exclude compileOnly
}
@@ -26,6 +48,7 @@ shadowJar {
transform(ServiceFileTransformer)
transform(PluginXmlTransformer)
+ exclude 'kotlin/**'
exclude 'colorScheme/**'
exclude 'fileTemplates/**'
exclude 'inspectionDescriptions/**'
@@ -44,6 +67,11 @@ publishing {
artifactId = 'dokka-fatjar'
project.shadow.component(publication)
}
+
+ dokkaFatApi(MavenPublication) {publication ->
+ artifactId = 'dokka-fatapi'
+ publication.artifact(project.tasks.apiShadow)
+ }
}
}
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 35ef118a..b668158d 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
@@ -63,6 +63,9 @@ open class DokkaTask : DefaultTask() {
@Input
var cacheRoot: String? = null
+ @Classpath
+ lateinit var pluginsConfiguration: Configuration
+
var multiplatform: NamedDomainObjectContainer<GradlePassConfigurationImpl>
@Suppress("UNCHECKED_CAST")
@Nested get() = (DslObject(this).extensions.getByName(MULTIPLATFORM_EXTENSION_NAME) as NamedDomainObjectContainer<GradlePassConfigurationImpl>)
@@ -155,13 +158,15 @@ open class DokkaTask : DefaultTask() {
val passConfigurationList = collectConfigurations()
.map { defaultPassConfiguration(it, globalConfig) }
- val configuration = GradleDokkaConfigurationImpl()
- configuration.outputDir = outputDirectory
- configuration.format = outputFormat
- configuration.generateIndexPages = true
- configuration.cacheRoot = cacheRoot
- configuration.impliedPlatforms = impliedPlatforms
- configuration.passesConfigurations = passConfigurationList
+ val configuration = GradleDokkaConfigurationImpl().apply {
+ outputDir = outputDirectory
+ format = outputFormat
+ generateIndexPages = true
+ cacheRoot = cacheRoot
+ impliedPlatforms = impliedPlatforms
+ passesConfigurations = passConfigurationList
+ pluginsClasspath = pluginsConfiguration.resolve().toList()
+ }
bootstrapProxy.configure(
BiConsumer { level, message ->
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..52caba41 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
@@ -124,6 +124,7 @@ class GradleDokkaConfigurationImpl: DokkaConfiguration {
override var cacheRoot: String? = null
override var impliedPlatforms: List<String> = emptyList()
override var passesConfigurations: List<GradlePassConfigurationImpl> = emptyList()
+ override var pluginsClasspath: List<File> = emptyList()
}
class GradlePackageOptionsImpl: PackageOptions, Serializable {
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..d75d3b21 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
@@ -17,7 +17,8 @@ open class DokkaPlugin : Plugin<Project> {
override fun apply(project: Project) {
loadDokkaVersion()
val dokkaRuntimeConfiguration = addConfiguration(project)
- addTasks(project, dokkaRuntimeConfiguration, DokkaTask::class.java)
+ val pluginsConfiguration = project.configurations.create("dokkaPlugins")
+ addTasks(project, dokkaRuntimeConfiguration, pluginsConfiguration, DokkaTask::class.java)
}
private fun loadDokkaVersion() = DokkaVersion.loadFrom(javaClass.getResourceAsStream("/META-INF/gradle-plugins/org.jetbrains.dokka.properties"))
@@ -27,7 +28,12 @@ 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>) {
+ private fun addTasks(
+ project: Project,
+ runtimeConfiguration: Configuration,
+ pluginsConfiguration: Configuration,
+ taskClass: Class<out DokkaTask>
+ ) {
if(GradleVersion.current() >= GradleVersion.version("4.10")) {
project.tasks.register(taskName, taskClass)
} else {
@@ -37,6 +43,7 @@ open class DokkaPlugin : Plugin<Project> {
task.multiplatform = project.container(GradlePassConfigurationImpl::class.java)
task.configuration = GradlePassConfigurationImpl()
task.dokkaRuntime = runtimeConfiguration
+ task.pluginsConfiguration = pluginsConfiguration
task.outputDirectory = File(project.buildDir, taskName).absolutePath
}
}