@Override public void start(BundleContext context) { logErrors = Boolean.parseBoolean(context.getProperty("osgi.jpms.layer.log.errors")); // Check that the launcher created a layer for the framework Module systemModule = context.getClass().getModule(); if (!Constants.SYSTEM_BUNDLE_SYMBOLICNAME.equals(systemModule.getName())) { throw new IllegalStateException("The framework launcher has not setup the system.bundle module for the framework implementation: " + getClass().getModule()); } logService = new ServiceTracker<>(context, LOG_SERVICE, null); logService.open(); // Create the LayerFactory implementation and register it factory = new LayerFactoryImpl(this, context, systemModule); // The factory is a bundle listener to keep track of resolved bundles context.addBundleListener(factory); // The factory is also a WovenClassListener to intercept bundle class loaders before // they define any classes. This is to ensure they are part of a layer before the // first class is defined. String[] serviceClasses = new String[] {LayerFactory.class.getName(), WovenClassListener.class.getName(), WeavingHook.class.getName()}; factoryReg = context.registerService(serviceClasses, factory, null); }
/** * ARIES-1019: Register with the highest possible service ranking to * avoid ClassNotFoundException caused by interfaces added by earlier * weaving hooks that are not yet visible to the bundle class loader. */ private void registerWeavingHook(BundleContext context, TransformerRegistry tr) { Dictionary<String, Object> props = new Hashtable<String, Object>(1); // NOSONAR props.put(Constants.SERVICE_RANKING, Integer.MAX_VALUE); context.registerService(WeavingHook.class.getName(), tr, props); }
private void registerOSGiHooks() { bundleContext.registerService(WeavingHook.class, new ValidationWeavingHook(), new Hashtable<>()); }
@Override public void start(BundleContext context) { LoadingHook hook = new LoadingHook(context); context.registerService(WeavingHook.class, hook, null); }
@Activate void activate(BundleContext context, Map<String, Object> props) throws Exception { this.context = context; config = Converter.cnv(Config.class, props); // // The Transformers hook enables weaving in OSGi // Every persistence unit will register itself with // the transformers hook. Order is important, once // the bundle tracker is called, the transformers // will be registered so do not move this method lower. // transformersHook = new TransformersHook(getImports(persistenceProvider)); context.registerService(WeavingHook.class, transformersHook, null); // // Track bundles with persistence units. // bundles = new BundleTracker<PersistentBundle>(context, Bundle.ACTIVE + Bundle.STARTING, null) { @Override public PersistentBundle addingBundle(Bundle bundle, BundleEvent event) { try { // // Parse any persistence units, returns null (not tracked) // when there is no PU // return parse(bundle); } catch (Exception e) { e.printStackTrace(); log.bundleParseException(bundle, e); return null; } } @Override public void removedBundle(Bundle bundle, BundleEvent event, PersistentBundle put) { put.close(); } }; bundles.open(); }