@@ -12,10 +12,14 @@ import org.gradle.api.attributes.plugin.GradlePluginApiVersion
12
12
import org.gradle.api.attributes.plugin.GradlePluginApiVersion.GRADLE_PLUGIN_API_VERSION_ATTRIBUTE
13
13
import org.gradle.api.file.DuplicatesStrategy
14
14
import org.gradle.api.file.RegularFileProperty
15
- import org.gradle.api.tasks.*
15
+ import org.gradle.api.tasks.Copy
16
+ import org.gradle.api.tasks.InputFile
17
+ import org.gradle.api.tasks.OutputFile
18
+ import org.gradle.api.tasks.SourceSetContainer
19
+ import org.gradle.api.tasks.TaskAction
16
20
import java.io.File
17
21
import java.time.ZonedDateTime
18
- import java.util.*
22
+ import java.util.Locale
19
23
20
24
private const val minimumGradleVersion = " 8.2"
21
25
@@ -25,38 +29,38 @@ fun Project.configureTestResources() {
25
29
// for different versions of the Android Gradle Plugin
26
30
tasks.named(" processTestResources" , Copy ::class .java).configure {
27
31
val tokens = mapOf (
28
- " COMPILE_SDK_VERSION" to Android .compileSdkVersion.toString(),
29
- " MIN_SDK_VERSION" to Android .sampleMinSdkVersion.toString(),
30
- " TARGET_SDK_VERSION" to Android .targetSdkVersion.toString(),
31
-
32
- " KOTLIN_VERSION" to libs.versions.kotlin,
33
- " JUNIT_JUPITER_VERSION" to libs.versions.junitJupiter,
34
- " JUNIT5_ANDROID_LIBS_VERSION" to Artifacts .Instrumentation .Core .latestStableVersion,
35
-
36
- // Collect all supported AGP versions into a single string.
37
- // This string is delimited with semicolons, and each of the separated values itself is a 4-tuple.
38
- //
39
- // Example:
40
- // AGP_VERSIONS = 3.5|3.5.3|;3.6|3.6.3|6.4;3.7|3.7.0|8.0|33
41
- //
42
- // Can be parsed into this list of values:
43
- // |___> Short: "3.5"
44
- // Full: "3.5.3"
45
- // Gradle Requirement: ""
46
- // Compile SDK: null
47
- //
48
- // |___> Short: "3.6"
49
- // Full: "3.6.3"
50
- // Gradle Requirement: "6.4"
51
- // Compile SDK: null
52
- //
53
- // |___> Short: "3.7"
54
- // Full: "3.7.0"
55
- // Gradle Requirement: "8.0"
56
- // Compile SDK: 33
57
- " AGP_VERSIONS" to SupportedAgp .values().joinToString(separator = " ;" ) { plugin ->
58
- " ${plugin.shortVersion} |${plugin.version} |${plugin.gradle} |${plugin.compileSdk ? : " " } "
59
- }
32
+ " COMPILE_SDK_VERSION" to Android .compileSdkVersion.toString(),
33
+ " MIN_SDK_VERSION" to Android .sampleMinSdkVersion.toString(),
34
+ " TARGET_SDK_VERSION" to Android .targetSdkVersion.toString(),
35
+
36
+ " KOTLIN_VERSION" to libs.versions.kotlin,
37
+ " JUNIT_JUPITER_VERSION" to libs.versions.junitJupiter,
38
+ " JUNIT5_ANDROID_LIBS_VERSION" to Artifacts .Instrumentation .Core .latestStableVersion,
39
+
40
+ // Collect all supported AGP versions into a single string.
41
+ // This string is delimited with semicolons, and each of the separated values itself is a 4-tuple.
42
+ //
43
+ // Example:
44
+ // AGP_VERSIONS = 3.5|3.5.3|;3.6|3.6.3|6.4;3.7|3.7.0|8.0|33
45
+ //
46
+ // Can be parsed into this list of values:
47
+ // |___> Short: "3.5"
48
+ // Full: "3.5.3"
49
+ // Gradle Requirement: ""
50
+ // Compile SDK: null
51
+ //
52
+ // |___> Short: "3.6"
53
+ // Full: "3.6.3"
54
+ // Gradle Requirement: "6.4"
55
+ // Compile SDK: null
56
+ //
57
+ // |___> Short: "3.7"
58
+ // Full: "3.7.0"
59
+ // Gradle Requirement: "8.0"
60
+ // Compile SDK: 33
61
+ " AGP_VERSIONS" to SupportedAgp .values().joinToString(separator = " ;" ) { plugin ->
62
+ " ${plugin.shortVersion} |${plugin.version} |${plugin.gradle} |${plugin.compileSdk ? : " " } "
63
+ }
60
64
)
61
65
62
66
inputs.properties(tokens)
@@ -125,17 +129,19 @@ fun Project.configureTestResources() {
125
129
// 2) Use resources from the plugin (i.e. plugin IDs etc.)
126
130
// 3) Use AGP-specific dependencies
127
131
val classesDirs = file(" $buildDir /classes" ).listFiles()
128
- ?.filter { it.isDirectory }
129
- ?.map { File (it, " main" ) }
130
- ?.filter { it.exists() && it.isDirectory && it.list()?.isEmpty() == false }
131
- ? : emptyList()
132
+ ?.filter { it.isDirectory }
133
+ ?.map { File (it, " main" ) }
134
+ ?.filter { it.exists() && it.isDirectory && it.list()?.isEmpty() == false }
135
+ ? : emptyList()
132
136
val resourcesDirs = file(" $buildDir /resources" ).listFiles()
133
- ?.filter { it.isDirectory }
134
- ? : emptyList()
137
+ ?.filter { it.isDirectory }
138
+ ? : emptyList()
135
139
136
140
writer.write(" implementation-classpath=" )
137
- writer.write((classesDirs + resourcesDirs + configuration)
138
- .joinToString(separator = " \\ :" ))
141
+ writer.write(
142
+ (classesDirs + resourcesDirs + configuration)
143
+ .joinToString(separator = " \\ :" )
144
+ )
139
145
}
140
146
}
141
147
}
@@ -146,7 +152,7 @@ fun findInstrumentationVersion(
146
152
pluginVersion : String = Artifacts .Plugin .currentVersion,
147
153
currentInstrumentationVersion : String = Artifacts .Instrumentation .Core .currentVersion,
148
154
stableInstrumentationVersion : String = Artifacts .Instrumentation .Core .latestStableVersion
149
- ): String {
155
+ ): String {
150
156
return when {
151
157
pluginVersion.endsWith(" -SNAPSHOT" ) -> currentInstrumentationVersion
152
158
currentInstrumentationVersion.endsWith(" -SNAPSHOT" ) -> stableInstrumentationVersion
@@ -197,12 +203,14 @@ abstract class GenerateReadme : DefaultTask() {
197
203
private const val PLUGIN_VERSION = " pluginVersion"
198
204
private const val INSTRUMENTATION_VERSION = " instrumentationVersion"
199
205
200
- private const val CONSTANTS_FILE = " android-junit5/src/main/kotlin/de/mannodermaus/gradle/plugins/junit5/internal/config/Constants.kt"
201
- private val CONSTANTS_FILE_REGEX = Regex (" const val (.*) = \" (.*)\" " )
206
+ private const val CONSTANTS_FILE =
207
+ " android-junit5/src/main/kotlin/de/mannodermaus/gradle/plugins/junit5/internal/config/Constants.kt"
208
+ private val CONSTANTS_FILE_REGEX1 = Regex (""" val (.*)\s*=\s*.+"(.*)".+""" )
209
+ private val CONSTANTS_FILE_REGEX2 = Regex (""" val (.*)\s*=\s*AndroidPluginVersion\((\d+)\s*,\s*(\d+)\)""" )
202
210
private val CONSTANT_MAPPINGS = mapOf (
203
- " minimumRequiredGradleVersion" to " MIN_REQUIRED_GRADLE_VERSION" ,
204
- " minimumRequiredAgpVersion" to " MIN_REQUIRED_AGP_VERSION" ,
205
- " currentYear" to " CURRENT_YEAR" ,
211
+ " minimumRequiredGradleVersion" to " MIN_REQUIRED_GRADLE_VERSION" ,
212
+ " minimumRequiredAgpVersion" to " MIN_REQUIRED_AGP_VERSION" ,
213
+ " currentYear" to " CURRENT_YEAR" ,
206
214
)
207
215
208
216
private val GENERATED_HEADER_COMMENT = """
@@ -241,7 +249,7 @@ abstract class GenerateReadme : DefaultTask() {
241
249
242
250
PLACEHOLDER_REGEX .findAll(templateText).forEach { match ->
243
251
val placeholder = match.groups.last()?.value
244
- ? : throw InvalidPlaceholder (match)
252
+ ? : throw InvalidPlaceholder (match)
245
253
246
254
// Local versions (plugin, instrumentation)
247
255
val replacement = when (placeholder) {
@@ -251,14 +259,16 @@ abstract class GenerateReadme : DefaultTask() {
251
259
val match2 = CONSTANT_REGEX .find(placeholder)
252
260
if (match2 != null ) {
253
261
val key = match2.groups.last()?.value
262
+ val constantKey1 = CONSTANT_MAPPINGS [key]
263
+ println (" Constant key. placeholder=$placeholder , match2=$match2 , constantKey1=$constantKey1 , constants=$constants " )
254
264
val constantKey = CONSTANT_MAPPINGS [key] ? : throw InvalidPlaceholder (match2)
255
265
constants[constantKey] ? : throw InvalidPlaceholder (match2)
256
266
257
267
} else {
258
268
val match3 = EXTERNAL_DEP_REGEX .find(placeholder)
259
- ? : throw InvalidPlaceholder (match)
269
+ ? : throw InvalidPlaceholder (match)
260
270
val externalDependency = match3.groups.last()?.value
261
- ? : throw InvalidPlaceholder (match3)
271
+ ? : throw InvalidPlaceholder (match3)
262
272
263
273
val field = libs.javaClass.getField(externalDependency)
264
274
field.get(null ) as String
@@ -284,15 +294,27 @@ abstract class GenerateReadme : DefaultTask() {
284
294
// Add hardcoded constants
285
295
constants[" CURRENT_YEAR" ] = ZonedDateTime .now().year.toString()
286
296
287
- CONSTANTS_FILE_REGEX .findAll(text).forEach { match ->
288
- constants[match.groups[1 ]!! .value] = match.groups[2 ]!! .value
297
+ CONSTANTS_FILE_REGEX1 .findAll(text).forEach { match ->
298
+ constants[match[1 ]] = match[2 ]
299
+ }
300
+
301
+ // Special case for AGP version
302
+ CONSTANTS_FILE_REGEX2 .findAll(text).forEach { match ->
303
+ constants[match[1 ]] = match.groupValues
304
+ .drop(2 )
305
+ .joinToString(separator = " ." , transform = String ::trim)
289
306
}
290
307
291
308
return constants
292
309
}
310
+
311
+ private operator fun MatchResult.get (index : Int ): String {
312
+ return this .groups[index]!! .value.trim()
313
+ }
293
314
}
294
315
295
- private class InvalidPlaceholder (matchResult : MatchResult ) : Exception(" Invalid match result: '${matchResult.groupValues} '" )
316
+ private class InvalidPlaceholder (matchResult : MatchResult ) :
317
+ Exception (" Invalid match result: '${matchResult.groupValues} '" )
296
318
297
319
private val Deployed .anyStableVersion: String
298
320
get() = if (currentVersion.endsWith(" -SNAPSHOT" )) {
0 commit comments