Skip to content

Commit

Permalink
extend bnd demo ws for .bndrun usecase
Browse files Browse the repository at this point in the history
- added a .bndrun in the demo.impl bundle which is used to build the executable jar (comparable to building the product)
- added another consumer bundle which
- installed Felix Gogo Shell, so that you can even start the application and type 'hello' in the console to get an output from the service. this is basically now a very simple OSGi application
- changed to Java17
- removed all warnings in Eclipse

Co-Authored-By: Christoph Läubrich <[email protected]>
(cherry picked from commit f5e7053)
  • Loading branch information
chrisrueger authored and eclipse-tycho-bot committed Feb 3, 2025
1 parent f7cef38 commit 099af7f
Show file tree
Hide file tree
Showing 12 changed files with 134 additions and 13 deletions.
2 changes: 2 additions & 0 deletions demo/bnd-workspace/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
generated/
target/
3 changes: 2 additions & 1 deletion demo/bnd-workspace/.mvn/maven.config
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
-Dtycho-version=4.0.11
-Dtycho-version=4.0.11
-Dbndrun.exports=tycho.demo.app
32 changes: 31 additions & 1 deletion demo/bnd-workspace/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,34 @@
Build BND Workspace Demo
========================

This example shows how one can build a BND Workspace with Maven without any poms.
This example shows how one can build a BND Workspace with Maven without any poms.

## Build

- `mvn clean install`

To build with the current snapshot build (e.g. during local development) use:

- `mvn clean install -Dtycho-version=5.0.0-SNAPSHOT`

## Running the demo application

The demo app lives in `tycho.demo.impl` which contains a `tycho.demo.app.bndrun`.

This `.bndrun` is referenced by the property `-Dbndrun.exports=tycho.demo.app` in the `.mvn/maven.config`, which will create an executable .jar after the build in `tycho.demo.impl/target/executable/tycho.demo.app.jar`.

You can run the demo application in this executable jar with with

`java -jar tycho.demo.impl/target/executable/tycho.demo.app.jar`

You will see a Gogo Shell like this:

```
Welcome to Apache Felix Gogo
g! Please type 'hello' into the console and press Enter, and magic will happen.
```

then type 'hello' in this shell and press enter.

Press `Ctrl + C` / `Cmd + C` to exit the shell.
7 changes: 6 additions & 1 deletion demo/bnd-workspace/cnf/build.bnd
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Bundle-Version: 1.0.0-SNAPSHOT
-runfw: org.eclipse.osgi
-runee: JavaSE-17

java: java
javac: javac
javac.source: 17
javac.target: 17
javac.debug: on
16 changes: 15 additions & 1 deletion demo/bnd-workspace/cnf/ext/central.mvn
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
# Contains all bundles to consume from maven central

org.eclipse.platform:org.eclipse.osgi:3.21.0
org.eclipse.platform:org.eclipse.osgi.util:3.7.300
org.eclipse.platform:org.eclipse.osgi.services:3.12.100

org.apache.felix:org.apache.felix.gogo.command:1.1.2
org.apache.felix:org.apache.felix.gogo.runtime:1.1.6
org.apache.felix:org.apache.felix.gogo.shell:1.1.4


org.osgi:osgi.core:8.0.0
org.osgi:osgi.annotation:8.1.0
org.osgi:org.osgi.service.component.annotations:1.5.1
org.osgi:org.osgi.service.component:1.5.1
org.osgi:org.osgi.util.function:1.1.0
org.apache.felix:org.apache.felix.scr:2.2.12
org.osgi:org.osgi.util.promise:1.3.0


org.commonmark:commonmark:0.22.0
org.commonmark:commonmark-ext-gfm-tables:0.22.0
org.commonmark:commonmark-ext-gfm-tables:0.22.0
2 changes: 1 addition & 1 deletion demo/bnd-workspace/cnf/ext/maven-layout.bnd
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Configure a layout that is usually used with a traditional maven build

target-dir = target
target-dir = ${if;${driver;tycho-maven-build};target;generated${if;${driver;eclipse};;/${driver}}}
main-dir = src/main
test-dir = src/test

