Skip to content

Instantly share code, notes, and snippets.

@wborn
Last active February 20, 2021 10:05
Show Gist options
  • Save wborn/0e3cd275be724e827ef88bb04b7eb12a to your computer and use it in GitHub Desktop.
Save wborn/0e3cd275be724e827ef88bb04b7eb12a to your computer and use it in GitHub Desktop.
#!/bin/bash
# Make sure to update the WORKSPACE dir in this script!
# The script will clean and reset the WORKSPACE so it's best to use a separate dir for this.
# Afterwards make sure you build with Maven and skip checks and tests with:
# mvn clean install -DskipChecks=true -Dmaven.test.skip=true -Dspotless.check.skip=true
WORKSPACE="$HOME/git/openhab/openhab-addons-port"
cd "$WORKSPACE"
git clean -dfx
git reset --hard
git pull
removed_modules=()
# remove Eclipse IoT Marketplace client
# all marketplace extensions are incompatible with OH3 and the marketplace itself will also be replaced
removed_modules+=("org.openhab.extensionservice.marketplace")
removed_modules+=("org.openhab.extensionservice.marketplace.automation")
# remove audio sinks as they are now part of core
removed_modules+=("org.openhab.io.javasound")
removed_modules+=("org.openhab.io.webaudio")
# remove rotalra1x binding
# the rotel binding should be used instead, see https://github.com/openhab/openhab-addons/issues/7577
removed_modules+=("org.openhab.binding.rotelra1x")
# remove netatmo binding
# the netatmo binding has a dependency to older swagger libs for code generation, this needs to be adapted for 3.x, see https://github.com/openhab/openhab-addons/issues/8274
removed_modules+=("org.openhab.binding.netatmo")
# remove velux binding
# the velux binding uses deprecated Thing API methods, this needs to be adapted for 3.x, see https://github.com/openhab/openhab-addons/issues/7402
removed_modules+=("org.openhab.binding.velux")
# remove modules that fail to compile due to the Whiteboard migration
# these modules have a dependency on Jersey which cannot be easily removed on the 2.5.x branch
removed_modules+=("org.openhab.io.hueemulation")
# remove imperihome-io add-on
# this bundle makes use of the persistence API which had breaking changes between 2.5 and 3.0, see https://github.com/openhab/openhab-addons/issues/8290
removed_modules+=("org.openhab.io.imperihome")
# remove modules for add-ons that already exist on main branch
for module in $(curl -s https://raw.githubusercontent.com/openhab/openhab-addons/main/bundles/pom.xml | grep '<module>' | sed -E 's|\s+<module>(.+)</module>|\1|')
do
removed_modules+=($module)
done
# remove module code, itest and update POMs
for module in ${removed_modules[@]}
do
if [ -d "${WORKSPACE}/bundles/$module" ]; then
echo "removing bundle $module"
rm -rf "${WORKSPACE}/bundles/$module"
sed -i "/<module>$module<\\/module>/d" "${WORKSPACE}/bundles/pom.xml"
if [ -d "${WORKSPACE}/itests/$module.tests" ]; then
echo "removing itest $module.tests"
rm -rf "${WORKSPACE}/itests/$module.tests"
sed -i "/<module>$module.tests<\\/module>/d" "${WORKSPACE}/itests/pom.xml"
fi
cat "${WORKSPACE}/bom/openhab-addons/pom.xml" |
tr '\n' '\f' |
sed -e "s| <dependency>\f <groupId>org.openhab.addons.bundles</groupId>\f <artifactId>$module</artifactId>\f <version>\${project.version}</version>\f </dependency>\f||" |
tr '\f' '\n' > "${WORKSPACE}/bom/openhab-addons/pom.xml.new"
mv "${WORKSPACE}/bom/openhab-addons/pom.xml.new" "${WORKSPACE}/bom/openhab-addons/pom.xml"
fi
done
mvn versions:set -DgenerateBackupPoms=false -DnewVersion=3.1.0-SNAPSHOT
# change ESH-INF to OH-INF
echo "renaming ESH-INF to OH-INF in bundles"
find ${WORKSPACE}/bundles -name "ESH-INF" -type d | grep -v "\.git" | grep -v "/target/" | while read f
do
newfile="${f/ESH-INF/OH-INF}"
mv $f $newfile
done
find ${WORKSPACE}/bundles -type f | grep -v "\.git" | grep -v "/target/" | while read f
do
sed -i "s|ESH-INF|OH-INF|g" "$f"
done
echo "renaming ESH-INF to OH-INF in itests"
find ${WORKSPACE}/itests -name "ESH-INF" -type d | grep -v "\.git" | grep -v "/target/" | while read f
do
newfile="${f/ESH-INF/OH-INF}"
mv $f $newfile
done
find ${WORKSPACE}/itests -type f | grep -v "\.git" | grep -v "/target/" | while read f
do
sed -i "s|ESH-INF|OH-INF|g" "$f"
done
# fix main pom.xml
sed -i "s|<ohc.version>2.5.0|<ohc.version>3.1.0-SNAPSHOT|g" "${WORKSPACE}/pom.xml"
sed -i "s|<oh.java.version>1.8|<oh.java.version>11|g" "${WORKSPACE}/pom.xml"
sed -i "s|<version>\[1.8.0\-40,1.9),\[9.0,12.0)|<version>\[11.0,12.0)|g" "${WORKSPACE}/pom.xml"
sed -i "s|<javase>1.8|<javase>11|g" "${WORKSPACE}/bundles/pom.xml"
sed -i "s|<javase>1.8|<javase>11|g" "${WORKSPACE}/features/pom.xml"
# exclude itests until updated to JUnit 5 Jupiter API
sed -i "s|<module>itests</module>|<!-- <module>itests</module> -->|g" "${WORKSPACE}/pom.xml"
# update Java version in .classpath and .bndrun files
find ${WORKSPACE} -name '.classpath' -o -name '*.bndrun' -type f | grep -v "\.git" | grep -v "/target/" | while read f
do
sed -i "s|JavaSE-1.8|JavaSE-11|g" "$f"
done
# change file content
find ${WORKSPACE}/bundles -type f | grep -v "\.git" | grep -v "/target/" | while read f
do
echo replace in file $f
sed -i "s|org\(.\)eclipse.smarthome|org\1openhab\1core|g" "$f"
sed -i "s|http://www.eclipse.org/smarthome|https://openhab.org|g" "$f"
sed -i "s|https://www.eclipse.org/smarthome|https://openhab.org|g" "$f"
sed -i "s|//eclipse.org/smarthome|//openhab.org|g" "$f"
# bruteforce strip double core names
sed -i "s|core\(.\)core|core|g" "$f"
done
find ${WORKSPACE}/itests -type f | grep -v "\.git" | grep -v "/target/" | while read f
do
echo replace in file $f
sed -i "s|org\(.\)eclipse.smarthome|org\1openhab\1core|g" "$f"
sed -i "s|http://www.eclipse.org/smarthome|https://openhab.org|g" "$f"
sed -i "s|https://www.eclipse.org/smarthome|https://openhab.org|g" "$f"
sed -i "s|//eclipse.org/smarthome|//openhab.org|g" "$f"
# bruteforce strip double core names
sed -i "s|core\(.\)core|core|g" "$f"
done
# update mqtt binding for https://github.com/openhab/openhab-core/pull/1291
find ${WORKSPACE}/bundles/org.openhab.binding.mqtt/src/test -type f | grep -v "\.git" | grep -v "/target/" | while read f
do
sed -i "s|TopicSubscribers|Subscription|g" "$f"
done
# this test fails to compile, see https://github.com/openhab/openhab-addons/issues/7590
mv "${WORKSPACE}/bundles/org.openhab.binding.mqtt/src/test/java/org/openhab/binding/mqtt/internal/MQTTTopicDiscoveryServiceTest.java" "${WORKSPACE}/bundles/org.openhab.binding.mqtt/src/test/java/org/openhab/binding/mqtt/internal/MQTTTopicDiscoveryServiceTest.java.tobefixed"
@cweitkamp
Copy link

Thanks for the script. I'm testing it right away.

Will add some comments of you don't mind. Build failed on some tests: 1 and 3 could be fixed easily - wondering why your script did not replace "ESH" by "OH" in those files.

https://github.com/openhab/openhab-addons/blob/b19b0b204aa2ae2ba11348589d717af5ca4b9382/bundles/org.openhab.binding.dwdunwetter/src/test/java/org/openhab/binding/dwdunwetter/DwdUnwetterHandlerTest.java#L106-L107

[ERROR] Tests run: 2, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.693 s <<< FAILURE! - in org.openhab.binding.dwdunwetter.DwdUnwetterHandlerTest
[ERROR] testLabels(org.openhab.binding.dwdunwetter.DwdUnwetterHandlerTest)  Time elapsed: 0.043 s  <<< ERROR!
java.lang.IllegalArgumentException: InputStream cannot be null
	at org.openhab.binding.dwdunwetter.DwdUnwetterHandlerTest.testLabels(DwdUnwetterHandlerTest.java:107)
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /home/christoph/openhab-master/git/openhab-addons/bundles/org.openhab.binding.mqtt/src/test/java/org/openhab/binding/mqtt/handler/MqttBrokerConnectionEx.java:[26,851] The import org.openhab.core.io.transport.mqtt.internal.TopicSubscribers cannot be resolved
[ERROR] /home/christoph/openhab-master/git/openhab-addons/bundles/org.openhab.binding.mqtt/src/test/java/org/openhab/binding/mqtt/handler/MqttBrokerConnectionEx.java:[58,2258] TopicSubscribers cannot be resolved to a type
[ERROR] /home/christoph/openhab-master/git/openhab-addons/bundles/org.openhab.binding.mqtt/src/test/java/org/openhab/binding/mqtt/internal/MQTTTopicDiscoveryServiceTest.java:[27,933] The import org.openhab.core.io.transport.mqtt.internal.TopicSubscribers cannot be resolved
[ERROR] /home/christoph/openhab-master/git/openhab-addons/bundles/org.openhab.binding.mqtt/src/test/java/org/openhab/binding/mqtt/internal/MQTTTopicDiscoveryServiceTest.java:[102,3371] The method getSubscribers() from the type MqttBrokerConnectionEx refers to the missing type TopicSubscribers
[ERROR] /home/christoph/openhab-master/git/openhab-addons/bundles/org.openhab.binding.mqtt/src/test/java/org/openhab/binding/mqtt/internal/MQTTTopicDiscoveryServiceTest.java:[117,3973] The method getSubscribers() from the type MqttBrokerConnectionEx refers to the missing type TopicSubscribers
[ERROR] /home/christoph/openhab-master/git/openhab-addons/bundles/org.openhab.binding.mqtt/src/test/java/org/openhab/binding/mqtt/internal/MQTTTopicDiscoveryServiceTest.java:[134,4627] The method getSubscribers() from the type MqttBrokerConnectionEx refers to the missing type TopicSubscribers
[ERROR] /home/christoph/openhab-master/git/openhab-addons/bundles/org.openhab.binding.mqtt/src/test/java/org/openhab/binding/mqtt/internal/MQTTTopicDiscoveryServiceTest.java:[134,4670] TopicSubscribers cannot be resolved to a type
[ERROR] /home/christoph/openhab-master/git/openhab-addons/bundles/org.openhab.binding.mqtt/src/test/java/org/openhab/binding/mqtt/internal/MQTTTopicDiscoveryServiceTest.java:[150,5270] The method getSubscribers() from the type MqttBrokerConnectionEx refers to the missing type TopicSubscribers
[ERROR] /home/christoph/openhab-master/git/openhab-addons/bundles/org.openhab.binding.mqtt/src/test/java/org/openhab/binding/mqtt/internal/MQTTTopicDiscoveryServiceTest.java:[150,5313] TopicSubscribers cannot be resolved to a type

https://github.com/openhab/openhab-addons/blob/b19b0b204aa2ae2ba11348589d717af5ca4b9382/bundles/org.openhab.binding.networkupstools/src/test/java/org/openhab/binding/networkupstools/internal/NutNameChannelsTest.java#L134-L135

[ERROR] Tests run: 2, Failures: 2, Errors: 0, Skipped: 0, Time elapsed: 0.16 s <<< FAILURE! - in org.openhab.binding.networkupstools.internal.NutNameChannelsTest
[ERROR] testReadmeMatchingChannels(org.openhab.binding.networkupstools.internal.NutNameChannelsTest)  Time elapsed: 0.089 s  <<< FAILURE!
java.lang.AssertionError: Could not read things xml from: /home/christoph/openhab-master/git/openhab-addons/bundles/org.openhab.binding.networkupstools/target/test-classes/../../src/main/resources/ESH-INF/thing
	at org.openhab.binding.networkupstools.internal.NutNameChannelsTest.readThingsXml(NutNameChannelsTest.java:141)
	at org.openhab.binding.networkupstools.internal.NutNameChannelsTest.testReadmeMatchingChannels(NutNameChannelsTest.java:88)

[ERROR] testNutNameMatchingReadme(org.openhab.binding.networkupstools.internal.NutNameChannelsTest)  Time elapsed: 0.009 s  <<< FAILURE!
java.lang.AssertionError: Could not read things xml from: /home/christoph/openhab-master/git/openhab-addons/bundles/org.openhab.binding.networkupstools/target/test-classes/../../src/main/resources/ESH-INF/thing
	at org.openhab.binding.networkupstools.internal.NutNameChannelsTest.readThingsXml(NutNameChannelsTest.java:141)
	at org.openhab.binding.networkupstools.internal.NutNameChannelsTest.testNutNameMatchingReadme(NutNameChannelsTest.java:111)

@wborn
Copy link
Author

wborn commented Apr 13, 2020

The script is almost the same as what Jenkins is using and I never got time to look into why the tests failed and are also skipped by Jenkins.

But it would be better if we have the option to enable them again! I always forget to add the option for skipping the tests. ;-)

@wborn
Copy link
Author

wborn commented May 8, 2020

I had some time to look into those build issues @cweitkamp.

Some of the grep -v ".git" commands weren't properly escaped so they would match all files if there was "git" in the workspace dir:

Which there was for me when using:
WORKSPACE="$HOME/git/openhab/openhab-addons-port"

So now it properly replaces all occurrences which fixes #1 and #3.

#2 seems to be caused by openhab/openhab-core#1291 where TopicSubscribers was replaced with a Subscription class. So it now replaces those imports. Though the constructor argument can no longer be used so MQTTTopicDiscoveryServiceTest fails to compile, so for now I've renamed it so it isn't run.

I've also added renaming of JavaSE-1.8 to JavaSE-11 in .classpath and .bndrun files.

After resolving the itest runbundles most itests work, except for the feed and ntp itests.

@cweitkamp
Copy link

cweitkamp commented May 9, 2020

👍

I cannot wait to test it. Maybe I will find some time this evening or tomorrow.

@cweitkamp
Copy link

I filed an issue for the MQTT TopicSubscribers issue and added it to OH3 project so we do not forget it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment