This is an automated email from the ASF dual-hosted git repository.
jdaugherty pushed a commit to branch test/gradle-model-io-7.0.x
in repository https://gitbox.apache.org/repos/asf/grails-core.git
The following commit(s) were added to refs/heads/test/gradle-model-io-7.0.x by
this push:
new 186b59c45d Tighten the Gradle model IO helper specs
186b59c45d is described below
commit 186b59c45d345d8a5d120146a84d51d0c75dff6c
Author: James Daugherty <[email protected]>
AuthorDate: Fri Oct 16 10:33:04 2026 -0400
Tighten the Gradle model IO helper specs
Clear the main-class cache in cleanup instead of removing hand-tracked keys,
so isolation no longer depends on how MainClassFinder formats its cache
keys.
Drop the assertion that pinned getPathFromRoot returning the whole path for
a
spring script; that is the generic group index misfiring on the single-group
spring pattern, not intended behaviour. Keep the artefact directory check.
Resolve the class-relative ClassPathResource fixture against a production
class rather than a sibling spec, label the repeated isGrailsPath lookup as
the
cache-hit check it is, cover the extractJarFileURL fallback for a jar
location
without a protocol, and reuse one UrlResource in the directory check.
---
.../groovy/org/grails/io/support/ClassPathResourceSpec.groovy | 2 +-
.../org/grails/io/support/GrailsResourceUtilsSpec.groovy | 11 +++++------
.../groovy/org/grails/io/support/MainClassFinderSpec.groovy | 7 +------
.../test/groovy/org/grails/io/support/UrlResourceSpec.groovy | 7 +++++--
4 files changed, 12 insertions(+), 15 deletions(-)
diff --git
a/grails-gradle/model/src/test/groovy/org/grails/io/support/ClassPathResourceSpec.groovy
b/grails-gradle/model/src/test/groovy/org/grails/io/support/ClassPathResourceSpec.groovy
index 5a2042c32a..4876c0d974 100644
---
a/grails-gradle/model/src/test/groovy/org/grails/io/support/ClassPathResourceSpec.groovy
+++
b/grails-gradle/model/src/test/groovy/org/grails/io/support/ClassPathResourceSpec.groovy
@@ -89,7 +89,7 @@ class ClassPathResourceSpec extends Specification {
relative.inputStream.withCloseable { it.read() } == 0xca
absolute.inputStream.withCloseable { it.read() } == 0xca
relative.description == 'class path resource
[org/grails/io/support/ClassPathResourceSpec.class]'
- relative.createRelative('MainClassFinderSpec.class').exists()
+ relative.createRelative('ClassPathResource.class').exists()
}
void 'the default constructor uses the context class loader'() {
diff --git
a/grails-gradle/model/src/test/groovy/org/grails/io/support/GrailsResourceUtilsSpec.groovy
b/grails-gradle/model/src/test/groovy/org/grails/io/support/GrailsResourceUtilsSpec.groovy
index c8457cf360..bbcb2b2f8c 100644
---
a/grails-gradle/model/src/test/groovy/org/grails/io/support/GrailsResourceUtilsSpec.groovy
+++
b/grails-gradle/model/src/test/groovy/org/grails/io/support/GrailsResourceUtilsSpec.groovy
@@ -33,6 +33,7 @@ class GrailsResourceUtilsSpec extends Specification {
GrailsResourceUtils.getClassName(path) == className
GrailsResourceUtils.isProjectSource(path) == projectSource
GrailsResourceUtils.isGrailsPath(path) == grailsPath
+ // the second lookup is answered from the known-path cache and must
agree with the first
GrailsResourceUtils.isGrailsPath(path) == grailsPath
where:
@@ -66,13 +67,9 @@ class GrailsResourceUtilsSpec extends Specification {
'/app/grails-app/views/book/show.gsp' | null
| null
}
- void 'spring script root lookup retains the full source path'() {
- given:
- String path = '/app/grails-app/conf/spring/resources.groovy'
-
+ void 'a spring script resolves to the conf artefact directory'() {
expect:
- GrailsResourceUtils.getPathFromRoot(path) == path
- GrailsResourceUtils.getArtefactDirectory(path) == 'conf'
+
GrailsResourceUtils.getArtefactDirectory('/app/grails-app/conf/spring/resources.groovy')
== 'conf'
}
void 'domain detection distinguishes source directories and extensions'() {
@@ -215,6 +212,7 @@ class GrailsResourceUtilsSpec extends Specification {
File file = new File(tempDir, 'with space.txt')
URL url = file.toURI().toURL()
URL jar = new URL('jar:' + url.toString() + '!/example/Book.class')
+ URL jarWithoutProtocol = new URL('jar', '',
'C:/mypath/myjar.jar!/example/Book.class')
expect:
GrailsResourceUtils.getFile(url, 'fixture') == file
@@ -228,6 +226,7 @@ class GrailsResourceUtilsSpec extends Specification {
!GrailsResourceUtils.isJarURL(url)
GrailsResourceUtils.extractJarFileURL(jar) == url
GrailsResourceUtils.extractJarFileURL(url) == url
+ GrailsResourceUtils.extractJarFileURL(jarWithoutProtocol) == new
URL('file:/C:/mypath/myjar.jar')
when:
def connection = url.openConnection()
diff --git
a/grails-gradle/model/src/test/groovy/org/grails/io/support/MainClassFinderSpec.groovy
b/grails-gradle/model/src/test/groovy/org/grails/io/support/MainClassFinderSpec.groovy
index cc3867f32e..21cc950339 100644
---
a/grails-gradle/model/src/test/groovy/org/grails/io/support/MainClassFinderSpec.groovy
+++
b/grails-gradle/model/src/test/groovy/org/grails/io/support/MainClassFinderSpec.groovy
@@ -32,10 +32,8 @@ class MainClassFinderSpec extends Specification {
@TempDir
File tempDir
- private final Set<String> cacheKeys = new HashSet<>()
-
void cleanup() {
- cacheKeys.each { MainClassFinder.mainClasses.remove(it) }
+ MainClassFinder.mainClasses.clear()
}
void 'findMainClass finds a nested Grails application and its class
file'() {
@@ -98,7 +96,6 @@ class MainClassFinderSpec extends Specification {
void 'findMainClass can bypass its cache and rescan after a cached class
is deleted'() {
given:
File application = writeClass(tempDir, 'example/Application')
- cacheKeys.add(tempDir.canonicalPath)
def original = MainClassFinder.findMainClass(tempDir)
when:
@@ -147,8 +144,6 @@ class MainClassFinderSpec extends Specification {
source.text = 'package example'
File classes = new File(tempDir, 'build/classes/main')
File application = writeClass(classes, 'example/Application')
- cacheKeys.add(source.toURI().toString())
- cacheKeys.add(classes.canonicalPath)
expect:
MainClassFinder.searchMainClass(source.toURI()) ==
'example.Application'
diff --git
a/grails-gradle/model/src/test/groovy/org/grails/io/support/UrlResourceSpec.groovy
b/grails-gradle/model/src/test/groovy/org/grails/io/support/UrlResourceSpec.groovy
index 48c93c7e94..ef06a5efb0 100644
---
a/grails-gradle/model/src/test/groovy/org/grails/io/support/UrlResourceSpec.groovy
+++
b/grails-gradle/model/src/test/groovy/org/grails/io/support/UrlResourceSpec.groovy
@@ -87,9 +87,12 @@ class UrlResourceSpec extends Specification {
}
void 'directories are not readable file resources'() {
+ given:
+ def resource = new UrlResource(tempDir.toURI())
+
expect:
- new UrlResource(tempDir.toURI()).exists()
- !new UrlResource(tempDir.toURI()).isReadable()
+ resource.exists()
+ !resource.isReadable()
}
void 'a non-file URI is preserved but cannot be resolved to a file'() {