openrewrite / openrewrite/rewrite

Interaction between ChangeTagValue & RemoveXmlTag leads to not executed recipe

Open
#4,842 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Java
Stars
3.7k
Forks
570
Avg merge
13h 12m
Merged PRs (30d)
261

Description

What version of OpenRewrite are you using?

I am using

  • OpenRewrite master branch

How are you running OpenRewrite?

I am using the Maven plugin, and my project is a multi module project.

  - org.openrewrite.xml.ChangeTagValue:
      elementName: //groupId
      oldValue: "^com\\.example\\.ws.$"
      newValue: "\\$\\{some.variable}"
      regex: true

  - org.openrewrite.xml.RemoveXmlTag:
      xPath: /project/dependencies/dependency[groupId='com.example.ws4']/version
  - org.openrewrite.xml.RemoveXmlTag:
      xPath: /project/dependencies/dependency[groupId='com.example.ws5']/version
  - org.openrewrite.xml.RemoveXmlTag:
      xPath: /project/dependencies/dependency[groupId='${some.variable}']/version

  - org.openrewrite.xml.RemoveXmlTag:
      xPath: /project/properties/*[local-name()='some.variable']

What did you expect to see?

I have this in my war-pom file:

        <dependency>
            <groupId>com.example.ws4</groupId>
            <artifactId>eb-proxima-connector</artifactId>
            <version>80.0.0</version>
        </dependency>

And expected to see:

        <dependency>
            <groupId>${some.variable}</groupId>
            <artifactId>eb-proxima-connector</artifactId>
        </dependency>

What did you see instead?

        <dependency>
            <groupId>${some.variable}</groupId>
            <artifactId>eb-proxima-connector</artifactId>
            <version>80.0.0</version>
        </dependency>

What is the full stack trace of any errors you encountered?

No stacktrace, just incorrect output

The thing is that both rules ChangeTagValue & RemoveXmlTag work fine by themselves. So I I keep the latter, it'll remove the version just fine. Well, and the former will always change the groupId.

However, combining them into the same recipe makes the latter not work anymore.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the YAML recipe with the Maven plugin against the multi-module project described, comparing ChangeTagValue and RemoveXmlTag when run together versus separately. Start by tracing the ChangeTagValue and RemoveXmlTag recipe entry points; done means the version element is removed after the groupId changes to ${some.variable}, while the existing removals still behave as expected.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.