-
-
Notifications
You must be signed in to change notification settings - Fork 31
/
BaseSentryPluginTest.kt
118 lines (104 loc) · 3.95 KB
/
BaseSentryPluginTest.kt
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
107
108
109
110
111
112
113
114
115
116
117
118
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 BaseSentryPluginTest(
private val androidGradlePluginVersion: String,
private val gradleVersion: String
) {
@get:Rule
val testProjectDir = TemporaryFolder()
private val projectTemplateFolder = File("src/test/resources/testFixtures/appTestProject")
private lateinit var rootBuildFile: File
protected lateinit var appBuildFile: 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")
rootBuildFile = testProjectDir.writeFile("build.gradle") {
// language=Groovy
"""
buildscript {
repositories {
google()
gradlePluginPortal()
}
dependencies {
classpath 'com.android.tools.build:gradle:$androidGradlePluginVersion'
// This is needed to populate the plugin classpath instead of using
// withPluginClasspath on the Gradle Runner.
classpath files($pluginClasspath)
$additionalBuildClasspath
}
}
allprojects {
repositories {
google()
mavenCentral()
maven { url 'https://appboy.github.io/appboy-android-sdk/sdk' }
}
}
subprojects {
pluginManager.withPlugin('com.android.application') {
android {
compileSdkVersion 31
defaultConfig {
applicationId "com.example"
minSdkVersion 21
}
buildTypes {
release {
minifyEnabled true
proguardFiles("src/release/proguard-rules.pro")
}
}
$additionalRootProjectConfig
}
}
}
""".trimIndent()
}
runner = GradleRunner.create()
.withProjectDir(testProjectDir.root)
.withArguments("--stacktrace")
.withPluginClasspath()
.withGradleVersion(gradleVersion)
}
companion object {
@Parameterized.Parameters(name = "AGP {0}, Gradle {1}")
@JvmStatic
fun parameters() = listOf(
// The supported Gradle version can be found here:
// https://developer.android.com/studio/releases/gradle-plugin#updating-gradle
// The pair is [AGP Version, Gradle Version]
arrayOf("7.0.4", "7.2"),
arrayOf("7.1.3", "7.2"),
arrayOf("7.2.1", "7.3.3"),
arrayOf("7.2.1", "7.4"),
arrayOf("7.2.1", "7.5"),
arrayOf("7.3.0", "7.4"),
arrayOf("7.3.0", "7.5"),
arrayOf("7.4.0-beta01", "7.5"),
arrayOf("8.0.0-alpha01", "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
}
}
}