admin管理员组

文章数量:1333196

I am trying to convert the following

me:
  cxf:
    jaxws:
      services:
        myconfig:
          retry:
            enabled: true
          sleuth:
            enabled: true

The problem here is this can be in properties or YAML. I need to change it to

me:
  cxf:
    jaxws:
      services:
        myconfig:
          retry:
            enabled: true
          observation:
            enabled: true

I tried

  - .openrewrite.java.spring.ChangeSpringPropertyKey:
      oldPropertyKey: me.cxf.jaxws.services.*.sleuth
      newPropertyKey: me.cxf.jaxws.services.{*}.observation

and

  - .openrewrite.java.spring.ChangeSpringPropertyKey:
      oldPropertyKey: me.cxf.jaxws.services.*.sleuth
      newPropertyKey: me.cxf.jaxws.services.*.observation

But these end up removing the myconfig

       services:
-        myconfig:
-          observation:
+          {*}.observation:
             enabled: true

So what is the correct way to use dynamic paths with the ChangeSpringPropertyKey?

I can't use ChangeKey because it only works for yaml and not .properties

update

So I was thinking about using both the ChangeKey and ChangeSpringPropertyKey but the problem seems to be based on the docs this wouldn't work for properties either. for example if I had

a.b.c.property=Something
a.f.c.otherProperty=Something

And I wanted to change it to

a.b.d.property=Something
a.f.d.otherProperty=Something

based on the docs I see here

The new name for the property key.

with no mention of glob vs the old one which does support it

The property key to rename. Supports glob

I am trying to convert the following

me:
  cxf:
    jaxws:
      services:
        myconfig:
          retry:
            enabled: true
          sleuth:
            enabled: true

The problem here is this can be in properties or YAML. I need to change it to

me:
  cxf:
    jaxws:
      services:
        myconfig:
          retry:
            enabled: true
          observation:
            enabled: true

I tried

  - .openrewrite.java.spring.ChangeSpringPropertyKey:
      oldPropertyKey: me.cxf.jaxws.services.*.sleuth
      newPropertyKey: me.cxf.jaxws.services.{*}.observation

and

  - .openrewrite.java.spring.ChangeSpringPropertyKey:
      oldPropertyKey: me.cxf.jaxws.services.*.sleuth
      newPropertyKey: me.cxf.jaxws.services.*.observation

But these end up removing the myconfig

       services:
-        myconfig:
-          observation:
+          {*}.observation:
             enabled: true

So what is the correct way to use dynamic paths with the ChangeSpringPropertyKey?

I can't use ChangeKey because it only works for yaml and not .properties

update

So I was thinking about using both the ChangeKey and ChangeSpringPropertyKey but the problem seems to be based on the docs this wouldn't work for properties either. for example if I had

a.b.c.property=Something
a.f.c.otherProperty=Something

And I wanted to change it to

a.b.d.property=Something
a.f.d.otherProperty=Something

based on the docs I see here

The new name for the property key.

with no mention of glob vs the old one which does support it

The property key to rename. Supports glob

Share Improve this question edited Nov 20, 2024 at 16:08 JGleason asked Nov 20, 2024 at 15:37 JGleasonJGleason 3,9586 gold badges29 silver badges61 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Thanks for sharing your findings! Indeed there seems to be a mismatch here: the ChangeSpringPropertyKey recipe delegates to two other recipes, which do not both support the same format. As such I've for now removed the indication that glob is supported, and we'll circle back to try to add that in.

There's some related work being done here that should make this easier to add:

  • https://github/openrewrite/rewrite/pull/4708

本文标签: springHow do I use wildcards with ChangeSpringPropertyKey OpenRewrite RecipeStack Overflow