Repository navigation
Conversation
|
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. An integration test loses the Spring beans that were left out of the packaged resources.
| for (File srcDir in sourceDirs) { | ||
| registerSourceDir(integrationTest, 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 integration tests have grails-app/conf as a resource directory of their own, which comes before the main resources on their classpath. processIntegrationTestResources copied its application.yml without replacing the info.app tokens, as processResources does in the main resources, so the integration 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 integration tests too.
5746f44 to
cb077a9
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.
| return | ||
| } | ||
| project.tasks.named(integrationTest.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 726524a: the token values are now an input of processIntegrationTestResources, and of processResources, which had the same gap. IntegrationTestGradlePluginSpec changes the version between two runs and checks both outputs.
| project.tasks.named(integrationTest.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 726524a: 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.
sbglasius
left a comment
There was a problem hiding this comment.
The approach is right: keeping grails-app/conf on the integration test resources and replacing the tokens there fixes the plugin compatibility warnings without changing what's on the classpath. Two things before I approve:
- The token values aren't task inputs. A small Gradle 8.14 build shows it: change
versionand rerun, and the resources task is UP-TO-DATE with the old value in application.yml. Please addtask.inputs.properties(replaceTokens)(or one map-valued property), and ideally do the same for the main processResources, which has the same gap. A test that changes the version and checks the output would cover it. - Every .groovy/.yml/.xml in the integration test resources is now decoded and re-encoded, so a non-UTF-8 XML fixture in src/integration-test/resources gets corrupted where it used to be copied byte for byte. Main resources already behave this way, so I can live with it if that's deliberate, but filtering only files that contain
@info.app.would avoid it.
Please also reply to Jeff's comment: the current version keeps grails-app/conf, so it isn't the breaking change he was worried about.
- Record the values of the tokens as an input of processResources and processIntegrationTestResources, so that they run again when the version changes, instead of leaving the old version in the processed application.yml - Filter only the integration test resources that contain a token, so that the others are copied unchanged, whatever their encoding
|
@jdaugherty Fair point: 8.0.x made that change in a major release. I've changed this PR to keep |
|
@sbglasius Thanks! Both are done in 726524a: the token values are inputs of |
jamesfredley
left a comment
There was a problem hiding this comment.
Requested changes. An earlier copy filter can now fail the task, 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 registers filter or expand before this action, Gradle throws UnsupportedOperationException when the action reads details.file. A matching file with no Grails token fails instead of being copied. Read the file without depending on another filter having left it unread.
There was a problem hiding this comment.
Fixed in 37b8e91: 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. Without the fix, it fails with this UnsupportedOperationException.
jdaugherty
left a comment
There was a problem hiding this comment.
Re-reviewed 726524a. My earlier concern about removing grails-app/conf is addressed: the integration tests still receive that directory, including a plugin spring/resources.groovy. Recording the token map as a task input also addresses the stale-version problem.
One remaining correction before approval: the details.file read can fail after a convention has registered an earlier filter or expand action. I independently reproduced the existing finding on Gradle 8.14.8 with a minimal Copy task: an XML file containing no Grails token copies successfully with the earlier filter alone, but adding this filesMatching action throws UnsupportedOperationException from DefaultFileCopyDetails.getFile. Please make the token check work with an existing filter chain and cover that ordering in the plugin tests, while retaining the byte-for-byte test for files without tokens.
Existing thread: #17305 (comment)
FileCopyDetails.getFile() fails once a file has a filter, so a filter or expand that a convention of the build added to processIntegrationTestResources before failed the task, even for a file without tokens. Read the file with open() instead, which applies those filters.
|
@jdaugherty Thanks for reproducing it. Fixed in 37b8e91, see the thread. 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 fail the task, 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.
A token-free file with an earlier expand filter is opened here to look for tokens. That runs the earlier filter before the copy decides to skip the file. A missing property in that filter fails the task. Previously the file was copied without running the filter. Do not run the earlier filters to decide whether a token is present.
There was a problem hiding this comment.
Fixed in c1ec106: 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, and an expand with a missing property no longer runs for a file that a later action excludes. The convention in IntegrationTestGradlePluginSpec now numbers the lines, and the file without a token gets 1: a: 1, 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-16 XML file that contains @info.app.name@, with filteringCharset set to UTF-16, is scanned as ISO-8859-1. The token is not seen, so the integration-test resource keeps the placeholder while the main resource gets the name. Scan with the charset the copy uses.
There was a problem hiding this comment.
Done in c1ec106: 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'.
sbglasius
left a comment
There was a problem hiding this comment.
Reviewed at 37b8e91.
Both points from my earlier review are fixed in 726524a: the token values are inputs of processIntegrationTestResources and processResources, and a file without a token is copied byte for byte. IntegrationTestGradlePluginSpec covers both. 37b8e91 reads the file through details.open(), so the expand of a convention no longer fails the check. The spec passes locally (5 tests).
On the two points from today, compared against the base 0b73627:
- An
expandwith a missing property on a.ymlwithout a token fails on the base as well, inprocessIntegrationTestResourcesand inprocessResources, because the copy runs that filter anyway. The only new failure I could make is a file that such a filter fails on and that a laterfilesMatching { exclude() }leaves out: the base never reads it, while the token check now runs the filter on it. That seems narrow enough not to block this. - A UTF-16
.xmlwith a token andfilteringCharset = 'UTF-16'keeps the token here, and also kept it on the base, so nothing regresses; the Javadoc says the check assumes an encoding that extends ASCII. Scanning withtask.filteringCharsetwould cover it, if you want to.
Approving.
sbglasius
left a comment
There was a problem hiding this comment.
A follow-up to my approval: the earlier-filter point that James raised on #17306 applies here too, since containsReplaceToken is the same. A convention filter that numbers lines with a counter writes 2: a: 1 instead of 1: a: 1 for a .yml without a token, because the check runs the filter once more before the copy. Details on #17306. Please carry the fix over to this PR as well.
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! Carried over in c1ec106: the check no longer runs the earlier filters, and your numbering convention from #17306 is the regression test, with |
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 integration-test resource keeps @info.app.name@. Scan with the charset of the copy that owns the file.
There was a problem hiding this comment.
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 integration test resources 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 integration tests 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 (25) 🏷️ Commit: c1ec106 Rerun ControlsClick the checkbox to trigger a rerun:
Learn more about TestLens at testlens.app/docs. |
The integration test source set has
grails-app/confas a resource directory of its own, soprocessIntegrationTestResourcescopiesapplication.ymltobuild/resources/integrationTestwithout replacing its@info.app.name@,@info.app.version@and@info.app.grailsVersion@tokens, asprocessResourcesdoes for the main resources. That copy comes before the processedbuild/resources/main/application.ymlon the classpath of the integration tests, andMetadatareads the firstapplication.ymlon the classpath. So in integration tests:DefaultGrailsPluginManagerlogs for every plugin, whenever the application starts, that it may not be compatible:This happens in every application that sets these properties in the first document of its
application.yml, as the applications generated by Forge do.This replaces the tokens in the resources of the integration tests as
processResourcesdoes in the main resources, with the same tokens.grails-app/confstays a resource directory of the integration tests, 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
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 up: 7.1.x moved this code to
TestPhasesGradlePlugin, which addsgrails-app/confto the resources of every test phase. #17306 replaces the tokens in the resources of every test phase there. 8.0.x no longer copiesgrails-app/conf, so it doesn't need this.Results that change
In integration tests,
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 the integration test resources that contain them, as in the main resources.processResourcesandprocessIntegrationTestResourcesrun 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:processIntegrationTestResourcesreplaces the tokens inapplication.yml, which fails without the change;processResourcesandprocessIntegrationTestResourceswrite the new version after it changed inbuild.gradle, which fails without the input of either;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();spring/resources.groovy, which fails without the copy ofgrails-app/conf../gradlew build codeStylepasses ingrails-gradle, and so do the integration tests of theissue11005andcacheexamples, whosebuild/resources/integrationTest/application.ymlhas the values instead of the tokens.