Apply except as a regex to YAML, and merge relocated sections - #1108
Draft
timtebeek wants to merge 2 commits into
Draft
Apply except as a regex to YAML, and merge relocated sections#1108timtebeek wants to merge 2 commits into
except as a regex to YAML, and merge relocated sections#1108timtebeek wants to merge 2 commits into
Conversation
`ChangeSpringPropertyKey` documents `except` as a regex and applies it as one to properties files, but `org.openrewrite.yaml.ChangePropertyKey` matches it as a glob, so `except: [ .+ ]` silently excluded nothing in YAML. Resolve the regex against the subkeys actually present under the old key, and pass those literal subkeys on to the YAML recipe. Relocating a property into a section that already exists also left two mapping entries with the same key, which made the recipe non-idempotent; merge those back together, limited to the segments of the new key. Fixes #436
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What's changed?
Two separate defects kept
logging.filefrom survivingUpgradeSpringBoot_2_2in YAML, and left the recipe non-idempotent:exceptwas a regex for properties but a glob for YAML. The option is documented as "Regex", andChangeSpringPropertyKeybuilds a real regex for the properties path, but it hands the same list straight toorg.openrewrite.yaml.ChangePropertyKey, which matches it as a glob. Soexcept: [ .+ ]— the wayspring-boot-22-properties.ymlsays "only renamelogging.filewhen it is a leaf" — excluded nothing at all in YAML, and alogging.filemapping got buried underlogging.file.name. The regex is now resolved against the subkeys actually present under the old key, and those literal subkeys are passed on to the YAML recipe, so both formats exclude the same subproperties. This is the mismatch @nmck257 called out on #581.2. Relocating a property into a section that already exists produced a duplicate key.
logging.path→logging.file.pathappended a secondfile:entry next to the existing one, and the next cycle then renamed the property again — so the recipe never converged. Duplicate entries are now merged back together, limited to the segments of the new key so unrelated duplicates elsewhere in the file are left alone.ChangeSpringPropertyKeyTest#loggingFileSubpropertiesYaml— replicated in feb28d5 back in 2023 and@Disabledever since — is enabled and passes. Two smaller tests pin each half of the fix on its own.Anything in particular you'd like reviewers to focus on?
MergeRelocatedSectionsVisitordeliberately does not reuseorg.openrewrite.yaml.MergeDuplicateSectionsVisitor: that one treats any non-newline entry prefix as a comment and bails, so it never merges anything indented, which is every case here. This visitor skips entries whose prefix actually contains a#instead.excludedSubkeysonly inspects direct children of a mapping spelled out under the old key, matching how theexceptoption is documented. A file that writes the old key in flattened form (logging.file.max-size: 10MB) is unchanged in behaviour by this PR.Related issues this does not close
org.openrewrite.yaml.ChangePropertyKeycopiesscope.getPrefix()onto the relocated entry (InsertSubpropertyVisitor, line 265); in a multi-document file that prefix carries the document's leading comment, so it gets emitted twice. That needs fixing upstream inopenrewrite/rewrite, where it affects every consumer.