Update to latest connect API
11 files changed
tree: 9e35a06f32d070f7305a8092850fbca2ac1189aa
  1. .github/
  2. .mvn/
  3. atomos.examples/
  4. atomos.framework/
  5. atomos.osgi.frameworks/
  6. atomos.substrate.config/
  7. atomos.tests/
  8. .gitattributes
  9. .gitignore
  10. LICENSE
  11. mvnw
  12. mvnw.cmd
  13. pom.xml
  14. README.md
README.md

Atomos Gitter chat

Atomos - A Java Module Framework using OSGi Connect

Atomos requires an OSGi Framework implementation which supports OSGi Connect initially described in this OSGi blog post. The OSGi Connect specification is currently being developed as an RFC with the OSGi Alliance and the current version of the RFC can be found here.

Currently a snapshot of the Equinox OSGi Framework is being used that implements the proposed OSGi Connect specification for an upcoming OSGi R8 Core specification. Source for the snapshot is found in https://git.eclipse.org/c/equinox/rt.equinox.framework.git in the osgiR8 branch and temporary binaries are pushed to https://github.com/tjwatson/atomos-temp-m2repo for Atomos. Similarly a snapshot of the Felix OSGi Framework is being used which also implements the OSGi Connect specification. This snapshot is also pushed to https://github.com/tjwatson/atomos-temp-m2repo for Atomos.

Atomos is an implementation of an OSGi Connect Framework that can be used to create an OSGi Framework instance. Framework instances created with Atomos add support to the OSGi Framework that enables bundles to be installed which are managed outside of the OSGi Framework module layer. Currently Atomos supports three different modes for loading bundles from outside the OSGi module layer:

  1. Module Path: Using the Java Platform Module System (JPMS) Atomos will discover the modules on the module path and will make any OSGi bundles found available for installation into the Framework. This also allows for Atomos and a set of OSGi bundles to be packaged into a jlink image resulting in a small fit-for-purpose JVM
  2. Class Path: When loaded from the class path Atomos will discover the JARs on the class path and will make any OSGi bundles found available for installation into the Framework.
  3. Graal Substrate Native Image: When compiled into a Substrate native image Atomos will discover the bundles that were included into the image. This requires configuration to enable the necessary reflection for things like bundle activators and declarative service components.

Build

Java 11 must be used to build Atomos. Atomos build uses the latest 1.0.0.Beta2 version of the moditect plugin (https://github.com/moditect/moditect.git).
This plugin provides some cool utilities for adding module-infos to existing dependency JARs and building jlink images. You can build the Atomos with the following:

./mvnw clean install -Pjava8 -Pequinox

Or if you want to use the Felix Framework

./mvnw clean install -Pjava8 -Pfelix

This should create a jlink image under atomos/atomos.examples/atomos.examples.jlink/target/atomos. Executing the following command against the jlink image should produce a gogo shell prompt:

./bin/atomos

You should see the following output:

Registered Echo service from activator.
____________________________
Welcome to Apache Felix Gogo

g! 

In order to successfully build a jlink image all bundles included in the image must contain a module-info.class, they cannot be automatic modules. The atomos/atomos.examples/atomos.examples.jlink example uses the latest 1.0.0.Beta2 version of the moditect-maven-plugin to add module-info.class as necessary to the bundles used in the image.

You can also load additional modules into atomos at:

  • System start by using the atomos.modules option when launching atomos. For example:
atomos/bin/atomos atomos.modules=/path/to/more/modules
  • Runtime by using the gogo command atomos:install For example:
atomos:install MyLayerName OSGI /path/to/more/modules

When doing that the additional modules will be loaded into a child layer where the Atomos OSGi Framework will control the class loaders. This will produce a class loader per module bundle installed. This has advantages because it allows the module class loader for the bundle to implement the org.osgi.framework.BundleReference interface.

Substrate

There are two examples projects that build native images using Graal Substrate:

  1. atomos/atomos.examples/atomos.examples.substrate.equinox - Using Eclipse Equinox Framework
  2. atomos/atomos.examples/atomos.examples.substrate.felix - Using Apache Felix Framework

These two example projects are not built as part of the main Atomos build because they require an installation of GraalVM CE 19.3.1 (Java 8 or Java 11 can be used) and the native-image tools for Substrate. The Java 11 version of Graal Substrate does not currently support full introspection at image runtime of the Java Platform Module System. Atomos Module support expects to have full introspection of the Java Platform Module System when running on Java versions greater than Java 8. Therefore the example will run in basic class path mode for both Java 8 and Java 11 when running with a native substrate image.

To build the native image you must install the native image support for Graal (see https://www.graalvm.org/docs/reference-manual/native-image/). You need to run the gu command that comes with Graal VM:

gu install native-image

If you are using GraalVM CE 19.3.1 Java 11 then you can build all of Atomos, including the substrate examples for Equinox and Felix, with the following single maven build using the substrate profile:

./mvnw clean install -Pjava8 -Psubstrate -Pequinox

If using GraalVM CE 19.3.1 Java 8 then you must first use Java 11 for the main Atomos build using the Java 8 profile:

./mvnw clean install -Pjava8 -Pequinox

Note that install target must be used so that Atomos is installed into your local m2 repository. This still requires Java 11 to be used to build but the result allows the atomos.framework JAR to be used on Java 8. Next you must switch to a Java installation of Graal with the Substrate native-image tools installed and then run the following maven builds:

./mvnw clean install -Pjava8 -f atomos.examples/atomos.examples.substrate.equinox/pom.xml

./mvnw clean install -Pjava8 -f atomos.examples/atomos.examples.substrate.felix/pom.xml

This will create a target/atomos executable in each substrate example project. If you launch atomos it will give you a gogo g! prompt to run gogo commands. Also included in this example is a version of the Felix web console. The web console can be access with http://localhost:8080/system/console/bundles and the id/password is admin/admin.

For the Felix example a directory target/substrate_lib/ is created. This contains all the original bundle JARs that got compiled into the native image atomos. In order to launch the native atomos you must be in the directory containing both atomos and the substrate_lib/ folder. This is a simple way for Atomos to discover the available bundlesand load additional bundle entries at runtime.

For the Equinox example the directory target/substrate_lib/ is not used. Instead the bundle entry resources are placed in an atomos/ folder which is placed on the classpath during native image compilation. The resources from the atomos/ folder are then included in the native image. The atomos/ folder has a file bundles.index that contains information for Atomos to discover the bundles and their entries that are included in the native image.

Hopefully substrate will add full introspection to the Java Platform Module System in the future which would allow Atomos to discover the modules within the image and load them as bundles. If a proper module reader could be obtained and contain the necessary resources from the original bundle JARs then it would eliminate the need for the substrate_lib/ or atomos/ resource folder.