質問

Lookin for some help with XmlSlurper to get all merge conflicts in a pom.xml file.

I want to get all tags with merge conflict markers (<<< === >>>) and update the file to use the higher version number.

So the resulting file would just have 1.2-SNAPSHOT with the conflict markers and version 1.1-SNAPSHOT removed.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.mycompany</groupId>
  <artifactId>myproj</artifactId>
<<<<<<< HEAD
  <version>1.2-SNAPSHOT</version>
=======
  <version>1.1-SNAPSHOT</version>
>>>>>>> myBranch
  <packaging>pom</packaging>
  <name>myproj</name>

    <dependencies>
        <dependency>
            <groupId>com.child1</groupId>
            <artifactId>child1proj</artifactId>
<<<<<<< HEAD
            <version>1.2-SNAPSHOT</version>
=======
            <version>1.1-SNAPSHOT</version>
>>>>>>> myBranch
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>
役に立ちましたか?

解決

As Tim says you can't use XmlSlurper on your file. You can however manipulate the text before parsing.

If you convert the markers to custom xml nodes e.g.

xml = xml.replace("<<<<<<< HEAD", "<patch><part branch='HEAD'>")
xml = xml.replace("=======", "</part><part branch='myBranch'>")
xml = xml.replace(">>>>>>> myBranch", "</part></patch>")

you can then use XmlSlurper to read the text.

For each "patch" you can then decide which "part" you want to keep. Removing the unnecessary node and migrating the other node's children into the parent should get you close to what you want.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top