aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Analysis/AnalysisEnvironment.kt23
-rw-r--r--test/data/format/crossLanguage/kotlinExtendsJava/Bar.html (renamed from test/data/format/crossLanguage/kotlinExtendsJava.html)0
-rw-r--r--test/src/TestAPI.kt45
-rw-r--r--test/src/format/HtmlFormatTest.kt10
-rw-r--r--test/src/model/PackageTest.kt13
5 files changed, 62 insertions, 29 deletions
diff --git a/src/Analysis/AnalysisEnvironment.kt b/src/Analysis/AnalysisEnvironment.kt
index 1d0631bb..164f76f5 100644
--- a/src/Analysis/AnalysisEnvironment.kt
+++ b/src/Analysis/AnalysisEnvironment.kt
@@ -16,10 +16,7 @@ import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
-import org.jetbrains.kotlin.cli.jvm.config.addJavaSourceRoot
-import org.jetbrains.kotlin.cli.jvm.config.addJvmClasspathRoot
-import org.jetbrains.kotlin.cli.jvm.config.addJvmClasspathRoots
-import org.jetbrains.kotlin.cli.jvm.config.jvmClasspathRoots
+import org.jetbrains.kotlin.cli.jvm.config.*
import org.jetbrains.kotlin.config.*
import org.jetbrains.kotlin.idea.caches.resolve.KotlinCacheService
import org.jetbrains.kotlin.idea.caches.resolve.LibraryModificationTracker
@@ -106,19 +103,23 @@ public class AnalysisEnvironment(val messageCollector: MessageCollector, body: A
*/
public fun addSources(list: List<String>) {
list.forEach {
- val file = File(it)
- if (file.extension == "java") {
- configuration.addJavaSourceRoot(file)
- } else {
- configuration.addKotlinSourceRoot(it)
- }
+ configuration.add(CommonConfigurationKeys.CONTENT_ROOTS, contentRootFromPath(it))
}
}
+ public fun addRoots(list: List<ContentRoot>) {
+ configuration.addAll(CommonConfigurationKeys.CONTENT_ROOTS, list)
+ }
+
/**
* Disposes the environment and frees all associated resources.
*/
public override fun dispose() {
Disposer.dispose(this)
}
-} \ No newline at end of file
+}
+
+public fun contentRootFromPath(path: String): ContentRoot {
+ val file = File(path)
+ return if (file.extension == "java") JavaSourceRoot(file) else KotlinSourceRoot(path)
+}
diff --git a/test/data/format/crossLanguage/kotlinExtendsJava.html b/test/data/format/crossLanguage/kotlinExtendsJava/Bar.html
index 5b93d837..5b93d837 100644
--- a/test/data/format/crossLanguage/kotlinExtendsJava.html
+++ b/test/data/format/crossLanguage/kotlinExtendsJava/Bar.html
diff --git a/test/src/TestAPI.kt b/test/src/TestAPI.kt
index ebee1290..171b5b9d 100644
--- a/test/src/TestAPI.kt
+++ b/test/src/TestAPI.kt
@@ -1,14 +1,20 @@
package org.jetbrains.dokka.tests
-import org.jetbrains.kotlin.cli.common.messages.*
-import com.intellij.openapi.util.*
-import kotlin.test.fail
-import org.jetbrains.dokka.*
-import java.io.File
import com.intellij.openapi.application.PathManager
+import com.intellij.openapi.util.Disposer
+import org.jetbrains.dokka.*
+import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation
+import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
+import org.jetbrains.kotlin.cli.common.messages.MessageCollector
+import org.jetbrains.kotlin.cli.jvm.config.JavaSourceRoot
+import org.jetbrains.kotlin.config.ContentRoot
+import org.jetbrains.kotlin.config.KotlinSourceRoot
+import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstance
import org.junit.Assert
+import java.io.File
+import kotlin.test.fail
-public fun verifyModel(vararg files: String, verifier: (DocumentationModule) -> Unit) {
+public fun verifyModel(vararg roots: ContentRoot, verifier: (DocumentationModule) -> Unit) {
val messageCollector = object : MessageCollector {
override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageLocation) {
when (severity) {
@@ -29,8 +35,7 @@ public fun verifyModel(vararg files: String, verifier: (DocumentationModule) ->
val environment = AnalysisEnvironment(messageCollector) {
val stringRoot = PathManager.getResourceRoot(javaClass<String>(), "/java/lang/String.class")
addClasspath(File(stringRoot))
- addSources(files.toList())
- addClasspath(files.map { File(it)}.filter { it.isDirectory()} )
+ addRoots(roots.toList())
}
val options = DocumentationOptions(includeNonPublic = true, skipEmptyPackages = false, sourceLinks = listOf<SourceLinkDefinition>())
val documentation = buildDocumentationModule(environment, "test", options, logger = DokkaConsoleLogger)
@@ -38,23 +43,32 @@ public fun verifyModel(vararg files: String, verifier: (DocumentationModule) ->
Disposer.dispose(environment)
}
-public fun verifyPackageMember(vararg files: String, verifier: (DocumentationNode) -> Unit) {
- verifyModel(*files) { model ->
+public fun verifyModel(source: String, verifier: (DocumentationModule) -> Unit) {
+ verifyModel(contentRootFromPath(source), verifier = verifier)
+}
+
+public fun verifyPackageMember(kotlinSource: String, verifier: (DocumentationNode) -> Unit) {
+ verifyModel(kotlinSource) { model ->
val pkg = model.members.single()
verifier(pkg.members.single())
}
}
-public fun verifyOutput(path: String, outputExtension: String, outputGenerator: (DocumentationModule, StringBuilder) -> Unit) {
- verifyModel(path) {
+public fun verifyOutput(roots: Array<ContentRoot>, outputExtension: String, outputGenerator: (DocumentationModule, StringBuilder) -> Unit) {
+ verifyModel(*roots) {
val output = StringBuilder()
outputGenerator(it, output)
val ext = outputExtension.trimLeading(".")
+ val path = roots.first().path
val expectedOutput = File(path.replaceAfterLast(".", ext, path + "." + ext)).readText()
assertEqualsIgnoringSeparators(expectedOutput, output.toString())
}
}
+public fun verifyOutput(path: String, outputExtension: String, outputGenerator: (DocumentationModule, StringBuilder) -> Unit) {
+ verifyOutput(arrayOf(contentRootFromPath(path)), outputExtension, outputGenerator)
+}
+
public fun assertEqualsIgnoringSeparators(expectedOutput: String, output: String) {
Assert.assertEquals(expectedOutput.replace("\r\n", "\n"), output.replace("\r\n", "\n"))
}
@@ -112,3 +126,10 @@ object InMemoryLocationService: LocationService {
}
val tempLocation = InMemoryLocation("")
+
+val ContentRoot.path: String
+ get() = when(this) {
+ is KotlinSourceRoot -> path
+ is JavaSourceRoot -> file.path
+ else -> throw UnsupportedOperationException()
+ }
diff --git a/test/src/format/HtmlFormatTest.kt b/test/src/format/HtmlFormatTest.kt
index 98b47f06..3d744b95 100644
--- a/test/src/format/HtmlFormatTest.kt
+++ b/test/src/format/HtmlFormatTest.kt
@@ -1,8 +1,12 @@
package org.jetbrains.dokka.tests
+import org.jetbrains.dokka.HtmlFormatService
import org.jetbrains.dokka.KotlinLanguageService
+import org.jetbrains.kotlin.cli.jvm.config.JavaSourceRoot
+import org.jetbrains.kotlin.config.ContentRoot
+import org.jetbrains.kotlin.config.KotlinSourceRoot
import org.junit.Test
-import org.jetbrains.dokka.HtmlFormatService
+import java.io.File
public class HtmlFormatTest {
private val htmlService = HtmlFormatService(InMemoryLocationService, KotlinLanguageService())
@@ -125,7 +129,9 @@ public class HtmlFormatTest {
}
Test fun crossLanguageKotlinExtendsJava() {
- verifyOutput("test/data/format/crossLanguage/kotlinExtendsJava", ".html") { model, output ->
+ verifyOutput(arrayOf(KotlinSourceRoot("test/data/format/crossLanguage/kotlinExtendsJava/Bar.kt"),
+ JavaSourceRoot(File("test/data/format/crossLanguage/kotlinExtendsJava"))),
+ ".html") { model, output ->
htmlService.appendNodes(tempLocation, output, model.members.single().members.filter { it.name == "Bar" })
}
}
diff --git a/test/src/model/PackageTest.kt b/test/src/model/PackageTest.kt
index 1f1a6ebf..701efbf0 100644
--- a/test/src/model/PackageTest.kt
+++ b/test/src/model/PackageTest.kt
@@ -1,8 +1,11 @@
package org.jetbrains.dokka.tests
+import org.jetbrains.dokka.Content
+import org.jetbrains.dokka.DocumentationNode
+import org.jetbrains.kotlin.config.KotlinSourceRoot
import org.junit.Test
-import kotlin.test.*
-import org.jetbrains.dokka.*
+import kotlin.test.assertEquals
+import kotlin.test.assertTrue
public class PackageTest {
Test fun rootPackage() {
@@ -45,7 +48,8 @@ public class PackageTest {
}
Test fun multipleFiles() {
- verifyModel("test/data/packages/dottedNamePackage.kt", "test/data/packages/simpleNamePackage.kt") { model ->
+ verifyModel(KotlinSourceRoot("test/data/packages/dottedNamePackage.kt"),
+ KotlinSourceRoot("test/data/packages/simpleNamePackage.kt")) { model ->
assertEquals(2, model.members.count())
with(model.members.single { it.name == "simple" }) {
assertEquals(DocumentationNode.Kind.Package, kind)
@@ -66,7 +70,8 @@ public class PackageTest {
}
Test fun multipleFilesSamePackage() {
- verifyModel("test/data/packages/simpleNamePackage.kt", "test/data/packages/simpleNamePackage2.kt") { model ->
+ verifyModel(KotlinSourceRoot("test/data/packages/simpleNamePackage.kt"),
+ KotlinSourceRoot("test/data/packages/simpleNamePackage2.kt")) { model ->
assertEquals(1, model.members.count())
with(model.members.elementAt(0)) {
assertEquals(DocumentationNode.Kind.Package, kind)