最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

spring - How do I use wildcards with ChangeSpringPropertyKey OpenRewrite Recipe - Stack Overflow

programmeradmin1浏览0评论

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
发布评论

评论列表(0)

  1. 暂无评论