apache / felix-atomos

Apache Felix Atomos
https://felix.apache.org/
Apache License 2.0
38 stars 19 forks source link

How to use JPMS Automatic Modules? #74

Open RefuX opened 1 year ago

RefuX commented 1 year ago

I'm trying to reference an automatic module bundle, but can't since it has no exports.

If I look at it in Gogo using the headers command:

Atomos-GeneratedManifest = true
Automatic-Module-Name = io.github.oshai.kotlinlogging
Bundle-ManifestVersion = 2
Bundle-SymbolicName = io.github.oshai.kotlinlogging; fragment-attachment:=never
Bundle-Version = 5.1.0
Manifest-Version = 1.0
Require-Bundle = java.base; resolution:=mandatory; visibility:=private

This makes sense from the ModuleLayer API since it states for a ModuleDescriptor: If this module is an automatic module then the set of exports is empty.

It's a bit confusing since most JPMS information states: An automatic module implicitly exports all its packages

So any insights on how to use automatic modules will be greatly appreciated.

tjwatson commented 1 year ago

I don't recall the details of why I didn't add all packages for automatic modules. But I do know the javadoc for ModuleDescriptor.exports states:

If this module is an automatic module then the set of exports is empty.

https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/module/ModuleDescriptor.html#exports()

And that is what is used to generate the OSGi bundle manifest header for exported packages (if the module does not container an OSGi bundle manifest already):

https://github.com/apache/felix-atomos/blob/master/atomos/src/main/java/org/apache/felix/atomos/impl/modules/AtomosModules.java#L530

Would you like to try creating a PR that changes that to check for automatic modules? Something like:

                if (desc.isAutomatic()) {
                    desc.packages().stream().sorted().forEach(p -> {
                        // add p to exportedPackageHeader
                    });
                }
                else
                {
                    // do the normal thing
                }