diff options
Diffstat (limited to 'src/main.kt')
-rw-r--r-- | src/main.kt | 75 |
1 files changed, 63 insertions, 12 deletions
diff --git a/src/main.kt b/src/main.kt index 970bbd8c..6f5cf796 100644 --- a/src/main.kt +++ b/src/main.kt @@ -6,11 +6,22 @@ import org.jetbrains.jet.cli.common.messages.* import org.jetbrains.jet.cli.common.arguments.* import org.jetbrains.jet.utils.PathUtil import java.io.File +import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor +import org.jetbrains.jet.lang.resolve.name.FqName +import java.lang.reflect.Constructor class DokkaArguments { Argument(value = "src", description = "Source file or directory (allows many paths separated by the system path separator)") ValueDescription("<path>") - public var src: String? = null + public var src: String = "" + + Argument(value = "include", description = "Markdown files to load (allows many paths separated by the system path separator)") + ValueDescription("<path>") + public var include: String = "" + + Argument(value = "samples", description = "Source root for samples") + ValueDescription("<path>") + public var samples: String = "" Argument(value = "output", description = "Output directory path for .md files") ValueDescription("<path>") @@ -23,21 +34,25 @@ class DokkaArguments { Argument(value = "classpath", description = "Classpath for symbol resolution") ValueDescription("<path>") public var classpath: String = "" + } public fun main(args: Array<String>) { - val arguments = DokkaArguments() - val sourceFiles = Args.parse(arguments, args) - val sources: List<String> = sourceFiles ?: listOf() + 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 environment = AnalysisEnvironment(MessageCollectorPlainTextToStream.PLAIN_TEXT_TO_SYSTEM_ERR) { addClasspath(PathUtil.getJdkClassesRoots()) + // addClasspath(PathUtil.getKotlinPathsForCompiler().getRuntimePath()) for (element in arguments.classpath.split(File.pathSeparatorChar)) { addClasspath(File(element)) } - // addClasspath(PathUtil.getKotlinPathsForCompiler().getRuntimePath()) + addSources(sources) + addSources(samples) } println("Module: ${arguments.moduleName}") @@ -47,15 +62,50 @@ public fun main(args: Array<String>) { println() - print("Analysing sources and libraries... ") + println("Analysing sources and libraries... ") val startAnalyse = System.currentTimeMillis() - val documentation = environment.withContext<DocumentationModule> { environment, module, context -> - val packageSet = environment.getSourceFiles().map { file -> - context.getPackageFragment(file)!!.fqName - }.toSet() - context.createDocumentationModule(arguments.moduleName, module, packageSet) + + val documentation = environment.withContext { environment, session -> + val fragmentFiles = environment.getSourceFiles().filter { + val sourceFile = File(it.getVirtualFile()!!.getPath()) + samples.none { sample -> + val canonicalSample = File(sample).canonicalPath + val canonicalSource = sourceFile.canonicalPath + canonicalSource.startsWith(canonicalSample) + } + } + val fragments = fragmentFiles.map { session.getPackageFragment(it.getPackageFqName()) }.filterNotNull().distinct() + val options = DocumentationOptions() + val documentationBuilder = DocumentationBuilder(session, options) + + with(documentationBuilder) { + + val moduleContent = Content() + for (include in includes) { + val text = File(include).readText() + val tree = MarkdownProcessor.parse(text) + val content = buildContent(tree, session.getPackageFragment(FqName.ROOT)) + moduleContent.children.addAll(content.children) + } + + val documentationModule = DocumentationModule(arguments.moduleName, moduleContent) + + val descriptors = hashMapOf<String, List<DeclarationDescriptor>>() + for ((name, parts) in fragments.groupBy { it.fqName }) { + descriptors.put(name.asString(), parts.flatMap { it.getMemberScope().getAllDescriptors() }) + } + for ((packageName, declarations) in descriptors) { + println(" package $packageName: ${declarations.count()} nodes") + val packageNode = DocumentationNode(packageName, Content.Empty, DocumentationNode.Kind.Package) + packageNode.appendChildren(declarations, DocumentationReference.Kind.Member) + documentationModule.append(packageNode, DocumentationReference.Kind.Member) + } + documentationBuilder.resolveReferences(documentationModule) + documentationModule + } } + val timeAnalyse = System.currentTimeMillis() - startAnalyse println("done in ${timeAnalyse / 1000} secs") @@ -64,9 +114,10 @@ public fun main(args: Array<String>) { val locationService = FoldersLocationService(arguments.outputDir) val templateService = HtmlTemplateService.default("/dokka/styles/style.css") +// val formatter = HtmlFormatService(locationService, signatureGenerator, templateService) val formatter = KotlinWebsiteFormatService(locationService, signatureGenerator) val generator = FileGenerator(signatureGenerator, locationService, formatter) - print("Building pages... ") + print("Generating pages... ") generator.buildPage(documentation) generator.buildOutline(documentation) val timeBuild = System.currentTimeMillis() - startBuild |