Expand Down
4 changes: 4 additions & 0 deletions demo/bnd-workspace/tycho.demo.consumer/bnd.bnd
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-buildpath: \
org.eclipse.osgi.services,\
tycho.demo.api,\
org.apache.felix.gogo.runtime
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*******************************************************************************
* Copyright (c) 2025 Christoph Rüger and others.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Christoph Rüger - extend example for .bndrun
*******************************************************************************/
package org.eclipse.tycho.demo.consumer;

import org.apache.felix.service.command.Descriptor;
import org.eclipse.tycho.demo.api.HelloWorld;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;

@Component(property = { "osgi.command.scope=tychodemo", "osgi.command.function=hello"}, service = Object.class, immediate = true)
public class Consumer {

@Reference
private HelloWorld service;

public Consumer() {
System.out.println("Please type 'hello' into the console and press Enter, and magic will happen.");
}


@Descriptor("Says hello, via HelloWorld service")
public void hello() {
service.sayHello();
}


}
10 changes: 6 additions & 4 deletions demo/bnd-workspace/tycho.demo.impl/bnd.bnd
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
-buildpath: osgi.annotation, \
tycho.demo.api, \
tycho.demo.markdown.api,\
org.osgi.service.component.annotations
-buildpath: \
osgi.annotation,\
tycho.demo.api,\
tycho.demo.markdown.api,\
org.osgi.service.component.annotations,\
osgi.core
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ public class HelloWorldService implements HelloWorld {
private MarkdownRenderer markdown;

public void sayHello() {
System.out.println("Hello BND Workspace!");

System.out.println("Render some markdown to HTML: " + markdown.render("## H2 Headline"));
System.out.println("Hello to you too! This BND Workspace has been built with Eclipse Tycho!");
System.out.println("And now see, how we use a service to render some markdown to HTML: " + markdown.render("## H2 Headline"));
}
}
23 changes: 23 additions & 0 deletions demo/bnd-workspace/tycho.demo.impl/tycho.demo.app.bndrun
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
-runrequires: \
bnd.identity;id='tycho.demo.impl',\
bnd.identity;id='org.apache.felix.gogo.shell',\
bnd.identity;id='org.apache.felix.gogo.command',\
bnd.identity;id='tycho.demo.consumer',\
bnd.identity;id='tycho.demo.markdown.impl'
-runee: JavaSE-17
-runfw: org.eclipse.osgi
-runbundles: \
org.apache.felix.gogo.runtime;version='[1.1.6,1.1.7)',\
org.apache.felix.gogo.shell;version='[1.1.4,1.1.5)',\
org.apache.felix.gogo.command;version='[1.1.2,1.1.3)',\
org.apache.felix.scr;version='[2.2.12,2.2.13)',\
org.osgi.service.component;version='[1.5.1,1.5.2)',\
org.osgi.util.function;version='[1.1.0,1.1.1)',\
org.osgi.util.promise;version='[1.3.0,1.3.1)',\
tycho.demo.api;version=snapshot,\
tycho.demo.impl;version=snapshot,\
tycho.demo.markdown.api;version=snapshot,\
tycho.demo.consumer;version=snapshot,\
tycho.demo.markdown.impl;version=snapshot
-runproperties: \
osgi.console=
6 changes: 5 additions & 1 deletion tycho-its/src/test/java/org/eclipse/tycho/test/DemoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ public void testTychoBndDemo() throws Exception {

@Test
public void testTychoBndWorkspaceDemo() throws Exception {
runDemo("bnd-workspace");
Verifier verifier = runDemo("bnd-workspace");
String expectedLocation = "tycho.demo.impl/target/executable/tycho.demo.app.jar";
File exportedJar = Path.of(verifier.getBasedir(), expectedLocation)
.toFile();
assertTrue("Did not find exported executable jar at expected location: " + expectedLocation, exportedJar.exists());
}

@Test
Expand Down

0 comments on commit 099af7f

Please sign in to comment.