Как вставить элемент в pom.xml, используя Maven или Python? - PullRequest
0 голосов
/ 30 мая 2019

Я пытаюсь автоматизировать процесс выпуска. Я написал скрипт bash, который преобразует XML-файлы с помощью Python3 ElementTree.

Я написал следующий скрипт, который следует добавить со следующими атрибутами в pom.xml. Артефакт не был добавлен в pom2.xml.

#!/usr/bin/python
import sys
import xml.etree.ElementTree as ET


    def updateAlsPomXml():
        tree = ET.parse('pom.xml')
        root = tree.getroot()
        version = "2.1.3"

        for build in root:
            if (build.tag == "build"):
                for plugins in build:
                    for plugin in plugins:
                        for executions in plugin:
                            for execution in executions:
                                for configuration in execution:
                                    for artifacts in configuration:
                                        for artifact in artifacts:
                                            art = ET.Element('artifact')

                                            id = ET.SubElement(art, "id")
                                            id.text = 'x.y.z' + version

                                            transitive = ET.SubElement(art, "transitive")
                                            transitive.text = "false"

                                            instructions = ET.SubElement(art, "instructions")
                                            bundleName = ET.SubElement(instructions, "instructions")
                                            bundleName.text = "${pom.name}"

                                            bundleVendor = ET.SubElement(instructions, "instructions")
                                            bundleVendor.text = "${pom.organization.name}"
                                            break

        tree.write("pom2.xml")
    updateAlsPomXml()

Для следующей пометки я хочу добавить элемент артефакта.

<?xml version="1.0" encoding="UTF-8"?>
<project
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
    xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>abc</groupId>
        <artifactId>abc</artifactId>
        <version>1.2.0-SNAPSHOT</version>
    </parent>
    <artifactId>dfg</artifactId>
    <version>1.2.0-SNAPSHOT</version>
    <name>ghj</name>
    <packaging>pom</packaging>
    <description>Test</description>
    <properties>
        <tycho.version>1.3.0</tycho.version>
    </properties>
    <build>
        <plugins>
            <plugin>
                <groupId>org.reficio</groupId>
                <artifactId>p2-maven-plugin</artifactId>
                <version>1.3.0</version>
                <executions>
                    <execution>
                        <id>default-cli</id>
                        <phase>package</phase>
                        <goals>
                            <goal>site</goal>
                        </goals>
                        <configuration>
                            <artifacts>
                                <artifact>
                                    <id>x.y.z</id>
                                    <transitive>false</transitive>
                                    <instructions>
                                        <Bundle-Name>${pom.name}</Bundle-Name>
                                        <Bundle-Vendor>${pom.organization.name}</Bundle-Vendor>
                                    </instructions>
                                </artifact>
                                <artifact>
                                    <id>c.y.z:1.1.7</id>
                                    <transitive>false</transitive>
                                    <instructions>
                                        <Bundle-Name>${pom.name}</Bundle-Name>
                                        <Bundle-Vendor>${pom.organization.name}</Bundle-Vendor>
                                    </instructions>
                                </artifact>
                            </artifacts>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.eclipse.tycho</groupId>
                <artifactId>tycho-p2-repository-plugin</artifactId>
                <version>${tycho.version}</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>archive-repository</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <!-- Attach zipped P2 repository to be installed and deployed
                in the Maven repository during the deploy phase. -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>3.0.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>attach-artifact</goal>
                        </goals>
                        <configuration>
                            <artifacts>
                                <artifact>
                                    <file>target/${project.artifactId}-${project.version}.zip</file>
                                    <type>zip</type>
                                </artifact>
                            </artifacts>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.eclipse.tycho</groupId>
                <artifactId>tycho-p2-repository-plugin</artifactId>
                <version>${tycho-version}</version>
                <configuration>
                    <compress>false</compress>
                    <includeAllDependencies>true</includeAllDependencies>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <pluginRepositories>
        <pluginRepository>
            <id>reficio</id>
            <url>http://repo.reficio.org/maven/</url>
        </pluginRepository>
    </pluginRepositories>
</project>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...