From 641e7d0cca37e1887e746648ddfcf9d6a6006813 Mon Sep 17 00:00:00 2001 From: Christoph Rueger Date: Thu, 30 Jan 2025 16:25:02 +0100 Subject: [PATCH] add bundle using bnd's sub-bundles via -sub: *.bnd MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit bump tycho version to 4.0.10 gitignore MacOS .DS_Store files add bundle using bnd's sub-bundles via -sub: *.bnd see the bnd.bnd of the new tycho.demo.markdown bundle. it uses the -sub: *.bnd instruction to create 2 jar files based on the other .bnd files (api.bnd and impl.bnd) this build currently fails and we want to use that to fix tycho to make it pass. It seems that tycho currently does not recognize the 2 (sub) jars so it cannot find them as dependencies for the HelloWorldService [ERROR] Failed to execute goal org.eclipse.tycho:tycho-bnd-plugin:4.0.10:compile (compile) on project tycho.demo.impl: javac failed /bnd-workspace/tycho.demo.impl/src/main/java/org/eclipse/tycho/demo/impl/HelloWorldService.java:18: error: package tycho.demo.utils.markdown.api does not exist [ERROR] import tycho.demo.utils.markdown.api.MarkdownRenderer; [ERROR] ^ [ERROR] /bnd-workspace/tycho.demo.impl/src/main/java/org/eclipse/tycho/demo/impl/HelloWorldService.java:24: error: cannot find symbol [ERROR] private MarkdownRenderer markdown; [ERROR] ^ [ERROR] symbol: class MarkdownRenderer [ERROR] location: class HelloWorldService [ERROR] 2 errors add licence headers Update demo/bnd-workspace/tycho.demo.markdown/src/main/java/tycho/demo/utils/markdown/impl/MarkdownRendererImpl.java Update demo/bnd-workspace/tycho.demo.markdown/src/main/java/tycho/demo/utils/markdown/api/MarkdownRenderer.java Co-Authored-By: Christoph Läubrich --- .gitignore | 1 + demo/bnd-workspace/.mvn/maven.config | 2 +- demo/bnd-workspace/cnf/ext/central.mvn | 6 ++- demo/bnd-workspace/tycho.demo.impl/bnd.bnd | 1 + .../tycho/demo/impl/HelloWorldService.java | 8 ++++ .../bnd-workspace/tycho.demo.markdown/api.bnd | 1 + .../bnd-workspace/tycho.demo.markdown/bnd.bnd | 8 ++++ .../tycho.demo.markdown/impl.bnd | 8 ++++ .../utils/markdown/api/MarkdownRenderer.java | 25 ++++++++++ .../markdown/impl/MarkdownRendererImpl.java | 47 +++++++++++++++++++ 10 files changed, 105 insertions(+), 2 deletions(-) create mode 100644 demo/bnd-workspace/tycho.demo.markdown/api.bnd create mode 100644 demo/bnd-workspace/tycho.demo.markdown/bnd.bnd create mode 100644 demo/bnd-workspace/tycho.demo.markdown/impl.bnd create mode 100644 demo/bnd-workspace/tycho.demo.markdown/src/main/java/tycho/demo/utils/markdown/api/MarkdownRenderer.java create mode 100644 demo/bnd-workspace/tycho.demo.markdown/src/main/java/tycho/demo/utils/markdown/impl/MarkdownRendererImpl.java diff --git a/.gitignore b/.gitignore index 79eeb49e6b..23e2622e27 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ pom-model-classic.xml project-dependencies.xml project-units.xml requirements.txt +.DS_Store \ No newline at end of file diff --git a/demo/bnd-workspace/.mvn/maven.config b/demo/bnd-workspace/.mvn/maven.config index 7084d8ecd9..737a4d8e8c 100644 --- a/demo/bnd-workspace/.mvn/maven.config +++ b/demo/bnd-workspace/.mvn/maven.config @@ -1 +1 @@ --Dtycho-version=4.0.0-SNAPSHOT \ No newline at end of file +-Dtycho-version=4.0.10 \ No newline at end of file diff --git a/demo/bnd-workspace/cnf/ext/central.mvn b/demo/bnd-workspace/cnf/ext/central.mvn index d19999ec2f..25e7e301b2 100644 --- a/demo/bnd-workspace/cnf/ext/central.mvn +++ b/demo/bnd-workspace/cnf/ext/central.mvn @@ -1,4 +1,8 @@ # Contains all bundles to consume from maven central +org.osgi:osgi.core:8.0.0 org.osgi:osgi.annotation:8.1.0 -org.osgi:org.osgi.service.component.annotations:1.5.1 \ No newline at end of file +org.osgi:org.osgi.service.component.annotations:1.5.1 +org.osgi:org.osgi.service.component:1.5.1 +org.commonmark:commonmark:0.22.0 +org.commonmark:commonmark-ext-gfm-tables:0.22.0 \ No newline at end of file diff --git a/demo/bnd-workspace/tycho.demo.impl/bnd.bnd b/demo/bnd-workspace/tycho.demo.impl/bnd.bnd index 9f6e68b8ec..7bc4e84a56 100644 --- a/demo/bnd-workspace/tycho.demo.impl/bnd.bnd +++ b/demo/bnd-workspace/tycho.demo.impl/bnd.bnd @@ -1,3 +1,4 @@ -buildpath: osgi.annotation, \ tycho.demo.api, \ + tycho.demo.markdown.api,\ org.osgi.service.component.annotations diff --git a/demo/bnd-workspace/tycho.demo.impl/src/main/java/org/eclipse/tycho/demo/impl/HelloWorldService.java b/demo/bnd-workspace/tycho.demo.impl/src/main/java/org/eclipse/tycho/demo/impl/HelloWorldService.java index fd79082d11..adc4e73aff 100644 --- a/demo/bnd-workspace/tycho.demo.impl/src/main/java/org/eclipse/tycho/demo/impl/HelloWorldService.java +++ b/demo/bnd-workspace/tycho.demo.impl/src/main/java/org/eclipse/tycho/demo/impl/HelloWorldService.java @@ -14,10 +14,18 @@ import org.eclipse.tycho.demo.api.HelloWorld; import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; +import tycho.demo.utils.markdown.api.MarkdownRenderer; @Component public class HelloWorldService implements HelloWorld { + + @Reference + private MarkdownRenderer markdown; + public void sayHello() { System.out.println("Hello BND Workspace!"); + + System.out.println("Render some markdown to HTML: " + markdown.render("## H2 Headline")); } } diff --git a/demo/bnd-workspace/tycho.demo.markdown/api.bnd b/demo/bnd-workspace/tycho.demo.markdown/api.bnd new file mode 100644 index 0000000000..bb9c7bd8cb --- /dev/null +++ b/demo/bnd-workspace/tycho.demo.markdown/api.bnd @@ -0,0 +1 @@ +Export-Package: com.synesty.utils.markdown.api \ No newline at end of file diff --git a/demo/bnd-workspace/tycho.demo.markdown/bnd.bnd b/demo/bnd-workspace/tycho.demo.markdown/bnd.bnd new file mode 100644 index 0000000000..e300fbe0f9 --- /dev/null +++ b/demo/bnd-workspace/tycho.demo.markdown/bnd.bnd @@ -0,0 +1,8 @@ +-sub: *.bnd + +-buildpath: \ + osgi.core;version=latest,\ + osgi.annotation;version=latest,\ + org.osgi.service.component.annotations;version=latest,\ + org.commonmark:commonmark;version=latest,\ + org.commonmark:commonmark-ext-gfm-tables;version=latest diff --git a/demo/bnd-workspace/tycho.demo.markdown/impl.bnd b/demo/bnd-workspace/tycho.demo.markdown/impl.bnd new file mode 100644 index 0000000000..075358770c --- /dev/null +++ b/demo/bnd-workspace/tycho.demo.markdown/impl.bnd @@ -0,0 +1,8 @@ +-privatepackage: tycho.demo.utils.markdown.impl + + + +-includeresource: \ + ${repo;org.commonmark:commonmark;latest}; lib:=true,\ + ${repo;org.commonmark:commonmark-ext-gfm-tables;latest}; lib:=true,\ + \ No newline at end of file diff --git a/demo/bnd-workspace/tycho.demo.markdown/src/main/java/tycho/demo/utils/markdown/api/MarkdownRenderer.java b/demo/bnd-workspace/tycho.demo.markdown/src/main/java/tycho/demo/utils/markdown/api/MarkdownRenderer.java new file mode 100644 index 0000000000..c24f53ac21 --- /dev/null +++ b/demo/bnd-workspace/tycho.demo.markdown/src/main/java/tycho/demo/utils/markdown/api/MarkdownRenderer.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * 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 to use bnd -sub instruction + *******************************************************************************/ +package tycho.demo.utils.markdown.api; + +public interface MarkdownRenderer { + + /** + * Renders markdown string to html. + * + * @param markdown + * @return + */ + String render(String markdown); + +} diff --git a/demo/bnd-workspace/tycho.demo.markdown/src/main/java/tycho/demo/utils/markdown/impl/MarkdownRendererImpl.java b/demo/bnd-workspace/tycho.demo.markdown/src/main/java/tycho/demo/utils/markdown/impl/MarkdownRendererImpl.java new file mode 100644 index 0000000000..4a9c8ad137 --- /dev/null +++ b/demo/bnd-workspace/tycho.demo.markdown/src/main/java/tycho/demo/utils/markdown/impl/MarkdownRendererImpl.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * 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 to use bnd -sub instruction + *******************************************************************************/ +package tycho.demo.utils.markdown.impl; + +import java.util.Arrays; +import java.util.List; + +import org.commonmark.Extension; +import org.commonmark.ext.gfm.tables.TablesExtension; +import org.commonmark.node.Node; +import org.commonmark.parser.Parser; +import org.commonmark.renderer.html.HtmlRenderer; +import org.osgi.service.component.annotations.Component; + +import tycho.demo.utils.markdown.api.MarkdownRenderer; + +@Component +public class MarkdownRendererImpl implements MarkdownRenderer { + + private Parser parser; + private HtmlRenderer renderer; + + public MarkdownRendererImpl() { + List extensions = Arrays.asList(TablesExtension.create()); + + this.parser = Parser.builder().extensions(extensions).build(); + this.renderer = HtmlRenderer.builder().extensions(extensions).build(); + } + + @Override + public String render(String markdown) { + + Node document = parser.parse(markdown); + return renderer.render(document); + } + +}