From b0e5553d309b16f6972ad492346a98d4fa817bc5 Mon Sep 17 00:00:00 2001 From: Wouter Born Date: Thu, 4 Jan 2024 22:55:35 +0100 Subject: [PATCH 1/5] 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 --- distributions/openhab/merge-addon-info.groovy | 45 +++++++++ distributions/openhab/pom.xml | 99 ++++++++++++++----- 2 files changed, 120 insertions(+), 24 deletions(-) create mode 100755 distributions/openhab/merge-addon-info.groovy diff --git a/distributions/openhab/merge-addon-info.groovy b/distributions/openhab/merge-addon-info.groovy new file mode 100755 index 0000000000..8fb98e7885 --- /dev/null +++ b/distributions/openhab/merge-addon-info.groovy @@ -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 = Files.readString(addonsXmlPath) +def header = addonsXml.substring(0, addonsXml.indexOf("-->") + 4) +def addonInfoList = new XmlParser().parseText(addonsXml) + +// 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 +assemblyXmlPath = baseDir.resolveSibling("target/assembly/runtime/etc/addons.xml") +println "Writing: ${assemblyXmlPath} (${addonInfoList.addons.'*'.size()} add-ons)" + +PrintWriter pw = new PrintWriter(Files.newOutputStream(assemblyXmlPath)); +pw.append(header) +XmlNodePrinter nodePrinter = new XmlNodePrinter(pw, "\t"); +nodePrinter.setPreserveWhitespace(true); +nodePrinter.print(addonInfoList); diff --git a/distributions/openhab/pom.xml b/distributions/openhab/pom.xml index 3b2f7dc264..bdb8695b08 100644 --- a/distributions/openhab/pom.xml +++ b/distributions/openhab/pom.xml @@ -109,32 +109,83 @@ copy + + + + org.openhab.core.tools + upgradetool + ${project.version} + jar + jar-with-dependencies + true + ${project.build.directory}/assembly/bin + upgradetool.jar + + + org.openhab.addons.features.karaf + org.openhab.addons.features.karaf.openhab-addons-external + ${project.version} + xml + addons + true + ${project.build.directory}/addon-xml + addons.xml + + + + + + unpack + process-resources + + unpack + + + + + org.openhab.addons.bundles + org.openhab.binding.zigbee + ${project.version} + jar + **/addon.xml + ${project.build.directory}/addon-xml/org.openhab.binding.zigbee + + + org.openhab.addons.bundles + org.openhab.binding.zwave + ${project.version} + jar + **/addon.xml + ${project.build.directory}/addon-xml/org.openhab.binding.zwave + + + + + + + + org.codehaus.gmaven + groovy-maven-plugin + 2.1.1 + + + org.apache.groovy + groovy-all + 4.0.13 + pom + + + + + + execute + + process-resources + + ${project.basedir}/merge-addon-info.groovy + - - - - org.openhab.core.tools - upgradetool - ${project.version} - jar - jar-with-dependencies - true - ${project.build.directory}/assembly/bin - upgradetool.jar - - - org.openhab.addons.features.karaf - org.openhab.addons.features.karaf.openhab-addons-external - ${project.version} - xml - addons - true - ${project.build.directory}/assembly/runtime/etc - addons.xml - - - org.apache.maven.plugins From 741980f5421d94d4cd9e8d7227e76e01d3d32bb0 Mon Sep 17 00:00:00 2001 From: Wouter Born Date: Fri, 5 Jan 2024 11:48:39 +0100 Subject: [PATCH 2/5] Improve different line endings support and some cleanup Signed-off-by: Wouter Born --- distributions/openhab/merge-addon-info.groovy | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/distributions/openhab/merge-addon-info.groovy b/distributions/openhab/merge-addon-info.groovy index 8fb98e7885..7f4736d682 100755 --- a/distributions/openhab/merge-addon-info.groovy +++ b/distributions/openhab/merge-addon-info.groovy @@ -21,8 +21,8 @@ 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 = Files.readString(addonsXmlPath) -def header = addonsXml.substring(0, addonsXml.indexOf("-->") + 4) +def addonsXml = String.join(System.lineSeparator(), Files.readAllLines(addonsXmlPath)) +def header = addonsXml.substring(0, addonsXml.indexOf("-->") + 3 + System.lineSeparator().length()) def addonInfoList = new XmlParser().parseText(addonsXml) // Read and append the addon info in addon.xml of other repositories @@ -35,11 +35,11 @@ Files.walk(xmlDir).forEach(path -> { }) // Write the combined addon info to addons.xml -assemblyXmlPath = baseDir.resolveSibling("target/assembly/runtime/etc/addons.xml") +def assemblyXmlPath = baseDir.resolveSibling("target/assembly/runtime/etc/addons.xml") println "Writing: ${assemblyXmlPath} (${addonInfoList.addons.'*'.size()} add-ons)" -PrintWriter pw = new PrintWriter(Files.newOutputStream(assemblyXmlPath)); +def pw = new PrintWriter(Files.newOutputStream(assemblyXmlPath)) pw.append(header) -XmlNodePrinter nodePrinter = new XmlNodePrinter(pw, "\t"); -nodePrinter.setPreserveWhitespace(true); -nodePrinter.print(addonInfoList); +def np = new XmlNodePrinter(pw, "\t") +np.setPreserveWhitespace(true) +np.print(addonInfoList) From 14518af03178e46ccc40507c188f7ea1439612bf Mon Sep 17 00:00:00 2001 From: Wouter Born Date: Fri, 5 Jan 2024 13:54:35 +0100 Subject: [PATCH 3/5] Use Unix line endings Signed-off-by: Wouter Born --- distributions/openhab/merge-addon-info.groovy | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/distributions/openhab/merge-addon-info.groovy b/distributions/openhab/merge-addon-info.groovy index 7f4736d682..4567672252 100755 --- a/distributions/openhab/merge-addon-info.groovy +++ b/distributions/openhab/merge-addon-info.groovy @@ -21,8 +21,8 @@ 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(System.lineSeparator(), Files.readAllLines(addonsXmlPath)) -def header = addonsXml.substring(0, addonsXml.indexOf("-->") + 3 + System.lineSeparator().length()) +def addonsXml = String.join("\n", Files.readAllLines(addonsXmlPath)) +def header = addonsXml.substring(0, addonsXml.indexOf("-->") + 4) def addonInfoList = new XmlParser().parseText(addonsXml) // Read and append the addon info in addon.xml of other repositories From 1e1c9f7b5b9f776c57c283e4ec08a5beb0d46273 Mon Sep 17 00:00:00 2001 From: Wouter Born Date: Fri, 5 Jan 2024 18:10:16 +0100 Subject: [PATCH 4/5] Fix encoding issues Signed-off-by: Wouter Born --- distributions/openhab/merge-addon-info.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/distributions/openhab/merge-addon-info.groovy b/distributions/openhab/merge-addon-info.groovy index 4567672252..ad553d74e9 100755 --- a/distributions/openhab/merge-addon-info.groovy +++ b/distributions/openhab/merge-addon-info.groovy @@ -23,7 +23,7 @@ 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().parseText(addonsXml) +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 -> { From f065c6e00ede61cd3f746a0f67251d74c16e6ceb Mon Sep 17 00:00:00 2001 From: Wouter Born Date: Fri, 5 Jan 2024 19:07:31 +0100 Subject: [PATCH 5/5] Fix encoding issues Signed-off-by: Wouter Born --- distributions/openhab/merge-addon-info.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/distributions/openhab/merge-addon-info.groovy b/distributions/openhab/merge-addon-info.groovy index ad553d74e9..a7b546ea1b 100755 --- a/distributions/openhab/merge-addon-info.groovy +++ b/distributions/openhab/merge-addon-info.groovy @@ -38,7 +38,7 @@ Files.walk(xmlDir).forEach(path -> { def assemblyXmlPath = baseDir.resolveSibling("target/assembly/runtime/etc/addons.xml") println "Writing: ${assemblyXmlPath} (${addonInfoList.addons.'*'.size()} add-ons)" -def pw = new PrintWriter(Files.newOutputStream(assemblyXmlPath)) +def pw = new PrintWriter(Files.newBufferedWriter(assemblyXmlPath)) pw.append(header) def np = new XmlNodePrinter(pw, "\t") np.setPreserveWhitespace(true)