From b536699655e40c62cd603e1f98869786566604bd Mon Sep 17 00:00:00 2001 From: Kamil Doległo Date: Tue, 10 Sep 2019 15:15:09 +0200 Subject: WIP on restructuring --- core/build.gradle | 51 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 18 deletions(-) (limited to 'core/build.gradle') diff --git a/core/build.gradle b/core/build.gradle index 697fd726..76601901 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -6,19 +6,24 @@ buildscript { } } -apply plugin: 'kotlin' +allprojects { + apply plugin: 'kotlin' -sourceCompatibility = 1.8 + sourceCompatibility = 1.8 -tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all { - kotlinOptions { - languageVersion = language_version - apiVersion = language_version - jvmTarget = "1.8" + tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all { + kotlinOptions { + languageVersion = language_version + apiVersion = language_version + jvmTarget = "1.8" + } } } dependencies { + compile project(":integration") + compile project(path: ":coreDependencies", configuration: "shadow") + compile "org.jetbrains.kotlin:kotlin-stdlib:$bundled_kotlin_compiler_version" compile "org.jetbrains.kotlin:kotlin-reflect:$bundled_kotlin_compiler_version" @@ -28,27 +33,37 @@ dependencies { compile "org.jetbrains.kotlin:kotlin-compiler:$bundled_kotlin_compiler_version" compile "org.jetbrains.kotlin:kotlin-script-runtime:$bundled_kotlin_compiler_version" - compile "teamcity:kotlin-ide-common:$bundled_kotlin_compiler_version" compile "org.jetbrains:markdown:$markdownVersion" - compile intellijCoreAnalysis() - - compile kotlinPluginDependency() - compile 'org.jetbrains.kotlinx:kotlinx-html-jvm:0.6.8' //tools.jar - def toolsJar = files(((URLClassLoader) ToolProvider.getSystemToolClassLoader()).getURLs().findAll { it.path.endsWith("jar") }) - compileOnly toolsJar - testCompile toolsJar +// def toolsJar = files(((URLClassLoader) ToolProvider.getSystemToolClassLoader()).getURLs().findAll { it.path.endsWith("jar") }) +// compileOnly toolsJar +// testCompile toolsJar - compile project(":integration") testCompile group: 'junit', name: 'junit', version: '4.12' testCompile group: 'org.jetbrains.kotlin', name: 'kotlin-test-junit', version: kotlin_version testCompile "com.nhaarman:mockito-kotlin-kt1.1:1.5.0" implementation "com.google.code.gson:gson:$gson_version" - testCompile ideaRT() + testImplementation "org.jetbrains.kotlin:kotlin-stdlib-js:$bundled_kotlin_compiler_version" testImplementation "org.jetbrains.kotlin:kotlin-stdlib-common:$bundled_kotlin_compiler_version" -} \ No newline at end of file + + testCompile ideaRT() +} + +apply plugin: 'maven-publish' + +publishing { + publications { + dokkaCore(MavenPublication) { publication -> + artifactId = 'dokka-core' + + from components.java + } + } +} + +bintrayPublication(project, ["dokkaCore"]) -- cgit From f4920fc9d067e59a5d843a185e07c5d321c91c6d Mon Sep 17 00:00:00 2001 From: Kamil Doległo Date: Wed, 11 Sep 2019 15:34:55 +0200 Subject: Extract testApi from core --- core/build.gradle | 1 + .../DokkaConfigurationTestImplementations.kt | 81 ----- core/src/test/kotlin/TestAPI.kt | 353 --------------------- core/src/test/kotlin/format/GFMFormatTest.kt | 6 +- core/src/test/kotlin/format/HtmlFormatTest.kt | 3 + .../kotlin/format/KotlinWebSiteHtmlFormatTest.kt | 8 +- core/src/test/kotlin/format/MarkdownFormatTest.kt | 9 +- core/src/test/kotlin/format/PackageDocsTest.kt | 3 +- core/src/test/kotlin/issues/IssuesTest.kt | 4 +- core/src/test/kotlin/model/ClassTest.kt | 4 + core/src/test/kotlin/model/CommentTest.kt | 9 +- core/src/test/kotlin/model/FunctionTest.kt | 5 +- core/src/test/kotlin/model/JavaTest.kt | 3 + core/src/test/kotlin/model/KotlinAsJavaTest.kt | 3 + core/src/test/kotlin/model/LinkTest.kt | 3 + core/src/test/kotlin/model/PackageTest.kt | 5 +- core/src/test/kotlin/model/PropertyTest.kt | 2 + core/src/test/kotlin/model/SourceLinksErrorTest.kt | 4 +- core/src/test/kotlin/model/SourceLinksTest.kt | 4 +- core/src/test/kotlin/model/TypeAliasTest.kt | 2 + core/testApi/build.gradle | 3 + .../DokkaConfigurationTestImplementations.kt | 81 +++++ core/testApi/src/main/kotlin/testApi/TestAPI.kt | 353 +++++++++++++++++++++ plugins/javadoc8/build.gradle | 4 +- .../src/test/kotlin/javadoc/JavadocTest.kt | 6 +- .../javadoc8/testdata/javadoc/argumentReference.kt | 4 + .../testdata/javadoc/blankLineInsideCodeBlock.kt | 12 + plugins/javadoc8/testdata/javadoc/bytearr.kt | 7 + .../testdata/javadoc/companionMethodReference.kt | 13 + .../testdata/javadoc/constructorParameters.kt | 14 + .../testdata/javadoc/defaultNoArgConstructor.kt | 12 + plugins/javadoc8/testdata/javadoc/deprecated.java | 28 ++ plugins/javadoc8/testdata/javadoc/exception.kt | 5 + .../testdata/javadoc/functionParameters.java | 17 + plugins/javadoc8/testdata/javadoc/internal.kt | 8 + plugins/javadoc8/testdata/javadoc/jvmname.kt | 6 + .../testdata/javadoc/kdocKeywordsOnMethod.kt | 12 + .../javadoc8/testdata/javadoc/noArgConstructor.kt | 12 + plugins/javadoc8/testdata/javadoc/obj.kt | 7 + plugins/javadoc8/testdata/javadoc/paramlink.kt | 10 + plugins/javadoc8/testdata/javadoc/stringarr.kt | 8 + plugins/javadoc8/testdata/javadoc/suppress.kt | 37 +++ plugins/javadoc8/testdata/javadoc/typealiases.kt | 11 + plugins/javadoc8/testdata/javadoc/types.kt | 4 + plugins/javadoc8/testdata/javadoc/vararg.kt | 3 + .../testdata/javadoc/visibilityModifiers.kt | 15 + 46 files changed, 746 insertions(+), 458 deletions(-) delete mode 100644 core/src/test/kotlin/DokkaConfigurationTestImplementations.kt delete mode 100644 core/src/test/kotlin/TestAPI.kt create mode 100644 core/testApi/src/main/kotlin/testApi/DokkaConfigurationTestImplementations.kt create mode 100644 core/testApi/src/main/kotlin/testApi/TestAPI.kt create mode 100644 plugins/javadoc8/testdata/javadoc/argumentReference.kt create mode 100644 plugins/javadoc8/testdata/javadoc/blankLineInsideCodeBlock.kt create mode 100644 plugins/javadoc8/testdata/javadoc/bytearr.kt create mode 100644 plugins/javadoc8/testdata/javadoc/companionMethodReference.kt create mode 100644 plugins/javadoc8/testdata/javadoc/constructorParameters.kt create mode 100644 plugins/javadoc8/testdata/javadoc/defaultNoArgConstructor.kt create mode 100644 plugins/javadoc8/testdata/javadoc/deprecated.java create mode 100644 plugins/javadoc8/testdata/javadoc/exception.kt create mode 100644 plugins/javadoc8/testdata/javadoc/functionParameters.java create mode 100644 plugins/javadoc8/testdata/javadoc/internal.kt create mode 100644 plugins/javadoc8/testdata/javadoc/jvmname.kt create mode 100644 plugins/javadoc8/testdata/javadoc/kdocKeywordsOnMethod.kt create mode 100644 plugins/javadoc8/testdata/javadoc/noArgConstructor.kt create mode 100644 plugins/javadoc8/testdata/javadoc/obj.kt create mode 100644 plugins/javadoc8/testdata/javadoc/paramlink.kt create mode 100644 plugins/javadoc8/testdata/javadoc/stringarr.kt create mode 100644 plugins/javadoc8/testdata/javadoc/suppress.kt create mode 100644 plugins/javadoc8/testdata/javadoc/typealiases.kt create mode 100644 plugins/javadoc8/testdata/javadoc/types.kt create mode 100644 plugins/javadoc8/testdata/javadoc/vararg.kt create mode 100644 plugins/javadoc8/testdata/javadoc/visibilityModifiers.kt (limited to 'core/build.gradle') diff --git a/core/build.gradle b/core/build.gradle index 76601901..f3fe35e4 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -50,6 +50,7 @@ dependencies { testImplementation "org.jetbrains.kotlin:kotlin-stdlib-js:$bundled_kotlin_compiler_version" testImplementation "org.jetbrains.kotlin:kotlin-stdlib-common:$bundled_kotlin_compiler_version" + testImplementation project(":core:testApi") testCompile ideaRT() } diff --git a/core/src/test/kotlin/DokkaConfigurationTestImplementations.kt b/core/src/test/kotlin/DokkaConfigurationTestImplementations.kt deleted file mode 100644 index a6f427b1..00000000 --- a/core/src/test/kotlin/DokkaConfigurationTestImplementations.kt +++ /dev/null @@ -1,81 +0,0 @@ -package org.jetbrains.dokka.tests - -import org.jetbrains.dokka.DokkaConfiguration -import org.jetbrains.dokka.Platform -import java.io.File - - -data class SourceLinkDefinitionImpl(override val path: String, - override val url: String, - override val lineSuffix: String?) : DokkaConfiguration.SourceLinkDefinition { - companion object { - fun parseSourceLinkDefinition(srcLink: String): DokkaConfiguration.SourceLinkDefinition { - val (path, urlAndLine) = srcLink.split('=') - return SourceLinkDefinitionImpl( - File(path).canonicalPath, - urlAndLine.substringBefore("#"), - urlAndLine.substringAfter("#", "").let { if (it.isEmpty()) null else "#$it" }) - } - } -} - -class SourceRootImpl(path: String) : DokkaConfiguration.SourceRoot { - override val path: String = File(path).absolutePath - - companion object { - fun parseSourceRoot(sourceRoot: String): DokkaConfiguration.SourceRoot = SourceRootImpl(sourceRoot) - } -} - -data class PackageOptionsImpl(override val prefix: String, - override val includeNonPublic: Boolean = false, - override val reportUndocumented: Boolean = true, - override val skipDeprecated: Boolean = false, - override val suppress: Boolean = false) : DokkaConfiguration.PackageOptions - - class DokkaConfigurationImpl( - override val outputDir: String = "", - override val format: String = "html", - override val generateIndexPages: Boolean = false, - override val cacheRoot: String? = null, - override val impliedPlatforms: List = emptyList(), - override val passesConfigurations: List = emptyList() -) : DokkaConfiguration - -class PassConfigurationImpl ( - override val classpath: List = emptyList(), - override val moduleName: String = "", - override val sourceRoots: List = emptyList(), - override val samples: List = emptyList(), - override val includes: List = emptyList(), - override val includeNonPublic: Boolean = false, - override val includeRootPackage: Boolean = false, - override val reportUndocumented: Boolean = false, - override val skipEmptyPackages: Boolean = false, - override val skipDeprecated: Boolean = false, - override val jdkVersion: Int = 6, - override val sourceLinks: List = emptyList(), - override val perPackageOptions: List = emptyList(), - externalDocumentationLinks: List = emptyList(), - override val languageVersion: String? = null, - override val apiVersion: String? = null, - override val noStdlibLink: Boolean = false, - override val noJdkLink: Boolean = false, - override val suppressedFiles: List = emptyList(), - override val collectInheritedExtensionsFromLibraries: Boolean = false, - override val analysisPlatform: Platform = Platform.DEFAULT, - override val targets: List = emptyList(), - override val sinceKotlin: String? = null -): DokkaConfiguration.PassConfiguration { - private val defaultLinks = run { - val links = mutableListOf() - 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() - links - } - override val externalDocumentationLinks = defaultLinks + externalDocumentationLinks -} - diff --git a/core/src/test/kotlin/TestAPI.kt b/core/src/test/kotlin/TestAPI.kt deleted file mode 100644 index 4f9af761..00000000 --- a/core/src/test/kotlin/TestAPI.kt +++ /dev/null @@ -1,353 +0,0 @@ -package org.jetbrains.dokka.tests - -import com.google.inject.Guice -import com.intellij.openapi.application.PathManager -import com.intellij.openapi.util.Disposer -import com.intellij.openapi.util.io.FileUtil -import com.intellij.rt.execution.junit.FileComparisonFailure -import org.jetbrains.dokka.* -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 -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 = arrayOf(), - val withJdk: Boolean = false, - val withKotlinRuntime: Boolean = false, - val format: String = "html", - val includeNonPublic: Boolean = true, - val perPackageOptions: List = emptyList(), - val analysisPlatform: Platform = Platform.DEFAULT, - val defaultPlatforms: List = emptyList(), - val noStdlibLink: Boolean = true, - val collectInheritedExtensionsFromLibraries: Boolean = false, - val sourceLinks: List = emptyList() -) - -fun verifyModel( - modelConfig: ModelConfig, - verifier: (DocumentationModule) -> Unit -) { - val documentation = DocumentationModule("test") - - val passConfiguration = PassConfigurationImpl( - includeNonPublic = modelConfig.includeNonPublic, - skipEmptyPackages = false, - includeRootPackage = true, - sourceLinks = modelConfig.sourceLinks, - perPackageOptions = modelConfig.perPackageOptions, - noStdlibLink = modelConfig.noStdlibLink, - noJdkLink = false, - languageVersion = null, - apiVersion = null, - collectInheritedExtensionsFromLibraries = modelConfig.collectInheritedExtensionsFromLibraries - ) - val configuration = DokkaConfigurationImpl( - outputDir = "", - format = modelConfig.format, - generateIndexPages = false, - cacheRoot = "default", - passesConfigurations = listOf(passConfiguration) - ) - - appendDocumentation(documentation, configuration, passConfiguration, modelConfig) - documentation.prepareForGeneration(configuration) - - verifier(documentation) -} - -fun appendDocumentation( - documentation: DocumentationModule, - dokkaConfiguration: DokkaConfiguration, - passConfiguration: DokkaConfiguration.PassConfiguration, - modelConfig: ModelConfig -) { - val messageCollector = object : MessageCollector { - override fun clear() { - - } - - override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageLocation?) { - when (severity) { - CompilerMessageSeverity.STRONG_WARNING, - CompilerMessageSeverity.WARNING, - CompilerMessageSeverity.LOGGING, - CompilerMessageSeverity.OUTPUT, - CompilerMessageSeverity.INFO, - CompilerMessageSeverity.ERROR -> { - println("$severity: $message at $location") - } - CompilerMessageSeverity.EXCEPTION -> { - fail("$severity: $message at $location") - } - } - } - - override fun hasErrors() = false - } - - val environment = AnalysisEnvironment(messageCollector, modelConfig.analysisPlatform) - environment.apply { - if (modelConfig.withJdk || modelConfig.withKotlinRuntime) { - addClasspath(PathUtil.getJdkClassesRootsFromCurrentJre()) - } - if (modelConfig.withKotlinRuntime) { - if (analysisPlatform == Platform.jvm) { - val kotlinStrictfpRoot = PathManager.getResourceRoot(Strictfp::class.java, "/kotlin/jvm/Strictfp.class") - addClasspath(File(kotlinStrictfpRoot)) - } - if (analysisPlatform == Platform.js) { - val kotlinStdlibJsRoot = PathManager.getResourceRoot(Any::class.java, "/kotlin/jquery") - addClasspath(File(kotlinStdlibJsRoot)) - } - - if (analysisPlatform == Platform.common) { - // TODO: Feels hacky - val kotlinStdlibCommonRoot = ClassLoader.getSystemResource("kotlin/UInt.kotlin_metadata") - addClasspath(File(kotlinStdlibCommonRoot.file.replace("file:", "").replaceAfter(".jar", ""))) - } - } - addRoots(modelConfig.roots.toList()) - - loadLanguageVersionSettings(passConfiguration.languageVersion, passConfiguration.apiVersion) - } - val defaultPlatformsProvider = object : DefaultPlatformsProvider { - override fun getDefaultPlatforms(descriptor: DeclarationDescriptor) = modelConfig.defaultPlatforms - } - - 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 checkSourceExistsAndVerifyModel( - source: String, - modelConfig: ModelConfig = ModelConfig(), - verifier: (DocumentationModule) -> Unit -) { - require(File(source).exists()) { - "Cannot find test data file $source" - } - 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, - modelConfig: ModelConfig = ModelConfig(), - verifier: (DocumentationNode) -> Unit -) { - 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, - modelConfig: ModelConfig = ModelConfig(), - verifier: (DocumentationModule) -> Unit -) { - val tempDir = FileUtil.createTempDirectory("dokka", "") - try { - val sourceFile = File(source) - FileUtil.copy(sourceFile, File(tempDir, sourceFile.name)) - verifyModel( - ModelConfig( - roots = arrayOf(JavaSourceRoot(tempDir, null)), - withJdk = true, - withKotlinRuntime = modelConfig.withKotlinRuntime, - analysisPlatform = modelConfig.analysisPlatform - ), - verifier = verifier - ) - } finally { - FileUtil.delete(tempDir) - } -} - -fun verifyJavaPackageMember( - source: String, - modelConfig: ModelConfig = ModelConfig(), - verifier: (DocumentationNode) -> Unit -) { - verifyJavaModel(source, modelConfig) { model -> - val pkg = model.members.single() - verifier(pkg.members.single()) - } -} - -fun verifyOutput( - modelConfig: ModelConfig = ModelConfig(), - outputExtension: String, - outputGenerator: (DocumentationModule, StringBuilder) -> Unit -) { - 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, - outputGenerator: (DocumentationModule, StringBuilder) -> Unit -) { - val output = StringBuilder() - outputGenerator(it, output) - val ext = outputExtension.removePrefix(".") - val expectedFile = File(sourcePath.replaceAfterLast(".", ext, sourcePath + "." + ext)) - assertEqualsIgnoringSeparators(expectedFile, output.toString()) -} - -fun verifyJavaOutput( - path: String, - outputExtension: String, - modelConfig: ModelConfig = ModelConfig(), - outputGenerator: (DocumentationModule, StringBuilder) -> Unit -) { - verifyJavaModel(path, modelConfig) { model -> - verifyModelOutput(model, outputExtension, path, outputGenerator) - } -} - -fun assertEqualsIgnoringSeparators(expectedFile: File, output: String) { - if (!expectedFile.exists()) expectedFile.createNewFile() - val expectedText = expectedFile.readText().replace("\r\n", "\n") - val actualText = output.replace("\r\n", "\n") - - if (expectedText != actualText) - throw FileComparisonFailure("", expectedText, actualText, expectedFile.canonicalPath) -} - -fun assertEqualsIgnoringSeparators(expectedOutput: String, output: String) { - Assert.assertEquals(expectedOutput.replace("\r\n", "\n"), output.replace("\r\n", "\n")) -} - -fun StringBuilder.appendChildren(node: ContentBlock): StringBuilder { - for (child in node.children) { - val childText = child.toTestString() - append(childText) - } - return this -} - -fun StringBuilder.appendNode(node: ContentNode): StringBuilder { - when (node) { - is ContentText -> { - append(node.text) - } - is ContentEmphasis -> append("*").appendChildren(node).append("*") - is ContentBlockCode -> { - if (node.language.isNotBlank()) - appendln("[code lang=${node.language}]") - else - appendln("[code]") - appendChildren(node) - appendln() - appendln("[/code]") - } - is ContentNodeLink -> { - append("[") - appendChildren(node) - append(" -> ") - append(node.node.toString()) - append("]") - } - is ContentBlock -> { - appendChildren(node) - } - is NodeRenderContent -> { - append("render(") - append(node.node) - append(",") - append(node.mode) - append(")") - } - is ContentSymbol -> { - append(node.text) - } - is ContentEmpty -> { /* nothing */ - } - else -> throw IllegalStateException("Don't know how to format node $node") - } - return this -} - -fun ContentNode.toTestString(): String { - val node = this - return StringBuilder().apply { - appendNode(node) - }.toString() -} - -val ContentRoot.path: String - get() = when (this) { - is KotlinSourceRoot -> path - is JavaSourceRoot -> file.path - else -> throw UnsupportedOperationException() - } diff --git a/core/src/test/kotlin/format/GFMFormatTest.kt b/core/src/test/kotlin/format/GFMFormatTest.kt index 60de7d29..4807d0f2 100644 --- a/core/src/test/kotlin/format/GFMFormatTest.kt +++ b/core/src/test/kotlin/format/GFMFormatTest.kt @@ -3,6 +3,8 @@ package org.jetbrains.dokka.tests import org.jetbrains.dokka.GFMFormatService import org.jetbrains.dokka.KotlinLanguageService import org.jetbrains.dokka.Platform +import org.jetbrains.dokka.testApi.ModelConfig +import org.jetbrains.dokka.testApi.verifyOutput import org.junit.Test abstract class BaseGFMFormatTest(val analysisPlatform: Platform) : FileGeneratorTestCase() { @@ -23,8 +25,8 @@ abstract class BaseGFMFormatTest(val analysisPlatform: Platform) : FileGenerator private fun verifyGFMNodeByName(fileName: String, name: String, modelConfig: ModelConfig) { verifyOutput("testdata/format/gfm/$fileName.kt", ".md", modelConfig) { model, output -> buildPagesAndReadInto( - model.members.single().members.filter { it.name == name }, - output + model.members.single().members.filter { it.name == name }, + output ) } } diff --git a/core/src/test/kotlin/format/HtmlFormatTest.kt b/core/src/test/kotlin/format/HtmlFormatTest.kt index 60e29006..a1742280 100644 --- a/core/src/test/kotlin/format/HtmlFormatTest.kt +++ b/core/src/test/kotlin/format/HtmlFormatTest.kt @@ -1,6 +1,9 @@ package org.jetbrains.dokka.tests import org.jetbrains.dokka.* +import org.jetbrains.dokka.testApi.ModelConfig +import org.jetbrains.dokka.testApi.verifyJavaOutput +import org.jetbrains.dokka.testApi.verifyOutput import org.jetbrains.kotlin.cli.common.config.KotlinSourceRoot import org.jetbrains.kotlin.cli.jvm.config.JavaSourceRoot import org.junit.Test diff --git a/core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt b/core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt index ebab5f36..d8b34394 100644 --- a/core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt +++ b/core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt @@ -2,6 +2,10 @@ package org.jetbrains.dokka.tests import org.jetbrains.dokka.* import org.jetbrains.dokka.Generation.DocumentationMerger +import org.jetbrains.dokka.testApi.ModelConfig +import org.jetbrains.dokka.testApi.appendDocumentation +import org.jetbrains.dokka.testApi.verifyModelOutput +import org.jetbrains.dokka.testApi.verifyOutput import org.junit.Test abstract class BaseKotlinWebSiteHtmlFormatTest(val analysisPlatform: Platform): FileGeneratorTestCase() { @@ -65,14 +69,14 @@ abstract class BaseKotlinWebSiteHtmlFormatTest(val analysisPlatform: Platform): private fun buildMultiplePlatforms(path: String): DocumentationModule { val moduleName = "test" - val passConfiguration = PassConfigurationImpl( + val passConfiguration = org.jetbrains.dokka.testApi.PassConfigurationImpl( noStdlibLink = true, noJdkLink = true, languageVersion = null, apiVersion = null ) - val dokkaConfiguration = DokkaConfigurationImpl( + val dokkaConfiguration = org.jetbrains.dokka.testApi.DokkaConfigurationImpl( outputDir = "", format = "kotlin-website-html", generateIndexPages = false, diff --git a/core/src/test/kotlin/format/MarkdownFormatTest.kt b/core/src/test/kotlin/format/MarkdownFormatTest.kt index 4984e1d5..8900b267 100644 --- a/core/src/test/kotlin/format/MarkdownFormatTest.kt +++ b/core/src/test/kotlin/format/MarkdownFormatTest.kt @@ -2,6 +2,7 @@ package org.jetbrains.dokka.tests import org.jetbrains.dokka.* import org.jetbrains.dokka.Generation.DocumentationMerger +import org.jetbrains.dokka.testApi.* import org.junit.Test abstract class BaseMarkdownFormatTest(val analysisPlatform: Platform): FileGeneratorTestCase() { @@ -257,14 +258,14 @@ abstract class BaseMarkdownFormatTest(val analysisPlatform: Platform): FileGener @Test fun packagePlatformsWithExtExtensions() { val path = "multiplatform/packagePlatformsWithExtExtensions" val module = DocumentationModule("test") - val passConfiguration = PassConfigurationImpl( + val passConfiguration = org.jetbrains.dokka.testApi.PassConfigurationImpl( noStdlibLink = true, noJdkLink = true, languageVersion = null, apiVersion = null ) - val dokkaConfiguration = DokkaConfigurationImpl( + val dokkaConfiguration = org.jetbrains.dokka.testApi.DokkaConfigurationImpl( outputDir = "", format = "html", generateIndexPages = false, @@ -388,13 +389,13 @@ abstract class BaseMarkdownFormatTest(val analysisPlatform: Platform): FileGener private fun buildMultiplePlatforms(path: String): DocumentationModule { val moduleName = "test" - val passConfiguration = PassConfigurationImpl( + val passConfiguration = org.jetbrains.dokka.testApi.PassConfigurationImpl( noStdlibLink = true, noJdkLink = true, languageVersion = null, apiVersion = null ) - val dokkaConfiguration = DokkaConfigurationImpl( + val dokkaConfiguration = org.jetbrains.dokka.testApi.DokkaConfigurationImpl( outputDir = "", format = "html", generateIndexPages = false, diff --git a/core/src/test/kotlin/format/PackageDocsTest.kt b/core/src/test/kotlin/format/PackageDocsTest.kt index 3ff5f123..c5fe7beb 100644 --- a/core/src/test/kotlin/format/PackageDocsTest.kt +++ b/core/src/test/kotlin/format/PackageDocsTest.kt @@ -7,10 +7,9 @@ import com.nhaarman.mockito_kotlin.doAnswer import com.nhaarman.mockito_kotlin.eq import com.nhaarman.mockito_kotlin.mock import org.jetbrains.dokka.* -import org.jetbrains.dokka.tests.assertEqualsIgnoringSeparators +import org.jetbrains.dokka.testApi.assertEqualsIgnoringSeparators import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment -import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreProjectEnvironment import org.jetbrains.kotlin.config.CompilerConfiguration import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor import org.junit.After diff --git a/core/src/test/kotlin/issues/IssuesTest.kt b/core/src/test/kotlin/issues/IssuesTest.kt index da5acd6e..80370d5e 100644 --- a/core/src/test/kotlin/issues/IssuesTest.kt +++ b/core/src/test/kotlin/issues/IssuesTest.kt @@ -3,8 +3,8 @@ package issues import org.jetbrains.dokka.DocumentationNode import org.jetbrains.dokka.NodeKind import org.jetbrains.dokka.Platform -import org.jetbrains.dokka.tests.ModelConfig -import org.jetbrains.dokka.tests.checkSourceExistsAndVerifyModel +import org.jetbrains.dokka.testApi.ModelConfig +import org.jetbrains.dokka.testApi.checkSourceExistsAndVerifyModel import org.junit.Test import kotlin.test.assertEquals diff --git a/core/src/test/kotlin/model/ClassTest.kt b/core/src/test/kotlin/model/ClassTest.kt index 35ec1d09..b479e59e 100644 --- a/core/src/test/kotlin/model/ClassTest.kt +++ b/core/src/test/kotlin/model/ClassTest.kt @@ -4,6 +4,10 @@ import org.jetbrains.dokka.Content import org.jetbrains.dokka.NodeKind import org.jetbrains.dokka.Platform import org.jetbrains.dokka.RefKind +import org.jetbrains.dokka.testApi.ModelConfig +import org.jetbrains.dokka.testApi.checkSourceExistsAndVerifyModel +import org.jetbrains.dokka.testApi.toTestString +import org.jetbrains.dokka.testApi.verifyPackageMember import org.junit.Assert import org.junit.Assert.assertEquals import org.junit.Assert.assertTrue diff --git a/core/src/test/kotlin/model/CommentTest.kt b/core/src/test/kotlin/model/CommentTest.kt index 08aa3572..b94e9d0c 100644 --- a/core/src/test/kotlin/model/CommentTest.kt +++ b/core/src/test/kotlin/model/CommentTest.kt @@ -1,8 +1,13 @@ package org.jetbrains.dokka.tests +import org.jetbrains.dokka.Content +import org.jetbrains.dokka.Platform +import org.jetbrains.dokka.testApi.ModelConfig +import org.jetbrains.dokka.testApi.assertEqualsIgnoringSeparators +import org.jetbrains.dokka.testApi.checkSourceExistsAndVerifyModel +import org.jetbrains.dokka.testApi.toTestString +import org.junit.Assert.assertEquals import org.junit.Test -import org.junit.Assert.* -import org.jetbrains.dokka.* abstract class BaseCommentTest(val analysisPlatform: Platform) { val defaultModelConfig = ModelConfig(analysisPlatform = analysisPlatform) diff --git a/core/src/test/kotlin/model/FunctionTest.kt b/core/src/test/kotlin/model/FunctionTest.kt index 4c6bfb74..9900446a 100644 --- a/core/src/test/kotlin/model/FunctionTest.kt +++ b/core/src/test/kotlin/model/FunctionTest.kt @@ -3,7 +3,10 @@ package org.jetbrains.dokka.tests import org.jetbrains.dokka.Content import org.jetbrains.dokka.NodeKind import org.jetbrains.dokka.Platform -import org.jetbrains.kotlin.analyzer.PlatformAnalysisParameters +import org.jetbrains.dokka.testApi.ModelConfig +import org.jetbrains.dokka.testApi.checkSourceExistsAndVerifyModel +import org.jetbrains.dokka.testApi.toTestString +import org.jetbrains.dokka.testApi.verifyPackageMember import org.junit.Assert import org.junit.Assert.assertEquals import org.junit.Assert.assertTrue diff --git a/core/src/test/kotlin/model/JavaTest.kt b/core/src/test/kotlin/model/JavaTest.kt index da9da624..018ab089 100644 --- a/core/src/test/kotlin/model/JavaTest.kt +++ b/core/src/test/kotlin/model/JavaTest.kt @@ -3,6 +3,9 @@ package org.jetbrains.dokka.tests import org.jetbrains.dokka.NodeKind import org.jetbrains.dokka.Platform import org.jetbrains.dokka.RefKind +import org.jetbrains.dokka.testApi.ModelConfig +import org.jetbrains.dokka.testApi.toTestString +import org.jetbrains.dokka.testApi.verifyJavaPackageMember import org.junit.Assert.* import org.junit.Ignore import org.junit.Test diff --git a/core/src/test/kotlin/model/KotlinAsJavaTest.kt b/core/src/test/kotlin/model/KotlinAsJavaTest.kt index 8249dd0f..80ff95bd 100644 --- a/core/src/test/kotlin/model/KotlinAsJavaTest.kt +++ b/core/src/test/kotlin/model/KotlinAsJavaTest.kt @@ -4,6 +4,9 @@ import org.jetbrains.dokka.DocumentationModule import org.jetbrains.dokka.NodeKind import org.jetbrains.dokka.Platform import org.jetbrains.dokka.RefKind +import org.jetbrains.dokka.testApi.ModelConfig +import org.jetbrains.dokka.testApi.checkSourceExistsAndVerifyModel +import org.jetbrains.dokka.testApi.toTestString import org.junit.Assert import org.junit.Assert.assertEquals import org.junit.Test diff --git a/core/src/test/kotlin/model/LinkTest.kt b/core/src/test/kotlin/model/LinkTest.kt index 6526a4db..08e27db8 100644 --- a/core/src/test/kotlin/model/LinkTest.kt +++ b/core/src/test/kotlin/model/LinkTest.kt @@ -4,6 +4,9 @@ import org.jetbrains.dokka.ContentBlock import org.jetbrains.dokka.ContentNodeLazyLink import org.jetbrains.dokka.NodeKind import org.jetbrains.dokka.Platform +import org.jetbrains.dokka.testApi.ModelConfig +import org.jetbrains.dokka.testApi.checkSourceExistsAndVerifyModel +import org.jetbrains.dokka.testApi.toTestString import org.junit.Assert.assertEquals import org.junit.Test diff --git a/core/src/test/kotlin/model/PackageTest.kt b/core/src/test/kotlin/model/PackageTest.kt index 47c88385..0afbbb5d 100644 --- a/core/src/test/kotlin/model/PackageTest.kt +++ b/core/src/test/kotlin/model/PackageTest.kt @@ -1,6 +1,9 @@ package org.jetbrains.dokka.tests import org.jetbrains.dokka.* +import org.jetbrains.dokka.testApi.ModelConfig +import org.jetbrains.dokka.testApi.checkSourceExistsAndVerifyModel +import org.jetbrains.dokka.testApi.verifyModel import org.jetbrains.kotlin.cli.common.config.KotlinSourceRoot import org.junit.Assert.* import org.junit.Test @@ -121,7 +124,7 @@ abstract class BasePackageTest(val analysisPlatform: Platform) { ModelConfig( roots = arrayOf(KotlinSourceRoot("testdata/packages/classInPackage.kt", false)), perPackageOptions = listOf( - PackageOptionsImpl(prefix = "simple.name", suppress = true) + org.jetbrains.dokka.testApi.PackageOptionsImpl(prefix = "simple.name", suppress = true) ), analysisPlatform = analysisPlatform ) diff --git a/core/src/test/kotlin/model/PropertyTest.kt b/core/src/test/kotlin/model/PropertyTest.kt index 9f070862..bce3c585 100644 --- a/core/src/test/kotlin/model/PropertyTest.kt +++ b/core/src/test/kotlin/model/PropertyTest.kt @@ -1,6 +1,8 @@ package org.jetbrains.dokka.tests import org.jetbrains.dokka.* +import org.jetbrains.dokka.testApi.ModelConfig +import org.jetbrains.dokka.testApi.checkSourceExistsAndVerifyModel import org.junit.Assert import org.junit.Assert.assertEquals import org.junit.Assert.assertTrue diff --git a/core/src/test/kotlin/model/SourceLinksErrorTest.kt b/core/src/test/kotlin/model/SourceLinksErrorTest.kt index 9812569d..2d587856 100644 --- a/core/src/test/kotlin/model/SourceLinksErrorTest.kt +++ b/core/src/test/kotlin/model/SourceLinksErrorTest.kt @@ -2,8 +2,8 @@ package org.jetbrains.dokka.tests.model import org.jetbrains.dokka.NodeKind import org.jetbrains.dokka.SourceLinkDefinitionImpl -import org.jetbrains.dokka.tests.ModelConfig -import org.jetbrains.dokka.tests.checkSourceExistsAndVerifyModel +import org.jetbrains.dokka.testApi.ModelConfig +import org.jetbrains.dokka.testApi.checkSourceExistsAndVerifyModel import org.junit.Assert import org.junit.Test import java.io.File diff --git a/core/src/test/kotlin/model/SourceLinksTest.kt b/core/src/test/kotlin/model/SourceLinksTest.kt index a4ba870c..8f7766f6 100644 --- a/core/src/test/kotlin/model/SourceLinksTest.kt +++ b/core/src/test/kotlin/model/SourceLinksTest.kt @@ -2,8 +2,8 @@ package org.jetbrains.dokka.tests.model import org.jetbrains.dokka.NodeKind import org.jetbrains.dokka.SourceLinkDefinitionImpl -import org.jetbrains.dokka.tests.ModelConfig -import org.jetbrains.dokka.tests.checkSourceExistsAndVerifyModel +import org.jetbrains.dokka.testApi.ModelConfig +import org.jetbrains.dokka.testApi.checkSourceExistsAndVerifyModel import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith diff --git a/core/src/test/kotlin/model/TypeAliasTest.kt b/core/src/test/kotlin/model/TypeAliasTest.kt index 71976dc3..6c9b90a8 100644 --- a/core/src/test/kotlin/model/TypeAliasTest.kt +++ b/core/src/test/kotlin/model/TypeAliasTest.kt @@ -3,6 +3,8 @@ package org.jetbrains.dokka.tests import junit.framework.TestCase.assertEquals import org.jetbrains.dokka.Content import org.jetbrains.dokka.NodeKind +import org.jetbrains.dokka.testApi.checkSourceExistsAndVerifyModel +import org.jetbrains.dokka.testApi.toTestString import org.junit.Test class TypeAliasTest { diff --git a/core/testApi/build.gradle b/core/testApi/build.gradle index 3d5bb61a..82d0fd41 100644 --- a/core/testApi/build.gradle +++ b/core/testApi/build.gradle @@ -1,3 +1,6 @@ dependencies { compileOnly project(":core") + implementation group: 'junit', name: 'junit', version: '4.12' + implementation group: 'org.jetbrains.kotlin', name: 'kotlin-test-junit', version: kotlin_version + implementation ideaRT() } \ No newline at end of file diff --git a/core/testApi/src/main/kotlin/testApi/DokkaConfigurationTestImplementations.kt b/core/testApi/src/main/kotlin/testApi/DokkaConfigurationTestImplementations.kt new file mode 100644 index 00000000..58356e27 --- /dev/null +++ b/core/testApi/src/main/kotlin/testApi/DokkaConfigurationTestImplementations.kt @@ -0,0 +1,81 @@ +package org.jetbrains.dokka.testApi + +import org.jetbrains.dokka.DokkaConfiguration +import org.jetbrains.dokka.Platform +import java.io.File + + +data class SourceLinkDefinitionImpl(override val path: String, + override val url: String, + override val lineSuffix: String?) : DokkaConfiguration.SourceLinkDefinition { + companion object { + fun parseSourceLinkDefinition(srcLink: String): DokkaConfiguration.SourceLinkDefinition { + val (path, urlAndLine) = srcLink.split('=') + return SourceLinkDefinitionImpl( + File(path).canonicalPath, + urlAndLine.substringBefore("#"), + urlAndLine.substringAfter("#", "").let { if (it.isEmpty()) null else "#$it" }) + } + } +} + +class SourceRootImpl(path: String) : DokkaConfiguration.SourceRoot { + override val path: String = File(path).absolutePath + + companion object { + fun parseSourceRoot(sourceRoot: String): DokkaConfiguration.SourceRoot = SourceRootImpl(sourceRoot) + } +} + +data class PackageOptionsImpl(override val prefix: String, + override val includeNonPublic: Boolean = false, + override val reportUndocumented: Boolean = true, + override val skipDeprecated: Boolean = false, + override val suppress: Boolean = false) : DokkaConfiguration.PackageOptions + + class DokkaConfigurationImpl( + override val outputDir: String = "", + override val format: String = "html", + override val generateIndexPages: Boolean = false, + override val cacheRoot: String? = null, + override val impliedPlatforms: List = emptyList(), + override val passesConfigurations: List = emptyList() +) : DokkaConfiguration + +class PassConfigurationImpl ( + override val classpath: List = emptyList(), + override val moduleName: String = "", + override val sourceRoots: List = emptyList(), + override val samples: List = emptyList(), + override val includes: List = emptyList(), + override val includeNonPublic: Boolean = false, + override val includeRootPackage: Boolean = false, + override val reportUndocumented: Boolean = false, + override val skipEmptyPackages: Boolean = false, + override val skipDeprecated: Boolean = false, + override val jdkVersion: Int = 6, + override val sourceLinks: List = emptyList(), + override val perPackageOptions: List = emptyList(), + externalDocumentationLinks: List = emptyList(), + override val languageVersion: String? = null, + override val apiVersion: String? = null, + override val noStdlibLink: Boolean = false, + override val noJdkLink: Boolean = false, + override val suppressedFiles: List = emptyList(), + override val collectInheritedExtensionsFromLibraries: Boolean = false, + override val analysisPlatform: Platform = Platform.DEFAULT, + override val targets: List = emptyList(), + override val sinceKotlin: String? = null +): DokkaConfiguration.PassConfiguration { + private val defaultLinks = run { + val links = mutableListOf() + 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() + links + } + override val externalDocumentationLinks = defaultLinks + externalDocumentationLinks +} + diff --git a/core/testApi/src/main/kotlin/testApi/TestAPI.kt b/core/testApi/src/main/kotlin/testApi/TestAPI.kt new file mode 100644 index 00000000..7856591c --- /dev/null +++ b/core/testApi/src/main/kotlin/testApi/TestAPI.kt @@ -0,0 +1,353 @@ +package org.jetbrains.dokka.testApi + +import com.google.inject.Guice +import com.intellij.openapi.application.PathManager +import com.intellij.openapi.util.Disposer +import com.intellij.openapi.util.io.FileUtil +import com.intellij.rt.execution.junit.FileComparisonFailure +import org.jetbrains.dokka.* +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 +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 = arrayOf(), + val withJdk: Boolean = false, + val withKotlinRuntime: Boolean = false, + val format: String = "html", + val includeNonPublic: Boolean = true, + val perPackageOptions: List = emptyList(), + val analysisPlatform: Platform = Platform.DEFAULT, + val defaultPlatforms: List = emptyList(), + val noStdlibLink: Boolean = true, + val collectInheritedExtensionsFromLibraries: Boolean = false, + val sourceLinks: List = emptyList() +) + +fun verifyModel( + modelConfig: ModelConfig, + verifier: (DocumentationModule) -> Unit +) { + val documentation = DocumentationModule("test") + + val passConfiguration = PassConfigurationImpl( + includeNonPublic = modelConfig.includeNonPublic, + skipEmptyPackages = false, + includeRootPackage = true, + sourceLinks = modelConfig.sourceLinks, + perPackageOptions = modelConfig.perPackageOptions, + noStdlibLink = modelConfig.noStdlibLink, + noJdkLink = false, + languageVersion = null, + apiVersion = null, + collectInheritedExtensionsFromLibraries = modelConfig.collectInheritedExtensionsFromLibraries + ) + val configuration = DokkaConfigurationImpl( + outputDir = "", + format = modelConfig.format, + generateIndexPages = false, + cacheRoot = "default", + passesConfigurations = listOf(passConfiguration) + ) + + appendDocumentation(documentation, configuration, passConfiguration, modelConfig) + documentation.prepareForGeneration(configuration) + + verifier(documentation) +} + +fun appendDocumentation( + documentation: DocumentationModule, + dokkaConfiguration: DokkaConfiguration, + passConfiguration: DokkaConfiguration.PassConfiguration, + modelConfig: ModelConfig +) { + val messageCollector = object : MessageCollector { + override fun clear() { + + } + + override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageLocation?) { + when (severity) { + CompilerMessageSeverity.STRONG_WARNING, + CompilerMessageSeverity.WARNING, + CompilerMessageSeverity.LOGGING, + CompilerMessageSeverity.OUTPUT, + CompilerMessageSeverity.INFO, + CompilerMessageSeverity.ERROR -> { + println("$severity: $message at $location") + } + CompilerMessageSeverity.EXCEPTION -> { + fail("$severity: $message at $location") + } + } + } + + override fun hasErrors() = false + } + + val environment = AnalysisEnvironment(messageCollector, modelConfig.analysisPlatform) + environment.apply { + if (modelConfig.withJdk || modelConfig.withKotlinRuntime) { + addClasspath(PathUtil.getJdkClassesRootsFromCurrentJre()) + } + if (modelConfig.withKotlinRuntime) { + if (analysisPlatform == Platform.jvm) { + val kotlinStrictfpRoot = PathManager.getResourceRoot(Strictfp::class.java, "/kotlin/jvm/Strictfp.class") + addClasspath(File(kotlinStrictfpRoot)) + } + if (analysisPlatform == Platform.js) { + val kotlinStdlibJsRoot = PathManager.getResourceRoot(Any::class.java, "/kotlin/jquery") + addClasspath(File(kotlinStdlibJsRoot)) + } + + if (analysisPlatform == Platform.common) { + // TODO: Feels hacky + val kotlinStdlibCommonRoot = ClassLoader.getSystemResource("kotlin/UInt.kotlin_metadata") + addClasspath(File(kotlinStdlibCommonRoot.file.replace("file:", "").replaceAfter(".jar", ""))) + } + } + addRoots(modelConfig.roots.toList()) + + loadLanguageVersionSettings(passConfiguration.languageVersion, passConfiguration.apiVersion) + } + val defaultPlatformsProvider = object : DefaultPlatformsProvider { + override fun getDefaultPlatforms(descriptor: DeclarationDescriptor) = modelConfig.defaultPlatforms + } + + 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 checkSourceExistsAndVerifyModel( + source: String, + modelConfig: ModelConfig = ModelConfig(), + verifier: (DocumentationModule) -> Unit +) { + require(File(source).exists()) { + "Cannot find test data file $source" + } + 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, + modelConfig: ModelConfig = ModelConfig(), + verifier: (DocumentationNode) -> Unit +) { + 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, + modelConfig: ModelConfig = ModelConfig(), + verifier: (DocumentationModule) -> Unit +) { + val tempDir = FileUtil.createTempDirectory("dokka", "") + try { + val sourceFile = File(source) + FileUtil.copy(sourceFile, File(tempDir, sourceFile.name)) + verifyModel( + ModelConfig( + roots = arrayOf(JavaSourceRoot(tempDir, null)), + withJdk = true, + withKotlinRuntime = modelConfig.withKotlinRuntime, + analysisPlatform = modelConfig.analysisPlatform + ), + verifier = verifier + ) + } finally { + FileUtil.delete(tempDir) + } +} + +fun verifyJavaPackageMember( + source: String, + modelConfig: ModelConfig = ModelConfig(), + verifier: (DocumentationNode) -> Unit +) { + verifyJavaModel(source, modelConfig) { model -> + val pkg = model.members.single() + verifier(pkg.members.single()) + } +} + +fun verifyOutput( + modelConfig: ModelConfig = ModelConfig(), + outputExtension: String, + outputGenerator: (DocumentationModule, StringBuilder) -> Unit +) { + 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, + outputGenerator: (DocumentationModule, StringBuilder) -> Unit +) { + val output = StringBuilder() + outputGenerator(it, output) + val ext = outputExtension.removePrefix(".") + val expectedFile = File(sourcePath.replaceAfterLast(".", ext, sourcePath + "." + ext)) + assertEqualsIgnoringSeparators(expectedFile, output.toString()) +} + +fun verifyJavaOutput( + path: String, + outputExtension: String, + modelConfig: ModelConfig = ModelConfig(), + outputGenerator: (DocumentationModule, StringBuilder) -> Unit +) { + verifyJavaModel(path, modelConfig) { model -> + verifyModelOutput(model, outputExtension, path, outputGenerator) + } +} + +fun assertEqualsIgnoringSeparators(expectedFile: File, output: String) { + if (!expectedFile.exists()) expectedFile.createNewFile() + val expectedText = expectedFile.readText().replace("\r\n", "\n") + val actualText = output.replace("\r\n", "\n") + + if (expectedText != actualText) + throw FileComparisonFailure("", expectedText, actualText, expectedFile.canonicalPath) +} + +fun assertEqualsIgnoringSeparators(expectedOutput: String, output: String) { + Assert.assertEquals(expectedOutput.replace("\r\n", "\n"), output.replace("\r\n", "\n")) +} + +fun StringBuilder.appendChildren(node: ContentBlock): StringBuilder { + for (child in node.children) { + val childText = child.toTestString() + append(childText) + } + return this +} + +fun StringBuilder.appendNode(node: ContentNode): StringBuilder { + when (node) { + is ContentText -> { + append(node.text) + } + is ContentEmphasis -> append("*").appendChildren(node).append("*") + is ContentBlockCode -> { + if (node.language.isNotBlank()) + appendln("[code lang=${node.language}]") + else + appendln("[code]") + appendChildren(node) + appendln() + appendln("[/code]") + } + is ContentNodeLink -> { + append("[") + appendChildren(node) + append(" -> ") + append(node.node.toString()) + append("]") + } + is ContentBlock -> { + appendChildren(node) + } + is NodeRenderContent -> { + append("render(") + append(node.node) + append(",") + append(node.mode) + append(")") + } + is ContentSymbol -> { + append(node.text) + } + is ContentEmpty -> { /* nothing */ + } + else -> throw IllegalStateException("Don't know how to format node $node") + } + return this +} + +fun ContentNode.toTestString(): String { + val node = this + return StringBuilder().apply { + appendNode(node) + }.toString() +} + +val ContentRoot.path: String + get() = when (this) { + is KotlinSourceRoot -> path + is JavaSourceRoot -> file.path + else -> throw UnsupportedOperationException() + } diff --git a/plugins/javadoc8/build.gradle b/plugins/javadoc8/build.gradle index e44fc94a..4f8d317b 100644 --- a/plugins/javadoc8/build.gradle +++ b/plugins/javadoc8/build.gradle @@ -8,7 +8,9 @@ dependencies { def toolsJar = files(((URLClassLoader) ToolProvider.getSystemToolClassLoader()).getURLs().findAll { it.path.endsWith("jar") }) compileOnly toolsJar testCompile toolsJar - testCompile project(":core").sourceSets.test.output +// testCompile project(":core").sourceSets.test.output + + testImplementation project(":core:testApi") testCompile group: 'junit', name: 'junit', version: '4.12' testCompile group: 'org.jetbrains.kotlin', name: 'kotlin-test-junit', version: kotlin_version } \ No newline at end of file diff --git a/plugins/javadoc8/src/test/kotlin/javadoc/JavadocTest.kt b/plugins/javadoc8/src/test/kotlin/javadoc/JavadocTest.kt index 1c4dd258..b65c8a3b 100644 --- a/plugins/javadoc8/src/test/kotlin/javadoc/JavadocTest.kt +++ b/plugins/javadoc8/src/test/kotlin/javadoc/JavadocTest.kt @@ -4,9 +4,9 @@ import com.sun.javadoc.Tag import com.sun.javadoc.Type import org.jetbrains.dokka.DokkaConsoleLogger import org.jetbrains.dokka.Platform -import org.jetbrains.dokka.tests.ModelConfig -import org.jetbrains.dokka.tests.assertEqualsIgnoringSeparators -import org.jetbrains.dokka.tests.checkSourceExistsAndVerifyModel +import org.jetbrains.dokka.testApi.ModelConfig +import org.jetbrains.dokka.testApi.assertEqualsIgnoringSeparators +import org.jetbrains.dokka.testApi.checkSourceExistsAndVerifyModel import org.junit.Assert.* import org.junit.Test import java.lang.reflect.Modifier.* diff --git a/plugins/javadoc8/testdata/javadoc/argumentReference.kt b/plugins/javadoc8/testdata/javadoc/argumentReference.kt new file mode 100644 index 00000000..ac3104e9 --- /dev/null +++ b/plugins/javadoc8/testdata/javadoc/argumentReference.kt @@ -0,0 +1,4 @@ +/** + * [error] + */ +fun argNamedError(error: String) {} \ No newline at end of file diff --git a/plugins/javadoc8/testdata/javadoc/blankLineInsideCodeBlock.kt b/plugins/javadoc8/testdata/javadoc/blankLineInsideCodeBlock.kt new file mode 100644 index 00000000..9430f4d5 --- /dev/null +++ b/plugins/javadoc8/testdata/javadoc/blankLineInsideCodeBlock.kt @@ -0,0 +1,12 @@ +/** + * ``` + * This is a test + * of Dokka's code blocks. + * Here is a blank line. + * + * The previous line was blank. + * ``` + */ +fun u() { + +} \ No newline at end of file diff --git a/plugins/javadoc8/testdata/javadoc/bytearr.kt b/plugins/javadoc8/testdata/javadoc/bytearr.kt new file mode 100644 index 00000000..84be1a70 --- /dev/null +++ b/plugins/javadoc8/testdata/javadoc/bytearr.kt @@ -0,0 +1,7 @@ +package foo + +class ByteArray { + fun foo(): IntArray { + return intArrayOf() + } +} \ No newline at end of file diff --git a/plugins/javadoc8/testdata/javadoc/companionMethodReference.kt b/plugins/javadoc8/testdata/javadoc/companionMethodReference.kt new file mode 100644 index 00000000..499e4492 --- /dev/null +++ b/plugins/javadoc8/testdata/javadoc/companionMethodReference.kt @@ -0,0 +1,13 @@ +package foo + + +/** + * Linking to [test] + */ +class TestClass { + + companion object { + + @JvmStatic fun test(arg: String) {} + } +} \ No newline at end of file diff --git a/plugins/javadoc8/testdata/javadoc/constructorParameters.kt b/plugins/javadoc8/testdata/javadoc/constructorParameters.kt new file mode 100644 index 00000000..c29ae912 --- /dev/null +++ b/plugins/javadoc8/testdata/javadoc/constructorParameters.kt @@ -0,0 +1,14 @@ +package bar + +/** + * Just a fruit + * + * @param weight in grams + * @param ranking quality from 0 to 10, where 10 is best + * @param color yellow is default + */ +class Banana ( + private val weight: Double, + private val ranking: Int, + color: String = "yellow" +) \ No newline at end of file diff --git a/plugins/javadoc8/testdata/javadoc/defaultNoArgConstructor.kt b/plugins/javadoc8/testdata/javadoc/defaultNoArgConstructor.kt new file mode 100644 index 00000000..3a6d04a5 --- /dev/null +++ b/plugins/javadoc8/testdata/javadoc/defaultNoArgConstructor.kt @@ -0,0 +1,12 @@ +package foo + +/** + * Description + * + * @constructor print peach + */ +class Peach { + init { + println("peach") + } +} \ No newline at end of file diff --git a/plugins/javadoc8/testdata/javadoc/deprecated.java b/plugins/javadoc8/testdata/javadoc/deprecated.java new file mode 100644 index 00000000..5a6cdd77 --- /dev/null +++ b/plugins/javadoc8/testdata/javadoc/deprecated.java @@ -0,0 +1,28 @@ +package bar; + +/** + * Just a fruit + */ +public class Banana { + private Double weight; + + /** + * Returns weight + * + * @return weight + * @deprecated + */ + public Double getWeight() { + return weight; + } + + /** + * Sets weight + * + * @param weight in grams + * @deprecated with message + */ + public void setWeight(Double weight) { + this.weight = weight; + } +} \ No newline at end of file diff --git a/plugins/javadoc8/testdata/javadoc/exception.kt b/plugins/javadoc8/testdata/javadoc/exception.kt new file mode 100644 index 00000000..ec0a5bbb --- /dev/null +++ b/plugins/javadoc8/testdata/javadoc/exception.kt @@ -0,0 +1,5 @@ +package foo + +class MyException : Exception { + fun foo() = "" +} diff --git a/plugins/javadoc8/testdata/javadoc/functionParameters.java b/plugins/javadoc8/testdata/javadoc/functionParameters.java new file mode 100644 index 00000000..8d5f5143 --- /dev/null +++ b/plugins/javadoc8/testdata/javadoc/functionParameters.java @@ -0,0 +1,17 @@ +package bar; + +/** + * Foo + */ + +public class Foo { + + /** perfom request + * + * @param name user name + * @param password user password + */ + public void request(String name, String password) { + + } +} \ No newline at end of file diff --git a/plugins/javadoc8/testdata/javadoc/internal.kt b/plugins/javadoc8/testdata/javadoc/internal.kt new file mode 100644 index 00000000..a57ea3b4 --- /dev/null +++ b/plugins/javadoc8/testdata/javadoc/internal.kt @@ -0,0 +1,8 @@ +package foo + +data class Person internal constructor( + val name: String = "", + val age: Int = 0 +) { + constructor(age: Int): this("", age) +} diff --git a/plugins/javadoc8/testdata/javadoc/jvmname.kt b/plugins/javadoc8/testdata/javadoc/jvmname.kt new file mode 100644 index 00000000..e4774cd6 --- /dev/null +++ b/plugins/javadoc8/testdata/javadoc/jvmname.kt @@ -0,0 +1,6 @@ +package foo + +class Apple { + @get:JvmName("_tree") + internal val source: Tree +} diff --git a/plugins/javadoc8/testdata/javadoc/kdocKeywordsOnMethod.kt b/plugins/javadoc8/testdata/javadoc/kdocKeywordsOnMethod.kt new file mode 100644 index 00000000..df5bbbe0 --- /dev/null +++ b/plugins/javadoc8/testdata/javadoc/kdocKeywordsOnMethod.kt @@ -0,0 +1,12 @@ +class FireException : Exception + + +/** + * COMM + * @param a Some string + * @return value of a + * @throws FireException in case of fire + */ +@Throws(FireException::class) +fun my(a: String): String = a + diff --git a/plugins/javadoc8/testdata/javadoc/noArgConstructor.kt b/plugins/javadoc8/testdata/javadoc/noArgConstructor.kt new file mode 100644 index 00000000..25e5548c --- /dev/null +++ b/plugins/javadoc8/testdata/javadoc/noArgConstructor.kt @@ -0,0 +1,12 @@ +package foo + +/** + * Description + * + * @constructor print plum + */ +class Plum() { + init { + println("plum") + } +} \ No newline at end of file diff --git a/plugins/javadoc8/testdata/javadoc/obj.kt b/plugins/javadoc8/testdata/javadoc/obj.kt new file mode 100644 index 00000000..1d10a422 --- /dev/null +++ b/plugins/javadoc8/testdata/javadoc/obj.kt @@ -0,0 +1,7 @@ +package foo + +class O { + companion object { + + } +} diff --git a/plugins/javadoc8/testdata/javadoc/paramlink.kt b/plugins/javadoc8/testdata/javadoc/paramlink.kt new file mode 100644 index 00000000..48972a22 --- /dev/null +++ b/plugins/javadoc8/testdata/javadoc/paramlink.kt @@ -0,0 +1,10 @@ +package demo + +/** + * You can [eat] it or cut it into slices using [cutIntoPieces] + */ +interface Apple { + fun eat() + + fun cutIntoPieces(pieces: Int) +} diff --git a/plugins/javadoc8/testdata/javadoc/stringarr.kt b/plugins/javadoc8/testdata/javadoc/stringarr.kt new file mode 100644 index 00000000..d6cd9dea --- /dev/null +++ b/plugins/javadoc8/testdata/javadoc/stringarr.kt @@ -0,0 +1,8 @@ +package foo + +class Foo { + companion object { + @JvmStatic fun main(args: Array) { + } + } +} \ No newline at end of file diff --git a/plugins/javadoc8/testdata/javadoc/suppress.kt b/plugins/javadoc8/testdata/javadoc/suppress.kt new file mode 100644 index 00000000..90f6c131 --- /dev/null +++ b/plugins/javadoc8/testdata/javadoc/suppress.kt @@ -0,0 +1,37 @@ +/** + * @suppress + */ +class Some { + +} + + +/** + * @suppress + * @author me + * @see other + */ +class SomeAgain { + +} + +class Same { + /** + * @suppress + */ + fun privateApi() { + + } + + /** + * @suppress + */ + val privateForSomeReason = "" +} + +/** + * @suppress + */ +interface Interface { + +} \ No newline at end of file diff --git a/plugins/javadoc8/testdata/javadoc/typealiases.kt b/plugins/javadoc8/testdata/javadoc/typealiases.kt new file mode 100644 index 00000000..bb09bfad --- /dev/null +++ b/plugins/javadoc8/testdata/javadoc/typealiases.kt @@ -0,0 +1,11 @@ +class A + +typealias B = A + +class C : B + +typealias D = (A) -> C + +fun some(d: D) { + +} \ No newline at end of file diff --git a/plugins/javadoc8/testdata/javadoc/types.kt b/plugins/javadoc8/testdata/javadoc/types.kt new file mode 100644 index 00000000..55be6058 --- /dev/null +++ b/plugins/javadoc8/testdata/javadoc/types.kt @@ -0,0 +1,4 @@ +package foo + +fun foo(x: Int, o: Any): String { +} diff --git a/plugins/javadoc8/testdata/javadoc/vararg.kt b/plugins/javadoc8/testdata/javadoc/vararg.kt new file mode 100644 index 00000000..aa6c26d7 --- /dev/null +++ b/plugins/javadoc8/testdata/javadoc/vararg.kt @@ -0,0 +1,3 @@ +fun vararg(a: String, vararg b: Int) {} + +fun varargInMiddle(a: String, vararg b: Int, c: Short) {} \ No newline at end of file diff --git a/plugins/javadoc8/testdata/javadoc/visibilityModifiers.kt b/plugins/javadoc8/testdata/javadoc/visibilityModifiers.kt new file mode 100644 index 00000000..e48e7f62 --- /dev/null +++ b/plugins/javadoc8/testdata/javadoc/visibilityModifiers.kt @@ -0,0 +1,15 @@ +package foo + +abstract class Apple { + protected var name: String = "foo" + internal var weight: Int = 180 + var rating: Int = 10 + private var color: String = "red" + + companion object { + @JvmStatic + val code : Int = 123456 + } + + +} \ No newline at end of file -- cgit From 50111daf07c7afd1c1b60e9672ed6786c96efdea Mon Sep 17 00:00:00 2001 From: Paweł Marks Date: Thu, 31 Oct 2019 15:26:20 +0100 Subject: Make things compile, no matter the cost --- .idea/compiler.xml | 10 + .idea/kotlinc.xml | 4 +- core/build.gradle | 4 +- core/src/main/kotlin/DokkaBootstrapImpl.kt | 76 --- core/src/main/kotlin/Formats/AnalysisComponents.kt | 45 -- core/src/main/kotlin/Formats/FormatDescriptor.kt | 43 -- core/src/main/kotlin/Generation/DokkaGenerator.kt | 214 --------- .../kotlin/Java/JavaPsiDocumentationBuilder.kt | 344 ------------- core/src/main/kotlin/Java/JavadocParser.kt | 402 ---------------- .../kotlin/Kotlin/DescriptorDocumentationParser.kt | 188 -------- .../src/main/kotlin/Kotlin/DocumentationBuilder.kt | 534 --------------------- .../Kotlin/KotlinElementSignatureProvider.kt | 33 -- .../main/kotlin/Kotlin/KotlinLanguageService.kt | 473 ------------------ .../main/kotlin/Languages/CommonLanguageService.kt | 84 ---- core/src/main/kotlin/Languages/LanguageService.kt | 41 -- core/src/main/kotlin/Model/PackageDocs.kt | 136 ------ core/src/main/kotlin/Utilities/DokkaModules.kt | 82 ---- .../transformers/DocumentationToPageTransformer.kt | 2 +- settings.gradle | 20 +- 19 files changed, 25 insertions(+), 2710 deletions(-) delete mode 100644 core/src/main/kotlin/DokkaBootstrapImpl.kt delete mode 100644 core/src/main/kotlin/Formats/AnalysisComponents.kt delete mode 100644 core/src/main/kotlin/Formats/FormatDescriptor.kt delete mode 100644 core/src/main/kotlin/Generation/DokkaGenerator.kt delete mode 100644 core/src/main/kotlin/Java/JavaPsiDocumentationBuilder.kt delete mode 100644 core/src/main/kotlin/Java/JavadocParser.kt delete mode 100644 core/src/main/kotlin/Kotlin/DescriptorDocumentationParser.kt delete mode 100644 core/src/main/kotlin/Kotlin/DocumentationBuilder.kt delete mode 100644 core/src/main/kotlin/Kotlin/KotlinElementSignatureProvider.kt delete mode 100644 core/src/main/kotlin/Kotlin/KotlinLanguageService.kt delete mode 100644 core/src/main/kotlin/Languages/CommonLanguageService.kt delete mode 100644 core/src/main/kotlin/Languages/LanguageService.kt delete mode 100644 core/src/main/kotlin/Model/PackageDocs.kt delete mode 100644 core/src/main/kotlin/Utilities/DokkaModules.kt (limited to 'core/build.gradle') diff --git a/.idea/compiler.xml b/.idea/compiler.xml index d3328b68..111dac2e 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -34,8 +34,18 @@ + + + + + + + + + + diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml index 38d23597..5a05248b 100644 --- a/.idea/kotlinc.xml +++ b/.idea/kotlinc.xml @@ -5,7 +5,7 @@