IDE & Build Setup for updating an old v1.x binding (NeoHub)

The NeoHub binding is an old v1 version which seems not to have been touched for a couple of years. The binding works with the manufacturers original “NeoStat” products, but it needs to be updated to add some properties and methods to support the manufacturers new “NeoPlug” products.

I have studied the binding source code, and I know exactly what updates need to be made. However I am having trouble to set up the Eclipse IDE to write/build/test these changes. The main problem seems to be broken dependencies between the v2.x core and the v1.x binding code on Git.

My questions are as follows…

  1. Can anyone please help me with setting up the Eclipse IDE so that I can (at least in the first phase) get the v1.x version of the NeoHub binding to compile (so that I can at least play with it locally and test it…)

  2. It occurs to me that if I am to update the v1.x binding, it would probably also make sense to migrate it to support the v2.x environment. (??) However this is probably a task “above my pay grade”, so I might need some in depth support on that. Can anyone help?


EDIT: below is the log that I get from mvn clean install

[ERROR] Cannot resolve project dependencies:
[ERROR] Software being installed: org.openhab.binding.neohub 1.14.0.qualifier
[ERROR] Missing requirement: org.openhab.binding.neohub 1.14.0.qualifier requires ‘package com.google.common.base 10.0.1’ but it could not be found
[ERROR]
[ERROR] See Tycho/Dependency Resolution Troubleshooting - Eclipsepedia for help.
[ERROR] Cannot resolve dependencies of MavenProject: org.openhab.binding:org.openhab.binding.neohub:1.14.0-SNAPSHOT @ G:\Users\Documents\03 Programming\git\openhab1-addons\bundles\binding\org.openhab.binding.neohub\pom.xml: See log for details → [Help 1]
org.apache.maven.MavenExecutionException: Cannot resolve dependencies of MavenProject: org.openhab.binding:org.openhab.binding.neohub:1.14.0-SNAPSHOT @ G:\Users\Documents\03 Programming\git\openhab1-addons\bundles\binding\org.openhab.binding.neohub\pom.xml
at org.eclipse.tycho.core.maven.TychoMavenLifecycleParticipant.afterProjectsRead (TychoMavenLifecycleParticipant.java:100)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:264)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:498)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: org.eclipse.tycho.artifacts.DependencyResolutionException: Cannot resolve dependencies of MavenProject: org.openhab.binding:org.openhab.binding.neohub:1.14.0-SNAPSHOT @ G:\Users\Documents\03 Programming\git\openhab1-addons\bundles\binding\org.openhab.binding.neohub\pom.xml[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MavenExecutionException

The problem is that we have changed the buildsystem recently (there was no new openHAB release since then even), and OH1-addons is still using the old buildsystem. There is no maintainer of OH1-addons anymore, so it would indeed make sense to make the binding work within the openhab2 environment.

What you can try is to move the code into openhab2-addons /bundles/ and replace the .project .classfile and pom.xml file with any of the existing bundles. Adapt the name, and potentially add missing dependencies to the pom.xml file (see openhab docs -> Buildsystem).

In theory the binding might compile, because the OH1-compatibility layer is still active.

We are unfortunately busy atm with finishing the migration so can’t assist that much. Just keep asking here.

Cheers, David

Many thanks David. Your suggestion helped me to make huge progress in compiling the binding.

However there is unfortunately one java module “NeoStatProperty.java” that uses two old – and I think deprecated – imports “com.google.common.base.Function” and “com.google.common.collect.Lists”, and as a result this module won’t compile. The original author was using some really exotic coding here with some kind of list transform and type casts (see code below), and honestly I don’t know what he was trying to achieve, so I have no idea how to re-code it using more current import modules.

public static List getBindings() {
return Lists.transform(Arrays.asList(NeoStatProperty.values()), new Function<NeoStatProperty, String>() {

        @Override
        public String apply(NeoStatProperty property) {
            return property.binding;
        }
    });

Probably the best solution is to ask the original author if he is still interested to modify his code? But to do that I would need to upload my modifications to his code to the right place on Git so he can look at it. I am not sure where or how to upload a new binding to Git so perhaps you can kindly advise me on that??

One of the reasons this library is deprecated it that this kind of functionality is standard available since Java 8. The method returns a list of all binding fields in the enum. You can replace the whole content of the method with this Java 8 notation:

public static List<String> getBindings() {
    return Stream.of(NeoStatProperty.values()).map(p -> p.binding).collect(Collectors.toList());
}

Brilliant Hillbrand! I got it to compile now. So I can make my changes now, and test it locally.

I hit a wall. I cannot install the modified binding in openHab since it reports the following error…

2019-05-07 16:30:47.270 [WARN ] [org.apache.felix.fileinstall ] - Error while starting bundle: file:/usr/share/openhab2/addons/org.openhab.binding.neohub.jar
org.osgi.framework.BundleException: Could not resolve module: org.openhab.binding.neohub [221]
Unresolved requirement: Import-Package: org.openhab.core.binding

This looks as if the compatibility layer is not activated. I’ve not done a lot with that part. But searching this forum I think you need to enable openHAB 1 bindings support, and if that doesn’t work yet install a openHAB1 binding, for example the exec1.

Ok. I will try your exec1 suggestion — many thanks :slight_smile:

Note: I already did feature-install of the compatibility v1x layer; which did resolve the top layer of dependencies; but it just revealed another lower dependency below that (something to do with code validation as I recall); I fear this process may go on and on like squeezing water out of a stone…

… I will get back to you…

I did two things: a) updated my test machine from running openHAB v2.4 stable to v2.5 snaphot (in case of version incompatibilities between OH v2.4 and my binding v2.5), and b) used PaperUI to install the Exec1 binding (presumably to pull in any core dependencies for v1 bingings) – and I made some progress as follows…

