-
-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathBaseSentryNonAndroidPluginTest.kt
More file actions
106 lines (92 loc) · 3.53 KB
/
BaseSentryNonAndroidPluginTest.kt
File metadata and controls
106 lines (92 loc) · 3.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package io.sentry.android.gradle
import java.io.File
import org.gradle.testkit.runner.GradleRunner
import org.gradle.testkit.runner.internal.PluginUnderTestMetadataReading
import org.junit.Before
import org.junit.Rule
import org.junit.rules.TemporaryFolder
import org.junit.runners.Parameterized
@Suppress("FunctionName")
abstract class BaseSentryNonAndroidPluginTest(
private val gradleVersion: String
) {
@get:Rule
val testProjectDir = TemporaryFolder()
private val projectTemplateFolder = File("src/test/resources/testFixtures/appTestProject")
private val mavenTestRepoPath = File("./../build/mavenTestRepo")
private lateinit var rootBuildFile: File
protected lateinit var appBuildFile: File
protected lateinit var moduleBuildFile: File
protected lateinit var sentryPropertiesFile: File
protected lateinit var runner: GradleRunner
protected open val additionalRootProjectConfig: String = ""
protected open val additionalBuildClasspath: String = ""
@Before
fun setup() {
projectTemplateFolder.copyRecursively(testProjectDir.root)
val pluginClasspath = PluginUnderTestMetadataReading.readImplementationClasspath()
.joinToString(separator = ", ") { "\"$it\"" }
.replace(File.separator, "/")
appBuildFile = File(testProjectDir.root, "app/build.gradle")
moduleBuildFile = File(testProjectDir.root, "module/build.gradle")
sentryPropertiesFile = File(testProjectDir.root, "sentry.properties")
rootBuildFile = testProjectDir.writeFile("build.gradle") {
// language=Groovy
"""
buildscript {
repositories {
google()
gradlePluginPortal()
mavenCentral()
}
dependencies {
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.0'
// This is needed to populate the plugin classpath instead of using
// withPluginClasspath on the Gradle Runner.
$additionalBuildClasspath
classpath files($pluginClasspath)
}
}
allprojects {
repositories {
maven {
url = "${mavenTestRepoPath.absoluteFile.toURI()}"
}
google()
mavenCentral()
mavenLocal()
}
}
""".trimIndent()
}
runner = GradleRunner.create()
.withProjectDir(testProjectDir.root)
.withArguments("--stacktrace")
.withPluginClasspath()
.withGradleVersion(gradleVersion)
}
companion object {
@Parameterized.Parameters(name = "Gradle {0}")
@JvmStatic
fun parameters() = listOf(
// The supported Gradle version can be found here:
// https://developer.android.com/studio/releases/gradle-plugin#updating-gradle
/*arrayOf("7.2"),
arrayOf("7.3.3"),
arrayOf("7.4"),
arrayOf("7.5"),
arrayOf("7.6"),
arrayOf("8.0.2"),
arrayOf("8.1")*/
arrayOf("7.5")
)
internal fun GradleRunner.appendArguments(vararg arguments: String) =
withArguments(this.arguments + arguments)
private fun TemporaryFolder.writeFile(fileName: String, text: () -> String): File {
val file = File(root, fileName)
file.parentFile.mkdirs()
file.writeText(text())
return file
}
}
}