Re: Optional Module Dependency

Emilian Bold <[email protected]> Sat, 11 Nov 2017 18:23:57 +0200
Newsgroups gmane.comp.java.netbeans.modules.openide.devel
Message-ID <CAL6R17AfJipvuj_veVka=_PRNnGuY3JLveccaRotwSUKb0RQOQ@mail.gmail.com>
Cobus, please use the [email protected] mailing list
as this one is going away.

The whole point of the module system is you don't get (or have to
handle yourself) NoClassDefFoundError. So, wanting something like

try { ModBClass  foo = new  ModBClass();}
catch (NoClassDefFoundError) ...

is... not good.

What you want is to Lookup a given service and maybe get a null. So,
the problem is how to get a service for that.

Look into creating an eager (bridge) module which depends on module B
and implements a Service (defined in module A or another module). Then
lookup your service and handle the null.

BTW: OpenIDE-Module-Provides/OpenIDE-Module-Requires/OpenIDE-Module-Needs/OpenIDE-Module-Recommends
work on *tokens* not classes. It's unfortunate that a popular NetBeans
Platform book uses class names instead of tokens since it leads people
to believe these manifest tags are for something else.


--emi


On Tue, Nov 7, 2017 at 6:02 PM, cobusve <[email protected]> wrote:
> Yes I did consider the service provider, but since the other module is not
> under my control that option does not work, as I would have to convince the
> vendor to ship their interface as a separate module.
>
> What you describe with the SystemClass Loader is exactly what I did to make
> it work using reflection, but I generally try to avoid reflection like the
> plague.
>
> I was hoping that I was missing some secret sauce, that I am just not using
> OpenIDE-Module-Recommends  correctly, because from the description that is
> exactly what I need.
>
> From the Modules API documentation "Moreover there is also
> OpenIDE-Module-Recommends which is even weaker version as it creates a
> conditional dependency - e.g. enables the module providing the token only if
> it is available, however if it is not, no dependency is broken."
>
> So this seemed like it will do exactly what I need - load the dependency
> when it exists and continue if it does not, and it does this when installing
> the module, but when you activate the module it fails activation, which gets
> me only halfway. If only the activation also paid attention to the
> OpenIDE-Module-Recommends ?
>
>
>
> --
> Sent from: http://netbeans-org.1045718.n5.nabble.com/Netbeans-RCP-Platform-Users-Open-API-f3018772.html