Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge addon info of all repos into one addons.xml file #1626

Merged
merged 5 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
*/
Comment on lines +1 to +12
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this license header needed, and if so, is there a configuration in this repository for automatically updating copyright year in license headers?

Copy link
Member Author

@wborn wborn Jan 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added it because we also have it on our other Groovy file.

There is no license-maven-plugin config currently but we can add it before 2025 when the header survives the pull request.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created #1627 for this

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