void checkCorrectlyInstalled(OsgiBundleWithUrl bundle, Bundle b) { String nv = b.getSymbolicName()+":"+b.getVersion().toString(); if (!isBundleNameEqualOrAbsent(bundle, b)) { throw new IllegalStateException("Bundle already installed as "+nv+" but user explicitly requested "+bundle); } List<Bundle> matches = Osgis.bundleFinder(framework) .symbolicName(b.getSymbolicName()) .version(b.getVersion().toString()) .findAll(); if (matches.isEmpty()) { log.error("OSGi could not find bundle "+nv+" in search after installing it from "+bundle); } else if (matches.size()==1) { log.debug("Bundle from "+bundle.getUrl()+" successfully installed as " + nv + " ("+b+")"); } else { log.warn("OSGi has multiple bundles matching "+nv+", when installing "+bundle+"; not guaranteed which versions will be consumed"); // TODO for snapshot versions we should indicate which one is best to use } }
/** @deprecated since 0.7.0 use {@link #bundleFinder(Framework)} */ @Deprecated public static Maybe<Bundle> getBundle(Framework framework, String symbolicName, Version version) { return bundleFinder(framework).symbolicName(symbolicName).version(Predicates.equalTo(version)).findUnique(); }
/** @deprecated since 0.7.0 use {@link #bundleFinder(Framework)} */ @Deprecated public static List<Bundle> getBundlesByName(Framework framework, String symbolicName, Predicate<Version> versionMatcher) { return bundleFinder(framework).symbolicName(symbolicName).version(versionMatcher).findAll(); }
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).symbolicName(suppliedKnownBundleMetadata.getSymbolicName()).version(suppliedKnownBundleMetadata.getSuppliedVersionString()).find();
.version(TEST_VERSION) .preferringFromUrl(BROOKLYN_TEST_MORE_ENTITIES_V2_EVIL_TWIN_URL).find(); Assert.assertTrue(versionIgnoresInvalidPreferredUrl.isPresent()); .version(TEST_VERSION) .requiringFromUrl(BROOKLYN_TEST_MORE_ENTITIES_V2_EVIL_TWIN_URL).find(); Assert.assertFalse(versionRespectsInvalidRequiredUrl.isPresent());
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");
List<Bundle> result = Osgis.bundleFinder(framework) .symbolicName("mybundle") .version("[1.0.0, 1.1.0)") .findAll(); assertEquals(result, ImmutableList.of(myBundle1_0_0)); .version("[1.0.0, 2.0.0)") .findAll(); assertEquals(result2, ImmutableList.of(myBundle1_0_0, myBundle1_1_0)); .version("[1.0.0, 2.0.0]") .findAll(); assertEquals(result3, ImmutableList.of(myBundle1_0_0, myBundle1_1_0, myBundle2_0_0)); .version("[2.0.0, 3.0.0)") .findAll(); assertEquals(result4, ImmutableList.of(myBundle2_0_0_snapshot, myBundle2_0_0)); .version("[1.0.0, 2.0.0)") .findAll(); assertEquals(result5, ImmutableList.of(snapshotBundle1_0_0_snapshot));
if (mb!=null) { bundleFinder.requiringFromUrl(null); bundleFinder.symbolicName(mb.getSymbolicName()).version(mb.getSuppliedVersionString()); result = bundleFinder.find(); if (result.isPresent()) { bundleFinder.symbolicName(catalogBundle.getSymbolicName()).version(catalogBundle.getSuppliedVersionString()); return bundleFinder.find();
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); } }
@SuppressWarnings("deprecation") @Test public void testInstallBundle() throws Exception { Map<String, String> manifest = ImmutableMap.of( Attributes.Name.MANIFEST_VERSION.toString(), "1.2.3", Constants.BUNDLE_VERSION, "4.5.6", Constants.BUNDLE_SYMBOLICNAME, "myname"); generatedJar = bundleMaker.copyAddingManifest(emptyJar, manifest); Bundle bundle = bundleMaker.installBundle(generatedJar, false); assertEquals(bundle.getSymbolicName(), "myname"); assertEquals(bundle.getVersion(), new Version("4.5.6")); // Confirm it really is installed in the management context's OSGi framework Bundle bundle2 = Osgis.bundleFinder(mgmt.getOsgiManager().get().getFramework()) .symbolicName("myname") .version("4.5.6") .findUnique() .get(); assertEquals(bundle2, bundle); }
/** @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(); }
@Test public void testFindAllByNameAndVersion() throws Exception { List<Bundle> result = Osgis.bundleFinder(framework) .symbolicName("mybundle") .version("1.0.0") .findAll(); assertEquals(result, ImmutableList.of(myBundle1_0_0)); }
public BundleFinder bundle(CatalogBundle bundle) { if (bundle.isNameResolved()) { symbolicName(bundle.getSymbolicName()); version(bundle.getSuppliedVersionString()); } if (bundle.getUrl() != null) { requiringFromUrl(bundle.getUrl()); } return this; }
private BundleFinder id(VersionedName nv) { symbolicName(nv.getSymbolicName()); if (nv.getVersionString() != null) { version(nv.getVersionString()); } return this; }
@Test public void testFindByNameAndVersion() throws Exception { Bundle result = Osgis.bundleFinder(framework) .symbolicName("mybundle") .version("1.0.0") .find() .get(); assertEquals(result, myBundle1_0_0); }