Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a demo with Jsonp that can be ran inside an OSGI container #291

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,8 @@
<Bundle-Description>Jakarta JSON Processing API ${spec.version}</Bundle-Description>
<Specification-Vendor>${vendor.name}</Specification-Vendor>
<Implementation-Build-Id>${buildNumber}</Implementation-Build-Id>
<Import-Package></Import-Package>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should not be empty, nothing (or default *) is usually the best

<Require-Capability>osgi.extender;filter:="(osgi.extender=osgi.serviceloader.processor)", osgi.serviceloader; filter:="(osgi.serviceloader=jakarta.json.spi.JsonProvider)"; cardinality:=multiple</Require-Capability>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that osgi extender required? can we avoid using it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

</instructions>
</configuration>
<executions>
Expand Down
233 changes: 233 additions & 0 deletions demos/jsonpointer-osgi/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Copyright (c) 2013, 2021 Oracle and/or its affiliates. All rights reserved.

This program and the accompanying materials are made available under the
terms of the Eclipse Distribution License v. 1.0, which is available at
http://www.eclipse.org/org/documents/edl-v10.php.

SPDX-License-Identifier: BSD-3-Clause

-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.eclipse.jsonp</groupId>
<artifactId>demos</artifactId>
<version>2.0.2-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>jsondemos-jsonpointer-osgi</artifactId>
<packaging>bundle</packaging>

<properties>
<main.class>JsonpointerOsgiDemo</main.class>
<modules.directory>${project.build.directory}/modules</modules.directory>
<spec.version>2.0</spec.version>
<json.api.version>2.0.1-SNAPSHOT</json.api.version>
<jsonp.impl.version>${project.version}</jsonp.impl.version>
</properties>

<dependencies>
<dependency>
<groupId>jakarta.json</groupId>
<artifactId>jakarta.json-api</artifactId>
<version>${json.api.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jsonp</groupId>
<artifactId>jsonp</artifactId>
<version>${jsonp.impl.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi.core</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.framework</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.eventadmin</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam-junit4</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam-container-forked</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam-link-mvn</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ops4j.pax.url</groupId>
<artifactId>pax-url-aether</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<scope>test</scope>
</dependency>

<!-- Used in feature.xml and in tests-->
<dependency>
<groupId>org.apache.aries.spifly</groupId>
<artifactId>org.apache.aries.spifly.dynamic.bundle</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-all</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.aries</groupId>
<artifactId>org.apache.aries.util</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>maven-paxexam-plugin</artifactId>
<executions>
<execution>
<id>generate-config</id>
<goals>
<goal>generate-depends-file</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<id>integration-tests</id>
<phase>verify</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<includes>
<include>**/*IT.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.glassfish.build</groupId>
<artifactId>spec-version-maven-plugin</artifactId>
<configuration>
<spec>
<nonFinal>${non.final}</nonFinal>
<jarType>api</jarType>
<specVersion>${spec.version}</specVersion>
<specImplVersion>${project.version}</specImplVersion>
<apiPackage>${project.artifactId}</apiPackage>
</spec>
</configuration>
<executions>
<execution>
<goals>
<goal>set-spec-properties</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<executions>
<execution>
<id>main-artifact-module</id>
<goals>
<goal>bundle</goal>
</goals>
<configuration>
<instructions>
<Bundle-Activator>org.eclipse.jsondemos.osgi.jsonpointer.JsonpointerOsgiDemo
</Bundle-Activator>
<Bundle-Version>${spec.bundle.version}</Bundle-Version>
<Bundle-SymbolicName>${spec.bundle.symbolic-name}</Bundle-SymbolicName>
<Include-Resource>{maven-resources},target/classes/module-info.class</Include-Resource>
</instructions>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.karaf.tooling</groupId>
<artifactId>karaf-maven-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<startLevel>80</startLevel>
<aggregateFeatures>false</aggregateFeatures>
<includeProjectArtifact>true</includeProjectArtifact>
<primaryFeatureName>${karaf.feature.name}</primaryFeatureName>
</configuration>
<executions>
<execution>
<id>generate-features-file</id>
<phase>package</phase>
<goals>
<goal>features-generate-descriptor</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
25 changes: 25 additions & 0 deletions demos/jsonpointer-osgi/src/main/feature/feature.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!--

Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved.

This program and the accompanying materials are made available under the
terms of the Eclipse Distribution License v. 1.0, which is available at
http://www.eclipse.org/org/documents/edl-v10.php.

SPDX-License-Identifier: BSD-3-Clause

-->

<!--Use for Karaf-->
<features>
<feature name="jsondemos-jsonpointer-osgi">
<bundle start-level="51">mvn:jakarta.json/jakarta.json-api/${project.version}</bundle>
<bundle start-level="51">mvn:org.eclipse.jsonp/jsonp/${project.version}</bundle>
<!-- Next 3 bundles are necessary for discovering and loading implementations matching a given interface (Java SPI), that used by jakarta.json-api-->
<bundle start-level="50">mvn:org.apache.aries.spifly/org.apache.aries.spifly.dynamic.bundle/${spifly.version}
</bundle>
<bundle start-level="50">mvn:org.ow2.asm/asm-all/${asm.all.version}</bundle>
<bundle start-level="50">mvn:org.apache.aries/org.apache.aries.util/${aries.util.version}</bundle>
</feature>
</features>
14 changes: 14 additions & 0 deletions demos/jsonpointer-osgi/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
*/

module org.eclipse.jsondemos.osgi.jsonpointer {
requires jakarta.json;
requires osgi.core;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
*/

package org.eclipse.jsondemos.osgi.jsonpointer;

import jakarta.json.JsonObject;

/**
* Implementation of this interface will be registered in OSGI container as a service.
*/
public interface JsonPointerService {

JsonObject read(String pathToResource);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
*/

package org.eclipse.jsondemos.osgi.jsonpointer;

import jakarta.json.Json;
import jakarta.json.JsonObject;
import jakarta.json.JsonReader;

import java.io.IOException;
import java.io.InputStream;

/**
* This class will be registered as a service inside an OSGI container and will be available for other bundles.
*/
public class JsonPointerServiceImpl implements JsonPointerService {
@Override
public JsonObject read(String pathToResource) {
try (
InputStream is = JsonpointerOsgiDemo.class.getResourceAsStream("/wiki.json");
JsonReader rdr = Json.createReader(is)
) {
return rdr.readObject();
} catch (IOException e) {
return null;
}
}
}
Loading