added a command line KDocCompiler so its easy to generate kdoc from command line or build tools. Also added generation of the kdoc documentation in a test case in the website project along with a simple html website
This commit is contained in:
+14
-4
@@ -1,14 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="false">
|
||||
<output url="file://$MODULE_DIR$/target/classes" />
|
||||
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/kotlin" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/kotlin" isTestSource="true" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module" module-name="stdlib" exported="" />
|
||||
<orderEntry type="module-library" exported="" scope="TEST">
|
||||
<library>
|
||||
<CLASSES>
|
||||
@@ -157,6 +158,15 @@
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
<orderEntry type="library" name="Maven: org.pegdown:pegdown:1.1.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.parboiled:parboiled-core:1.0.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.parboiled:parboiled-java:1.0.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: asm:asm:3.3.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: asm:asm-util:3.3.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: asm:asm-tree:3.3.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: asm:asm-analysis:3.3.1" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.9" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
package org.jetbrains.kotlin.doc
|
||||
|
||||
import org.jetbrains.jet.cli.KotlinCompiler
|
||||
import org.jetbrains.jet.compiler.CompileEnvironment
|
||||
import org.jetbrains.jet.cli.CompilerArguments
|
||||
import java.io.PrintStream
|
||||
import java.io.File
|
||||
import kotlin.util.orEmpty
|
||||
|
||||
/**
|
||||
* Main for running the KDocCompiler
|
||||
*/
|
||||
fun main(args: Array<String?>): Unit {
|
||||
KotlinCompiler.doMain(KDocCompiler(), args);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A version of the [[KotlinCompiler]] which includes the [[KDoc]] compiler plugin and allows
|
||||
* command line validation or for the configuration to be provided via [[KDocArguments]]
|
||||
*/
|
||||
class KDocCompiler() : KotlinCompiler() {
|
||||
|
||||
override fun configureEnvironment(environment : CompileEnvironment?, arguments : CompilerArguments?, errStream : PrintStream?) {
|
||||
// TODO lets clear the docOutput as a temporary hack while
|
||||
// KotlinCompiler has a KDoc hook...
|
||||
val docOutputDir = if (arguments != null) {
|
||||
val answer = arguments.docOutputDir
|
||||
arguments.docOutputDir = null
|
||||
answer
|
||||
} else null
|
||||
|
||||
super.configureEnvironment(environment, arguments, errStream)
|
||||
val coreEnvironment = environment?.getMyEnvironment()
|
||||
if (coreEnvironment != null) {
|
||||
// now lets add the KDoc plugin
|
||||
val outDir = File(docOutputDir ?: "target/apidocs")
|
||||
val kdoc = KDoc(outDir)
|
||||
|
||||
if (arguments is KDocArguments) {
|
||||
kdoc.config = arguments.apply()
|
||||
}
|
||||
coreEnvironment.getCompilerPlugins().orEmpty().add(kdoc);
|
||||
}
|
||||
}
|
||||
|
||||
override fun createArguments() : CompilerArguments? {
|
||||
return KDocArguments()
|
||||
}
|
||||
|
||||
override fun usage(target : PrintStream?) {
|
||||
target?.println("Usage: KDocCompiler -docOutput <docOutputDir> [-output <outputDir>|-jar <jarFileName>] [-stdlib <path to runtime.jar>] [-src <filename or dirname>|-module <module file>] [-includeRuntime]");
|
||||
}
|
||||
}
|
||||
|
||||
class KDocArguments() : CompilerArguments() {
|
||||
|
||||
public var docConfig: KDocConfig = KDocConfig()
|
||||
|
||||
/**
|
||||
* Applies the command line arguments to the given KDoc configuration
|
||||
*/
|
||||
fun apply(): KDocConfig {
|
||||
// TODO...
|
||||
return docConfig
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add more configurations here when value attributes supported
|
||||
* see: KT-1522
|
||||
|
||||
@Argument(value = "docOutput", description = "KDoc output directory")
|
||||
public String docOutputDir;
|
||||
*/
|
||||
}
|
||||
@@ -1,9 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="false">
|
||||
<output url="file://$MODULE_DIR$/target/classes" />
|
||||
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/kotlin" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
@@ -16,7 +19,8 @@
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
<orderEntry type="module" module-name="stdlib" />
|
||||
<orderEntry type="library" name="Maven: junit:junit:4.9" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="false">
|
||||
<output url="file://$MODULE_DIR$/target/classes" />
|
||||
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" exported="" name="kotlin-runtime" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.9" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
|
||||
+43
-29
@@ -24,6 +24,49 @@
|
||||
<artifactId>pegdown</artifactId>
|
||||
<version>${pegdown.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- add the kdoc dependency for generating kdoc -->
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kdoc</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>picocontainer</groupId>
|
||||
<artifactId>picocontainer</artifactId>
|
||||
<version>1.0</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${kotlin-sdk}/lib/picocontainer.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>trove4j</groupId>
|
||||
<artifactId>trove4j</artifactId>
|
||||
<version>1.0</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${kotlin-sdk}/lib/trove4j.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>11.0.1</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${kotlin-sdk}/lib/guava-11.0.1.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>asm</groupId>
|
||||
<artifactId>asm-commons</artifactId>
|
||||
<version>1.0</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${kotlin-sdk}/lib/asm-commons.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>asm</groupId>
|
||||
<artifactId>asm</artifactId>
|
||||
<version>1.0</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${kotlin-sdk}/lib/asm.jar</systemPath>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
@@ -35,35 +78,6 @@
|
||||
<plugin>
|
||||
<groupId>com.goldin.plugins</groupId>
|
||||
<artifactId>kotlin-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>compile-kotlin-sources</id>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<docOutput>${project.basedir}/target/site/apidocs</docOutput>
|
||||
<sources>
|
||||
<src>${project.basedir}/../stdlib/src</src>
|
||||
<src>${project.basedir}/../kunit/src</src>
|
||||
</sources>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kdoc</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<!-- TODO not sure why I need to add the transitive dependencies too? -->
|
||||
<dependency>
|
||||
<groupId>org.pegdown</groupId>
|
||||
<artifactId>pegdown</artifactId>
|
||||
<version>${pegdown.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
||||
|
||||
|
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.8 KiB |
@@ -18,15 +18,22 @@ class SiteGenerator(val sourceDir: File, val outputDir: File) : Runnable {
|
||||
if (it.isFile()) {
|
||||
var relativePath = sourceDir.relativePath(it)
|
||||
println("Processing ${relativePath}")
|
||||
var text = it.readText()
|
||||
var output: String? = null
|
||||
if (it.extension == "md") {
|
||||
text = markdownProcessor.markdownToHtml(text, linkRendered) ?: ""
|
||||
val text = it.readText()
|
||||
output = markdownProcessor.markdownToHtml(text, linkRendered) ?: ""
|
||||
relativePath = relativePath.trimTrailing(it.extension) + "html"
|
||||
} else if (it.extension == "html") {
|
||||
output = it.readText()
|
||||
}
|
||||
text = layout(relativePath, it, text)
|
||||
val outFile = File(outputDir, relativePath)
|
||||
outFile.directory.mkdirs()
|
||||
outFile.writeText(text)
|
||||
if (output != null) {
|
||||
val text = layout(relativePath, it, output.sure())
|
||||
outFile.writeText(text)
|
||||
} else {
|
||||
it.copyTo(outFile)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ Welcome to [Kotlin](http://www.jetbrains.com/kotlin)!
|
||||
|
||||
Some handy links
|
||||
|
||||
* [API Docs](apidocs/index.html)
|
||||
* [API Docs](versions/snapshot/apidocs/index.html)
|
||||
* [Kotlin Blog](http://blog.jetbrains.com/kotlin/)
|
||||
* [Web Demo](http://kotlin-demo.jetbrains.com/)
|
||||
* [Issue Tracker](http://youtrack.jetbrains.com/issues/KT)
|
||||
|
||||
@@ -3,15 +3,60 @@ package org.jetbrains.kotlin.site
|
||||
import junit.framework.TestCase
|
||||
import java.io.File
|
||||
import kotlin.util.arrayList
|
||||
import org.jetbrains.kotlin.doc.KDocArguments
|
||||
import org.jetbrains.kotlin.doc.KDocCompiler
|
||||
|
||||
class GenerateSiteTest : TestCase() {
|
||||
val srcDir = findTemplateDir()
|
||||
val siteOutputDir = File(srcDir, "../../../target/site")
|
||||
|
||||
// TODO find version from environment?
|
||||
val version = "snapshot"
|
||||
|
||||
fun testGenerateSite(): Unit {
|
||||
val srcDir = findTemplateDir()
|
||||
val generator = SiteGenerator(srcDir, File(srcDir, "../../../target/site"))
|
||||
val generator = SiteGenerator(srcDir, siteOutputDir)
|
||||
generator.run()
|
||||
}
|
||||
|
||||
fun testGenerateStdlibKDoc(): Unit {
|
||||
val outDir = File(siteOutputDir, "versions/$version/apidocs")
|
||||
println("Generating stdlib KDocs to $outDir")
|
||||
|
||||
copyDocResources(outDir)
|
||||
val args = KDocArguments()
|
||||
args.setSrc("../stdlib/src")
|
||||
args.setDocOutputDir(outDir.toString())
|
||||
args.setOutputDir("target/classes-stdlib")
|
||||
|
||||
val compiler = KDocCompiler()
|
||||
compiler.exec(System.out, args)
|
||||
}
|
||||
|
||||
/**
|
||||
fun testGenerateJsKDoc(): Unit {
|
||||
val args = KDocArguments()
|
||||
args.docOutputDir = File(siteOutputDir, "versions/$version/apidocs").toString()
|
||||
args.src = "../js/src"
|
||||
args.outputDir = "target/classes-js"
|
||||
|
||||
val compiler = KDocCompiler()
|
||||
compiler.exec(System.out, args)
|
||||
}
|
||||
*/
|
||||
|
||||
fun copyDocResources(outDir: File): Unit {
|
||||
val sourceDir = File(srcDir, "../apidocs")
|
||||
sourceDir.recurse {
|
||||
if (it.isFile()) {
|
||||
var relativePath = sourceDir.relativePath(it)
|
||||
val outFile = File(outDir, relativePath)
|
||||
outFile.directory.mkdirs()
|
||||
it.copyTo(outFile)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun findTemplateDir(): File {
|
||||
val path = "src/main/templates"
|
||||
for (p in arrayList(".", "apidocs", "library/apidocs")) {
|
||||
|
||||
@@ -11,14 +11,20 @@
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="Maven: org.jetbrains.kotlin:stdlib:1.0-SNAPSHOT" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.jetbrains.kotlin:kotlin-compiler:0.2.3.8" level="project" />
|
||||
<orderEntry type="module" module-name="stdlib" />
|
||||
<orderEntry type="library" name="Maven: org.pegdown:pegdown:1.1.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.parboiled:parboiled-core:1.0.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.parboiled:parboiled-java:1.0.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: asm:asm:3.3.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: asm:asm:1.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: asm:asm-util:3.3.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: asm:asm-tree:3.3.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: asm:asm-analysis:3.3.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.jetbrains.kotlin:kotlin-compiler:0.2.3.8" level="project" />
|
||||
<orderEntry type="module" module-name="kdoc" scope="TEST" />
|
||||
<orderEntry type="library" name="Maven: picocontainer:picocontainer:1.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: trove4j:trove4j:1.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: guava:guava:11.0.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: asm:asm-commons:1.0" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.9" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />
|
||||
</component>
|
||||
|
||||
Reference in New Issue
Block a user