diff options
author | KrystianUjma <kujma@virtuslab.com> | 2019-03-19 11:34:38 +0100 |
---|---|---|
committer | KrystianUjma <kujma@virtuslab.com> | 2019-03-19 15:56:01 +0100 |
commit | 2e94ac4098d9e2582223485b981114fa462e5757 (patch) | |
tree | ed1b772bce9d790c473b346bcce435e893b29be7 /core/src/test/kotlin/TestAPI.kt | |
parent | b566f8852e94f9a17be86bf845aeff6c36bd8378 (diff) | |
parent | a9c91cb7dc54c1554be5cf8de90516c929c0c1cb (diff) | |
download | dokka-2e94ac4098d9e2582223485b981114fa462e5757.tar.gz dokka-2e94ac4098d9e2582223485b981114fa462e5757.tar.bz2 dokka-2e94ac4098d9e2582223485b981114fa462e5757.zip |
Merge branch 'kotlin-website-jonnyzzz' into multiplatform-support
Diffstat (limited to 'core/src/test/kotlin/TestAPI.kt')
-rw-r--r-- | core/src/test/kotlin/TestAPI.kt | 238 |
1 files changed, 133 insertions, 105 deletions
diff --git a/core/src/test/kotlin/TestAPI.kt b/core/src/test/kotlin/TestAPI.kt index 4f77a2f6..6ee610cd 100644 --- a/core/src/test/kotlin/TestAPI.kt +++ b/core/src/test/kotlin/TestAPI.kt @@ -8,6 +8,7 @@ import com.intellij.rt.execution.junit.FileComparisonFailure import org.jetbrains.dokka.* import org.jetbrains.dokka.DokkaConfiguration.SourceLinkDefinition import org.jetbrains.dokka.Utilities.DokkaAnalysisModule +import org.jetbrains.dokka.Utilities.DokkaRunModule import org.jetbrains.kotlin.cli.common.config.ContentRoot import org.jetbrains.kotlin.cli.common.config.KotlinSourceRoot import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation @@ -15,54 +16,59 @@ 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.descriptors.DeclarationDescriptor +import org.jetbrains.kotlin.utils.PathUtil import org.junit.Assert import org.junit.Assert.fail import java.io.File +data class ModelConfig( + val roots: Array<ContentRoot> = arrayOf(), + val withJdk: Boolean = false, + val withKotlinRuntime: Boolean = false, + val format: String = "html", + val includeNonPublic: Boolean = true, + val perPackageOptions: List<DokkaConfiguration.PackageOptions> = emptyList(), + val analysisPlatform: Platform = Platform.DEFAULT, + val defaultPlatforms: List<String> = emptyList(), + val noStdlibLink: Boolean = true, + val collectInheritedExtensionsFromLibraries: Boolean = false, + val sourceLinks: List<SourceLinkDefinition> = emptyList() +) -fun verifyModel(vararg roots: ContentRoot, - withJdk: Boolean = false, - withKotlinRuntime: Boolean = false, - format: String = "html", - includeNonPublic: Boolean = true, - perPackageOptions: List<DokkaConfiguration.PackageOptions> = emptyList(), - noStdlibLink: Boolean = true, - collectInheritedExtensionsFromLibraries: Boolean = false, - sourceLinks: List<SourceLinkDefinition> = emptyList(), +fun verifyModel(modelConfig: ModelConfig, verifier: (DocumentationModule) -> Unit) { val documentation = DocumentationModule("test") - val options = DocumentationOptions( - "", - format, - includeNonPublic = includeNonPublic, + val passConfiguration = PassConfigurationImpl ( + includeNonPublic = modelConfig.includeNonPublic, skipEmptyPackages = false, includeRootPackage = true, - sourceLinks = sourceLinks, - perPackageOptions = perPackageOptions, - generateIndexPages = false, - noStdlibLink = noStdlibLink, + sourceLinks = modelConfig.sourceLinks, + perPackageOptions = modelConfig.perPackageOptions, + noStdlibLink = modelConfig.noStdlibLink, noJdkLink = false, - cacheRoot = "default", languageVersion = null, apiVersion = null, - collectInheritedExtensionsFromLibraries = collectInheritedExtensionsFromLibraries + collectInheritedExtensionsFromLibraries = modelConfig.collectInheritedExtensionsFromLibraries + ) + val configuration = DokkaConfigurationImpl( + outputDir = "", + format = modelConfig.format, + generateIndexPages = false, + cacheRoot = "default", + passesConfigurations = listOf(passConfiguration) ) - appendDocumentation(documentation, *roots, - withJdk = withJdk, - withKotlinRuntime = withKotlinRuntime, - options = options) - documentation.prepareForGeneration(options) + appendDocumentation(documentation, configuration, passConfiguration, modelConfig) + documentation.prepareForGeneration(configuration) verifier(documentation) } fun appendDocumentation(documentation: DocumentationModule, - vararg roots: ContentRoot, - withJdk: Boolean = false, - withKotlinRuntime: Boolean = false, - options: DocumentationOptions, - defaultPlatforms: List<String> = emptyList()) { + dokkaConfiguration: DokkaConfiguration, + passConfiguration: DokkaConfiguration.PassConfiguration, + modelConfig: ModelConfig +) { val messageCollector = object : MessageCollector { override fun clear() { @@ -87,66 +93,106 @@ fun appendDocumentation(documentation: DocumentationModule, override fun hasErrors() = false } - val environment = AnalysisEnvironment(messageCollector) + val environment = AnalysisEnvironment(messageCollector, modelConfig.analysisPlatform) environment.apply { - if (withJdk || withKotlinRuntime) { - val stringRoot = PathManager.getResourceRoot(String::class.java, "/java/lang/String.class") - addClasspath(File(stringRoot)) + if (modelConfig.withJdk || modelConfig.withKotlinRuntime) { + addClasspath(PathUtil.getJdkClassesRootsFromCurrentJre()) } - if (withKotlinRuntime) { - val kotlinStrictfpRoot = PathManager.getResourceRoot(Strictfp::class.java, "/kotlin/jvm/Strictfp.class") - addClasspath(File(kotlinStrictfpRoot)) + if (modelConfig.withKotlinRuntime) { + if (analysisPlatform == Platform.jvm) { + val kotlinStrictfpRoot = PathManager.getResourceRoot(Strictfp::class.java, "/kotlin/jvm/Strictfp.class") + addClasspath(File(kotlinStrictfpRoot)) + } + // TODO: Fix concrete path to correct gradle path providing + if (analysisPlatform == Platform.js) { + addClasspath(File("/home/jetbrains/.local/share/JetBrains/Toolbox/apps/IDEA-U/ch-0/181.5281.24/plugins/Kotlin/kotlinc/lib/kotlin-jslib.jar")) + addClasspath(File("/home/jetbrains/.local/share/JetBrains/Toolbox/apps/IDEA-U/ch-0/181.5281.24/plugins/Kotlin/kotlinc/lib/kotlin-stdlib-js.jar")) + addClasspath(File("/home/jetbrains/.local/share/JetBrains/Toolbox/apps/IDEA-U/ch-0/181.5281.24/plugins/Kotlin/kotlinc/lib/kotlin-stdlib-js-sources.jar")) + } + if (analysisPlatform == Platform.common) { + addClasspath(File("/home/jetbrains/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.2.51/e4a9d4b13ab19ed1e6531fce6df98e8cfa7f7301/kotlin-stdlib-common-1.2.51.jar")) + } } - addRoots(roots.toList()) + addRoots(modelConfig.roots.toList()) - loadLanguageVersionSettings(options.languageVersion, options.apiVersion) + loadLanguageVersionSettings(passConfiguration.languageVersion, passConfiguration.apiVersion) } val defaultPlatformsProvider = object : DefaultPlatformsProvider { - override fun getDefaultPlatforms(descriptor: DeclarationDescriptor) = defaultPlatforms + override fun getDefaultPlatforms(descriptor: DeclarationDescriptor) = modelConfig.defaultPlatforms } - val injector = Guice.createInjector( - DokkaAnalysisModule(environment, options, defaultPlatformsProvider, documentation.nodeRefGraph, DokkaConsoleLogger)) + + val globalInjector = Guice.createInjector( + DokkaRunModule(dokkaConfiguration) + ) + + val injector = globalInjector.createChildInjector( + DokkaAnalysisModule( + environment, + dokkaConfiguration, + defaultPlatformsProvider, + documentation.nodeRefGraph, + passConfiguration, + DokkaConsoleLogger + ) + ) + buildDocumentationModule(injector, documentation) Disposer.dispose(environment) } -fun verifyModel(source: String, - withJdk: Boolean = false, - withKotlinRuntime: Boolean = false, - format: String = "html", - includeNonPublic: Boolean = true, - sourceLinks: List<SourceLinkDefinition> = emptyList(), - verifier: (DocumentationModule) -> Unit) { +fun checkSourceExistsAndVerifyModel(source: String, + modelConfig: ModelConfig = ModelConfig(), + verifier: (DocumentationModule) -> Unit) { require (File(source).exists()) { "Cannot find test data file $source" } - verifyModel(contentRootFromPath(source), - withJdk = withJdk, - withKotlinRuntime = withKotlinRuntime, - format = format, - includeNonPublic = includeNonPublic, - sourceLinks = sourceLinks, - verifier = verifier) + verifyModel( + ModelConfig( + roots = arrayOf(contentRootFromPath(source)), + withJdk = modelConfig.withJdk, + withKotlinRuntime = modelConfig.withKotlinRuntime, + format = modelConfig.format, + includeNonPublic = modelConfig.includeNonPublic, + sourceLinks = modelConfig.sourceLinks, + analysisPlatform = modelConfig.analysisPlatform + ), + + verifier = verifier + ) } fun verifyPackageMember(source: String, - withJdk: Boolean = false, - withKotlinRuntime: Boolean = false, + modelConfig: ModelConfig = ModelConfig(), verifier: (DocumentationNode) -> Unit) { - verifyModel(source, withJdk = withJdk, withKotlinRuntime = withKotlinRuntime) { model -> + checkSourceExistsAndVerifyModel( + source, + modelConfig = ModelConfig( + withJdk = modelConfig.withJdk, + withKotlinRuntime = modelConfig.withKotlinRuntime, + analysisPlatform = modelConfig.analysisPlatform + ) + ) { model -> val pkg = model.members.single() verifier(pkg.members.single()) } } fun verifyJavaModel(source: String, - withKotlinRuntime: Boolean = false, + modelConfig: ModelConfig = ModelConfig(), verifier: (DocumentationModule) -> Unit) { val tempDir = FileUtil.createTempDirectory("dokka", "") try { val sourceFile = File(source) FileUtil.copy(sourceFile, File(tempDir, sourceFile.name)) - verifyModel(JavaSourceRoot(tempDir, null), withJdk = true, withKotlinRuntime = withKotlinRuntime, verifier = verifier) + verifyModel( + ModelConfig( + roots = arrayOf(JavaSourceRoot(tempDir, null)), + withJdk = true, + withKotlinRuntime = modelConfig.withKotlinRuntime, + analysisPlatform = modelConfig.analysisPlatform + ), + verifier = verifier + ) } finally { FileUtil.delete(tempDir) @@ -154,36 +200,42 @@ fun verifyJavaModel(source: String, } fun verifyJavaPackageMember(source: String, - withKotlinRuntime: Boolean = false, + modelConfig: ModelConfig = ModelConfig(), verifier: (DocumentationNode) -> Unit) { - verifyJavaModel(source, withKotlinRuntime) { model -> + verifyJavaModel(source, modelConfig) { model -> val pkg = model.members.single() verifier(pkg.members.single()) } } -fun verifyOutput(roots: Array<ContentRoot>, +fun verifyOutput(modelConfig: ModelConfig = ModelConfig(), outputExtension: String, - withJdk: Boolean = false, - withKotlinRuntime: Boolean = false, - format: String = "html", - includeNonPublic: Boolean = true, - noStdlibLink: Boolean = true, - collectInheritedExtensionsFromLibraries: Boolean = false, outputGenerator: (DocumentationModule, StringBuilder) -> Unit) { - verifyModel( - *roots, - withJdk = withJdk, - withKotlinRuntime = withKotlinRuntime, - format = format, - includeNonPublic = includeNonPublic, - noStdlibLink = noStdlibLink, - collectInheritedExtensionsFromLibraries = collectInheritedExtensionsFromLibraries - ) { - verifyModelOutput(it, outputExtension, roots.first().path, outputGenerator) + verifyModel(modelConfig) { + verifyModelOutput(it, outputExtension, modelConfig.roots.first().path, outputGenerator) } } +fun verifyOutput(path: String, + outputExtension: String, + modelConfig: ModelConfig = ModelConfig(), + outputGenerator: (DocumentationModule, StringBuilder) -> Unit) { + verifyOutput( + ModelConfig( + roots = arrayOf(contentRootFromPath(path)) + modelConfig.roots, + withJdk = modelConfig.withJdk, + withKotlinRuntime = modelConfig.withKotlinRuntime, + format = modelConfig.format, + includeNonPublic = modelConfig.includeNonPublic, + analysisPlatform = modelConfig.analysisPlatform, + noStdlibLink = modelConfig.noStdlibLink, + collectInheritedExtensionsFromLibraries = modelConfig.collectInheritedExtensionsFromLibraries + ), + outputExtension, + outputGenerator + ) +} + fun verifyModelOutput(it: DocumentationModule, outputExtension: String, sourcePath: String, @@ -195,35 +247,11 @@ fun verifyModelOutput(it: DocumentationModule, assertEqualsIgnoringSeparators(expectedFile, output.toString()) } -fun verifyOutput( - path: String, - outputExtension: String, - withJdk: Boolean = false, - withKotlinRuntime: Boolean = false, - format: String = "html", - includeNonPublic: Boolean = true, - noStdlibLink: Boolean = true, - collectInheritedExtensionsFromLibraries: Boolean = false, - outputGenerator: (DocumentationModule, StringBuilder) -> Unit -) { - verifyOutput( - arrayOf(contentRootFromPath(path)), - outputExtension, - withJdk, - withKotlinRuntime, - format, - includeNonPublic, - noStdlibLink, - collectInheritedExtensionsFromLibraries, - outputGenerator - ) -} - fun verifyJavaOutput(path: String, outputExtension: String, - withKotlinRuntime: Boolean = false, + modelConfig: ModelConfig = ModelConfig(), outputGenerator: (DocumentationModule, StringBuilder) -> Unit) { - verifyJavaModel(path, withKotlinRuntime) { model -> + verifyJavaModel(path, modelConfig) { model -> verifyModelOutput(model, outputExtension, path, outputGenerator) } } |