Closed maggu2810 closed 5 years ago
The build system has been migrated to a Mave + Bnd based build system. We are not accepting new pull requests that are still using the old way from here on.
openHAB is a java project that is build around the OSGi framework. openHAB add-ons are OSGi bundles.
Over the years the bnd software ("bnd is the engine behind a number of popular software development tools that support OSGi") has established itself as the defacto standard for creating OSGi bundles.
The openHAB maintainers have decided to move from the very Eclipse centric buildsystem to maven/bnd. A combination that not only allows to develop bindings seamlessly in other IDEs than Eclipse, but Java beginners and intermediates find a commonly known maven buildsystem.
The easiest way to migrate is to use the create_openhab_binding_skeleton
script in the bundles
folder and create the basis for your migrated binding and than copy your binding into the new generated folder:
create_openhab_binding_skeleton <binding name> "<your full name>" <your github name>
. (This script also updates the CODEOWNERS and bom addons pom. So if you have already updated those files you need to clean that up).src/main
to the new binding folder in binding in bundles
. README.md
to the new binding folder. If you have any non standard additional files. Move them also (like images used in your readme) pom.xml
file if your add-on requires dependencies like so:
<dependencies>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient-osgi</artifactId>
<version>4.5.2</version>
<scope>provided</scope>
</dependency>
</dependencies>
Remove those included jar files. ONLY IF you can't find a maven central bundle you can keep the jar file in the lib/
directory.
ESH-INF
to src/main/resources/ESH-INF
.test
project into src/test
.itests/
directory for examples.src/main/feature/feature.xml
to add any external dependencies, you must list them here, too. An example:
<feature name="openhab-binding-lgwebos" description="LG webOS Binding" version="${project.version}">
...
<bundle dependency="true">mvn:org.apache.httpcomponents/httpclient-osgi/4.5.2</bundle>
<bundle start-level="80">mvn:org.openhab.binding/org.openhab.binding.lgwebos/${project.version}</bundle>
</feature>
There are two types of external libraries. Those that are ready for OSGi (like the one above) and those that aren't. The latter ones are listed with a wrap prefix keyword like this:
<feature prerequisite="true">wrap</feature>
<bundle dependency="true">wrap:mvn:io.netty/netty-common/4.1.34.Final$Bundle-Name=Netty%20Common&Bundle-SymbolicName=io.netty.netty-common&Bundle-Version=4.1.34</bundle>
Please ask for details and review if in doubt.
Enter mvn clean install -DskipChecks
in the project directory or itest project directory.
Subsequent calls can include the -o
for offline.
For integration tests you might need to run: mvn clean install -DwithResolver
.
Skip checks and tests if you just want to test the compilation process and perform the command from within the directory of the bundle that you want to build:
mvn clean install -DskipChecks -DskipTests -o
git clone --depth=1 https://github.com/maggu2810/openhab-demo
.git clone --depth=1 https://github.com/openhab/openhab2-addons
pom.xml
in the demo-app project.
Add your add-on as maven dependency like so:
<project ...>
...
<dependencies>
<dependency>
<groupId>org.openhab.addons.bundles</groupId>
<artifactId>org.openhab.binding.astro</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</project>
app.bndrun
in the demo-app project. Double click (takes a few seconds).git\openhab2-addons\bom\openhab-addons
mvn -DskipChecks -DskipTests clean install
app.bndrun
file and now you should be able to find the binding in the listThe demo application runs a slim set of openHAB core bundles including automations (next gen rules) and PaperUI (http://127.0.0.1:8080/paperui/). The startup should only take about 5 seconds and you are greeted by the openHAB console where you can type in console commands.
But it should be simple for Bintray.
It's sure a lot easier to create your own Bintray repo compared to uploading to Maven Central. Isn't it also easier for them being removed one day causing builds to fail? As fallback we'll probably still have such JAR artifacts in stable/milestone/snapshot releases.
But IMHO this would be just as problematic as when someone decides to delete their GitHub repo containing all the source code of a library. Since we don't store such sources or source JARs.
To mitigate these issues we could also setup an openHAB repo proxy to such 3rd party repos.
why are we trying to use local JAR files at all
I'd like to manage them using dependencies in POMs as well. It would be a good improvement to be able to update libraries and all their dependencies by just updating a version number. :-)
So, my offer: You (who) tells me an addon project name that also offers an OSGi based test project. I assume it should be one with no -- in the best case -- PR opened. Perhaps for the very beginning it should be one without a 3rd party JAR that is not available on a Maven repo.
I try to start the base work:
bundles
)itests
)That's just an offer to help. If another one volunteers to do that job, I am happy, too.
astro is a perfect match, isn't it? I would then migrate MQTT as soon as the remaining PRs are in, to test how well the migration process works.
I'm OK with Astro as well. The binding itself doesn't really matter as long as it's a bit representative of most projects. If we run into issues while migrating other add-ons we can always ask for more help. :wink:
Thanks for adding a migration guide @davidgraeff ! Didn't notice the first post was updated. :-)
Can we add that to the developer documentation (esp. the Part about eclipse)?
One thing regarding the miration guide: "remove '/lib'" is a good idea but will not work out-of-the-box for all bindings, since not all libs are availabe on bintray. And not all of those that are available can easily be used. So this should be checked before migration.
@J-N-K There was a discussion about this between Markus and Wouter (I think?) and the agreement afaik is to move everything to (if necessary private) bintray/maven repos. For new contributions I also tend to say to either include the source code completely or only allow "established" libraries on maven central.
The end of this discussion was, that a decision by oh2-maintainers should be made about that. AFAIK this is still pending.
Including the source code maybe difficult. For example the Allplay binding includes a lib (Tchaikovsky) that is build with gradle and includes other libs that are not available on bintray (source is available on GitHub, though). Integrating that into our own build would greatly increase build time.
My long time dream for openHab is Gradle as well, but Markus will slowly poke me to death with a spoon if I suggest that :D (But the speed advantage is real)
What I was trying to say: other project might use other build systems and integrating those with our own is quite some effort and may not be worth the time (compared to building them and uploading a binary to our own 3rd-party-libs repo).
What I was trying to say: other project might use other build systems and integrating those with our own is quite some effort and may not be worth the time
The idea is to go to the maintainer of such a library and ask for a maven publish. There is even a maven plugin that uses github pages as a static repository site. We do not depend on their build system.
I am locked on the last step, that is launching the demo app. When I double-click on the file app.bndrun, it simply opens the file in the Eclipse editor. With what app should I open this file to start the demo app ?
it simply opens the file in the Eclipse editor
It's like with pom.xml files: You can edit the source file or have the eclipse UI. The same for bndrun files: The default view might be text for you, but there should be the tab to show the UI (you see the glimpse of this selection in the screenshot above).
If not, your eclipse installation is missing bndtools (which is fatal). Please either manually install them or use the eclipse installer for openhab-core development. Let it do whatever it does, remove everything from the workspace again and then perform the steps from above.
Bndtools is now (manually) installed and I can see the dialog box with run requirements. But I can't add my binding from openhab2-addons. In the Browser repos at left, I see apparently only bundles from org.openhab.core.bom.openhab-core-index. No binding here, mainly core stuff.
If I click on the green +, it opens the "Add Bundle Requirement" dialog box but this is empty, I only see at left "Workspace default-ws" with nothing inside.
Same for Run Bundles. Project run path dialog box shows an empty workspace.
If I drag my project from the project explorer into the run requirements, I get this error: Error adding one or more requirements Error generating requirement Unable to derive identity from an object of type Project
I can go one step later, that is I can now add my binding and start OH. The problem is that it fails to start.
Great tutorial. This will help others a lot. I walked through it step by step and want to add the following things:
- Remove
META-INF
andOSGI-INF
We have to remove the build.properties
file too.
- Move unit tests from a potential separate
.test
project intosrc/main/test
.
Move unit tests from a potential separate .test
project into src/test
.
Additional changes need to be done in the files CODEOWNERS
, the BOM (bom/openhab-addons/pom.xml
, groupId) and features/karaf/openhab-addons/src/main/feature/feature.xml
(bundle).
But I get a 404 error if I try to open the dashboard or Basic UI ! Is the demo app fully prepared/packaged to run UIs with the demo sitemap ?
The demo only runs paperUI. You see that in the "Run requirements" section. There is only paperUI referenced. Add whatever you need there (you don't need to adapt pom.xml, because bnd knowns about all openhab-core and openhab-webui bundles)
Btw paperUI can be reached directly via http://openhab-ip/paperui without the dashboard (which is deprecated... next to PaperUI but that's another story.)
I have added some UI bundles. I don't see traces for Paper UI. Now when I try to access UI, I am requested a login/password for OSGi Management console ! I never had to enter that before. What has to be entered ?
Just to be clear, here is what I get by default (that is if I change nothing): No trace of Paper UI.
I tried admin / admin but then I still get 404 errors for any UI including Paper UI.
Drag paperui over then from the "Browse Repos" window. It is called "org.openhab.ui.paper". No idea why credentials are required.
But I don't have org.openhab.ui.paper ! Are there several demo app ? I am using the one from openhab-core.
Yes there are multiple one, that's why I added a screenshot to the list. There is only one org.openhab.demo.app bundle. The core has its own, but that one can only reference to core bundles and not to uis and is not really of any use. Markus wanted to remove it actually, but Kai not.
Ok I am not using the right one ! It looks like a new repo is requireed, openhab-demo.
Shall we still clone https://github.com/maggu2810/openhab-demo or is there now a openhab-demo repo ?
That's the correct repo. Check your pom.xml of your demo app if it includes paperui:
<dependency>
<groupId>org.openhab.ui</groupId>
<artifactId>org.openhab.ui.paper</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
And what you can also do is to open the bndrun file and click the "Resolve" button, it will print some errors if something is not found etc.
It looks like the server is started. But still no WEB access. Doing a netstat command, I even have the feeling that there is no ports 8080 and 8443 opened ! I give up...
The rest interface on /rest should work, it works for me. But yeah would be helpful if the others can comment on this, so that we get a better migration guide.
Like before, we should have a setup that by default allows starting and running the openHAB demo, including of course dashboard, Paper UI and Basic UI.
The constraint to update now a POM to add a particular binding is not as cool and easy as before (simply select your binding in Eclipse UI).
Making this easy and working again should be a priority IMHO. Without the ability to test your code in Eclipse, a lot of contributors will probably give up.
@lolodomo The day is unfortunately only that long and almost everybody here does it in his freetime and the one guy that does it for a living (Markus) is in holiday.
The entire documentation for binding development need to be changed. And yes, changing a pom is not nice, there is a UI for this in eclipse as well though. I guess you can also drag&drop the project into that UI. We just need to find out what the easiest way is.
CODEOWENERS
will almost always give us merge conflicts.
We should probably script migrate all extensions without tests and jars in one go?
So do we stop migrating our bindings individually ?
@lolodomo No. The problem with the script migration is that some bindings should not yet be ported (those with open PRs). So please keep porting your bindings.
The RFXCOM binding is using an external lib, jd2xx. Source code is in sourceforge: https://sourceforge.net/projects/d2xx/files/ Last update is dated 2011 ! How do you want to handle such a dependency ? Can you accept keeping libraries in such a case ?
This is discussed e.g. in #5117 but not yet decided.
I'd say we include the source files of that library (dual licensed and we pick the bsd one).
I discovered that the old way to start openHAB in Eclipse is still working well (and with all UIs available). The only problem is that the migrated bindings are no more presented. Don't know if this can be fixed. For the developers that need running and testing their bindings from inside Eclipse, until a clear and working guide is provided with the demo app, I would suggest to not migrate immediately.
@lolodomo You are in the wrong topic for this suggestion. Here it is all about migrating all bindings as fast and clean as possible, because the core is currently "broken" until all bindings have been migrated.
After the migration and after the core has been fixed, we will think about how to develop bindings under these new conditions.
It may not even be Eclipse anymore, but Visual Studio Code as it is super easy to write addons for it. With an addon we can add "Run" and "Debug" buttons that do all the fancy OSGi container starting and maven dependency manipulation in the background.
We should probably script migrate all extensions without tests and jars in one go?
I'd prefer one PR per binding. Else, you will have one humongous PR blocking everything else, and if it part of it needs to be reverted (e.g. some binding does not work even if it technically "migrated" as in "compiles"), you would break the complete master. Faced that pain too many times myself.
jd2xx nowadays cause more issues than it gains. Windows, linux and osx have native FTDI drivers, so binding is able to discover rfxcom bridge, but connection doesn’t work properly because of native driver. Additionally, most of the beginners try to introduce jd2xx bridge rather than direct serial port bridge, so I propose to remove whole bridge auto discovery and jd2xx staff from rfxcom binding.
@paulianttila this is a good solution to solve the problem :-) If we do that, this will break things at least for some users ?
If we do that, this will break things at least for some users ?
Already configured things should not be influenced I guess? As far as I understood, jd2xx is only used for auto discovery. The readme should be amended to reflect that there is no discovery anymore.
No, my understanding of the code is that if a bridge was discovered with JD2xx then the connection to the serial port is done using JD2xx library. To avoid that, we will need at least the port name in the configuration but we don't have it.
@clinique : the netatmo binding could be a very difficult challenge with its 9 external libraries. You are probably the only one to understand/know how some of them were produced. What could be the solution for this binding ?
@lolodomo : my plan is to start by some simple bindings (Synop, OpenUV) to understand the move, and then go to Netatmo :) I did no see this thread before you pinged me, but I think it may answer question I raised on the forum right this morning !
It looks like the server is started. But still no WEB access. Doing a netstat command, I even have the feeling that there is no ports 8080 and 8443 opened ! I give up...
Hello @lolodomo , I'm stuck at the very same step. Did you find a solution ?
@clinique Is the rest interface working? (/rest) You may need to add the "org.openhab.ui.dashboard" bundle to the xml and to the run requirements as well. This demo app just has never been really tested with uis.
We are in the process of changing the build system. We are not accepting new pull requests that are still using the old way from here on.
For further information see: Migration to a Maven + Bnd based build system