diff options
Diffstat (limited to 'runners')
-rw-r--r-- | runners/ant/src/main/kotlin/ant/dokka.kt | 8 | ||||
-rw-r--r-- | runners/cli/src/main/kotlin/cli/main.kt | 4 | ||||
-rw-r--r-- | runners/gradle-plugin/src/main/kotlin/main.kt | 97 | ||||
-rw-r--r-- | runners/maven-plugin/src/main/kotlin/DokkaMojo.kt | 8 |
4 files changed, 80 insertions, 37 deletions
diff --git a/runners/ant/src/main/kotlin/ant/dokka.kt b/runners/ant/src/main/kotlin/ant/dokka.kt index c05cf1cb..54694880 100644 --- a/runners/ant/src/main/kotlin/ant/dokka.kt +++ b/runners/ant/src/main/kotlin/ant/dokka.kt @@ -17,9 +17,9 @@ class AntLogger(val task: Task): DokkaLogger { class AntSourceLinkDefinition(var path: String? = null, var url: String? = null, var lineSuffix: String? = null) class AntSourceRoot(var path: String? = null, var platforms: String? = null) { - fun toSourceRoot(): SourceRoot? = path?.let { + fun toSourceRoot(): SourceRootImpl? = path?.let { path -> - SourceRoot(path, platforms?.split(',').orEmpty()) + SourceRootImpl(path, platforms?.split(',').orEmpty()) } } @@ -104,13 +104,13 @@ class DokkaAntTask: Task() { val sourceLinks = antSourceLinks.map { val path = it.path ?: throw BuildException("'path' attribute of a <sourceLink> element is required") val url = it.url ?: throw BuildException("'url' attribute of a <sourceLink> element is required") - SourceLinkDefinition(File(path).canonicalFile.absolutePath, url, it.lineSuffix) + SourceLinkDefinitionImpl(File(path).canonicalFile.absolutePath, url, it.lineSuffix) } val generator = DokkaGenerator( AntLogger(this), compileClasspath.list().toList(), - sourcePath.list().map { SourceRoot(it) } + antSourceRoots.mapNotNull { it.toSourceRoot() }, + sourcePath.list().map { SourceRootImpl(it) } + antSourceRoots.mapNotNull { it.toSourceRoot() }, samplesPath.list().toList(), includesPath.list().toList(), moduleName!!, diff --git a/runners/cli/src/main/kotlin/cli/main.kt b/runners/cli/src/main/kotlin/cli/main.kt index 78e3077d..0d1ff76c 100644 --- a/runners/cli/src/main/kotlin/cli/main.kt +++ b/runners/cli/src/main/kotlin/cli/main.kt @@ -65,7 +65,7 @@ object MainKt { val includes = if (arguments.include.isNotEmpty()) arguments.include.split(File.pathSeparatorChar).toList() else listOf() val sourceLinks = if (arguments.srcLink.isNotEmpty() && arguments.srcLink.contains("=")) - listOf(parseSourceLinkDefinition(arguments.srcLink)) + listOf(SourceLinkDefinitionImpl.parseSourceLinkDefinition(arguments.srcLink)) else { if (arguments.srcLink.isNotEmpty()) { println("Warning: Invalid -srcLink syntax. Expected: <path>=<url>[#lineSuffix]. No source links will be generated.") @@ -87,7 +87,7 @@ object MainKt { val generator = DokkaGenerator( DokkaConsoleLogger, classPath, - sources.map(::parseSourceRoot), + sources.map(SourceRootImpl.Companion::parseSourceRoot), samples, includes, arguments.moduleName, diff --git a/runners/gradle-plugin/src/main/kotlin/main.kt b/runners/gradle-plugin/src/main/kotlin/main.kt index 959698c3..7aa871ad 100644 --- a/runners/gradle-plugin/src/main/kotlin/main.kt +++ b/runners/gradle-plugin/src/main/kotlin/main.kt @@ -9,9 +9,13 @@ import org.gradle.api.plugins.JavaBasePlugin import org.gradle.api.plugins.JavaPluginConvention import org.gradle.api.tasks.* import org.jetbrains.dokka.DokkaBootstrap +import org.jetbrains.dokka.DokkaConfiguration +import org.jetbrains.dokka.SerializeOnlyDokkaConfiguration import org.jetbrains.dokka.automagicTypedProxy import org.jetbrains.dokka.gradle.ClassloaderContainer.fatJarClassLoader import org.jetbrains.dokka.gradle.DokkaVersion.version +import ru.yole.jkid.JsonExclude +import ru.yole.jkid.serialization.serialize import java.io.File import java.io.InputStream import java.io.Serializable @@ -69,6 +73,9 @@ open class DokkaTask : DefaultTask() { var jdkVersion: Int = 6 @Input var sourceDirs: Iterable<File> = emptyList() + + @Input var sourceRoots: MutableList<SourceRoot> = arrayListOf() + @Input var dokkaFatJar: Any = "org.jetbrains.dokka:dokka-fatjar:$version" @@ -84,7 +91,7 @@ open class DokkaTask : DefaultTask() { closure.delegate = mapping closure.call() - if (mapping.dir.isEmpty()) { + if (mapping.path.isEmpty()) { throw IllegalArgumentException("Link mapping should have dir") } if (mapping.url.isEmpty()) { @@ -94,6 +101,12 @@ open class DokkaTask : DefaultTask() { linkMappings.add(mapping) } + fun sourceRoot(closure: Closure<Any?>) { + val sourceRoot = SourceRoot() + closure.delegate = sourceRoot + closure.call() + sourceRoots.add(sourceRoot) + } fun tryResolveFatJar(project: Project): File { return try { @@ -126,7 +139,7 @@ open class DokkaTask : DefaultTask() { val project = project val sdkProvider = sdkProvider - val sourceDirectories = getSourceDirectories() + val sourceRoots = collectSourceRoots() val allConfigurations = project.configurations val classpath = @@ -135,7 +148,7 @@ open class DokkaTask : DefaultTask() { .map { allConfigurations?.getByName(it.toString()) ?: throw IllegalArgumentException("No configuration $it found") } .flatMap { it } - if (sourceDirectories.isEmpty()) { + if (sourceRoots.isEmpty()) { logger.warn("No source directories found: skipping dokka generation") return } @@ -146,17 +159,10 @@ open class DokkaTask : DefaultTask() { val bootstrapProxy: DokkaBootstrap = automagicTypedProxy(javaClass.classLoader, bootstrapInstance) - bootstrapProxy.configure( - BiConsumer { level, message -> - when (level) { - "info" -> logger.info(message) - "warn" -> logger.warn(message) - "error" -> logger.error(message) - } - }, + val configuration = SerializeOnlyDokkaConfiguration( moduleName, classpath.map { it.absolutePath }, - sourceDirectories.map { it.absolutePath }, + sourceRoots, samples.filterNotNull().map { project.file(it).absolutePath }, includes.filterNotNull().map { project.file(it).absolutePath }, outputDirectory, @@ -168,10 +174,19 @@ open class DokkaTask : DefaultTask() { skipDeprecated, 6, true, - linkMappings.map { - val path = project.file(it.dir).absolutePath - "$path=${it.url}${it.suffix}" - }) + linkMappings) + + + bootstrapProxy.configure( + BiConsumer { level, message -> + when (level) { + "info" -> logger.info(message) + "warn" -> logger.warn(message) + "error" -> logger.error(message) + } + }, + serialize(configuration) + ) bootstrapProxy.generate() @@ -180,7 +195,11 @@ open class DokkaTask : DefaultTask() { } } - fun getSourceDirectories(): Collection<File> { + fun collectSourceRoots(): List<SourceRoot> { + if (sourceRoots.any()) { + return sourceRoots + } + val provider = sdkProvider val sourceDirs = if (sourceDirs.any()) { logger.info("Dokka: Taking source directories provided by the user") @@ -195,13 +214,13 @@ open class DokkaTask : DefaultTask() { sourceSets?.allSource?.srcDirs } - return sourceDirs?.filter { it.exists() } ?: emptyList() + return sourceDirs?.filter { it.exists() }?.map { SourceRoot().apply { path = it.path } } ?: emptyList() } @InputFiles @SkipWhenEmpty fun getInputFiles(): FileCollection = - project.files(getSourceDirectories().map { project.fileTree(it) }) + + project.files(collectSourceRoots().map { project.fileTree(File(it.path)) }) + project.files(includes) + project.files(samples.map { project.fileTree(it) }) @@ -213,10 +232,34 @@ open class DokkaTask : DefaultTask() { } } -open class LinkMapping : Serializable { - var dir: String = "" - var url: String = "" - var suffix: String? = null +class SourceRoot : DokkaConfiguration.SourceRoot { + override var path: String = "" + set(value) { + field = File(value).absolutePath + } + + override var defaultPlatforms: List<String> = arrayListOf() +} + +open class LinkMapping : Serializable, DokkaConfiguration.SourceLinkDefinition { + @JsonExclude + var dir: String + get() = path + set(value) { + path = value + } + + override var path: String = "" + override var url: String = "" + + @JsonExclude + var suffix: String? + get() = lineSuffix + set(value) { + lineSuffix = value + } + + override var lineSuffix: String? = null override fun equals(other: Any?): Boolean { if (this === other) return true @@ -224,17 +267,17 @@ open class LinkMapping : Serializable { other as LinkMapping - if (dir != other.dir) return false + if (path != other.path) return false if (url != other.url) return false - if (suffix != other.suffix) return false + if (lineSuffix != other.lineSuffix) return false return true } override fun hashCode(): Int { - var result = dir.hashCode() + var result = path.hashCode() result = 31 * result + url.hashCode() - result = 31 * result + (suffix?.hashCode() ?: 0) + result = 31 * result + (lineSuffix?.hashCode() ?: 0) return result } diff --git a/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt b/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt index c3cf7509..dcccdb1f 100644 --- a/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt +++ b/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt @@ -11,8 +11,8 @@ import org.codehaus.plexus.archiver.Archiver import org.codehaus.plexus.archiver.jar.JarArchiver import org.jetbrains.dokka.DocumentationOptions import org.jetbrains.dokka.DokkaGenerator -import org.jetbrains.dokka.SourceLinkDefinition -import org.jetbrains.dokka.SourceRoot +import org.jetbrains.dokka.SourceLinkDefinitionImpl +import org.jetbrains.dokka.SourceRootImpl import java.io.File class SourceLinkMapItem { @@ -67,12 +67,12 @@ abstract class AbstractDokkaMojo : AbstractMojo() { val gen = DokkaGenerator( MavenDokkaLogger(log), classpath, - sourceDirectories.map { SourceRoot(it) }, + sourceDirectories.map { SourceRootImpl(it) }, samplesDirs, includeDirs + includes, moduleName, DocumentationOptions(getOutDir(), getOutFormat(), - sourceLinks = sourceLinks.map { SourceLinkDefinition(it.dir, it.url, it.urlSuffix) }, + sourceLinks = sourceLinks.map { SourceLinkDefinitionImpl(it.dir, it.url, it.urlSuffix) }, jdkVersion = jdkVersion ) ) |