Skip to content

Commit

Permalink
Merge addon info of all repos into one addons.xml file (#1626)
Browse files Browse the repository at this point in the history
* Merge addon info of all repos into one addons.xml file

Extracts the ZigBee and Z-Wave addon.xml files and merges them into the addons.xml file using Groovy.

Signed-off-by: Wouter Born <github@maindrain.net>
  • Loading branch information
wborn committed Jan 5, 2024
1 parent 0081983 commit eeae654
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 24 deletions.
45 changes: 45 additions & 0 deletions distributions/openhab/merge-addon-info.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* Copyright (c) 2010-2024 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
import java.nio.file.Files
import java.nio.file.Paths
import groovy.xml.XmlNodePrinter
import groovy.xml.XmlParser

def baseDir = Paths.get(getClass().protectionDomain.codeSource.location.toURI()).toAbsolutePath()
def xmlDir = baseDir.resolveSibling("target/addon-xml")

// Read the addons.xml containing the addon info of openhab-addons
def addonsXmlPath = xmlDir.resolve("addons.xml")
println "Reading: ${addonsXmlPath}"
def addonsXml = String.join("\n", Files.readAllLines(addonsXmlPath))
def header = addonsXml.substring(0, addonsXml.indexOf("-->") + 4)
def addonInfoList = new XmlParser().parse(Files.newBufferedReader(addonsXmlPath))

// Read and append the addon info in addon.xml of other repositories
Files.walk(xmlDir).forEach(path -> {
if (Files.isRegularFile(path) && "addon.xml" == path.getFileName().toString()) {
println "Reading: ${path}"
def addonInfo = new XmlParser().parse(Files.newBufferedReader(path))
addonInfoList.children().get(0).append(addonInfo)
}
})

// Write the combined addon info to addons.xml
def assemblyXmlPath = baseDir.resolveSibling("target/assembly/runtime/etc/addons.xml")
println "Writing: ${assemblyXmlPath} (${addonInfoList.addons.'*'.size()} add-ons)"

def pw = new PrintWriter(Files.newBufferedWriter(assemblyXmlPath))
pw.append(header)
def np = new XmlNodePrinter(pw, "\t")
np.setPreserveWhitespace(true)
np.print(addonInfoList)
99 changes: 75 additions & 24 deletions distributions/openhab/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,32 +109,83 @@
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.openhab.core.tools</groupId>
<artifactId>upgradetool</artifactId>
<version>${project.version}</version>
<type>jar</type>
<classifier>jar-with-dependencies</classifier>
<overWrite>true</overWrite>
<outputDirectory>${project.build.directory}/assembly/bin</outputDirectory>
<destFileName>upgradetool.jar</destFileName>
</artifactItem>
<artifactItem>
<groupId>org.openhab.addons.features.karaf</groupId>
<artifactId>org.openhab.addons.features.karaf.openhab-addons-external</artifactId>
<version>${project.version}</version>
<type>xml</type>
<classifier>addons</classifier>
<overWrite>true</overWrite>
<outputDirectory>${project.build.directory}/addon-xml</outputDirectory>
<destFileName>addons.xml</destFileName>
</artifactItem>
</artifactItems>
</configuration>
</execution>
<execution>
<id>unpack</id>
<phase>process-resources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.openhab.addons.bundles</groupId>
<artifactId>org.openhab.binding.zigbee</artifactId>
<version>${project.version}</version>
<type>jar</type>
<includes>**/addon.xml</includes>
<outputDirectory>${project.build.directory}/addon-xml/org.openhab.binding.zigbee</outputDirectory>
</artifactItem>
<artifactItem>
<groupId>org.openhab.addons.bundles</groupId>
<artifactId>org.openhab.binding.zwave</artifactId>
<version>${project.version}</version>
<type>jar</type>
<includes>**/addon.xml</includes>
<outputDirectory>${project.build.directory}/addon-xml/org.openhab.binding.zwave</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>groovy-maven-plugin</artifactId>
<version>2.1.1</version>
<dependencies>
<dependency>
<groupId>org.apache.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>4.0.13</version>
<type>pom</type>
</dependency>
</dependencies>
<executions>
<execution>
<goals>
<goal>execute</goal>
</goals>
<phase>process-resources</phase>
<configuration>
<source>${project.basedir}/merge-addon-info.groovy</source>
</configuration>
</execution>
</executions>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.openhab.core.tools</groupId>
<artifactId>upgradetool</artifactId>
<version>${project.version}</version>
<type>jar</type>
<classifier>jar-with-dependencies</classifier>
<overWrite>true</overWrite>
<outputDirectory>${project.build.directory}/assembly/bin</outputDirectory>
<destFileName>upgradetool.jar</destFileName>
</artifactItem>
<artifactItem>
<groupId>org.openhab.addons.features.karaf</groupId>
<artifactId>org.openhab.addons.features.karaf.openhab-addons-external</artifactId>
<version>${project.version}</version>
<type>xml</type>
<classifier>addons</classifier>
<overWrite>true</overWrite>
<outputDirectory>${project.build.directory}/assembly/runtime/etc</outputDirectory>
<destFileName>addons.xml</destFileName>
</artifactItem>
</artifactItems>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down

0 comments on commit eeae654

Please sign in to comment.