-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathEnvironment.kt
179 lines (157 loc) · 6.07 KB
/
Environment.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import Platform.Android
import Platform.Java
import org.gradle.api.Project
import java.io.File
import java.util.Properties
enum class SupportedAgp(
val version: String,
val gradle: String? = null
) {
AGP_8_0("8.0.2", gradle = "8.0"),
AGP_8_1("8.1.4", gradle = "8.0"),
AGP_8_2("8.2.2", gradle = "8.2"),
AGP_8_3("8.3.2", gradle = "8.4"),
AGP_8_4("8.4.2", gradle = "8.6"),
AGP_8_5("8.5.2", gradle = "8.7"),
AGP_8_6("8.6.1", gradle = "8.7"),
AGP_8_7("8.7.3", gradle = "8.9"),
AGP_8_8("8.8.1", gradle = "8.10.2"),
AGP_8_9("8.9.0-rc01", gradle = "8.11.1"),
AGP_8_10("8.10.0-alpha05", gradle = "8.11.1"),
;
companion object {
val oldest = values().first()
val newestStable = values().reversed().first { '-' !in it.version }
}
val shortVersion: String = run {
// Extract first two components of the Maven dependency's version string.
val components = version.split('.')
if (components.size < 2) {
throw IllegalArgumentException("Cannot derive AGP configuration name from: $this")
}
"${components[0]}.${components[1]}"
}
val configurationName = "testAgp${shortVersion.replace(".", "")}x"
}
object Android {
const val compileSdkVersion = 34
const val targetSdkVersion = 34
const val sampleMinSdkVersion = 21
val testRunnerMinSdkVersion = (Artifacts.Instrumentation.Runner.platform as Android).minSdk
val testCoreMinSdkVersion = (Artifacts.Instrumentation.Core.platform as Android).minSdk
val testComposeMinSdkVersion = (Artifacts.Instrumentation.Compose.platform as Android).minSdk
}
sealed class Platform(val name: String) {
object Java : Platform("java")
class Android(val minSdk: Int) : Platform("android")
}
/**
* Encapsulation for "deployable" library artifacts,
* containing all sorts of configuration related to Maven coordinates, for instance.
*/
class Deployed internal constructor(
val platform: Platform,
val groupId: String,
val artifactId: String,
val currentVersion: String,
val latestStableVersion: String,
val description: String,
)
object Artifacts {
const val GITHUB_URL = "https://github.com/mannodermaus/android-junit5"
const val GITHUB_REPO = "mannodermaus/android-junit5"
const val LICENSE = "Apache-2.0"
/**
* Retrieve the artifact configuration based on a Gradle project reference.
* Return null if none can be found
*/
fun from(project: Project) =
when (project.name) {
"core" -> Instrumentation.Core
"runner" -> Instrumentation.Runner
"android-junit5" -> Plugin
else -> null
}
/**
* Gradle Plugin artifact
*/
val Plugin = Deployed(
platform = Java,
groupId = "de.mannodermaus.gradle.plugins",
artifactId = "android-junit5",
currentVersion = "1.12.0.0-SNAPSHOT",
latestStableVersion = "1.11.3.0",
description = "Unit Testing with JUnit 5 for Android."
)
/**
* Instrumentation Test artifacts
*/
object Instrumentation {
const val groupId = "de.mannodermaus.junit5"
private const val currentVersion = "1.7.0-SNAPSHOT"
private const val latestStableVersion = "1.6.0"
val Core = Deployed(
platform = Android(minSdk = 19),
groupId = groupId,
artifactId = "android-test-core",
currentVersion = currentVersion,
latestStableVersion = latestStableVersion,
description = "Extensions for instrumented Android tests with JUnit 5."
)
val Extensions = Deployed(
platform = Android(minSdk = 19),
groupId = groupId,
artifactId = "android-test-extensions",
currentVersion = currentVersion,
latestStableVersion = latestStableVersion,
description = "Optional extensions for instrumented Android tests with JUnit 5."
)
val Runner = Deployed(
platform = Android(minSdk = 19),
groupId = groupId,
artifactId = "android-test-runner",
currentVersion = currentVersion,
latestStableVersion = latestStableVersion,
description = "Runner for integration of instrumented Android tests with JUnit 5."
)
val Compose = Deployed(
platform = Android(minSdk = 21),
groupId = groupId,
artifactId = "android-test-compose",
currentVersion = currentVersion,
latestStableVersion = latestStableVersion,
description = "Extensions for Jetpack Compose tests with JUnit 5."
)
}
}
class DeployedCredentials(private val project: Project) {
var signingKeyId: String?
var signingPassword: String?
var signingKeyRingFile: String?
var ossrhUsername: String?
var ossrhPassword: String?
var sonatypeStagingProfileId: String?
init {
// Populate deployment credentials in an environment-aware fashion.
//
// * Local development:
// Stored in local.properties file on the machine
// (in the root folder of the project – the one containing "plugin/" and "instrumentation/")
// * CI Server:
// Stored in environment variables before launch
val properties = Properties().apply {
val credentialsFile = File(project.rootDir.parentFile, "local.properties")
if (credentialsFile.exists()) {
load(credentialsFile.inputStream())
}
}
this.signingKeyId = properties.getOrEnvvar("SIGNING_KEY_ID")
this.signingPassword = properties.getOrEnvvar("SIGNING_PASSWORD")
this.signingKeyRingFile = properties.getOrEnvvar("SIGNING_KEY_RING_FILE")
this.ossrhUsername = properties.getOrEnvvar("OSSRH_USERNAME")
this.ossrhPassword = properties.getOrEnvvar("OSSRH_PASSWORD")
this.sonatypeStagingProfileId = properties.getOrEnvvar("SONATYPE_STAGING_PROFILE_ID")
}
private fun Properties.getOrEnvvar(key: String): String? =
getProperty(key, System.getenv(key))
}