Skip to content

Commit

Permalink
Add K2 analysis switcher
Browse files Browse the repository at this point in the history
  • Loading branch information
vmishenev committed Sep 1, 2023
1 parent 02f30b1 commit f26b021
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,23 @@ class BasicGradleIntegrationTest : AbstractGradleIntegrationTest() {
}
}

@ParameterizedTest(name = "{0}")
@ArgumentsSource(AllSupportedTestedVersionsArgumentsProvider::class)
fun execute(buildVersions: BuildVersions) {
runAndAssertOutcome(buildVersions, TaskOutcome.SUCCESS)
runAndAssertOutcome(buildVersions, TaskOutcome.UP_TO_DATE)
@ParameterizedTest(name = "{0} {1}")
@ArgumentsSource(AllSupportedTestedVersionsWithK2SwitcherArgumentsProvider::class)
fun execute(buildVersions: BuildVersions, extraParameter: String) {
runAndAssertOutcome(buildVersions, TaskOutcome.SUCCESS, extraParameter)
runAndAssertOutcome(buildVersions, TaskOutcome.UP_TO_DATE, extraParameter)
}

private fun runAndAssertOutcome(buildVersions: BuildVersions, expectedOutcome: TaskOutcome) {
private fun runAndAssertOutcome(buildVersions: BuildVersions, expectedOutcome: TaskOutcome, extraParameter: String) {
val result = createGradleRunner(
buildVersions,
"dokkaHtml",
"dokkaJavadoc",
"dokkaGfm",
"dokkaJekyll",
"-i",
"-s"
"-s",
extraParameter
).buildRelaxed()

assertEquals(expectedOutcome, assertNotNull(result.task(":dokkaHtml")).outcome)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ class JsIRGradleIntegrationTest : AbstractGradleIntegrationTest() {
File(templateProjectDir, "src").copyRecursively(File(projectDir, "src"))
}

@ParameterizedTest(name = "{0}")
@ArgumentsSource(AllSupportedTestedVersionsArgumentsProvider::class)
fun execute(buildVersions: BuildVersions) {
@ParameterizedTest(name = "{0} {1}")
@ArgumentsSource(AllSupportedTestedVersionsWithK2SwitcherArgumentsProvider::class)
fun execute(buildVersions: BuildVersions, extraParameter: String) {
if (ignoredKotlinVersions.contains(buildVersions.kotlinVersion)) {
return
}

val reactVersion = TestedVersions.KT_REACT_WRAPPER_MAPPING[buildVersions.kotlinVersion]
?: throw IllegalStateException("Unspecified version of react for kotlin " + buildVersions.kotlinVersion)
val result = createGradleRunner(buildVersions, "-Preact_version=$reactVersion", "dokkaHtml", "-i", "-s").buildRelaxed()
val result = createGradleRunner(buildVersions, "-Preact_version=$reactVersion", "dokkaHtml", "-i", "-s", extraParameter).buildRelaxed()
assertEquals(TaskOutcome.SUCCESS, assertNotNull(result.task(":dokkaHtml")).outcome)

val htmlOutputDir = File(projectDir, "build/dokka/html")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ class MultiModule0IntegrationTest : AbstractGradleIntegrationTest() {
File(templateProjectDir, "moduleA").copyRecursively(File(projectDir, "moduleA"))
}

@ParameterizedTest(name = "{0}")
@ArgumentsSource(AllSupportedTestedVersionsArgumentsProvider::class)
fun execute(buildVersions: BuildVersions) {
@ParameterizedTest(name = "{0} {1}")
@ArgumentsSource(AllSupportedTestedVersionsWithK2SwitcherArgumentsProvider::class)
fun execute(buildVersions: BuildVersions, extraParameter: String) {
val result = createGradleRunner(
buildVersions,
":moduleA:dokkaHtmlMultiModule",
":moduleA:dokkaGfmMultiModule",
":moduleA:dokkaJekyllMultiModule",
"-i", "-s"
"-i", "-s", extraParameter
).buildRelaxed()

assertEquals(TaskOutcome.SUCCESS, assertNotNull(result.task(":moduleA:dokkaHtmlMultiModule")).outcome)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ class MultiModule1IntegrationTest : AbstractGradleIntegrationTest() {
File(templateProjectDir, "second").copyRecursively(File(projectDir, "second"))
}

@ParameterizedTest(name = "{0}")
@ArgumentsSource(AllSupportedTestedVersionsArgumentsProvider::class)
fun execute(buildVersions: BuildVersions) {
@ParameterizedTest(name = "{0} {1}")
@ArgumentsSource(AllSupportedTestedVersionsWithK2SwitcherArgumentsProvider::class)
fun execute(buildVersions: BuildVersions, extraParameter: String) {
val result = createGradleRunner(
buildVersions,
":second:dokkaHtml",
"-i", "-s"
"-i", "-s", extraParameter
).buildRelaxed()

assertEquals(TaskOutcome.SUCCESS, assertNotNull(result.task(":second:dokkaHtml")).outcome)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ class Multiplatform0GradleIntegrationTest : AbstractGradleIntegrationTest() {
File(templateProjectDir, "src").copyRecursively(File(projectDir, "src"))
}

@ParameterizedTest(name = "{0}")
@ArgumentsSource(AllSupportedTestedVersionsArgumentsProvider::class)
fun execute(buildVersions: BuildVersions) {
val result = createGradleRunner(buildVersions, "dokkaHtml", "-i", "-s").buildRelaxed()
@ParameterizedTest(name = "{0} {1}")
@ArgumentsSource(AllSupportedTestedVersionsWithK2SwitcherArgumentsProvider::class)
fun execute(buildVersions: BuildVersions, extraParameter: String) {
val result = createGradleRunner(buildVersions, "dokkaHtml", "-i", "-s", extraParameter).buildRelaxed()

assertEquals(TaskOutcome.SUCCESS, assertNotNull(result.task(":dokkaHtml")).outcome)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import org.junit.jupiter.params.provider.Arguments
import org.junit.jupiter.params.provider.ArgumentsProvider
import java.util.stream.Stream

const val useK2PropertyCLIArgument = "-Porg.jetbrains.dokka.useK2=true"
internal class LatestTestedVersionsArgumentsProvider : TestedVersionsArgumentsProvider(listOf(TestedVersions.LATEST))
internal open class AllSupportedTestedVersionsArgumentsProvider : TestedVersionsArgumentsProvider(TestedVersions.ALL_SUPPORTED)
internal open class AllSupportedTestedVersionsWithK2SwitcherArgumentsProvider : TestedVersionsWithK2SwitcherArgumentsProvider(listOf(TestedVersions.LATEST))

internal object TestedVersions {

Expand Down Expand Up @@ -68,3 +70,12 @@ abstract class TestedVersionsArgumentsProvider(private val buildVersions: List<B
return buildVersions.stream().map { Arguments.of(it) }
}
}

/**
* The first argument is [BuildVersions], the second one is an extra CLI argument for Gradle
*/
internal abstract class TestedVersionsWithK2SwitcherArgumentsProvider(private val buildVersions: List<BuildVersions>) : ArgumentsProvider {
override fun provideArguments(context: ExtensionContext?): Stream<out Arguments> {
return (buildVersions.map { Arguments.of(it, "") } + buildVersions.map { Arguments.of(it, useK2PropertyCLIArgument) }).stream()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import kotlin.test.assertEquals
import kotlin.test.assertNotNull
import kotlin.test.assertTrue

internal class WasmTestedVersionsArgumentsProvider : AllSupportedTestedVersionsArgumentsProvider() {
internal class WasmTestedVersionsArgumentsProvider : AllSupportedTestedVersionsWithK2SwitcherArgumentsProvider() {
override fun provideArguments(context: ExtensionContext?): Stream<out Arguments> {
return super.provideArguments(context).filter {
val buildVersions = it.get().single() as BuildVersions
val buildVersions = it.get().first() as BuildVersions
buildVersions.kotlinVersion >= "1.8.20" // 1.8.20 is the first public version that can be tested with wasm
}
}
Expand All @@ -40,10 +40,10 @@ class WasmGradleIntegrationTest : AbstractGradleIntegrationTest() {
File(templateProjectDir, "src").copyRecursively(File(projectDir, "src"))
}

@ParameterizedTest(name = "{0}")
@ParameterizedTest(name = "{0} {1}")
@ArgumentsSource(WasmTestedVersionsArgumentsProvider::class)
fun execute(buildVersions: BuildVersions) {
val result = createGradleRunner(buildVersions, "dokkaHtml", "-i", "-s").buildRelaxed()
fun execute(buildVersions: BuildVersions, extraParameter: String) {
val result = createGradleRunner(buildVersions, "dokkaHtml", "-i", "-s", extraParameter).buildRelaxed()
assertEquals(TaskOutcome.SUCCESS, assertNotNull(result.task(":dokkaHtml")).outcome)

val htmlOutputDir = File(projectDir, "build/dokka/html")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public abstract class AbstractGradleIntegrationTest : AbstractIntegrationTest()
"-Pdokka_it_android_gradle_plugin_version=$androidVersion"
},
* arguments
)
).filter { it.isNotBlank() }
).run { this as DefaultGradleRunner }
.withJvmArguments(jvmArgs)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ internal class DokkaArtifacts(private val project: Project) {

// TODO [beresnev] analysis switcher
val analysisKotlinDescriptors get() = fromModuleName("analysis-kotlin-descriptors")
val analysisKotlinSymbols get() = fromModuleName("analysis-kotlin-symbols")

val allModulesPage get() = fromModuleName("all-modules-page-plugin")
val dokkaCore get() = fromModuleName("dokka-core")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ open class DokkaPlugin : Plugin<Project> {
if (GradleVersion.version(project.gradle.gradleVersion) < GradleVersion.version("5.6")) {
project.logger.warn("Dokka: Build is using unsupported gradle version, expected at least 5.6 but got ${project.gradle.gradleVersion}. This may result in strange errors")
}
if (project.shouldUseK2())
project.logger.info("K2 Analysis is using")

project.setupDokkaTasks("dokkaHtml") {
description = "Generates documentation in 'html' format"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import org.gradle.api.artifacts.Dependency
import org.gradle.api.attributes.Usage
import org.gradle.kotlin.dsl.named

internal fun Project.shouldUseK2() =
(findProperty("org.jetbrains.dokka.useK2") as? String)?.toBoolean() ?: false

internal fun Project.maybeCreateDokkaDefaultPluginConfiguration(): Configuration {
return configurations.maybeCreate("dokkaPlugin") {
attributes.attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage.JAVA_RUNTIME))
Expand All @@ -29,7 +32,10 @@ internal fun Project.maybeCreateDokkaPluginConfiguration(dokkaTaskName: String,
extendsFrom(maybeCreateDokkaDefaultPluginConfiguration())
attributes.attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage.JAVA_RUNTIME))
isCanBeConsumed = false
dependencies.add(project.dokkaArtifacts.analysisKotlinDescriptors)
dependencies.add(
if (shouldUseK2()) project.dokkaArtifacts.analysisKotlinSymbols
else project.dokkaArtifacts.analysisKotlinDescriptors
)
dependencies.add(project.dokkaArtifacts.dokkaBase)
dependencies.addAll(additionalDependencies)
}
Expand Down
4 changes: 2 additions & 2 deletions subprojects/analysis-kotlin-symbols/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ plugins {

dependencies {
compileOnly(projects.core)
compileOnly(projects.subprojects.analysisKotlinApi)
implementation(projects.subprojects.analysisKotlinApi)

implementation(projects.subprojects.analysisMarkdownJb)
implementation(projects.subprojects.analysisJavaPsi)
Expand Down Expand Up @@ -73,7 +73,7 @@ dependencies {
isTransitive = false // see KTIJ-19820
}
}
runtimeOnly(libs.kotlinx.collections.immutable)
implementation(libs.kotlinx.collections.immutable)
implementation(libs.kotlin.compiler.k2) {
isTransitive = false
}
Expand Down

0 comments on commit f26b021

Please sign in to comment.