private void loadProvider(final BundleContext bundleContext, final BundleWiring bundleWiring) { final String filter = "(APIVersion>=2.6.0)"; try { final Collection<ServiceReference<Provider>> serviceReferences = bundleContext.getServiceReferences(Provider.class, filter); Provider maxProvider = null; for (final ServiceReference<Provider> serviceReference : serviceReferences) { final Provider provider = bundleContext.getService(serviceReference); if (maxProvider == null || provider.getPriority() > maxProvider.getPriority()) { maxProvider = provider; } } if (maxProvider != null) { ProviderUtil.addProvider(maxProvider); } } catch (final InvalidSyntaxException ex) { LOGGER.error("Invalid service filter: " + filter, ex); } final List<URL> urls = bundleWiring.findEntries("META-INF", "log4j-provider.properties", 0); for (final URL url : urls) { ProviderUtil.loadProvider(url, bundleWiring.getClassLoader()); } }
public static void testAllServicesAreAvailable() { Set<String> osgiAvailableClasses = stream(spliterator(OsgiServiceLoader.load(ServiceFactory.class).iterator(), Long.MAX_VALUE, 0), false) .map(f -> f.getClass().getName()) .collect(toSet()); Set<String> jdkAvailableClasses = of(EhcacheActivator.getCoreBundle().getBundles()) .map(b -> b.adapt(BundleWiring.class).getClassLoader()) .flatMap(cl -> stream(spliterator(ServiceLoader.load(ServiceFactory.class, cl).iterator(), Long.MAX_VALUE, 0), false) .map(f -> f.getClass().getName())) .collect(toSet()); assertThat(osgiAvailableClasses, hasItems(jdkAvailableClasses.toArray(new String[0]))); }
public static void testAllServicesAreAvailable() { Set<String> osgiAvailableClasses = stream(spliterator(OsgiServiceLoader.load(ServiceFactory.class).iterator(), Long.MAX_VALUE, 0), false) .map(f -> f.getClass().getName()) .collect(toSet()); Set<String> jdkAvailableClasses = of(EhcacheActivator.getCoreBundle().getBundles()) .map(b -> b.adapt(BundleWiring.class).getClassLoader()) .flatMap(cl -> stream(spliterator(ServiceLoader.load(ServiceFactory.class, cl).iterator(), Long.MAX_VALUE, 0), false) .map(f -> f.getClass().getName())) .collect(toSet()); assertThat(osgiAvailableClasses, hasItems(jdkAvailableClasses.toArray(new String[0]))); } }
public static void testAllServicesAreAvailable() { Set<String> osgiAvailableClasses = stream(spliterator(OsgiServiceLoader.load(ServiceFactory.class).iterator(), Long.MAX_VALUE, 0), false) .map(f -> f.getClass().getName()) .collect(toSet()); Set<String> jdkAvailableClasses = of(EhcacheActivator.getCoreBundle().getBundles()) .map(b -> b.adapt(BundleWiring.class).getClassLoader()) .flatMap(cl -> stream(spliterator(ServiceLoader.load(ServiceFactory.class, cl).iterator(), Long.MAX_VALUE, 0), false) .map(f -> f.getClass().getName())) .collect(toSet()); assertThat(osgiAvailableClasses, hasItems(jdkAvailableClasses.toArray(new String[0]))); } }
BundleWiring bundleWiring = context.getBundle().adapt(BundleWiring.class); ClassLoader bundleClassLoader = bundleWiring.getClassLoader(); Thread currentThread = Thread.currentThread(); ClassLoader originalCl = currentThread.getContextClassLoader() currentThread.setContectClassLoader(bundleClassLoader); try { System.err.println("Shiro : " + ClassUtils.forName("com.firm.demo.MyCustomClass")); } finally { currentThread.setContextClassLoader(originalCl); }
public ModuleApplicationContextRegistrator( Bundle extendeeBundle, Bundle extenderBundle, ServiceConfigurator serviceConfigurator) { _extendeeBundle = extendeeBundle; _extenderBundle = extenderBundle; _serviceConfigurator = serviceConfigurator; BundleWiring bundleWiring = _extendeeBundle.adapt(BundleWiring.class); _extendeeClassLoader = bundleWiring.getClassLoader(); }
private static ClassLoader getClassloader(Bundle bundle) { if (bundle == null) return ProxyClassLoader.class.getClassLoader(); BundleWiring wiring = bundle != null ? bundle.adapt(BundleWiring.class) : null; return wiring != null ? wiring.getClassLoader() : null; }
public PersistenceUnit(Bundle bundle, String persistenceUnitName, PersistenceUnitTransactionType transactionType) { this.bundle = bundle; this.persistenceUnitName = persistenceUnitName; this.transactionType = transactionType; this.props = new Properties(); this.classLoader = bundle.adapt(BundleWiring.class).getClassLoader(); this.classNames = new HashSet<String>(); this.mappingFileNames = new HashSet<String>(); }
@Override public ClassLoader getClassLoader() { return this.bundle.adapt(BundleWiring.class).getClassLoader(); }
@Override public ClassLoader getClassLoader() { return this.bundle.adapt(BundleWiring.class).getClassLoader(); }
public ShimBridgingClassloader( ClassLoader parentClassLoader, BundleContext bundleContext ) { super( parentClassLoader ); this.bundleWiring = (BundleWiring) bundleContext.getBundle().adapt( BundleWiring.class ); this.bundleWiringClassloader = new PublicLoadResolveClassLoader( bundleWiring.getClassLoader() ); }
private static void scanBundleForPlugins(final Bundle bundle) { final long bundleId = bundle.getBundleId(); // LOG4J2-920: don't scan system bundle for plugins if (bundle.getState() == Bundle.ACTIVE && bundleId != 0) { LOGGER.trace("Scanning bundle [{}, id=%d] for plugins.", bundle.getSymbolicName(), bundleId); PluginRegistry.getInstance().loadFromBundle(bundleId, bundle.adapt(BundleWiring.class).getClassLoader()); } }
protected KieContainer resolveKContainer( ReleaseId releaseId ) { if (releaseId == null) { throw new IllegalArgumentException("Cannot resolve a KieContainer using a null ReleaseId"); } if (bundleContext == null) { throw new IllegalStateException("Blueprint 'bundleContext' was not set! It is needed in order to create new KieContainer."); } KieContainer kieContainer = KieServices.Factory.get().newKieContainer( releaseId, bundleContext.getBundle().adapt( BundleWiring.class ).getClassLoader() ); if ( kieContainer == null) { throw new IllegalArgumentException("Could not find a KModule with ReleaseId ("+releaseId+")"); } return kieContainer; }
@Override public ClassLoader getClassLoader(String componentName, String componentVersion, ComponentReference componentReference) { Bundle bundle = getBundle(componentName, componentVersion, componentReference); BundleWiring bundleWiring = bundle.adapt(BundleWiring.class); return bundleWiring.getClassLoader(); }
public boolean isSuperClassWoven(WovenClass wovenClass) { ClassReader cReader = new ClassReader(wovenClass.getBytes()); try { Class<?> superClass = Class.forName(cReader.getSuperName().replace('/', '.'), false, wovenClass.getBundleWiring().getClassLoader()); return WovenProxy.class.isAssignableFrom(superClass); } catch (ClassNotFoundException e) { throw weavingException(wovenClass, e); } }
private static BundleWiring createMockBundleWiring(ClassLoader classLoader) { BundleWiring mockBundleWiring = Mockito.mock(BundleWiring.class); Mockito.when(mockBundleWiring.getClassLoader()).thenReturn(classLoader); return mockBundleWiring; }
public static BundleInfo createBundleInfo(Bundle bundle, Collection<String> classEntries) { BundleInfo bundleInfo = new BundleInfo(bundle.getSymbolicName(), bundle.getVersion(), bundle.getLocation(), webInfUrl(bundle), bundle.adapt(BundleWiring.class).getClassLoader()); bundleInfo.setClassEntries(classEntries); return bundleInfo; }
public RenderContextImpl(ExtensionRegistryService extensionRegistryService, ScriptContext scriptContext) { this.extensionRegistryService = extensionRegistryService; bindings = scriptContext.getBindings(ScriptContext.ENGINE_SCOPE); Bundle scriptProvidingBundle = (Bundle) scriptContext.getAttribute("org.apache.sling.scripting.resolver.provider.bundle", SlingScriptConstants.SLING_SCOPE); if (scriptProvidingBundle != null) { bindings.put("org.apache.sling.scripting.sightly.render_unit.loader", scriptProvidingBundle.adapt(BundleWiring.class).getClassLoader()); } }
private void _cleanInstropectionCaches(Bundle bundle) { BundleWiring bundleWiring = bundle.adapt(BundleWiring.class); CachedIntrospectionResults.clearClassLoader( bundleWiring.getClassLoader()); Introspector.flushCaches(); }
@SuppressWarnings("null") @Override public N load() throws IOException { return ExtendedFXMLLoader.<N, Object> loadWithController(bundle.adapt(BundleWiring.class).getClassLoader(), this.resourceBundle, new ControllerFactory(context), bundleRelativeFxmlPath).getNode(); }