When I manually copy the .jar file produced by the Eclipse IDE into the addons folder of my test machine, I now get the following in the log…

2019-05-08 14:01:48.233 [DEBUG] [org.openhab.binding.neohub          ] - BundleEvent INSTALLED - org.openhab.binding.neohub
2019-05-08 14:01:48.811 [DEBUG] [org.openhab.binding.neohub          ] - BundleEvent RESOLVED - org.openhab.binding.neohub
2019-05-08 14:01:48.825 [DEBUG] [org.openhab.binding.neohub          ] - BundleEvent STARTING - org.openhab.binding.neohub
2019-05-08 14:01:48.831 [DEBUG] [org.openhab.binding.neohub          ] - BundleEvent STARTED - org.openhab.binding.neohub

However the binding is still not actually functioning; so I need to DEBUG it within the IDE. I am not sure how to do that (yet) so I would appreciate some tips. :wink:

I really need some help how to attach my version of the binding to a running instance of openHab in a debugger.

{ Note: I have no problem to compile the code in Eclipse IDE and/or with MVN (including all the code beautification tests) and this creates a JAR without problem. However adding the JAR to the /addons folder of a standalone openHab system does not run. So I need to bind the binding within an openHab instance running in the IDE debugger… }

It’s enough actually if you build a kar instead of a jar and drop that into the add-ons directory. I don’t know the maven command line though.

The debugger will end the bundle when the debugging session is closed afaik so that doesn’t help much does it?

David, thanks for responding. But I am not sure I understand your point above? I want to set breakpoints on the binding code and step though it, so that I can see if resp. how it is being called from openHab, and work out what is going wrong…

It sounded like you just want to build for deployment. If you want to debug, you can just google karaf debug and find all information. Start openhab with the openhab_debug.sh (which configures karaf for live debugging) and follow information on the different web pages. (You basically use Debug->Remote something in Eclipse).

Thanks for tip about remote debugging.

Unfortunately I am still not able to get the modified plug in to even load in a stable OpenHab running environment. The latest unresolved dependency is…

2019-05-11 17:02:41.686 [WARN ] [org.apache.felix.fileinstall        ] - Error while starting bundle: file:/G:/openhab_runtime/addons/org.openhab.binding.neohub-2.5.0-SNAPSHOT.jar
org.osgi.framework.BundleException: Could not resolve module: org.openhab.binding.neohub [232]
  Unresolved requirement: Import-Package: org.codehaus.jackson.annotate; version="[1.9.0,2.0.0)"

=> When do you guys expect to have a stable, and properly documented, environment for building and testing plugins? (especially for migrating v1.x plugins) At the moment it is just too difficult to do it, and there is not enough clear documentation to help with that; and even when there is documentation, it is out of date or wrong… (rant over)

1 Like

That should not be the case. I have basically rewritten the developer docu a few weeks ago.

That’s the issue right now. The guide on our docs works, but it involves a lot of manual steps to set the IDE up. Kai is working on a new setup file for Eclipse.

Just to be sure: You are on OH 2.5 snapshots? Because “org.codehaus.jackson.annotate” is a very old library, that got replaced by “fasterxml.jackson” or something (the successor) and core is only using the new one. You might check “neohub” if it still uses the old namespace and maybe create a PR to migrate to the new namespace.

David, I am referring to the bit at the bottom of this page Developer Guide | openHAB which IMHO is not correct…

That is essentially my problem. I am indeed on the OH 2.5 snapshots, and the binding is not explicitly using those imports, so I am totally confused why the debug environment is falling over because of dependencies that apparently neither the plugin nor the core actually need to have… Grrr…

You can click on the .target directory of the neo addon in eclipse and double-click the generated jar file. There should be a text file like interface that tells you all imported and exported libraries and in which packages they are used. Maybe you can track down where that library is used.

David, I am referring to the bit at the bottom of this page Developer Guide | openHAB which IMHO is not correct…

That has been changed weeks ago, but I forgot that the documentation cannot be build at the moment (super old, fragile, entangled buildsystem unfortunately. The docu guys are working on it).

This is the new version of the (temporary) setup guide for Eclipse IDE that should work. Try it.

[https://github.com/mvalla/openhab-docs/blob/master/developers/index.md]

1 Like

Hi Massimo, thank you for responding. The new instructions are really helpful. Many thanks. I don’t want to be negative though, but they don’t (yet) cover my own use case, which is to modernise a very old 1.x binding by firstly 1) migrating it into the v2 build system, and secondly 2) converting its code to a v2 binding class framework. (I don’t want to do both 1) and 2) at the same time for fear of breaking something).

Dear David, many thanks for the tip. I will follow your suggestion and get back to you. I had built the JAR using “mvn clean install” so perhaps the dependency somehow got pulled in by the code prettification checks ?? (I see from Massimo’s new instructions that there are switches to turn off the pretification tests, and so I will try that too).