如何使用不在父,构建或依赖性标签中的powershell中提取pom.xml中的artrifactid

发布于 2025-02-10 04:45:35 字数 2618 浏览 4 评论 0原文

我有以下pom.xml文件,我只想阅读以下伪像数据,而忽略了使用PowerShell Regex Match在下面的标签和标签之间的伪影信息,

**<groupId>com.frt</groupId>
<artifactId>documents-v1</artifactId>
<version>2.0.3</version>
<packaging>application</packaging>
<name>documents</name>
<description>To raise a client request </description**>
    <modelVersion>4.5.0</modelVersion>
    <parent>
        <groupId>com.frt</groupId>
        <artifactId>parent-pom</artifactId>
        <version>2.0.0</version>
    </parent>

    <groupId>com.frt</groupId>
    <artifactId>documents-v1</artifactId>
    <version>2.0.3</version>
    <packaging>application</packaging>
    <name>documents</name>
    <description>To raise a client request </description>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-clean-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.tools.maven</groupId>
                <artifactId>maven-plugin</artifactId>
                <configuration>
                    <classifier>application</classifier>
                </configuration>
            </plugin>
            <plugin>
                <groupId>com.munit.tools</groupId>
                <artifactId>munit-maven-plugin</artifactId>
                <configuration>
                    <runtimeProduct>4.5.0</runtimeProduct>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>9072cf0-111fc2b0fae6</groupId>
            <artifactId>json-logger</artifactId>
            <classifier>mulr-plugin</classifier>
        </dependency>
        <dependency>
            <groupId>org.mul2.connectors</groupId>
            <artifactId>mul2-http-connector</artifactId>
            <classifier>mul2-plugin</classifier>
        </dependency>

我尝试过,它给出了所有伪像的名称,我不确定如何获得我想要的方式,

Get-Content pom.xml -Raw | % { [regex]::matches($_ , '<artifactId>([\s\S]*?)</artifactId>')} |% {$_.Groups[1].Value}

将不胜感激

I have the below pom.xml file and i want to read only below artifact data and ignore the artifact info that are in between the and tags using powershell regex match

**<groupId>com.frt</groupId>
<artifactId>documents-v1</artifactId>
<version>2.0.3</version>
<packaging>application</packaging>
<name>documents</name>
<description>To raise a client request </description**>
    <modelVersion>4.5.0</modelVersion>
    <parent>
        <groupId>com.frt</groupId>
        <artifactId>parent-pom</artifactId>
        <version>2.0.0</version>
    </parent>

    <groupId>com.frt</groupId>
    <artifactId>documents-v1</artifactId>
    <version>2.0.3</version>
    <packaging>application</packaging>
    <name>documents</name>
    <description>To raise a client request </description>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-clean-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.tools.maven</groupId>
                <artifactId>maven-plugin</artifactId>
                <configuration>
                    <classifier>application</classifier>
                </configuration>
            </plugin>
            <plugin>
                <groupId>com.munit.tools</groupId>
                <artifactId>munit-maven-plugin</artifactId>
                <configuration>
                    <runtimeProduct>4.5.0</runtimeProduct>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>9072cf0-111fc2b0fae6</groupId>
            <artifactId>json-logger</artifactId>
            <classifier>mulr-plugin</classifier>
        </dependency>
        <dependency>
            <groupId>org.mul2.connectors</groupId>
            <artifactId>mul2-http-connector</artifactId>
            <classifier>mul2-plugin</classifier>
        </dependency>

Below is what i tried and its giving all the artifact names, i am not sure how to get the way i want it

Get-Content pom.xml -Raw | % { [regex]::matches($_ , '<artifactId>([\s\S]*?)</artifactId>')} |% {$_.Groups[1].Value}

Any help would be appreciated

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

哆兒滾 2025-02-17 04:45:35

正则是最后的手段。 PowerShell可以为您解析XML!

而是尝试一下:

$x = [xml](gc pom.xml)

这个^对我失败了,因为我认为您没有在问题中包含XML文件的全部内容。

$x | FL

在这里,您会发现您的财产和下一个“点”。如果建造是属性,则...

$x.build | fl 

冲洗并重复

Regex is a last resort. PowerShell can parse XML for you!

Try this instead:

$x = [xml](gc pom.xml)

This^ failed for me because I assume you did not include the entire contents of the XML file in your question.

$x | FL

After here you would find your property and next "dot" into it. If build was the property then...

$x.build | fl 

Rinse and repeat

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文