osgi
osgi copied to clipboard
Enhance Resolver Service with SPI Support
Enables obtaining resolver instances outside OSGi frameworks using Java SPI, similar to FrameworkFactory
Problem
Resolvers are needed in many scenarios before/outside OSGi:
- Framework initialization
- Build tools (Maven, Gradle, bnd)
- IDEs analyzing dependencies
- Provisioning tools
- Feature launchers
Currently requires referencing specific implementation classes.
Solution
New ResolverFactory interface using Java Service Provider mechanism, plus osgi.resolver.class framework property for resolver selection.
Changes
- ResolverFactory.java: New interface for creating resolvers
-
Constants.java: Added
FRAMEWORK_RESOLVER_CLASSconstant - service.resolver.xml: New "Obtaining Resolvers Outside OSGi" section
-
framework.lifecycle.xml: Added
osgi.resolver.classproperty documentation
Usage
ServiceLoader<ResolverFactory> loader =
ServiceLoader.load(ResolverFactory.class);
Resolver resolver = loader.findFirst()
.map(ResolverFactory::getResolver)
.orElseThrow();
Benefits
- Standard, discoverable way to obtain resolvers
- Frameworks expose resolvers for tooling
- Same resolution algorithm in dev and runtime
- Pluggable resolver implementations
- Optional logging for debugging
@tjwatson I (hopefully) addressed your review comments now that is:
- Using Resolver as the SPI interface directly, no factory
- Removing any changes in the core spec, focus on Resolver spec only.