jakartaee / mail-api

Jakarta Mail Specification project
https://jakartaee.github.io/mail-api
Other
242 stars 100 forks source link

Using service loader mediator annotations (see #630). #632

Closed mnlipp closed 1 year ago

mnlipp commented 1 year ago

Shows the usage of the service locator mediator with annotations that generate the "Require-Capability" header in MANIFEST.MF. (Alternatively the Header can be specified directly in pom.xml.)

The Providers (in angus-mail) need a corresponding @ServiceProvider annotation such as:

@aQute.bnd.annotation.spi.ServiceProvider(value = StreamProvider.class)
public class MailStreamProvider implements StreamProvider {

(Sorry, can't provide a PR for that, maven compilation for angus-mail doesn't work.)

jbescos commented 1 year ago

Thank you for the PR.

The solution looks nice, as it very easily deal with OSGi.

I am curious to know how adding some depenencies it is able to modify the MANIFEST.MF. I guess maven-bundle-plugin:5.1.1:manifest is detecting these dependencies and it is delegating on them.

The only thing that I don't like is that if you decompile Session or StreamProvider, you are going to find the ServiceConsumer annotation, and also in the module-info. As this is only needed to generate the manfest, it looks too intrusive to find it in the generated jar.

Ideally there should be a plugin to deal with the manifest. Something like this:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-osgi-plugin</artifactId>
    <configuration>
        <jakarta.mail.util.StreamProvider>jakarta.mail.Provider</jakarta.mail.util.StreamProvider>
        <jakarta.mail.util.StreamProvider>jakarta.mail.util.StreamProvider</jakarta.mail.util.StreamProvider>
    </configuration>
</plugin>

I bring the attention of @lukasj. He has been dealing with OSGi more time than me, in other words, he knows more than me :).

mnlipp commented 1 year ago

Ideally there should be a plugin to deal with the manifest.

You don't need an extra plugin. You can simply add this information using the Felix maven bundle plugin which is already in pom.xml with instructions <Provide-Capability> and <Require-Capability> (that's doing it "manually", see https://github.com/jakartaee/mail-api/issues/630#issuecomment-1287852918). In general, the manual approach is considered a bit more difficult to maintain, but once it's there, it rarely changes (only if you add another loaded service).

If it helps, I can provide another PR with the pom.xml based solution.

mnlipp commented 1 year ago

It is currently not allowed to depend on 3rd party libraries from APIs

This is why this has actually been superseded by https://github.com/jakartaee/mail-api/pull/633.

lukasj commented 1 year ago

so this should have been closed then