aboutsummaryrefslogtreecommitdiff
path: root/dokka-integration-tests/gradle/src/main
diff options
context:
space:
mode:
authorIgnat Beresnev <ignat.beresnev@jetbrains.com>2023-11-10 11:46:54 +0100
committerGitHub <noreply@github.com>2023-11-10 11:46:54 +0100
commit8e5c63d035ef44a269b8c43430f43f5c8eebfb63 (patch)
tree1b915207b2b9f61951ddbf0ff2e687efd053d555 /dokka-integration-tests/gradle/src/main
parenta44efd4ba0c2e4ab921ff75e0f53fc9335aa79db (diff)
downloaddokka-8e5c63d035ef44a269b8c43430f43f5c8eebfb63.tar.gz
dokka-8e5c63d035ef44a269b8c43430f43f5c8eebfb63.tar.bz2
dokka-8e5c63d035ef44a269b8c43430f43f5c8eebfb63.zip
Restructure the project to utilize included builds (#3174)
* Refactor and simplify artifact publishing * Update Gradle to 8.4 * Refactor and simplify convention plugins and build scripts Fixes #3132 --------- Co-authored-by: Adam <897017+aSemy@users.noreply.github.com> Co-authored-by: Oleg Yukhnevich <whyoleg@gmail.com>
Diffstat (limited to 'dokka-integration-tests/gradle/src/main')
-rw-r--r--dokka-integration-tests/gradle/src/main/kotlin/org/jetbrains/dokka/it/gradle/AbstractGradleIntegrationTest.kt84
-rw-r--r--dokka-integration-tests/gradle/src/main/kotlin/org/jetbrains/dokka/it/gradle/BuildVersions.kt52
-rw-r--r--dokka-integration-tests/gradle/src/main/kotlin/org/jetbrains/dokka/it/gradle/TestEnvironment.kt18
3 files changed, 154 insertions, 0 deletions
diff --git a/dokka-integration-tests/gradle/src/main/kotlin/org/jetbrains/dokka/it/gradle/AbstractGradleIntegrationTest.kt b/dokka-integration-tests/gradle/src/main/kotlin/org/jetbrains/dokka/it/gradle/AbstractGradleIntegrationTest.kt
new file mode 100644
index 00000000..5c5d1892
--- /dev/null
+++ b/dokka-integration-tests/gradle/src/main/kotlin/org/jetbrains/dokka/it/gradle/AbstractGradleIntegrationTest.kt
@@ -0,0 +1,84 @@
+/*
+ * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
+ */
+
+package org.jetbrains.dokka.it.gradle
+
+import org.gradle.testkit.runner.BuildResult
+import org.gradle.testkit.runner.GradleRunner
+import org.gradle.testkit.runner.internal.DefaultGradleRunner
+import org.gradle.tooling.GradleConnectionException
+import org.gradle.util.GradleVersion
+import org.jetbrains.dokka.it.AbstractIntegrationTest
+import java.io.File
+import java.net.URI
+import kotlin.test.BeforeTest
+
+public abstract class AbstractGradleIntegrationTest : AbstractIntegrationTest() {
+
+ @BeforeTest
+ public fun copyTemplates() {
+ File("projects").listFiles().orEmpty()
+ .filter { it.isFile }
+ .filter { it.name.startsWith("template.") }
+ .forEach { file -> file.copyTo(File(tempFolder, file.name)) }
+ }
+
+ public fun createGradleRunner(
+ buildVersions: BuildVersions,
+ vararg arguments: String,
+ jvmArgs: List<String> = listOf("-Xmx2G", "-XX:MaxMetaspaceSize=1G")
+ ): GradleRunner {
+ return GradleRunner.create()
+ .withProjectDir(projectDir)
+ .forwardOutput()
+ .withJetBrainsCachedGradleVersion(buildVersions.gradleVersion)
+ .withTestKitDir(File("build", "gradle-test-kit").absoluteFile)
+ .withArguments(
+ listOfNotNull(
+ "-Pdokka_it_dokka_version=${System.getenv("DOKKA_VERSION")}",
+ "-Pdokka_it_kotlin_version=${buildVersions.kotlinVersion}",
+ buildVersions.androidGradlePluginVersion?.let { androidVersion ->
+ "-Pdokka_it_android_gradle_plugin_version=$androidVersion"
+ },
+ * arguments
+ )
+ ).run { this as DefaultGradleRunner }
+ .withJvmArguments(jvmArgs)
+ }
+
+ public fun GradleRunner.buildRelaxed(): BuildResult {
+ return try {
+ build()
+ } catch (e: Throwable) {
+ val gradleConnectionException = e.withAllCauses().find { it is GradleConnectionException }
+ if (gradleConnectionException != null) {
+ gradleConnectionException.printStackTrace()
+ throw IllegalStateException("Assumed Gradle connection", gradleConnectionException)
+
+ }
+ throw e
+ }
+ }
+}
+
+private fun GradleRunner.withJetBrainsCachedGradleVersion(version: GradleVersion): GradleRunner {
+ return withGradleDistribution(
+ URI.create(
+ "https://cache-redirector.jetbrains.com/" +
+ "services.gradle.org/distributions/" +
+ "gradle-${version.version}-bin.zip"
+ )
+ )
+}
+
+private fun Throwable.withAllCauses(): Sequence<Throwable> {
+ val root = this
+ return sequence {
+ yield(root)
+ val cause = root.cause
+ if (cause != null && cause != root) {
+ yieldAll(cause.withAllCauses())
+ }
+ }
+}
diff --git a/dokka-integration-tests/gradle/src/main/kotlin/org/jetbrains/dokka/it/gradle/BuildVersions.kt b/dokka-integration-tests/gradle/src/main/kotlin/org/jetbrains/dokka/it/gradle/BuildVersions.kt
new file mode 100644
index 00000000..ab387420
--- /dev/null
+++ b/dokka-integration-tests/gradle/src/main/kotlin/org/jetbrains/dokka/it/gradle/BuildVersions.kt
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
+ */
+
+package org.jetbrains.dokka.it.gradle
+
+import org.gradle.util.GradleVersion
+
+public data class BuildVersions(
+ val gradleVersion: GradleVersion,
+ val kotlinVersion: String,
+ val androidGradlePluginVersion: String? = null,
+) {
+ public constructor(
+ gradleVersion: String,
+ kotlinVersion: String,
+ androidGradlePluginVersion: String? = null
+ ) : this(
+ gradleVersion = GradleVersion.version(gradleVersion),
+ kotlinVersion = kotlinVersion,
+ androidGradlePluginVersion = androidGradlePluginVersion
+ )
+
+ override fun toString(): String {
+ return buildString {
+ append("Gradle ${gradleVersion.version}, Kotlin $kotlinVersion")
+ if (androidGradlePluginVersion != null) {
+ append(", Android $androidGradlePluginVersion")
+ }
+ }
+ }
+
+ public companion object {
+ public fun permutations(
+ gradleVersions: List<String>,
+ kotlinVersions: List<String>,
+ androidGradlePluginVersions: List<String?> = listOf(null)
+ ): List<BuildVersions> {
+ return gradleVersions.distinct().flatMap { gradleVersion ->
+ kotlinVersions.distinct().flatMap { kotlinVersion ->
+ androidGradlePluginVersions.distinct().map { androidVersion ->
+ BuildVersions(
+ gradleVersion = gradleVersion,
+ kotlinVersion = kotlinVersion,
+ androidGradlePluginVersion = androidVersion
+ )
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/dokka-integration-tests/gradle/src/main/kotlin/org/jetbrains/dokka/it/gradle/TestEnvironment.kt b/dokka-integration-tests/gradle/src/main/kotlin/org/jetbrains/dokka/it/gradle/TestEnvironment.kt
new file mode 100644
index 00000000..174060aa
--- /dev/null
+++ b/dokka-integration-tests/gradle/src/main/kotlin/org/jetbrains/dokka/it/gradle/TestEnvironment.kt
@@ -0,0 +1,18 @@
+/*
+ * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
+ */
+
+package org.jetbrains.dokka.it.gradle
+
+public object TestEnvironment {
+ public val isExhaustive: Boolean = checkNotNull(System.getenv("isExhaustive")) {
+ "Missing `isExhaustive` environment variable"
+ }.toBoolean()
+}
+
+/**
+ * Will only return values if [TestEnvironment.isExhaustive] is set to true
+ */
+public inline fun <reified T> ifExhaustive(vararg values: T): Array<out T> {
+ return if (TestEnvironment.isExhaustive) values else emptyArray()
+}