diff options
Diffstat (limited to 'runners')
-rw-r--r-- | runners/ant/src/main/kotlin/ant/dokka.kt | 221 | ||||
-rw-r--r-- | runners/cli/build.gradle | 6 | ||||
-rw-r--r-- | runners/cli/src/main/kotlin/cli/DokkaArgumentsParser.kt | 185 | ||||
-rw-r--r-- | runners/cli/src/main/kotlin/cli/main.kt | 308 | ||||
-rw-r--r-- | runners/gradle-plugin/src/main/kotlin/main.kt | 9 | ||||
-rw-r--r-- | runners/maven-plugin/src/main/kotlin/DokkaMojo.kt | 50 |
6 files changed, 545 insertions, 234 deletions
diff --git a/runners/ant/src/main/kotlin/ant/dokka.kt b/runners/ant/src/main/kotlin/ant/dokka.kt index b23328e0..fe793396 100644 --- a/runners/ant/src/main/kotlin/ant/dokka.kt +++ b/runners/ant/src/main/kotlin/ant/dokka.kt @@ -17,54 +17,103 @@ 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(): SourceRootImpl? = path?.let { - path -> - SourceRootImpl(path, platforms?.split(',').orEmpty()) +class AntSourceRoot(var path: String? = null) { + fun toSourceRoot(): SourceRootImpl? = path?.let { path -> + SourceRootImpl(path) } } -class AntPackageOptions( - override var prefix: String = "", - override var includeNonPublic: Boolean = false, - override var reportUndocumented: Boolean = true, - override var skipDeprecated: Boolean = false, - override var suppress: Boolean = false) : DokkaConfiguration.PackageOptions - +class TextProperty(var value: String = "") + +class AntPassConfig(task: Task) : DokkaConfiguration.PassConfiguration { + override var moduleName: String = "" + override val classpath: List<String> + get() = buildClassPath.list().toList() + + override val sourceRoots: List<DokkaConfiguration.SourceRoot> + get() = sourcePath.list().map { SourceRootImpl(it) } + antSourceRoots.mapNotNull { it.toSourceRoot() } + + override val samples: List<String> + get() = samplesPath.list().toList() + override val includes: List<String> + get() = includesPath.list().toList() + override var includeNonPublic: Boolean = false + override var includeRootPackage: Boolean = true + override var reportUndocumented: Boolean = false + override var skipEmptyPackages: Boolean = true + override var skipDeprecated: Boolean = false + override var jdkVersion: Int = 6 + override val sourceLinks: List<DokkaConfiguration.SourceLinkDefinition> + get() = antSourceLinkDefinition.map { + val path = it.path!! + val url = it.url!! + SourceLinkDefinitionImpl(File(path).canonicalFile.absolutePath, url, it.lineSuffix) + } + override val perPackageOptions: MutableList<DokkaConfiguration.PackageOptions> = mutableListOf() + override val externalDocumentationLinks: List<ExternalDocumentationLink> + get() = buildExternalLinksBuilders.map { it.build() } + defaultExternalDocumentationLinks + + override var languageVersion: String? = null + override var apiVersion: String? = null + override var noStdlibLink: Boolean = false + override var noJdkLink: Boolean = false + override var suppressedFiles: MutableList<String> = mutableListOf() + override var collectInheritedExtensionsFromLibraries: Boolean = false + override var analysisPlatform: Platform = Platform.DEFAULT + override var targets: List<String> = listOf() + get() = buildTargets.filter { it.value != "" } + .map { it.value } + + override var sinceKotlin: String = "1.0" + + private val samplesPath: Path by lazy { Path(task.project) } + private val includesPath: Path by lazy { Path(task.project) } + private val buildClassPath: Path by lazy { Path(task.project) } + val sourcePath: Path by lazy { Path(task.project) } + val antSourceRoots: MutableList<AntSourceRoot> = mutableListOf() + + private val buildTargets: MutableList<TextProperty> = mutableListOf() + private val buildExternalLinksBuilders: MutableList<ExternalDocumentationLink.Builder> = mutableListOf() + val antSourceLinkDefinition: MutableList<AntSourceLinkDefinition> = mutableListOf() + + private val defaultExternalDocumentationLinks: List<DokkaConfiguration.ExternalDocumentationLink> + get() { + val links = mutableListOf<DokkaConfiguration.ExternalDocumentationLink>() + if (!noJdkLink) + links += DokkaConfiguration.ExternalDocumentationLink.Builder("https://docs.oracle.com/javase/$jdkVersion/docs/api/").build() + + if (!noStdlibLink) + links += DokkaConfiguration.ExternalDocumentationLink.Builder("https://kotlinlang.org/api/latest/jvm/stdlib/").build() + return links + } -class DokkaAntTask: Task() { - var moduleName: String? = null - var outputDir: String? = null - var outputFormat: String = "html" - var impliedPlatforms: String = "" - var jdkVersion: Int = 6 - var noStdlibLink: Boolean = false - var noJdkLink: Boolean = false + fun setSamples(ref: Path) { + samplesPath.append(ref) + } - var skipDeprecated: Boolean = false + fun setSamplesRef(ref: Reference) { + samplesPath.createPath().refid = ref + } - var cacheRoot: String? = null + fun setInclude(ref: Path) { + includesPath.append(ref) + } - var languageVersion: String? = null - var apiVersion: String? = null + fun setClasspath(classpath: Path) { + buildClassPath.append(classpath) + } - 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()) } + fun createPackageOptions(): AntPackageOptions = AntPackageOptions().apply { perPackageOptions.add(this) } - val antSourceLinks: MutableList<AntSourceLinkDefinition> = arrayListOf() - val antSourceRoots: MutableList<AntSourceRoot> = arrayListOf() - val antPackageOptions: MutableList<AntPackageOptions> = arrayListOf() - val antExternalDocumentationLinks = mutableListOf<ExternalDocumentationLink.Builder>() + fun createSourceRoot(): AntSourceRoot = AntSourceRoot().apply { antSourceRoots.add(this) } - fun setClasspath(classpath: Path) { - compileClasspath.append(classpath) + fun createTarget(): TextProperty = TextProperty().apply { + buildTargets.add(this) } fun setClasspathRef(ref: Reference) { - compileClasspath.createPath().refid = ref + buildClassPath.createPath().refid = ref } fun setSrc(src: Path) { @@ -75,73 +124,69 @@ class DokkaAntTask: Task() { 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) + antSourceLinkDefinition.add(def) return def } - fun createSourceRoot(): AntSourceRoot = AntSourceRoot().apply { antSourceRoots.add(this) } + fun createExternalDocumentationLink() = + ExternalDocumentationLink.Builder().apply { buildExternalLinksBuilders.add(this) } + +} + +class AntPackageOptions( + override var prefix: String = "", + override var includeNonPublic: Boolean = false, + override var reportUndocumented: Boolean = true, + override var skipDeprecated: Boolean = false, + override var suppress: Boolean = false) : DokkaConfiguration.PackageOptions + +class DokkaAntTask: Task(), DokkaConfiguration { - fun createPackageOptions(): AntPackageOptions = AntPackageOptions().apply { antPackageOptions.add(this) } + override var format: String = "html" + override var generateIndexPages: Boolean = false + override var outputDir: String = "" + override var impliedPlatforms: List<String> = listOf() + get() = buildImpliedPlatforms.map { it.value }.toList() + private val buildImpliedPlatforms: MutableList<TextProperty> = mutableListOf() + + override var cacheRoot: String? = null + override val passesConfigurations: MutableList<AntPassConfig> = mutableListOf() + + fun createPassConfig() = AntPassConfig(this).apply { passesConfigurations.add(this) } + fun createImpliedPlatform(): TextProperty = TextProperty().apply { buildImpliedPlatforms.add(this) } - fun createExternalDocumentationLink() = ExternalDocumentationLink.Builder().apply { antExternalDocumentationLinks.add(this) } override fun execute() { - if (sourcePath.list().isEmpty() && antSourceRoots.isEmpty()) { - 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") - if (path.contains("\\")) { - throw BuildException("'dir' attribute of a <sourceLink> - incorrect value, only Unix based path allowed.") + for (passConfig in passesConfigurations) { + if (passConfig.sourcePath.list().isEmpty() && passConfig.antSourceRoots.isEmpty()) { + throw BuildException("At least one source path needs to be specified") } - val url = it.url ?: throw BuildException("'url' attribute of a <sourceLink> element is required") - SourceLinkDefinitionImpl(File(path).canonicalFile.absolutePath, url, it.lineSuffix) + if (passConfig.moduleName == "") { + throw BuildException("Module name needs to be specified and not empty") + } + + for (sourceLink in passConfig.antSourceLinkDefinition) { + if (sourceLink.path == null) { + throw BuildException("'path' attribute of a <sourceLink> element is required") + } + if (sourceLink.path.contains("\\")) { + throw BuildException("'dir' attribute of a <sourceLink> - incorrect value, only Unix based path allowed") + } + + if (sourceLink.url == null) { + throw BuildException("'url' attribute of a <sourceLink> element is required") + } + } + } + + if (outputDir == "") { + throw BuildException("Output directory needs to be specified and not empty") } - val generator = DokkaGenerator( - AntLogger(this), - compileClasspath.list().toList(), - sourcePath.list().map { SourceRootImpl(it) } + antSourceRoots.mapNotNull { it.toSourceRoot() }, - samplesPath.list().toList(), - includesPath.list().toList(), - moduleName!!, - DocumentationOptions( - outputDir!!, - outputFormat, - skipDeprecated = skipDeprecated, - sourceLinks = sourceLinks, - jdkVersion = jdkVersion, - impliedPlatforms = impliedPlatforms.split(','), - perPackageOptions = antPackageOptions, - externalDocumentationLinks = antExternalDocumentationLinks.map { it.build() }, - noStdlibLink = noStdlibLink, - noJdkLink = noJdkLink, - cacheRoot = cacheRoot, - languageVersion = languageVersion, - apiVersion = apiVersion - ) - ) + val generator = DokkaGenerator(this, AntLogger(this)) generator.generate() } }
\ No newline at end of file diff --git a/runners/cli/build.gradle b/runners/cli/build.gradle index 7f733140..4ef5d419 100644 --- a/runners/cli/build.gradle +++ b/runners/cli/build.gradle @@ -10,7 +10,11 @@ tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all { } } +repositories { + mavenLocal() +} + dependencies { compile project(":core") - compile "com.github.spullara.cli-parser:cli-parser:1.1.1" + compile "org.jetbrains.kotlinx:cli:0.1" } diff --git a/runners/cli/src/main/kotlin/cli/DokkaArgumentsParser.kt b/runners/cli/src/main/kotlin/cli/DokkaArgumentsParser.kt new file mode 100644 index 00000000..5d795da7 --- /dev/null +++ b/runners/cli/src/main/kotlin/cli/DokkaArgumentsParser.kt @@ -0,0 +1,185 @@ +package org.jetbrains.dokka + +import kotlinx.cli.* +import kotlin.reflect.KProperty + +class ParseContext(val cli: CommandLineInterface = CommandLineInterface("dokka")) { + private val transformActions = mutableMapOf<KProperty<*>, (String) -> Unit>() + private val flagActions = mutableMapOf<KProperty<*>, () -> Unit>() + + fun registerFlagAction( + keys: List<String>, + help: String, + property: KProperty<*>, + invoke: () -> Unit + ) { + if (property !in flagActions.keys) { + cli.flagAction(keys, help) { + flagActions[property]!!() + } + } + flagActions[property] = invoke + + } + + fun registerSingleOption( + keys: List<String>, + help: String, + property: KProperty<*>, + invoke: (String) -> Unit + ) { + if (property !in transformActions.keys) { + cli.singleAction(keys, help) { + transformActions[property]!!(it) + } + } + transformActions[property] = invoke + } + + fun registerRepeatableOption( + keys: List<String>, + help: String, + property: KProperty<*>, + invoke: (String) -> Unit + ) { + if (property !in transformActions.keys) { + cli.repeatingAction(keys, help) { + transformActions[property]!!(it) + } + } + transformActions[property] = invoke + } + + fun parse(args: Array<String>) { + cli.parseArgs(*args) + } + +} + +fun CommandLineInterface.singleAction( + keys: List<String>, + help: String, + invoke: (String) -> Unit +) = registerAction( + object : FlagActionBase(keys, help) { + override fun invoke(arguments: ListIterator<String>) { + if (arguments.hasNext()) { + val msg = arguments.next() + invoke(msg) + } + } + + override fun invoke() { + error("should be never called") + } + } +) + +fun CommandLineInterface.repeatingAction( + keys: List<String>, + help: String, + invoke: (String) -> Unit +) = registerAction( + object : FlagActionBase(keys, help) { + override fun invoke(arguments: ListIterator<String>) { + while (arguments.hasNext()) { + val message = arguments.next() + + if (this@repeatingAction.getFlagAction(message) != null) { + arguments.previous() + break + } + invoke(message) + } + } + + override fun invoke() { + error("should be never called") + } + } + +) + + +class DokkaArgumentsParser(val args: Array<String>, val parseContext: ParseContext) { + class OptionDelegate<T>( + var value: T, + private val action: (delegate: OptionDelegate<T>, property: KProperty<*>) -> Unit + ) { + operator fun getValue(thisRef: Any?, property: KProperty<*>): T = value + operator fun provideDelegate(thisRef: Any, property: KProperty<*>): OptionDelegate<T> { + action(this, property) + return this + } + } + + fun <T> parseInto(dest: T): T { + // TODO: constructor: (DokkaArgumentsParser) -> T + parseContext.parse(args) + return dest + } + + fun <T> repeatableOption( + keys: List<String>, + help: String, + transform: (String) -> T + ) = OptionDelegate(mutableListOf<T>()) { delegate, property -> + parseContext.registerRepeatableOption(keys, help, property) { + delegate.value.add(transform(it)) + } + } + + fun <T : String?> repeatableOption( + keys: List<String>, + help: String + ) = repeatableOption(keys, help) { it as T } + + fun <T> repeatableFlag( + keys: List<String>, + help: String, + initElement: (ParseContext) -> T + ) = OptionDelegate(mutableListOf<T>()) { delegate, property -> + parseContext.registerFlagAction(keys, help, property) { + delegate.value.add(initElement(parseContext)) + } + } + + fun <T> singleFlag( + keys: List<String>, + help: String, + initElement: (ParseContext) -> T, + transform: () -> T + ) = OptionDelegate(initElement(parseContext)) { delegate, property -> + parseContext.registerFlagAction(keys, help, property) { + delegate.value = transform() + } + } + + fun singleFlag( + keys: List<String>, + help: String + ) = singleFlag(keys, help, { false }, { true }) + + fun <T : String?> stringOption( + keys: List<String>, + help: String, + defaultValue: T + ) = singleOption(keys, help, { it as T }, { defaultValue }) + + fun <T> singleOption( + keys: List<String>, + help: String, + transform: (String) -> T, + initElement: (ParseContext) -> T + ) = OptionDelegate(initElement(parseContext)) { delegate, property -> + parseContext.registerSingleOption(keys, help, property) { + val toAdd = transform(it) + delegate.value = toAdd + } + } +} + + +//`(-perPackage fqName [-include-non-public] [...other flags])*` (edited) +//`(-sourceLink dir url [-urlSuffix value])*` +//`(-extLink url [packageListUrl])*`
\ No newline at end of file diff --git a/runners/cli/src/main/kotlin/cli/main.kt b/runners/cli/src/main/kotlin/cli/main.kt index f871f406..d67a9875 100644 --- a/runners/cli/src/main/kotlin/cli/main.kt +++ b/runners/cli/src/main/kotlin/cli/main.kt @@ -1,78 +1,157 @@ package org.jetbrains.dokka - -import com.sampullara.cli.Args -import com.sampullara.cli.Argument +import kotlinx.cli.registerAction import org.jetbrains.dokka.DokkaConfiguration.ExternalDocumentationLink +import org.jetbrains.kotlin.daemon.common.compareDaemonJVMOptionsMemory import java.io.File import java.net.MalformedURLException import java.net.URL import java.net.URLClassLoader -class DokkaArguments { - @set:Argument(value = "src", description = "Source file or directory (allows many paths separated by the system path separator)") - var src: String = "" - - @set:Argument(value = "srcLink", description = "Mapping between a source directory and a Web site for browsing the code") - var srcLink: String = "" - - @set:Argument(value = "include", description = "Markdown files to load (allows many paths separated by the system path separator)") - var include: String = "" - - @set:Argument(value = "samples", description = "Source root for samples") - var samples: String = "" - - @set:Argument(value = "output", description = "Output directory path") - var outputDir: String = "out/doc/" - - @set:Argument(value = "format", description = "Output format (text, html, markdown, jekyll, kotlin-website)") - var outputFormat: String = "html" - - @set:Argument(value = "module", description = "Name of the documentation module") - var moduleName: String = "" - - @set:Argument(value = "classpath", description = "Classpath for symbol resolution") - 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 - - @set:Argument(value = "impliedPlatforms", description = "List of implied platforms (comma-separated)") - var impliedPlatforms: String = "" - - @set:Argument(value = "packageOptions", description = "List of package options in format \"prefix,-deprecated,-privateApi,+warnUndocumented,+suppress;...\" ") - var packageOptions: String = "" - - @set:Argument(value = "links", description = "External documentation links in format url^packageListUrl^^url2...") - var links: String = "" - - @set:Argument(value = "noStdlibLink", description = "Disable documentation link to stdlib") - var noStdlibLink: Boolean = false - - @set:Argument(value = "noJdkLink", description = "Disable documentation link to jdk") - var noJdkLink: Boolean = false - - @set:Argument(value = "cacheRoot", description = "Path to cache folder, or 'default' to use ~/.cache/dokka, if not provided caching is disabled") - var cacheRoot: String? = null - - @set:Argument(value = "languageVersion", description = "Language Version to pass to Kotlin Analysis") - var languageVersion: String? = null - - @set:Argument(value = "apiVersion", description = "Kotlin Api Version to pass to Kotlin Analysis") - var apiVersion: String? = null - - @set:Argument(value = "collectInheritedExtensionsFromLibraries", description = "Search for applicable extensions in libraries") - var collectInheritedExtensionsFromLibraries: Boolean = false - +open class GlobalArguments(parser: DokkaArgumentsParser) : DokkaConfiguration { + override val outputDir: String by parser.stringOption( + listOf("-output"), + "Output directory path", + "") + + override val format: String by parser.stringOption( + listOf("-format"), + "Output format (text, html, markdown, jekyll, kotlin-website)", + "") + + override val generateIndexPages: Boolean by parser.singleFlag( + listOf("-generateIndexPages"), + "Generate index page" + ) + + override val cacheRoot: String? by parser.stringOption( + listOf("-cacheRoot"), + "Path to cache folder, or 'default' to use ~/.cache/dokka, if not provided caching is disabled", + null) + + override val impliedPlatforms: List<String> by parser.repeatableOption( + listOf("-impliedPlatforms"), + "List of implied platforms (comma-separated)" + ) + + override val passesConfigurations: List<Arguments> by parser.repeatableFlag( + listOf("-pass"), + "Single dokka pass" + ) { + Arguments(parser) + } } +class Arguments(val parser: DokkaArgumentsParser) : DokkaConfiguration.PassConfiguration { + override val moduleName: String by parser.stringOption( + listOf("-module"), + "Name of the documentation module", + "") + + override val classpath: List<String> by parser.repeatableOption( + listOf("-classpath"), + "Classpath for symbol resolution" + ) + + override val sourceRoots: List<DokkaConfiguration.SourceRoot> by parser.repeatableOption( + listOf("-src"), + "Source file or directory (allows many paths separated by the system path separator)" + ) { SourceRootImpl.parseSourceRoot(it) } + + override val samples: List<String> by parser.repeatableOption( + listOf("-samples"), + "Source root for samples" + ) + + override val includes: List<String> by parser.repeatableOption( + listOf("-include"), + "Markdown files to load (allows many paths separated by the system path separator)" + ) + + override val includeNonPublic: Boolean by parser.singleFlag( + listOf("-includeNonPublic"), + "Include non public") + + override val includeRootPackage: Boolean by parser.singleFlag( + listOf("-includeRootPackage"), + "Include non public") + + override val reportUndocumented: Boolean by parser.singleFlag( + listOf("-reportUndocumented"), + "Include non public") + + override val skipEmptyPackages: Boolean by parser.singleFlag( + listOf("-skipEmptyPackages"), + "Include non public") + + override val skipDeprecated: Boolean by parser.singleFlag( + listOf("-skipDeprecated"), + "Include non public") + + override val jdkVersion: Int by parser.singleOption( + listOf("jdkVersion"), + "Version of JDK to use for linking to JDK JavaDoc", + { it.toInt() }, + { 6 } + ) + + override val languageVersion: String? by parser.stringOption( + listOf("-languageVersion"), + "Language Version to pass to Kotlin Analysis", + null) + + override val apiVersion: String? by parser.stringOption( + listOf("-apiVesion"), + "Kotlin Api Version to pass to Kotlin Analysis", + null + ) + + override val noStdlibLink: Boolean by parser.singleFlag( + listOf("-noStdlibLink"), + "Disable documentation link to stdlib") + + override val noJdkLink: Boolean by parser.singleFlag( + listOf("-noJdkLink"), + "Disable documentation link to stdlib") + + override val suppressedFiles: List<String> by parser.repeatableOption( + listOf("-suppresedFiles"), + "" + ) + + override val sinceKotlin: String by parser.stringOption( + listOf("-sinceKotlin"), + "Kotlin Api version to use as base version, if none specified", + "1.0" + ) + + override val collectInheritedExtensionsFromLibraries: Boolean by parser.singleFlag( + listOf("-collectInheritedExtensionsFromLibraries"), + "Search for applicable extensions in libraries") + + override val analysisPlatform: Platform by parser.singleOption( + listOf("-analysisPlatform"), + "Platform for analysis", + { Platform.fromString(it) }, + { Platform.DEFAULT } + ) + + override val targets: List<String> by parser.repeatableOption( + listOf("-targets"), + "Generation targets" + ) + + + + override val sourceLinks: MutableList<DokkaConfiguration.SourceLinkDefinition> = mutableListOf() + + override val perPackageOptions: MutableList<DokkaConfiguration.PackageOptions> = mutableListOf() + + override val externalDocumentationLinks: MutableList<DokkaConfiguration.ExternalDocumentationLink> = mutableListOf() +} object MainKt { - fun parseLinks(links: String): List<ExternalDocumentationLink> { val (parsedLinks, parsedOfflineLinks) = links.split("^^") .map { it.split("^").map { it.trim() }.filter { it.isNotBlank() } } @@ -93,50 +172,8 @@ object MainKt { } @JvmStatic - fun entry(args: Array<String>) { - val arguments = DokkaArguments() - val freeArgs: List<String> = Args.parse(arguments, args) ?: 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(SourceLinkDefinitionImpl.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, - impliedPlatforms = arguments.impliedPlatforms.split(','), - perPackageOptions = parsePerPackageOptions(arguments.packageOptions), - jdkVersion = arguments.jdkVersion, - externalDocumentationLinks = parseLinks(arguments.links), - noStdlibLink = arguments.noStdlibLink, - cacheRoot = arguments.cacheRoot, - languageVersion = arguments.languageVersion, - apiVersion = arguments.apiVersion, - collectInheritedExtensionsFromLibraries = arguments.collectInheritedExtensionsFromLibraries, - noJdkLink = arguments.noJdkLink - ) - - val generator = DokkaGenerator( - DokkaConsoleLogger, - classPath, - sources.map(SourceRootImpl.Companion::parseSourceRoot), - samples, - includes, - arguments.moduleName, - documentationOptions) - + fun entry(configuration: DokkaConfiguration) { + val generator = DokkaGenerator(configuration, DokkaConsoleLogger) generator.generate() DokkaConsoleLogger.report() } @@ -162,27 +199,68 @@ object MainKt { return URLClassLoader(urls, ClassLoader.getSystemClassLoader().parent) } - fun startWithToolsJar(args: Array<String>) { + fun startWithToolsJar(configuration: DokkaConfiguration) { try { javaClass.classLoader.loadClass("com.sun.tools.doclets.formats.html.HtmlDoclet") - entry(args) + entry(configuration) } catch (e: ClassNotFoundException) { val classLoader = createClassLoaderWithTools() classLoader.loadClass("org.jetbrains.dokka.MainKt") .methods.find { it.name == "entry" }!! - .invoke(null, args) + .invoke(null, configuration) + } + } + + fun createConfiguration(args: Array<String>): GlobalArguments { + val parseContext = ParseContext() + val parser = DokkaArgumentsParser(args, parseContext) + + + val configuration = GlobalArguments(parser) + + + parseContext.cli.singleAction( + listOf("-pckageOptions"), + "List of package passConfiguration in format \"prefix,-deprecated,-privateApi,+warnUndocumented,+suppress;...\" " + ) { + configuration.passesConfigurations.last().perPackageOptions.addAll(parsePerPackageOptions(it)) + } + + parseContext.cli.singleAction( + listOf("-links"), + "External documentation links in format url^packageListUrl^^url2..." + ) { + configuration.passesConfigurations.last().externalDocumentationLinks.addAll(MainKt.parseLinks(it)) } + + parseContext.cli.singleAction( + listOf("-srcLink"), + "Mapping between a source directory and a Web site for browsing the code" + ) { + val newSourceLinks = if (it.isNotEmpty() && it.contains("=")) + listOf(SourceLinkDefinitionImpl.parseSourceLinkDefinition(it)) + else { + if (it.isNotEmpty()) { + println("Warning: Invalid -srcLink syntax. Expected: <path>=<url>[#lineSuffix]. No source links will be generated.") + } + listOf() + } + + configuration.passesConfigurations.last().sourceLinks.addAll(newSourceLinks) + + } + + parser.parseInto(configuration) + return configuration } @JvmStatic fun main(args: Array<String>) { - val arguments = DokkaArguments() - Args.parse(arguments, args) - - if (arguments.outputFormat == "javadoc") - startWithToolsJar(args) + val configuration = createConfiguration(args) + if (configuration.format == "javadoc") + startWithToolsJar(configuration) else - entry(args) + entry(configuration) } } diff --git a/runners/gradle-plugin/src/main/kotlin/main.kt b/runners/gradle-plugin/src/main/kotlin/main.kt index f4adc1c3..f726c6c7 100644 --- a/runners/gradle-plugin/src/main/kotlin/main.kt +++ b/runners/gradle-plugin/src/main/kotlin/main.kt @@ -325,6 +325,8 @@ open class DokkaTask : DefaultTask() { val bootstrapProxy: DokkaBootstrap = automagicTypedProxy(javaClass.classLoader, bootstrapInstance) + TODO("Fix Configuration in Gradle") + /* val configuration = SerializeOnlyDokkaConfiguration( moduleName, fullClasspath.map { it.absolutePath }, @@ -365,6 +367,7 @@ open class DokkaTask : DefaultTask() { serialize(configuration) ) + */ bootstrapProxy.generate() } finally { @@ -436,11 +439,7 @@ class SourceRoot : DokkaConfiguration.SourceRoot, Serializable { field = File(value).absolutePath } - override var platforms: List<String> = arrayListOf() - - override fun toString(): String { - return "${platforms.joinToString()}::$path" - } + override fun toString(): String = path } open class LinkMapping : Serializable, DokkaConfiguration.SourceLinkDefinition { diff --git a/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt b/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt index 324703a0..ed8a659f 100644 --- a/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt +++ b/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt @@ -37,9 +37,6 @@ abstract class AbstractDokkaMojo : AbstractMojo() { class SourceRoot : DokkaConfiguration.SourceRoot { @Parameter(required = true) override var path: String = "" - - @Parameter - override var platforms: List<String> = emptyList() } class PackageOptions : DokkaConfiguration.PackageOptions { @@ -132,30 +129,33 @@ abstract class AbstractDokkaMojo : AbstractMojo() { } } - val gen = DokkaGenerator( - MavenDokkaLogger(log), - classpath, - sourceDirectories.map { SourceRootImpl(it) } + sourceRoots, - samplesDirs, - includeDirs + includes, - moduleName, - DocumentationOptions(getOutDir(), getOutFormat(), - sourceLinks = sourceLinks.map { SourceLinkDefinitionImpl(it.dir, it.url, it.urlSuffix) }, - jdkVersion = jdkVersion, - skipDeprecated = skipDeprecated, - skipEmptyPackages = skipEmptyPackages, - reportUndocumented = reportNotDocumented, - impliedPlatforms = impliedPlatforms, - perPackageOptions = perPackageOptions, - externalDocumentationLinks = externalDocumentationLinks.map { it.build() }, - noStdlibLink = noStdlibLink, - noJdkLink = noJdkLink, - cacheRoot = cacheRoot, - languageVersion = languageVersion, - apiVersion = apiVersion - ) + val passConfiguration = PassConfigurationImpl( + sourceLinks = sourceLinks.map { SourceLinkDefinitionImpl(it.dir, it.url, it.urlSuffix) }, + jdkVersion = jdkVersion, + skipDeprecated = skipDeprecated, + skipEmptyPackages = skipEmptyPackages, + reportUndocumented = reportNotDocumented, + perPackageOptions = perPackageOptions, + externalDocumentationLinks = externalDocumentationLinks.map { it.build() }, + noStdlibLink = noStdlibLink, + noJdkLink = noJdkLink, + languageVersion = languageVersion, + apiVersion = apiVersion + ) + val configuration = DokkaConfigurationImpl( + outputDir = getOutDir(), + format = getOutFormat(), + impliedPlatforms = impliedPlatforms, + cacheRoot = cacheRoot, + passesConfigurations = listOf( + passConfiguration + ) + ) + + val gen = DokkaGenerator(configuration, MavenDokkaLogger(log)) + gen.generate() } } |