Skip to content

Commit 3298dc8

Browse files
authored
[development] Adding generic, maven based run and debug. (#2435)
* [development] Adding generic, maven based run and debug. Also see openhab/openhab-distro#1707 Signed-off-by: Gwendal Roulleau <gwendal.roulleau@gmail.com> * [development] Adding generic, maven based run and debug. Apply MR comments Signed-off-by: Gwendal Roulleau <gwendal.roulleau@gmail.com> * [development] Adding generic, maven based run and debug. Apply MR comments Signed-off-by: Gwendal Roulleau <gwendal.roulleau@gmail.com> --------- Signed-off-by: Gwendal Roulleau <gwendal.roulleau@gmail.com>
1 parent c64ed13 commit 3298dc8

File tree

9 files changed

+138
-18
lines changed

9 files changed

+138
-18
lines changed

.vuepress/docs-sidebar.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,15 @@ module.exports = [
213213
collapsable: true,
214214
children: [
215215
['developer/', 'Overview & Introduction'],
216+
{ title: 'IDEs',
217+
collapsable: true,
218+
children: [
219+
'developer/ide/eclipse',
220+
'developer/ide/intellij',
221+
'developer/ide/vscode',
222+
'developer/ide/generic',
223+
]
224+
},
216225
'developer/guidelines',
217226
'developer/addons/',
218227
'developer/bindings/',

developers/ide/generic.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
---
2+
layout: developersguide
3+
title: Generic IDEs hints
4+
---
5+
6+
# Generic setup for your IDE
7+
8+
## The demo project with Maven
9+
10+
It can be particularly useful, regardless of the IDE, to be able to launch a development instance of openHAB.
11+
This is the purpose of the `org.openhab.demo.app` project, which can be found in the `openhab-distro` repository.
12+
13+
To do this, you need to clone the [openhab distro repository](https://www.github.com/openhab/openhab-distro)
14+
15+
To launch the demo project, Eclipse [has its bnd plugin](./eclipse.html#working-with-add-ons).
16+
However, it can sometimes be particularly slow. Maven is therefore a completely viable alternative (and the only option
17+
available for other IDEs).
18+
Using the demo project through Maven will allow you to run an openHAB instance that uses the artifacts present in your
19+
local Maven repository (and downloads them beforehand if they are not already present).
20+
21+
This means that if you develop an add-on (or even a `openhab-core` module), once you have built and installed it, it
22+
will be available in your local repository and the demo project will be able to use your development.
23+
24+
### Build project
25+
26+
::: warning
27+
Make sure you meet the prerequisites like the Java and Maven version. As of openHAB 5.x Java 21.x is required and at least mvn 3.8.6.
28+
:::
29+
30+
Use Maven to build the projects you want to develop for. It is important to use the `mvn install` option to copy the artifact in your local repository.
31+
32+
### Preparation
33+
34+
There are two files to take care of:
35+
36+
- `/openhab-distro/launch/app/pom.xml` must contain the artifact you are developing in the dependencies section (search for "uncomment this and add the name of your binding that you want to work on")
37+
38+
- `/openhab-distro/launch/app/app.bndrun` will list the modules needed by the OSGi runtime. You also have to add your add-on in the `runrequires` section (e.g. `bnd.identity;id='org.openhab.binding.YOURBINDINGNAME'` and don't forget to add the `\` to the previous line if you adding it to the end of the list)
39+
40+
After editing this two files, use this maven command from the `/openhab-distro/launch/app/` directory:
41+
42+
`mvn bnd-resolver:resolve`
43+
44+
This will ask the bnd plugin to 'resolve' the dependencies (i.e. to calculate which bundles to run in the OSGi runtime) and update
45+
the `runbundles` section of the `app.bndrun` file accordingly.
46+
Each time you add a dependency or change the version, you HAVE to run a resolve task.
47+
48+
::: warning
49+
The `pom.xml` file is versioned. The version fields present in the file must match the modules
50+
you are developing. For example, if you are developing a module for `openhab-core` and it is deployed as version
51+
5.0.0-SNAPSHOT in your local repository, you must use this same 5.0.0-SNAPSHOT version in the version field of the
52+
`org.openhab.demo.app` artifact. Similarly, for add-on development, ensure that the version field of your add-on in the
53+
pom.xml file matches the version you are currently developing. If you use incorrect versions, you will not understand
54+
why your changes are not being taken into account
55+
:::
56+
57+
### Launching and debugging
58+
59+
Go to the directory `/openhab-distro/launch/app`
60+
61+
To launch the demo app, using the content of the `app.bndrun` file:
62+
63+
`mvn bnd-run:run`
64+
65+
You can now open the app in your browser via [http://localhost:8080/](http://localhost:8080/).
66+
67+
To launch in debug mode:
68+
69+
`mvn -D-runjdb=10001 package bnd-run:run`
70+
71+
Wait for the process to pause and show the log `Listening for transport...` then attach your IDE to the remote debugging
72+
session (here, on port 10001). The openHAB demo project startup process will then resume and you will be able to
73+
open it in your browser.
74+
75+
Each modification of your code requires rebuilding your add-on with `mvn clean install` so that it is
76+
deployed in your local repository and accessible for the next execution.

developers/ide/images/generic_ide.pdn

67.9 KB
Binary file not shown.

developers/ide/images/generic_ide.png

42.5 KB
Loading
Loading
Loading
Loading

developers/ide/intellij.md

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,44 @@ title: IntelliJ
77

88
## Prerequisites
99

10-
- git, Maven, IntelliJ and Java 17 are installed
10+
- git, Maven (at least 3.8.6), IntelliJ and Java (21) are installed and available in the path.
1111

12-
## Install openHAB distribution
12+
## Build the repositories
1313

14-
1. Install the official [openHAB distribution](https://www.openhab.org/download/)
15-
1. Start the distribution **in debug mode** (use `./start_debug.sh` instead of `./start.sh` in step 4)
14+
1. Fork and clone the repositories into a parent directory (Reference `<PARENT_DIR>` from now on for this article). Take only the one(s) you will work on:
1615

17-
This article refers to the directory where you installed the distribution as `<DISTRO_DIR>`.
16+
- [openhab addons repository](https://www.github.com/openhab/openhab-addons)
17+
- [openhab core repository](https://www.github.com/openhab/openhab-core)
18+
- [openhab webui repository](https://www.github.com/openhab/openhab-webui)
1819

19-
## Build the addons repository
20+
Use the command `git clone https://github.com/<yourgitusername>/openhab-<addons|core|webui>` (replace git user name accordingly).
2021

21-
1. Fork and clone the [openhab addons repository](https://www.github.com/openhab/openhab-addons) into a new directory (Reference `<ADDON_DIR>` from now on for this article) with `git clone https://github.com/<yourgitusername>/openhab-addons` (replace git user name accordingly)
22+
1. Open IntelliJ, select the file/open, and choose the `<PARENT_DIR>`
23+
1. Open The Module settings (inside `Project Settings`, or use F4). Click on the + button and select `Import module`.
24+
1. Choose one of the repository directory you just cloned. select the Maven external model as import format.
25+
IntelliJ will start importing and indexing. It will take while, wait until finished. The Module window should now be filled with a bunch of projects.
26+
![Import modules](images/ide_setup_intellij_import_module.png)
27+
1. Repeat step 2 and 3 for all repositories you cloned.
28+
1. Use Maven to clean & install projects. Make sure you use the required Maven version (3.8.6 is recommended).
2229

23-
1. Open IntelliJ and create a new project from existing sources (File | New | Project from existing sources) and pick `<ADDON_DIR>`/pom.xml
30+
- `mvn clean install` in the root of the repositories using commandline Maven (or IntelliJ Maven view)
31+
- some of the add-ons might fail to build - if it's not the one you're interested in, that should not bother you
32+
- when the Maven project finished, you should find the freshly built addon JAR in the target directory
2433

25-
IntelliJ will start importing, indexing and building, it will take while, wait until finished (see status bar)
34+
You then have two main options to run your development: use the official distribution, or use Maven.
2635

27-
1. Use Maven to clean & install the addons project
36+
## Option 1: Use and debug from the official distribution
2837

29-
- mvn clean install in the root of `<ADDON_DIR>` using commandline Maven (or IntelliJ Maven view)
30-
- some of the add-ons might fail to build - if it's not the one, you're interested in that should not bother you
31-
- when the Maven project finished, you should find the freshly built addon JAR in the target directory
38+
This is the simpler option, but you can only use it for add-on development.
3239

33-
## Debug your addon
40+
### Install openHAB distribution
41+
42+
1. Install the official [openHAB distribution](https://www.openhab.org/download/)
43+
1. Start the distribution **in debug mode** (use `./start_debug.sh` instead of `./start.sh` in step 4)
44+
45+
This article refers to the directory where you installed the distribution as `<DISTRO_DIR>`.
46+
47+
### Debug your addon
3448

3549
1. Copy the addon JAR to Openhab distribution created before
3650

@@ -52,3 +66,19 @@ This article refers to the directory where you installed the distribution as `<D
5266
![Remote Debug Run Configuration](images/ide_setup_intellij_debug_configuration.png)
5367

5468
You can now add breakpoints to your project now and your test distro should stop there.
69+
70+
## Option 2: Use maven-bdn plugin and the demo project
71+
72+
This option is more complex, but will allow you to run/debug anything.
73+
You will have to clone the additional repository openhab-distro repository in your `<PARENT_DIR>`. It contains the demo project.
74+
Look at the [generic IDEs information](./generic.md) to know more about how to prepare and launch the demo project.
75+
76+
After this, instead of using the command line, you can setup IntelliJ to launch the maven tasks.
77+
78+
![Launch Maven Task](./images/ide_setup_intellij_debug.png)
79+
80+
When launching the demo project from IntelliJ with the bnd debug option (in VM options in the screenshot above),
81+
look in the Run window for the mention "Listening for transport".
82+
You can then click on the `Attach debugger` to automatically start a debugging session.
83+
84+
![Attach debugger](./images/ide_setup_intellij_debug_attach.png)

developers/index.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,22 +63,27 @@ We have prepared some step-by-step guides for the following IDEs:
6363

6464
<table style="width:100%">
6565
<tr>
66-
<td style="width:30%">
66+
<td style="width:50%">
6767

6868
[![Visual Studio Code](./ide/images/vscode.jpg)](ide/vscode.html)
6969

7070
</td>
71-
<td style="width:30%">
71+
<td style="width:50%">
7272

7373
[![Eclipse IDE](./ide/images/eclipse.jpg)](ide/eclipse.html)
7474

7575
</td>
76-
<td style="width:30%">
76+
</tr>
77+
<tr>
78+
<td style="width:50%">
7779

7880
[![IntelliJ IDE](./ide/images/intellij.jpg)](ide/intellij.html)
7981

8082
</td>
81-
</tr>
83+
<td style="width:50%">
84+
85+
[![Generic IDE](./ide/images/generic_ide.png)](ide/generic.html)
86+
8287
</table>
8388

8489
Not sure what to choose?: openHAB maintainers use [Eclipse IDE](https://wiki.eclipse.org/Eclipse_Installer).

0 commit comments

Comments
 (0)