diff options
author | Paweł Marks <pmarks@virtuslab.com> | 2020-07-17 16:36:09 +0200 |
---|---|---|
committer | Paweł Marks <pmarks@virtuslab.com> | 2020-07-17 16:36:09 +0200 |
commit | 6996b1135f61c7d2cb60b0652c6a2691dda31990 (patch) | |
tree | d568096c25e31c28d14d518a63458b5a7526b896 /integration-tests/gradle/src/main | |
parent | de56cab76f556e5b4af0b8c8cb08d8b482b86d0a (diff) | |
parent | 1c3530dcbb50c347f80bef694829dbefe89eca77 (diff) | |
download | dokka-6996b1135f61c7d2cb60b0652c6a2691dda31990.tar.gz dokka-6996b1135f61c7d2cb60b0652c6a2691dda31990.tar.bz2 dokka-6996b1135f61c7d2cb60b0652c6a2691dda31990.zip |
Merge branch 'dev-0.11.0'
Diffstat (limited to 'integration-tests/gradle/src/main')
2 files changed, 122 insertions, 0 deletions
diff --git a/integration-tests/gradle/src/main/kotlin/org/jetbrains/dokka/it/gradle/AbstractGradleIntegrationTest.kt b/integration-tests/gradle/src/main/kotlin/org/jetbrains/dokka/it/gradle/AbstractGradleIntegrationTest.kt new file mode 100644 index 00000000..f852dc8b --- /dev/null +++ b/integration-tests/gradle/src/main/kotlin/org/jetbrains/dokka/it/gradle/AbstractGradleIntegrationTest.kt @@ -0,0 +1,74 @@ +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.jetbrains.dokka.it.AbstractIntegrationTest +import org.junit.Assume +import org.junit.Assume.assumeFalse +import org.junit.AssumptionViolatedException +import org.junit.runner.RunWith +import org.junit.runners.Parameterized +import java.io.File +import kotlin.test.BeforeTest + +@RunWith(Parameterized::class) +abstract class AbstractGradleIntegrationTest : AbstractIntegrationTest() { + + abstract val versions: BuildVersions + + @BeforeTest + fun copyTemplates() { + File("projects").listFiles().orEmpty() + .filter { it.isFile } + .filter { it.name.startsWith("template.") } + .forEach { file -> file.copyTo(File(temporaryTestFolder.root, file.name)) } + } + + fun createGradleRunner( + vararg arguments: String + ): GradleRunner { + return GradleRunner.create() + .withProjectDir(projectDir) + .withGradleVersion(versions.gradleVersion.version) + .forwardOutput() + .withTestKitDir(File("build", "gradle-test-kit").absoluteFile) + .withArguments( + listOfNotNull( + "-Pkotlin_version=${versions.kotlinVersion}", + "-Pdokka_it_kotlin_version=${versions.kotlinVersion}", + versions.androidGradlePluginVersion?.let { androidVersion -> + "-Pdokka_it_android_gradle_plugin_version=$androidVersion" + }, + * arguments + ) + ).run { this as DefaultGradleRunner } + .withJvmArguments("-Xmx4G", "-XX:MaxMetaspaceSize=2G") + } + + fun GradleRunner.buildRelaxed(): BuildResult { + return try { + build() + } catch (e: Throwable) { + val gradleConnectionException = e.withAllCauses().find { it is GradleConnectionException } + if (gradleConnectionException != null) { + gradleConnectionException.printStackTrace() + throw AssumptionViolatedException("Assumed Gradle connection", gradleConnectionException) + + } + throw e + } + } +} + +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/integration-tests/gradle/src/main/kotlin/org/jetbrains/dokka/it/gradle/BuildVersions.kt b/integration-tests/gradle/src/main/kotlin/org/jetbrains/dokka/it/gradle/BuildVersions.kt new file mode 100644 index 00000000..84a7f1e8 --- /dev/null +++ b/integration-tests/gradle/src/main/kotlin/org/jetbrains/dokka/it/gradle/BuildVersions.kt @@ -0,0 +1,48 @@ +package org.jetbrains.dokka.it.gradle + +import org.gradle.util.GradleVersion + +data class BuildVersions( + val gradleVersion: GradleVersion, + val kotlinVersion: String, + val androidGradlePluginVersion: String? = null, +) { + 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") + } + } + } + + companion object { + 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 + ) + } + } + } + } + } +} |