Skip to content

Commit 7dba275

Browse files
authored
Provide 'compat' features which bridge oh and osh features. (#12)
Signed-off-by: Łukasz Dywicki <[email protected]>
1 parent 9e1995c commit 7dba275

File tree

3 files changed

+187
-9
lines changed

3 files changed

+187
-9
lines changed

features/karaf/compat.xsl

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<!--
3+
4+
Copyright (c) 2019-2020 Contributors to the OpenSmartHouse project
5+
6+
See the NOTICE file(s) distributed with this work for additional
7+
information.
8+
9+
This program and the accompanying materials are made available under the
10+
terms of the Eclipse Public License 2.0 which is available at
11+
http://www.eclipse.org/legal/epl-2.0
12+
13+
SPDX-License-Identifier: EPL-2.0
14+
-->
15+
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
16+
xmlns:features="http://karaf.apache.org/xmlns/features/v1.4.0" exclude-result-prefixes="features">
17+
18+
<!--
19+
This basic transformation set allows to generate "compat" feature set which allows to run standard
20+
OH bindings with OSH. Entire thing is generating "openhab-xyz" feature which refer source feature
21+
"opensmarthouse-xyz".
22+
-->
23+
<xsl:output method="xml" encoding="utf-8" indent="yes" />
24+
25+
<xsl:template match="/">
26+
<xsl:copy>
27+
<xsl:apply-templates select="@*|node()"/>
28+
</xsl:copy>
29+
</xsl:template>
30+
31+
<xsl:template match="node()|@*">
32+
<xsl:copy>
33+
<xsl:apply-templates select="node()|@*"/>
34+
</xsl:copy>
35+
</xsl:template>
36+
37+
<xsl:template match="features:features/@name">
38+
<xsl:attribute name="name">
39+
<xsl:value-of select="concat(., '-compat')" />
40+
</xsl:attribute>
41+
</xsl:template>
42+
43+
<xsl:template match="features:feature">
44+
<xsl:element name="feature" namespace="{namespace-uri()}">
45+
<xsl:attribute name="name">
46+
<xsl:call-template name="string-replace-all">
47+
<xsl:with-param name="text" select="attribute::name"/>
48+
<xsl:with-param name="replace" select="'opensmarthouse-'"/>
49+
<xsl:with-param name="by" select="'openhab-'"/>
50+
</xsl:call-template>
51+
</xsl:attribute>
52+
<xsl:element name="feature" namespace="{namespace-uri()}">
53+
<xsl:value-of select="@name" />
54+
</xsl:element>
55+
</xsl:element>
56+
</xsl:template>
57+
58+
<!-- string-replace-all from http://geekswithblogs.net/Erik/archive/2008/04/01/120915.aspx -->
59+
<xsl:template name="string-replace-all">
60+
<xsl:param name="text" />
61+
<xsl:param name="replace" />
62+
<xsl:param name="by" />
63+
<xsl:choose>
64+
<xsl:when test="contains($text, $replace)">
65+
<xsl:value-of select="substring-before($text,$replace)" />
66+
<xsl:value-of select="$by" />
67+
<xsl:call-template name="string-replace-all">
68+
<xsl:with-param name="text"
69+
select="substring-after($text,$replace)" />
70+
<xsl:with-param name="replace" select="$replace" />
71+
<xsl:with-param name="by" select="$by" />
72+
</xsl:call-template>
73+
</xsl:when>
74+
<xsl:otherwise>
75+
<xsl:value-of select="$text" />
76+
</xsl:otherwise>
77+
</xsl:choose>
78+
</xsl:template>
79+
80+
</xsl:stylesheet>

features/karaf/opensmarthouse-core/pom.xml

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,63 @@
4141

4242
<build>
4343
<plugins>
44+
<plugin>
45+
<groupId>org.codehaus.mojo</groupId>
46+
<artifactId>build-helper-maven-plugin</artifactId>
47+
<executions>
48+
<execution>
49+
<id>attach-artifacts</id>
50+
<goals>
51+
<goal>attach-artifact</goal>
52+
</goals>
53+
<phase>package</phase>
54+
<configuration>
55+
<artifacts>
56+
<artifact>
57+
<file>${project.build.directory}/feature/feature-compat.xml</file>
58+
<type>xml</type>
59+
<classifier>compat</classifier>
60+
</artifact>
61+
</artifacts>
62+
</configuration>
63+
</execution>
64+
</executions>
65+
</plugin>
4466
<plugin>
4567
<groupId>org.apache.karaf.tooling</groupId>
4668
<artifactId>karaf-maven-plugin</artifactId>
4769
<version>${karaf.tooling.version}</version>
48-
49-
<executions>
50-
<execution>
51-
<id>verify</id>
52-
<phase>none</phase>
53-
</execution>
54-
</executions>
55-
70+
</plugin>
71+
<plugin>
72+
<groupId>org.codehaus.mojo</groupId>
73+
<artifactId>xml-maven-plugin</artifactId>
74+
<version>1.0.2</version>
75+
<configuration>
76+
<transformationSets>
77+
<transformationSet>
78+
<dir>${project.build.directory}/feature/</dir>
79+
<outputDir>${project.build.directory}/feature/</outputDir>
80+
<stylesheet>${project.basedir}/../compat.xsl</stylesheet>
81+
<includes>
82+
<include>feature.xml</include>
83+
</includes>
84+
<fileMappers>
85+
<fileMapper implementation="org.codehaus.plexus.components.io.filemappers.RegExpFileMapper">
86+
<pattern>feature.xml</pattern>
87+
<replacement>feature-compat.xml</replacement>
88+
</fileMapper>
89+
</fileMappers>
90+
</transformationSet>
91+
</transformationSets>
92+
</configuration>
93+
<executions>
94+
<execution>
95+
<goals>
96+
<goal>transform</goal>
97+
</goals>
98+
<phase>compile</phase>
99+
</execution>
100+
</executions>
56101
</plugin>
57102
</plugins>
58103
</build>

features/karaf/opensmarthouse-tp/pom.xml

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
1+
<?xml version="1.0" encoding="UTF-8"?>
22
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
33
<modelVersion>4.0.0</modelVersion>
44

@@ -15,11 +15,64 @@
1515

1616
<build>
1717
<plugins>
18+
<plugin>
19+
<groupId>org.codehaus.mojo</groupId>
20+
<artifactId>build-helper-maven-plugin</artifactId>
21+
<executions>
22+
<execution>
23+
<id>attach-artifacts</id>
24+
<goals>
25+
<goal>attach-artifact</goal>
26+
</goals>
27+
<phase>package</phase>
28+
<configuration>
29+
<artifacts>
30+
<artifact>
31+
<file>${project.build.directory}/feature/feature-compat.xml</file>
32+
<type>xml</type>
33+
<classifier>compat</classifier>
34+
</artifact>
35+
</artifacts>
36+
</configuration>
37+
</execution>
38+
</executions>
39+
</plugin>
1840
<plugin>
1941
<groupId>org.apache.karaf.tooling</groupId>
2042
<artifactId>karaf-maven-plugin</artifactId>
2143
<version>${karaf.tooling.version}</version>
2244
</plugin>
45+
<plugin>
46+
<groupId>org.codehaus.mojo</groupId>
47+
<artifactId>xml-maven-plugin</artifactId>
48+
<version>1.0.2</version>
49+
<configuration>
50+
<transformationSets>
51+
<transformationSet>
52+
<dir>${project.build.directory}/feature/</dir>
53+
<outputDir>${project.build.directory}/feature/</outputDir>
54+
<stylesheet>${project.basedir}/../compat.xsl</stylesheet>
55+
<includes>
56+
<include>feature.xml</include>
57+
</includes>
58+
<fileMappers>
59+
<fileMapper implementation="org.codehaus.plexus.components.io.filemappers.RegExpFileMapper">
60+
<pattern>feature.xml</pattern>
61+
<replacement>feature-compat.xml</replacement>
62+
</fileMapper>
63+
</fileMappers>
64+
</transformationSet>
65+
</transformationSets>
66+
</configuration>
67+
<executions>
68+
<execution>
69+
<goals>
70+
<goal>transform</goal>
71+
</goals>
72+
<phase>compile</phase>
73+
</execution>
74+
</executions>
75+
</plugin>
2376
</plugins>
2477
</build>
2578

0 commit comments

Comments
 (0)