Skip to content

Commit 6b538da

Browse files
committed
chore(config): relocate spring-bigdata-test.toml to improve resource organization
- Moved `spring-bigdata-test.toml` from `src/main/resources` to `src/test/resources`. - Updated Gradle plugin to account for resource directories in all source sets (`main`, `test`, etc.). - Revised documentation to clarify resource lookup logic for Gradle source sets.
1 parent 9e66855 commit 6b538da

3 files changed

Lines changed: 35 additions & 28 deletions

File tree

doc/user-guide.adoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1807,7 +1807,7 @@ bigDataTest {
18071807
}
18081808
----
18091809

1810-
`config` loads startup TOML using the same table names as JUnit startup config where the Gradle plugin has matching fields. It is applied as Gradle property conventions, so explicit DSL values win over TOML values:
1810+
`config` loads startup TOML using the same table names as JUnit startup config where the Gradle plugin has matching fields. `classpath:` locations are resolved from Gradle source-set resources, including `src/main/resources` and `src/test/resources`. It is applied as Gradle property conventions, so explicit DSL values win over TOML values:
18111811

18121812
[source,toml]
18131813
----
@@ -1943,8 +1943,8 @@ The Gradle plugin has three separate classpath/resource concepts:
19431943
|This classpath is used only by bigdata-test extension execution. Dependencies added here can affect `spark-sql-prep`, JCEKS generation, Kafka Avro seeding, and other extensions.
19441944

19451945
|Extension config and SQL/resource lookup
1946-
|Use `extensionConfig.add(...)`. `classpath:` resources are searched from the extension runtime first and then from the project's main resource directories, including `src/main/resources` and compiled main resources.
1947-
|There is no dedicated DSL property for extra arbitrary resource directories today. Put files under main resources, reference an absolute or relative `file:` path, or add a small resource jar to `bigDataTestExtensionRuntime`.
1946+
|Use `extensionConfig.add(...)`. `classpath:` resources are searched from the extension runtime first and then from the project's Gradle source-set resource directories, including `src/main/resources`, `src/test/resources`, and compiled resource outputs.
1947+
|There is no dedicated DSL property for extra arbitrary resource directories today. Put files under a Gradle source-set resource directory, reference an absolute or relative `file:` path, or add a small resource jar to `bigDataTestExtensionRuntime`.
19481948

19491949
|Gradle task JVM
19501950
|Configure Gradle itself with `org.gradle.jvmargs`, `GRADLE_OPTS`, or `JAVA_TOOL_OPTIONS`.

example/spring-gradle-plugin/src/main/resources/spring-bigdata-test.toml renamed to example/spring-gradle-plugin/src/test/resources/spring-bigdata-test.toml

File renamed without changes.

gradle-plugin/src/main/kotlin/org/openprojectx/bigdata/test/gradle/BigDataTestGradlePlugin.kt

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -252,18 +252,19 @@ class BigDataTestGradlePlugin : Plugin<Project> {
252252
javaClass.`package`.implementationVersion?.takeIf { it.isNotBlank() } ?: "0.1.12-SNAPSHOT"
253253

254254
private fun Project.extensionResourceDirectories(): List<String> {
255-
val sourceSets = extensions.findByName("sourceSets") as? SourceSetContainer
256-
val main = sourceSets?.findByName("main")
257255
return buildList {
258-
main?.resources?.srcDirs
259-
?.filter { it.isDirectory }
260-
?.mapTo(this) { it.absolutePath }
261-
main?.output?.resourcesDir
262-
?.takeIf { it.isDirectory }
263-
?.let { add(it.absolutePath) }
256+
resourceSourceSets()
257+
.flatMap { sourceSet ->
258+
sourceSet.resources.srcDirs + listOfNotNull(sourceSet.output.resourcesDir)
259+
}
260+
.filter { it.isDirectory }
261+
.mapTo(this) { it.absolutePath }
264262
file("src/main/resources")
265263
.takeIf { it.isDirectory }
266264
?.let { add(it.absolutePath) }
265+
file("src/test/resources")
266+
.takeIf { it.isDirectory }
267+
?.let { add(it.absolutePath) }
267268
}.distinct()
268269
}
269270

@@ -276,15 +277,7 @@ class BigDataTestGradlePlugin : Plugin<Project> {
276277
resolved.startsWith("file:") -> file(resolved.removePrefix("file:")).readText()
277278
resolved.startsWith("classpath:") -> {
278279
val resource = resolved.removePrefix("classpath:").trimStart('/')
279-
val sourceSets = extensions.findByName("sourceSets") as? SourceSetContainer
280-
val resourceFile = sourceSets
281-
?.findByName("main")
282-
?.resources
283-
?.srcDirs
284-
?.asSequence()
285-
?.map { it.resolve(resource) }
286-
?.firstOrNull { it.isFile }
287-
resourceFile?.readText().orEmpty()
280+
classpathResourceFile(resource)?.readText().orEmpty()
288281
}
289282
else -> file(resolved).readText()
290283
}
@@ -406,17 +399,31 @@ class BigDataTestGradlePlugin : Plugin<Project> {
406399
private fun Project.resolveExtensionConfigLocation(location: String): String {
407400
if (!location.startsWith("classpath:")) return location
408401
val resource = location.removePrefix("classpath:").trimStart('/')
409-
val sourceSets = extensions.findByName("sourceSets") as? SourceSetContainer
410-
val resourceFile = sourceSets
411-
?.findByName("main")
412-
?.resources
413-
?.srcDirs
414-
?.asSequence()
415-
?.map { it.resolve(resource) }
416-
?.firstOrNull { it.isFile }
402+
val resourceFile = classpathResourceFile(resource)
417403
return resourceFile?.let { "file:${it.absolutePath}" } ?: location
418404
}
419405

406+
private fun Project.classpathResourceFile(resource: String) =
407+
resourceSourceSets()
408+
.asSequence()
409+
.flatMap { sourceSet ->
410+
(sourceSet.resources.srcDirs + listOfNotNull(sourceSet.output.resourcesDir)).asSequence()
411+
}
412+
.map { it.resolve(resource) }
413+
.firstOrNull { it.isFile }
414+
415+
private fun Project.resourceSourceSets() =
416+
(extensions.findByName("sourceSets") as? SourceSetContainer)
417+
?.toList()
418+
.orEmpty()
419+
.sortedBy { sourceSet ->
420+
when (sourceSet.name) {
421+
"main" -> 0
422+
"test" -> 1
423+
else -> 2
424+
}
425+
}
426+
420427
private fun <T : Any> Property<T>.tomlConvention(value: T?) {
421428
if (value != null) convention(value)
422429
}

0 commit comments

Comments
 (0)