openhab / openhab-core

Core framework of openHAB
https://www.openhab.org/
Eclipse Public License 2.0
925 stars 425 forks source link

Automatic dependency installation for packages already included in the core #3848

Closed morph166955 closed 1 year ago

morph166955 commented 1 year ago

This would be a feature request that would help both developers and marketplace users.

I will use https://github.com/openhab/openhab-addons/pull/15753 as an example here. The sonyprojector binding uses the openhab-transport-serial package. Normally that package is installed when the addon is added. Unfortunately, that doesn't happen when a jar is installed because of the missing dependencies xml files.

2023-10-14 15:02:27.475 [WARN ] [org.apache.felix.fileinstall ] - Error while starting bundle: file:/usr/share/openhab/addons/org.openhab.binding.sonyprojector-4.1.0-SNAPSHOT.jar
org.osgi.framework.BundleException: Could not resolve module: org.openhab.binding.sonyprojector [297]
Unresolved requirement: Import-Package: org.openhab.core.io.transport.serial

The AndroidTV binding similarly has dependencies for mdns and upnp. Dozens of others have dependencies on things that exist in the core. It would be very helpful if the core (or karaf) could automatically install the necessary dependencies when they are already included as part of openhab.

Alternative, would it be possible to simply load some of these "common" dependencies on start by default so that addons would be able to access them if added later?

I'm not suggesting 3rd party be pulled in (although that would be great), but if it's something that already exists in the core we should be able to load it automatically.

J-N-K commented 1 year ago

We already have that in place: the dependencies are defined in the feature.xml and what is defined there will automatically be installed. However, it does not work if you use a .jar, because the feature.xml is not included there (that is the difference to a .kar which has that information).

The .jar only contains the java packages (as import statement) that are required, not the features that need to be installed to provide those packages and there is no easy way to determine that, because without installing the feature, you can only determine the bundles in that feature, not the packages that are exported by these bundles.

So the real question is: why do you install .jars? Probably because the default build setting in openhab-addons does only create a .jar, not a .kar for a single add-on. That would be a build improvement in add-ons, not a core issue.

morph166955 commented 1 year ago

So I both agree and disagree with your statement. Yes, a kar fixes this. Personally I've had very bad luck generating kar's successfully. There always seems to be issues with dependencies on more complex bindings. I tried to do it for the AndroidTV binding when I added the PhilipsTV bits and could not get it to build cleanly. In the case of testing small changes to the binding, going through the process of building a kar is unnecessarily long. In the case of AndroidTV, I compile in all of the necessary external dependencies so the only things that have to be grabbed are internal openhab-* dependencies.

In respect to this request, could we not catch the exception and attempt to lookup the missing component (assuming it's an org.openhab.core.* component), load it, and then attempt to reload the jar file?