Skip to content

Commit eeae654

Browse files
authored
Merge addon info of all repos into one addons.xml file (#1626)
* 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 <[email protected]>
1 parent 0081983 commit eeae654

File tree

2 files changed

+120
-24
lines changed

2 files changed

+120
-24
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* Copyright (c) 2010-2024 Contributors to the openHAB project
3+
*
4+
* See the NOTICE file(s) distributed with this work for additional
5+
* information.
6+
*
7+
* This program and the accompanying materials are made available under the
8+
* terms of the Eclipse Public License 2.0 which is available at
9+
* http://www.eclipse.org/legal/epl-2.0
10+
*
11+
* SPDX-License-Identifier: EPL-2.0
12+
*/
13+
import java.nio.file.Files
14+
import java.nio.file.Paths
15+
import groovy.xml.XmlNodePrinter
16+
import groovy.xml.XmlParser
17+
18+
def baseDir = Paths.get(getClass().protectionDomain.codeSource.location.toURI()).toAbsolutePath()
19+
def xmlDir = baseDir.resolveSibling("target/addon-xml")
20+
21+
// Read the addons.xml containing the addon info of openhab-addons
22+
def addonsXmlPath = xmlDir.resolve("addons.xml")
23+
println "Reading: ${addonsXmlPath}"
24+
def addonsXml = String.join("\n", Files.readAllLines(addonsXmlPath))
25+
def header = addonsXml.substring(0, addonsXml.indexOf("-->") + 4)
26+
def addonInfoList = new XmlParser().parse(Files.newBufferedReader(addonsXmlPath))
27+
28+
// Read and append the addon info in addon.xml of other repositories
29+
Files.walk(xmlDir).forEach(path -> {
30+
if (Files.isRegularFile(path) && "addon.xml" == path.getFileName().toString()) {
31+
println "Reading: ${path}"
32+
def addonInfo = new XmlParser().parse(Files.newBufferedReader(path))
33+
addonInfoList.children().get(0).append(addonInfo)
34+
}
35+
})
36+
37+
// Write the combined addon info to addons.xml
38+
def assemblyXmlPath = baseDir.resolveSibling("target/assembly/runtime/etc/addons.xml")
39+
println "Writing: ${assemblyXmlPath} (${addonInfoList.addons.'*'.size()} add-ons)"
40+
41+
def pw = new PrintWriter(Files.newBufferedWriter(assemblyXmlPath))
42+
pw.append(header)
43+
def np = new XmlNodePrinter(pw, "\t")
44+
np.setPreserveWhitespace(true)
45+
np.print(addonInfoList)

distributions/openhab/pom.xml

+75-24
Original file line numberDiff line numberDiff line change
@@ -109,32 +109,83 @@
109109
<goals>
110110
<goal>copy</goal>
111111
</goals>
112+
<configuration>
113+
<artifactItems>
114+
<artifactItem>
115+
<groupId>org.openhab.core.tools</groupId>
116+
<artifactId>upgradetool</artifactId>
117+
<version>${project.version}</version>
118+
<type>jar</type>
119+
<classifier>jar-with-dependencies</classifier>
120+
<overWrite>true</overWrite>
121+
<outputDirectory>${project.build.directory}/assembly/bin</outputDirectory>
122+
<destFileName>upgradetool.jar</destFileName>
123+
</artifactItem>
124+
<artifactItem>
125+
<groupId>org.openhab.addons.features.karaf</groupId>
126+
<artifactId>org.openhab.addons.features.karaf.openhab-addons-external</artifactId>
127+
<version>${project.version}</version>
128+
<type>xml</type>
129+
<classifier>addons</classifier>
130+
<overWrite>true</overWrite>
131+
<outputDirectory>${project.build.directory}/addon-xml</outputDirectory>
132+
<destFileName>addons.xml</destFileName>
133+
</artifactItem>
134+
</artifactItems>
135+
</configuration>
136+
</execution>
137+
<execution>
138+
<id>unpack</id>
139+
<phase>process-resources</phase>
140+
<goals>
141+
<goal>unpack</goal>
142+
</goals>
143+
<configuration>
144+
<artifactItems>
145+
<artifactItem>
146+
<groupId>org.openhab.addons.bundles</groupId>
147+
<artifactId>org.openhab.binding.zigbee</artifactId>
148+
<version>${project.version}</version>
149+
<type>jar</type>
150+
<includes>**/addon.xml</includes>
151+
<outputDirectory>${project.build.directory}/addon-xml/org.openhab.binding.zigbee</outputDirectory>
152+
</artifactItem>
153+
<artifactItem>
154+
<groupId>org.openhab.addons.bundles</groupId>
155+
<artifactId>org.openhab.binding.zwave</artifactId>
156+
<version>${project.version}</version>
157+
<type>jar</type>
158+
<includes>**/addon.xml</includes>
159+
<outputDirectory>${project.build.directory}/addon-xml/org.openhab.binding.zwave</outputDirectory>
160+
</artifactItem>
161+
</artifactItems>
162+
</configuration>
163+
</execution>
164+
</executions>
165+
</plugin>
166+
<plugin>
167+
<groupId>org.codehaus.gmaven</groupId>
168+
<artifactId>groovy-maven-plugin</artifactId>
169+
<version>2.1.1</version>
170+
<dependencies>
171+
<dependency>
172+
<groupId>org.apache.groovy</groupId>
173+
<artifactId>groovy-all</artifactId>
174+
<version>4.0.13</version>
175+
<type>pom</type>
176+
</dependency>
177+
</dependencies>
178+
<executions>
179+
<execution>
180+
<goals>
181+
<goal>execute</goal>
182+
</goals>
183+
<phase>process-resources</phase>
184+
<configuration>
185+
<source>${project.basedir}/merge-addon-info.groovy</source>
186+
</configuration>
112187
</execution>
113188
</executions>
114-
<configuration>
115-
<artifactItems>
116-
<artifactItem>
117-
<groupId>org.openhab.core.tools</groupId>
118-
<artifactId>upgradetool</artifactId>
119-
<version>${project.version}</version>
120-
<type>jar</type>
121-
<classifier>jar-with-dependencies</classifier>
122-
<overWrite>true</overWrite>
123-
<outputDirectory>${project.build.directory}/assembly/bin</outputDirectory>
124-
<destFileName>upgradetool.jar</destFileName>
125-
</artifactItem>
126-
<artifactItem>
127-
<groupId>org.openhab.addons.features.karaf</groupId>
128-
<artifactId>org.openhab.addons.features.karaf.openhab-addons-external</artifactId>
129-
<version>${project.version}</version>
130-
<type>xml</type>
131-
<classifier>addons</classifier>
132-
<overWrite>true</overWrite>
133-
<outputDirectory>${project.build.directory}/assembly/runtime/etc</outputDirectory>
134-
<destFileName>addons.xml</destFileName>
135-
</artifactItem>
136-
</artifactItems>
137-
</configuration>
138189
</plugin>
139190
<plugin>
140191
<groupId>org.apache.maven.plugins</groupId>

0 commit comments

Comments
 (0)