private void registerExistingBundles() { for (final Bundle bundle : bundleContext.getBundles()) { if (bundle.getState() == Bundle.RESOLVED || bundle.getState() == Bundle.STARTING || bundle.getState() == Bundle.ACTIVE || bundle.getState() == Bundle.STOPPING) { register(bundle); } } }
private void registerExistingBundles() { for (final Bundle bundle : bundleContext.getBundles()) { if (bundle.getState() == Bundle.RESOLVED || bundle.getState() == Bundle.STARTING || bundle.getState() == Bundle.ACTIVE || bundle.getState() == Bundle.STOPPING) { register(bundle); } } }
Class<?> cls = null; Bundle[] bundles = bundle.getBundleContext().getBundles();
/** * Tries to load resource bundle via OSGi means. No caching involved here, * as localization properties are being cached in Localizer class already. * * @param bundleName name of the resource bundle to load * @return resource bundle instance if found, null otherwise */ public ResourceBundle getResourceBundle(final String bundleName) { final int lastDotIndex = bundleName.lastIndexOf('.'); final String path = bundleName.substring(0, lastDotIndex).replace('.', '/'); final String propertiesName = bundleName.substring(lastDotIndex + 1, bundleName.length()) + ".properties"; for (final Bundle bundle : bundleContext.getBundles()) { final Enumeration<URL> entries = findEntries(bundle, path, propertiesName, false); if (entries != null && entries.hasMoreElements()) { final URL entryUrl = entries.nextElement(); try { return new PropertyResourceBundle(entryUrl.openStream()); } catch (final IOException ex) { if (LOGGER.isLoggable(Level.FINE)) { // does not make sense to localize this LOGGER.fine("Exception caught when tried to load resource bundle in OSGi"); } return null; } } } return null; }
/** * Tries to load resource bundle via OSGi means. No caching involved here, * as localization properties are being cached in Localizer class already. * * @param bundleName name of the resource bundle to load * @return resource bundle instance if found, null otherwise */ public ResourceBundle getResourceBundle(final String bundleName) { final int lastDotIndex = bundleName.lastIndexOf('.'); final String path = bundleName.substring(0, lastDotIndex).replace('.', '/'); final String propertiesName = bundleName.substring(lastDotIndex + 1, bundleName.length()) + ".properties"; for (final Bundle bundle : bundleContext.getBundles()) { final Enumeration<URL> entries = findEntries(bundle, path, propertiesName, false); if (entries != null && entries.hasMoreElements()) { final URL entryUrl = entries.nextElement(); try { return new PropertyResourceBundle(entryUrl.openStream()); } catch (final IOException ex) { if (LOGGER.isLoggable(Level.FINE)) { // does not make sense to localize this LOGGER.fine("Exception caught when tried to load resource bundle in OSGi"); } return null; } } } return null; }
@Override public void start(final BundleContext bundleContext) throws Exception { ProviderUtil.STARTUP_LOCK.lock(); lockingProviderUtil = true; final BundleWiring self = bundleContext.getBundle().adapt(BundleWiring.class); final List<BundleWire> required = self.getRequiredWires(LoggerContextFactory.class.getName()); for (final BundleWire wire : required) { loadProvider(bundleContext, wire.getProviderWiring()); } bundleContext.addBundleListener(this); final Bundle[] bundles = bundleContext.getBundles(); for (final Bundle bundle : bundles) { loadProvider(bundle); } unlockIfReady(); }
synchronized (t) { context.addBundleListener(t); Bundle[] bundles = context.getBundles(); if (bundles != null) { int length = bundles.length;
@Override public synchronized void start(BundleContext bundleContext) throws Exception { // This is how we replace the default FactoryFinder strategy // with one that is more compatible in an OSGi env. FactoryFinder.setObjectFactory(this); debug("activating"); this.bundleContext = bundleContext; cachePackageCapabilities(Service.class, Transport.class, DiscoveryAgent.class, PersistenceAdapter.class); debug("checking existing bundles"); bundleContext.addBundleListener(this); for (Bundle bundle : bundleContext.getBundles()) { if (bundle.getState() == Bundle.RESOLVED || bundle.getState() == Bundle.STARTING || bundle.getState() == Bundle.ACTIVE || bundle.getState() == Bundle.STOPPING) { register(bundle); } } debug("activated"); }
private void assertActiveBundle(String symbolicName) { for (Bundle bundle : bundleContext.getBundles()) { if (bundle.getSymbolicName().equals( symbolicName )) { Assert.assertEquals( symbolicName + " was found, but not in an ACTIVE state.", Bundle.ACTIVE, bundle.getState()); return; } } Assert.fail("Could not find bundle: " + symbolicName); } }
final List<URL> result = new LinkedList<URL>(); for (final Bundle bundle : bundleContext.getBundles()) {
final List<URL> result = new LinkedList<URL>(); for (final Bundle bundle : bundleContext.getBundles()) {
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]))); } }
/** * @throws Exception */ @Test public void testAllBundlesActiveAndFeaturesInstalled() throws Exception { // Asssert all bundles except fragments are ACTIVE. for (Bundle b : bundleCtx.getBundles()) { System.out.println(String.format("Checking state of bundle [symbolicName=%s, state=%s]", b.getSymbolicName(), b.getState())); if (b.getHeaders().get(Constants.FRAGMENT_HOST) == null) assertTrue(b.getState() == Bundle.ACTIVE); } // Check that according to the FeaturesService, all Ignite features except ignite-log4j are installed. Feature[] features = featuresSvc.getFeatures(IGNITE_FEATURES_NAME_REGEX); assertNotNull(features); assertEquals(EXPECTED_FEATURES, features.length); for (Feature f : features) { if (IGNORED_FEATURES.contains(f.getName())) continue; boolean installed = featuresSvc.isInstalled(f); System.out.println(String.format("Checking if feature is installed [featureName=%s, installed=%s]", f.getName(), installed)); assertTrue(installed); assertEquals(PROJECT_VERSION.replaceAll("-", "."), f.getVersion().replaceAll("-", ".")); } }
private Bundle getBundle(String bundleSymbolicName) throws InvalidSyntaxException { // Getting all bundles for (Bundle bundle : bundleContext.getBundles()) { if (bundle.getSymbolicName().equals(bundleSymbolicName)) { return bundle; } } throw new RuntimeException("Unable to find bundle " + bundleSymbolicName); }
/** * Method to get all names of installed bundles on * Spring Roo Shell * * @return list with all names of installed bundles */ private List<String> getNamesOfInstalledBundles() { List<String> names = new ArrayList<String>(); // Getting all installed bundles Bundle[] bundles = context.getBundles(); for (Bundle bundle : bundles) { names.add(bundle.getSymbolicName()); } return names; }
protected String getBundleVersion(String pSymbolicName) { BundleContext context = JolokiaServlet.getCurrentBundleContext(); if (context != null) { for (Bundle bundle: context.getBundles()) { if (pSymbolicName.equalsIgnoreCase(bundle.getSymbolicName())) { Dictionary headers = bundle.getHeaders(); return (String) headers.get("Bundle-Version"); } } } return null; }
/** * Method to check if some bundle is installed on OSGi * @param bundle * @return */ private boolean checkIfBundleIsInstalled(ObrBundle bundle) { // Refreshing installed bundles Bundle[] allInstalledBundles = context.getBundles(); // Checking if bundles is installed for (Bundle installedBundle : allInstalledBundles) { if (installedBundle.getSymbolicName().equals(bundle.getSymbolicName())) { return true; } } return false; }
/** * Executes the given callback on any bundles in the given context * * @param callback can be <code>null</code> to do nothing * @param context can be <code>null</code> to do nothing */ public static void execute(final BundleCallback callback, final BundleContext context) { if (callback == null || context == null) { return; } final Bundle[] bundles = context.getBundles(); if (bundles == null) { return; } for (final Bundle bundle : bundles) { callback.execute(bundle); } }