Skip to content

SeparateApplicationYamlByProfile: merge into existing profile files#937

Merged
timtebeek merged 4 commits intomainfrom
fix-yaml-profile-merge-existing
Feb 24, 2026
Merged

SeparateApplicationYamlByProfile: merge into existing profile files#937
timtebeek merged 4 commits intomainfrom
fix-yaml-profile-merge-existing

Conversation

@Jenson3210
Copy link
Copy Markdown
Contributor

Summary

  • SeparateApplicationYamlByProfile now merges extracted profile content into existing application-{profile}.yml files instead of generating duplicates
  • Added tests for the merge scenario and for leaving unrelated existing profile files untouched

Problem

When application.yml contains a profile section (e.g. spring.config.activate.on-profile: dev) and application-dev.yml already exists, the recipe's generate() method creates a new source file with the same path. Since the framework tracks files by UUID rather than path, this results in a duplicate file that can overwrite the existing one when applied.

Solution

  1. Scanner: Now also detects existing application-*.yml files and records their paths
  2. Generate: Only creates new files for profiles where no target file exists; queues documents for merging when target files already exist
  3. Visitor: Appends extracted profile documents (with --- separator) to existing profile files

Test plan

  • Existing tests pass (separateProfile, separateProfileList, leaveProfileExpressionsAlone)
  • New test: mergeIntoExistingProfileFile — verifies content is appended to existing profile file
  • New test: doNotModifyExistingProfileFileWhenNoMatchingProfile — verifies unrelated profile files are untouched

Comment thread src/main/java/org/openrewrite/java/spring/SeparateApplicationYamlByProfile.java Outdated
Comment thread src/main/java/org/openrewrite/java/spring/SeparateApplicationYamlByProfile.java Outdated
@Jenson3210 Jenson3210 requested a review from timtebeek February 18, 2026 20:49
SeparateApplicationYamlByProfile would generate a new file even when
application-{profile}.yml already existed, creating a duplicate source
file that could overwrite the existing one when applied.

Now the scanner tracks existing application-*.yml files, generate()
only creates files that don't exist yet, and the visitor merges
extracted profile documents into existing files as new YAML documents.
Address review feedback:
- Match both .yml and .yaml extensions for existing profile files
- Use MergeYamlVisitor to deep-merge properties into existing profile
  files instead of appending separate YAML documents
@Jenson3210 Jenson3210 force-pushed the fix-yaml-profile-merge-existing branch from 97488e5 to 30ef19a Compare February 19, 2026 11:13
@github-project-automation github-project-automation Bot moved this from In Progress to Ready to Review in OpenRewrite Feb 24, 2026
@timtebeek timtebeek merged commit 0b40718 into main Feb 24, 2026
1 check passed
@timtebeek timtebeek deleted the fix-yaml-profile-merge-existing branch February 24, 2026 13:15
@github-project-automation github-project-automation Bot moved this from Ready to Review to Done in OpenRewrite Feb 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants