diff options
Diffstat (limited to 'core/src/main')
-rw-r--r-- | core/src/main/kotlin/Generation/DokkaGenerator.kt (renamed from core/src/main/kotlin/main.kt) | 141 | ||||
-rw-r--r-- | core/src/main/kotlin/Utilities/DokkaLogging.kt | 27 | ||||
-rw-r--r-- | core/src/main/kotlin/ant/dokka.kt | 101 |
3 files changed, 41 insertions, 228 deletions
diff --git a/core/src/main/kotlin/main.kt b/core/src/main/kotlin/Generation/DokkaGenerator.kt index 22859187..8d846904 100644 --- a/core/src/main/kotlin/main.kt +++ b/core/src/main/kotlin/Generation/DokkaGenerator.kt @@ -7,10 +7,8 @@ import com.intellij.openapi.vfs.VirtualFileManager import com.intellij.psi.PsiFile import com.intellij.psi.PsiJavaFile import com.intellij.psi.PsiManager -import com.sampullara.cli.Args -import com.sampullara.cli.Argument +import org.jetbrains.dokka.* import org.jetbrains.dokka.Utilities.DokkaModule -import org.jetbrains.kotlin.cli.common.arguments.ValueDescription import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity import org.jetbrains.kotlin.cli.common.messages.MessageCollector @@ -24,130 +22,6 @@ import org.jetbrains.kotlin.utils.PathUtil import java.io.File import kotlin.system.measureTimeMillis -class DokkaArguments { - @set:Argument(value = "src", description = "Source file or directory (allows many paths separated by the system path separator)") - @ValueDescription("<path>") - var src: String = "" - - @set:Argument(value = "srcLink", description = "Mapping between a source directory and a Web site for browsing the code") - @ValueDescription("<path>=<url>[#lineSuffix]") - var srcLink: String = "" - - @set:Argument(value = "include", description = "Markdown files to load (allows many paths separated by the system path separator)") - @ValueDescription("<path>") - var include: String = "" - - @set:Argument(value = "samples", description = "Source root for samples") - @ValueDescription("<path>") - var samples: String = "" - - @set:Argument(value = "output", description = "Output directory path") - @ValueDescription("<path>") - var outputDir: String = "out/doc/" - - @set:Argument(value = "format", description = "Output format (text, html, markdown, jekyll, kotlin-website)") - @ValueDescription("<name>") - var outputFormat: String = "html" - - @set:Argument(value = "module", description = "Name of the documentation module") - @ValueDescription("<name>") - var moduleName: String = "" - - @set:Argument(value = "classpath", description = "Classpath for symbol resolution") - @ValueDescription("<path>") - var classpath: String = "" - - @set:Argument(value = "nodeprecated", description = "Exclude deprecated members from documentation") - var nodeprecated: Boolean = false - - @set:Argument(value = "jdkVersion", description = "Version of JDK to use for linking to JDK JavaDoc") - var jdkVersion: Int = 6 -} - -private fun parseSourceLinkDefinition(srcLink: String): SourceLinkDefinition { - val (path, urlAndLine) = srcLink.split('=') - return SourceLinkDefinition(File(path).absolutePath, - urlAndLine.substringBefore("#"), - urlAndLine.substringAfter("#", "").let { if (it.isEmpty()) null else "#" + it }) -} - -fun main(args: Array<String>) { - val arguments = DokkaArguments() - val freeArgs: List<String> = Args.parse(arguments, args, false) ?: listOf() - val sources = if (arguments.src.isNotEmpty()) arguments.src.split(File.pathSeparatorChar).toList() + freeArgs else freeArgs - val samples = if (arguments.samples.isNotEmpty()) arguments.samples.split(File.pathSeparatorChar).toList() else listOf() - 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)) - else { - if (arguments.srcLink.isNotEmpty()) { - println("Warning: Invalid -srcLink syntax. Expected: <path>=<url>[#lineSuffix]. No source links will be generated.") - } - listOf() - } - - val classPath = arguments.classpath.split(File.pathSeparatorChar).toList() - - val documentationOptions = DocumentationOptions( - arguments.outputDir.let { if (it.endsWith('/')) it else it + '/' }, - arguments.outputFormat, - skipDeprecated = arguments.nodeprecated, - sourceLinks = sourceLinks - ) - - val generator = DokkaGenerator( - DokkaConsoleLogger, - classPath, - sources, - samples, - includes, - arguments.moduleName, - documentationOptions) - - generator.generate() - DokkaConsoleLogger.report() -} - -interface DokkaLogger { - fun info(message: String) - fun warn(message: String) - fun error(message: String) -} - -object DokkaConsoleLogger: DokkaLogger { - var warningCount: Int = 0 - - override fun info(message: String) = println(message) - override fun warn(message: String) { - println("WARN: $message") - warningCount++ - } - - override fun error(message: String) = println("ERROR: $message") - - fun report() { - if (warningCount > 0) { - println("generation completed with $warningCount warnings") - } else { - println("generation completed successfully") - } - } -} - -class DokkaMessageCollector(val logger: DokkaLogger): MessageCollector { - private var seenErrors = false - - override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageLocation) { - if (severity == CompilerMessageSeverity.ERROR) { - seenErrors = true - } - logger.error(MessageRenderer.PLAIN_FULL_PATHS.render(severity, message, location)) - } - - override fun hasErrors() = seenErrors -} - class DokkaGenerator(val logger: DokkaLogger, val classpath: List<String>, val sources: List<String>, @@ -209,6 +83,19 @@ class DokkaGenerator(val logger: DokkaLogger, } } +class DokkaMessageCollector(val logger: DokkaLogger): MessageCollector { + private var seenErrors = false + + override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageLocation) { + if (severity == CompilerMessageSeverity.ERROR) { + seenErrors = true + } + logger.error(MessageRenderer.PLAIN_FULL_PATHS.render(severity, message, location)) + } + + override fun hasErrors() = seenErrors +} + fun buildDocumentationModule(injector: Injector, moduleName: String, filesToDocumentFilter: (PsiFile) -> Boolean = { file -> true }, diff --git a/core/src/main/kotlin/Utilities/DokkaLogging.kt b/core/src/main/kotlin/Utilities/DokkaLogging.kt new file mode 100644 index 00000000..1ef52837 --- /dev/null +++ b/core/src/main/kotlin/Utilities/DokkaLogging.kt @@ -0,0 +1,27 @@ +package org.jetbrains.dokka + +interface DokkaLogger { + fun info(message: String) + fun warn(message: String) + fun error(message: String) +} + +object DokkaConsoleLogger : DokkaLogger { + var warningCount: Int = 0 + + override fun info(message: String) = println(message) + override fun warn(message: String) { + println("WARN: $message") + warningCount++ + } + + override fun error(message: String) = println("ERROR: $message") + + fun report() { + if (warningCount > 0) { + println("generation completed with $warningCount warnings") + } else { + println("generation completed successfully") + } + } +} diff --git a/core/src/main/kotlin/ant/dokka.kt b/core/src/main/kotlin/ant/dokka.kt deleted file mode 100644 index 38dc543b..00000000 --- a/core/src/main/kotlin/ant/dokka.kt +++ /dev/null @@ -1,101 +0,0 @@ -package org.jetbrains.dokka.ant - -import org.apache.tools.ant.BuildException -import org.apache.tools.ant.Project -import org.apache.tools.ant.Task -import org.apache.tools.ant.types.Path -import org.apache.tools.ant.types.Reference -import org.jetbrains.dokka.DocumentationOptions -import org.jetbrains.dokka.DokkaGenerator -import org.jetbrains.dokka.DokkaLogger -import org.jetbrains.dokka.SourceLinkDefinition -import java.io.File - -class AntLogger(val task: Task): DokkaLogger { - override fun info(message: String) = task.log(message, Project.MSG_INFO) - override fun warn(message: String) = task.log(message, Project.MSG_WARN) - override fun error(message: String) = task.log(message, Project.MSG_ERR) -} - -class AntSourceLinkDefinition(var path: String? = null, var url: String? = null, var lineSuffix: String? = null) - -class DokkaAntTask(): Task() { - var moduleName: String? = null - var outputDir: String? = null - var outputFormat: String = "html" - var jdkVersion: Int = 6 - - var skipDeprecated: Boolean = false - - val compileClasspath: Path by lazy { Path(getProject()) } - val sourcePath: Path by lazy { Path(getProject()) } - val samplesPath: Path by lazy { Path(getProject()) } - val includesPath: Path by lazy { Path(getProject()) } - - val antSourceLinks: MutableList<AntSourceLinkDefinition> = arrayListOf() - - fun setClasspath(classpath: Path) { - compileClasspath.append(classpath) - } - - fun setClasspathRef(ref: Reference) { - compileClasspath.createPath().refid = ref - } - - fun setSrc(src: Path) { - sourcePath.append(src) - } - - fun setSrcRef(ref: Reference) { - sourcePath.createPath().refid = ref - } - - fun setSamples(samples: Path) { - samplesPath.append(samples) - } - - fun setSamplesRef(ref: Reference) { - samplesPath.createPath().refid = ref - } - - fun setInclude(include: Path) { - includesPath.append(include) - } - - fun createSourceLink(): AntSourceLinkDefinition { - val def = AntSourceLinkDefinition() - antSourceLinks.add(def) - return def - } - - override fun execute() { - if (sourcePath.list().size == 0) { - throw BuildException("At least one source path needs to be specified") - } - if (moduleName == null) { - throw BuildException("Module name needs to be specified") - } - if (outputDir == null) { - throw BuildException("Output directory needs to be specified") - } - 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) - } - - val generator = DokkaGenerator( - AntLogger(this), - compileClasspath.list().toList(), - sourcePath.list().toList(), - samplesPath.list().toList(), - includesPath.list().toList(), - moduleName!!, - DocumentationOptions(outputDir!!, outputFormat, - skipDeprecated = skipDeprecated, - sourceLinks = sourceLinks, - jdkVersion = jdkVersion) - ) - generator.generate() - } -}
\ No newline at end of file |