Class OsgiUtils


  • public class OsgiUtils
    extends Object
    This util helps plugins to do shady things directly with OSGi.
    Since:
    7.0.1
    • Constructor Detail

      • OsgiUtils

        public OsgiUtils()
    • Method Detail

      • findApplicationContextInOsgiBundle

        public static Optional<Object> findApplicationContextInOsgiBundle​(com.atlassian.plugin.Plugin plugin)
        HACK Grab the bean with a name matching the jobKey from the target plugin's. Ideally, we'd be loading an OSGi ServiceReference by name, but that won't work for us here, due to spring-scanner not supporting adding custom properties, and OSGi not having named service instances by default. Sigh DO NOT DO WHAT I HAVE DONE :(

        The reason why this method returns Optional<Object> instead of Optional<ApplicationContext> is to avoid class casting errors between different classloaders, e.g.

        java.lang.ClassCastException: org.springframework.osgi.atlassian.NonValidatingOsgiBundleXmlApplicationContext cannot be cast to org.springframework.context.ApplicationContext