@Override protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { int separator = name.indexOf(":"); if (separator>=0) { Bundle bundle = Osgis.bundleFinder(framework).symbolicName(name.substring(0, separator)).find().get(); return bundle.loadClass(name.substring(separator+1)); } else { return super.loadClass(name, resolve); } } }
/** * Tries to find a bundle in the given framework with name matching either `name' or `name:version'. * @deprecated since 0.7.0 use {@link #bundleFinder(Framework)} */ @Deprecated public static Maybe<Bundle> getBundle(Framework framework, String symbolicNameOptionallyWithVersion) { return bundleFinder(framework).id(symbolicNameOptionallyWithVersion).find(); }
@Override protected Class<?> findClass(String name) throws ClassNotFoundException { int separator = name.indexOf(":"); if (separator>=0) { Bundle bundle = Osgis.bundleFinder(framework).symbolicName(name.substring(0, separator)).find().get(); return bundle.loadClass(name.substring(separator+1)); } else { return super.findClass(name); } }
result.metadata = inferredMetadata; Maybe<Bundle> b = Osgis.bundleFinder(osgiManager.framework).symbolicName(result.getMetadata().getSymbolicName()).version(result.getMetadata().getSuppliedVersionString()).find(); if (b.isPresent()) {
installedBundle = Osgis.bundleFinder(osgiManager.framework).requiringFromUrl(suppliedKnownBundleMetadata.getOsgiUniqueUrl()).find(); installedBundle = Osgis.bundleFinder(osgiManager.framework).requiringFromUrl(suppliedKnownBundleMetadata.getUrl()).find(); installedBundle = Osgis.bundleFinder(osgiManager.framework).symbolicName(suppliedKnownBundleMetadata.getSymbolicName()).version(suppliedKnownBundleMetadata.getSuppliedVersionString()).find();
.symbolicName(OsgiTestResources.BROOKLYN_TEST_MORE_ENTITIES_SYMBOLIC_NAME_FULL).find(); Assert.assertTrue(preferredVersion.isPresent()); Assert.assertEquals(preferredVersion.get().getVersion().toString(), "0.2.0"); preferringFromUrl(BROOKLYN_TEST_MORE_ENTITIES_V2_EVIL_TWIN_URL).find(); Assert.assertTrue(evilVersion.isPresent()); Assert.assertEquals(evilVersion.get().getVersion().toString(), "0.2.0"); .symbolicName(OsgiTestResources.BROOKLYN_TEST_MORE_ENTITIES_SYMBOLIC_NAME_FULL) .version(TEST_VERSION) .preferringFromUrl(BROOKLYN_TEST_MORE_ENTITIES_V2_EVIL_TWIN_URL).find(); Assert.assertTrue(versionIgnoresInvalidPreferredUrl.isPresent()); Assert.assertEquals(versionIgnoresInvalidPreferredUrl.get().getVersion().toString(), TEST_VERSION); .symbolicName(OsgiTestResources.BROOKLYN_TEST_MORE_ENTITIES_SYMBOLIC_NAME_FULL) .version(TEST_VERSION) .requiringFromUrl(BROOKLYN_TEST_MORE_ENTITIES_V2_EVIL_TWIN_URL).find(); Assert.assertFalse(versionRespectsInvalidRequiredUrl.isPresent());
BundleFinder bundleFinder = Osgis.bundleFinder(framework); bundleFinder.requiringFromUrl(catalogBundle.getUrl()); result = bundleFinder.find(); if (result.isPresent()) { return result; bundleFinder.requiringFromUrl(null); bundleFinder.symbolicName(mb.getSymbolicName()).version(mb.getSuppliedVersionString()); result = bundleFinder.find(); if (result.isPresent()) { return result; BundleFinder bundleFinder = Osgis.bundleFinder(framework); bundleFinder.symbolicName(catalogBundle.getSymbolicName()).version(catalogBundle.getSuppliedVersionString()); return bundleFinder.find();
String bundleUrl = bundleMetadata.getUrl(); if (bundleUrl != null) { Maybe<Bundle> installedBundle = Osgis.bundleFinder(framework).requiringFromUrl(bundleUrl).find(); if (installedBundle.isPresent()) { Bundle b = installedBundle.get(); Maybe<Bundle> installedBundle; if (bundleMetadata.isNameResolved()) { installedBundle = Osgis.bundleFinder(framework).symbolicName(bundleMetadata.getSymbolicName()).version(bundleMetadata.getSuppliedVersionString()).find(); } else { installedBundle = Maybe.absent("Bundle metadata does not have URL nor does it have both name and version");
protected <T> Maybe<T> tryLoadFromBundle(LoaderDispatcher<T> dispatcher, String symbolicName, String version, String name) { Framework framework = getFramework(); if (framework != null) { Maybe<Bundle> bundle = Osgis.bundleFinder(framework) .symbolicName(symbolicName) .version(version) .find(); if (bundle.isAbsent()) { throw new IllegalStateException("Bundle " + toBundleString(symbolicName, version) + " not found to load " + name); } return dispatcher.tryLoadFrom(bundle.get(), name); } else { log.warn("Request for bundle '"+symbolicName+"' "+(Strings.isNonBlank(version) ? "("+version+") " : "")+"will be ignored as no framework available; will look for '"+name+"' in plain old classpath"); return dispatcher.tryLoadFrom(classLoader, name); } }
/** @deprecated since 0.7.0 use {@link #bundleFinder(Framework)} */ @Deprecated public static Maybe<Bundle> getBundle(Framework framework, String symbolicName, String version) { return bundleFinder(framework).symbolicName(symbolicName).version(version).find(); }
private Bundle getBundle(ManagementContext mgmt, final String symbolicName) throws Exception { OsgiManager osgiManager = ((ManagementContextInternal)mgmt).getOsgiManager().get(); Framework framework = osgiManager.getFramework(); Maybe<Bundle> result = Osgis.bundleFinder(framework) .symbolicName(symbolicName) .find(); return result.get(); }
private Bundle getBundle(ManagementContext mgmt, final String symbolicName) throws Exception { OsgiManager osgiManager = ((ManagementContextInternal)mgmt).getOsgiManager().get(); Framework framework = osgiManager.getFramework(); Maybe<Bundle> result = Osgis.bundleFinder(framework) .symbolicName(symbolicName) .find(); return result.get(); }
@Test public void testFindByNameAndVersion() throws Exception { Bundle result = Osgis.bundleFinder(framework) .symbolicName("mybundle") .version("1.0.0") .find() .get(); assertEquals(result, myBundle1_0_0); }
private Bundle getBundle(ManagementContext mgmt, final String symbolicName) throws Exception { OsgiManager osgiManager = ((ManagementContextInternal)mgmt).getOsgiManager().get(); Framework framework = osgiManager.getFramework(); Maybe<Bundle> result = Osgis.bundleFinder(framework) .symbolicName(symbolicName) .find(); return result.get(); }