Repository navigation
Conversation
|
The same concern I posted here: Isn't this a breaking change? we've always told people that grails/conf is where you configure environments, and by not copying that config, you're now expecting people to define their config with the test resources directory instead. I'm not against this change, but this feels breaking and thus should go on a major release. |
jamesfredley
left a comment
There was a problem hiding this comment.
Requested changes. A plugin integration test loses the Spring beans that were left out of the packaged resources.
| registerSourceDir(phaseSourceSet, srcDir) | ||
| acceptedSourceDirs.add(srcDir) | ||
| } | ||
| } |
There was a problem hiding this comment.
A plugin leaves spring/resources.groovy out of the packaged resources, and an integration test needs the bean it defines. The test should see that file. It does not, because this no longer copies the configuration the package excludes. Keep that copy, and still use the processed application.yml.
The test phases, such as the integration tests, have grails-app/conf as a resource directory of their own, which comes before the main resources on their classpath. The processResources tasks of the test phases copied its application.yml without replacing the info.app tokens, as processResources does in the main resources, so the tests read the tokens instead of the values, and every plugin logged that it may not be compatible with the Grails version '@info.app.grailsVersion@'. Replace the tokens in the resources of the test phases too.
02aae28 to
08677da
Compare
jamesfredley
left a comment
There was a problem hiding this comment.
The earlier missing Spring beans are addressed. Requested changes. A changed version can leave the old value in the processed file, and a file with no token can be rewritten.
| testPhases.configureEach { TestPhase phase -> | ||
| SourceSet phaseSourceSet = SourceSets.findSourceSet(project, phase.name) | ||
| project.tasks.named(phaseSourceSet.processResourcesTaskName, ProcessResources).configure { ProcessResources task -> | ||
| Map<String, String> replaceTokens = resolveReplaceTokens(project, grailsVersion) |
There was a problem hiding this comment.
The version changes between two runs, and a file contains that token. The second run should write the new version. It can keep the old one, because this does not record the token values as inputs. Record them.
There was a problem hiding this comment.
Done in 86862a8: the token values are now an input of the resources task of every test phase, and of processResources, which had the same gap. IntegrationTestGradlePluginSpec changes the version between two runs and checks both outputs, for integrationTest and functionalTest.
| project.tasks.named(phaseSourceSet.processResourcesTaskName, ProcessResources).configure { ProcessResources task -> | ||
| Map<String, String> replaceTokens = resolveReplaceTokens(project, grailsVersion) | ||
| task.filesMatching(['**/*.groovy', '**/*.yml', '**/*.xml']) { FileCopyDetails details -> | ||
| details.filter([tokens: replaceTokens], ReplaceTokens) |
There was a problem hiding this comment.
A file has no token and is not UTF-8. It should be copied unchanged. A character is corrupted, because this filters every file. Leave a file with no token alone.
There was a problem hiding this comment.
Done in 86862a8: only the files that contain one of the tokens are filtered now, so the others are copied byte for byte, as before. IntegrationTestGradlePluginSpec checks it with an ISO-8859-1 file in both phases.
sbglasius
left a comment
There was a problem hiding this comment.
Same feedback as on #17305, applied to every test phase here: please declare the token values as inputs of each phase's resources task (a small Gradle 8.14 build shows the stale version), and consider filtering only files that contain @info.app. so non-UTF-8 XML in the phase resource dirs isn't rewritten. The configureEach ordering with TestPhasesGradlePlugin looks fine, and the functionalTest case covers a phase declared in build.gradle.
One small correction to the description: merging #17305 up would fix integrationTest on 7.1.x, since that phase exists before GrailsGradlePlugin configures resources. It just wouldn't cover custom phases, which is why this version is better. Please keep the two PRs in sync when you make the input fix.
- Record the values of the tokens as an input of processResources and of the resources tasks of the test phases, so that they run again when the version changes, instead of leaving the old version in the processed application.yml - Filter only the resources of the test phases that contain a token, so that the others are copied unchanged, whatever their encoding
|
@jdaugherty As on #17305: this PR now keeps |
|
@sbglasius Thanks! Done here too in 86862a8, for the resources task of every test phase and |
jamesfredley
left a comment
There was a problem hiding this comment.
Requested changes. An earlier copy filter can now fail resource processing, including for a file that has no token.
| Map<String, String> replaceTokens = resolveReplaceTokens(project, grailsVersion) | ||
| task.inputs.property('replaceTokens', replaceTokens) | ||
| task.filesMatching(['**/*.groovy', '**/*.yml', '**/*.xml']) { FileCopyDetails details -> | ||
| if (containsReplaceToken(details.file, replaceTokens)) { |
There was a problem hiding this comment.
If a convention plugin adds an earlier filter or expand action to a matching XML file, Gradle throws UnsupportedOperationException on details.file. Resource processing fails even when the file contains no Grails token. Read the file without depending on another filter having left it unread.
There was a problem hiding this comment.
Fixed in 5e02ba8, as in #17305: the check reads the file with details.open(), which applies the earlier filters, instead of details.file. IntegrationTestGradlePluginSpec adds an expand from a convention, configured in settings.gradle before the Grails plugin is applied, and checks a file with a token and one without, for integrationTest and functionalTest. Without the fix, it fails with this UnsupportedOperationException.
jdaugherty
left a comment
There was a problem hiding this comment.
Re-reviewed 86862a8. Keeping grails-app/conf addresses my earlier compatibility concern. The configureEach ordering follows the creation of each phase source set, and the integrationTest and functionalTest cases cover the intended scope. The input map and unchanged-encoding tests address the earlier findings.
The remaining filter-chain failure is shared with #17305. On Gradle 8.14.8, a minimal Copy task with an earlier filter succeeds until this filesMatching action reads details.file; it then throws UnsupportedOperationException from DefaultFileCopyDetails.getFile, including for XML with no Grails tokens. Please fix this in both branches and add a regression covering an earlier convention filter or expand action.
Existing thread: #17306 (comment)
FileCopyDetails.getFile() fails once a file has a filter, so a filter or expand that a convention of the build added to the resources task of a test phase before failed the task, even for a file without tokens. Read the file with open() instead, which applies those filters.
|
@jdaugherty Fixed here too in 5e02ba8, in sync with #17305, with the regression test for both phases. The byte-for-byte test for files without tokens is unchanged. |
jamesfredley
left a comment
There was a problem hiding this comment.
Requested changes. An earlier filter can still break resource processing, and a UTF-16 resource keeps an unresolved token.
| * ASCII, so they are found in the bytes of a file in UTF-8, ISO-8859-1 or another encoding that extends ASCII. | ||
| */ | ||
| protected static boolean containsReplaceToken(FileCopyDetails details, Map<String, String> replaceTokens) { | ||
| String content = details.open().withStream { InputStream input -> |
There was a problem hiding this comment.
Opening the file to look for tokens runs an earlier filter, then the copy runs it again. A filter that numbers lines writes 2 where it should write 1, even when the file has no Grails token. A filter that consumes its input fails on the second run. Do not run the earlier filters to decide whether a token is present.
There was a problem hiding this comment.
Fixed in 45a6ddb, as in #17305: the check no longer runs the earlier filters. A file that already has a filter, for which getFile() fails, is filtered without the check: that filter decodes and encodes the file anyway, so a file without tokens is written as it leaves it. The convention in IntegrationTestGradlePluginSpec now numbers the lines, and the file without a token gets 1: a: 1 in both phases, as on the base.
| */ | ||
| protected static boolean containsReplaceToken(FileCopyDetails details, Map<String, String> replaceTokens) { | ||
| String content = details.open().withStream { InputStream input -> | ||
| new String(input.bytes, StandardCharsets.ISO_8859_1) |
There was a problem hiding this comment.
A UTF-16LE XML file that contains @info.app.name@, with filteringCharset set to UTF-16LE, is scanned as ISO-8859-1. The token is not seen, so the resource keeps the placeholder. Scan with the charset the copy uses.
There was a problem hiding this comment.
Done in 45a6ddb: the check reads the file with the filteringCharset of the task, the charset that ReplaceTokens reads it with. IntegrationTestGradlePluginSpec checks a UTF-16 file with filteringCharset = 'UTF-16' in both phases.
sbglasius
left a comment
There was a problem hiding this comment.
Reviewed at 5e02ba8.
My two earlier points are fixed in 86862a8, for both phases, and 5e02ba8 fixes the getFile() failure after a convention's filter. IntegrationTestGradlePluginSpec passes locally (9 tests).
The point about the earlier filters running twice reproduces here, and it changes the output of a file without a token. A convention that numbers lines, int n = 0; filesMatching('**/counted.yml') { filter { line -> "${++n}: ${line}" } }, on a counted.yml of a: 1 writes 1: a: 1 on the base 73d42a0 and 2: a: 1 at this head, in processIntegrationTestResources and processFunctionalTestResources. The description says files without a token are copied unchanged, so the check should look for the tokens without running the earlier filters, for example in the source file before any filter is applied.
For comparison with the base, the other two points from today: an expand with a missing property on a file without a token fails on the base as well, and only newly fails when a later action excludes the file; a UTF-16 file with a token kept the token on the base too.
The same containsReplaceToken is in #17305, so the fix belongs in both.
Reading a file with open() to look for the tokens ran the filters that a convention of the build added before once more, so a filter that numbers the lines started at 2. Filter a file that already has a filter without looking for the tokens, since that filter decodes and encodes it anyway, and read the other files with the filtering charset of the task, so that the tokens of a file in UTF-16 are found.
|
@sbglasius Thanks for the reproduction! Fixed in 45a6ddb, in sync with #17305. Gradle doesn't give the source file of a file that already has a filter, so such a file is filtered without the check instead: the earlier filter decodes and encodes it anyway, and |
jamesfredley
left a comment
There was a problem hiding this comment.
Requested changes. An earlier filter no longer fails the task by itself. A UTF-16 resource added on a child copy still keeps an unresolved token.
| } catch (UnsupportedOperationException ignored) { | ||
| return true | ||
| } | ||
| String content = new String(file.bytes, charset) |
There was a problem hiding this comment.
A UTF-16 XML file added with from(...) { filteringCharset = 'UTF-16' }, under a task whose charset is UTF-8, is scanned with the task charset. The token is not seen, so the resource keeps @info.app.name@. Scan with the charset of the copy that owns the file.
There was a problem hiding this comment.
As in #17305, I'd leave this one as it is, because the charset of the copy that owns a file isn't available to a copy action: FileCopyDetails has no getter for it, and it is only in the internal CopySpecResolver of the copy. The bytes can't tell it either: a UTF-16 file in a child copy with filteringCharset = 'UTF-16' has the same bytes as a UTF-16 fixture in a UTF-8 copy, which should be copied unchanged. Looking for the tokens in every charset would garble that fixture, and reading the charset of the copy would need reflection on Gradle internals.
It isn't a regression: the base doesn't replace the tokens in the resources of the test phases at all. processResources doesn't replace them in a child copy either, whatever its charset, since its filters are on its own copies of the source set's resources. The test phases already replace them in a child copy that has the charset of the task.
🚨 All tests passed but jobs failed 🚨Failed Jobs without Test Failures❌ CI / Hibernate5 Functional Tests (Java 25, indy=false) 🏷️ Commit: 45a6ddb Rerun ControlsClick the checkbox to trigger a rerun:
Learn more about TestLens at testlens.app/docs. |
The fix of #17305 for 7.1.x, where the code moved:
TestPhasesGradlePluginaddsgrails-app/confto the resources of every test phase. Merging #17305 up would fix the integration tests here too, sinceIntegrationTestGradlePlugincreates that phase beforeGrailsGradlePluginconfigures the resources, but not the other test phases, such as afunctionalTestphase declared inbuild.gradle. This replaces the tokens in the resources of every test phase.processResourcesreplaces the@info.app.name@,@info.app.version@and@info.app.grailsVersion@tokens ofapplication.ymlin the main resources, butgrails-app/confis also a resource directory of each test phase, where it is copied unprocessed. That copy comes before the processed one on the classpath of the tests, andMetadatareads the firstapplication.ymlon the classpath. So in the tests, the name, version and Grails version of the application are the tokens, andDefaultGrailsPluginManagerlogs for every plugin, whenever the application starts, that it may not be compatible with the Grails version@info.app.grailsVersion@(see #17305).This replaces the tokens in the resources of every test phase as
processResourcesdoes in the main resources, with the same tokens.grails-app/confstays a resource directory of the test phases, so they see the same files as before, including thespring/resources.groovyof a plugin, whichprocessResourcesof a plugin leaves out. Only the files that contain a token are filtered, so the others are copied unchanged, whatever their encoding. The check reads the file with thefilteringCharsetof the task, the charset thatReplaceTokensreads it with. A file that an earlier filter changes, such as anexpandof a convention of the build, is filtered without the check:getFile()fails for it, and reading it withopen()would run that filter once more. That filter decodes and encodes the file anyway, so a file without tokens is written as it leaves it.The values of the tokens are an input of the resources task of each test phase, such as
processIntegrationTestResources, and now also ofprocessResources, which had the same gap: without it,processResourcesstays up to date when the version changes, and leaves the old version inapplication.yml.8.0.x removed
grails-app/conffrom the resources of the test phases instead, in 289519a ("Prevent duplicate resources on the classpath", part of #15541), which needed 75e7336 forresources.groovy. This keeps it, so that nothing else changes in a patch release.Merging: merging 7.0.x up after #17305 conflicts in
GrailsGradlePlugin,IntegrationTestGradlePluginSpecand thebuild.gradleof its test project: keep the versions of this PR, which cover every test phase. On 8.0.x, which no longer copiesgrails-app/conf, keep its version:configureTestPhaseResourcesisn't needed there.Results that change
In the tests of every test phase,
info.app.name,info.app.versionandinfo.app.grailsVersion, and sograilsApplication.metadata, have the values of the running application instead of the tokens. The same tokens are replaced in the other*.groovy,*.ymland*.xmlfiles of their resources that contain them, as in the main resources.processResourcesand the resources tasks of the test phases run again when the name or version of the project or the Grails version changes. I don't see a use for the old results, so this adds no setting.Testing
IntegrationTestGradlePluginSpecchecks, for the integration tests and afunctionalTestphase declared inbuild.gradle:application.ymlwith the tokens replaced, which fails without the change;build.gradle, which fails without the input of either task;filteringCharsetis UTF-16, which fails when the check reads the file as ISO-8859-1;settings.gradleadds before the Grails plugin is applied, and that a file without tokens is numbered once, which fails withUnsupportedOperationExceptionwhen the check callsgetFile()without handling it, and with2: a: 1when it reads the file withopen().It also checks that the integration tests of a plugin still get its
spring/resources.groovy, which fails without the copy ofgrails-app/conf../gradlew build codeStylepasses ingrails-gradle, and so do the integration tests of theissue11005,cacheandmicronautexamples.