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 } }
protected Maybe<Bundle> findOne(boolean requireExactlyOne) { if (symbolicName==null && url==null) throw new IllegalStateException(this+" must be given either a symbolic name or a URL"); List<Bundle> result = findAll(); if (result.isEmpty()) return Maybe.absent("No bundle matching "+getConstraintsDescription()); if (requireExactlyOne && result.size()>1) return Maybe.absent("Multiple bundles ("+result.size()+") matching "+getConstraintsDescription()); // take the highest version of the first symbolic name alphabetically Bundle r1 = result.get(0); for (int i=1; i<result.size(); i++) { if (result.get(i).getSymbolicName().equals(r1.getSymbolicName())) { r1 = result.get(i); } else { // was in order so no more symbolic names break; } } return Maybe.of(r1); }
@Test public void testFindAllByNameOnly() throws Exception { List<Bundle> result = Osgis.bundleFinder(framework) .symbolicName("mybundle") .findAll(); assertEquals(result, ImmutableList.of(myBundle2_0_0_snapshot, myBundle1_0_0, myBundle1_1_0, myBundle2_0_0)); } }
.symbolicName(OsgiTestResources.BROOKLYN_TEST_MORE_ENTITIES_SYMBOLIC_NAME_FULL).findAll(); Assert.assertEquals(bundles.size(), 3, "Wrong list of bundles: "+bundles);
.symbolicName("mybundle") .version("[1.0.0, 1.1.0)") .findAll(); assertEquals(result, ImmutableList.of(myBundle1_0_0)); .symbolicName("mybundle") .version("[1.0.0, 2.0.0)") .findAll(); assertEquals(result2, ImmutableList.of(myBundle1_0_0, myBundle1_1_0)); .symbolicName("mybundle") .version("[1.0.0, 2.0.0]") .findAll(); assertEquals(result3, ImmutableList.of(myBundle1_0_0, myBundle1_1_0, myBundle2_0_0)); .symbolicName("mybundle") .version("[2.0.0, 3.0.0)") .findAll(); assertEquals(result4, ImmutableList.of(myBundle2_0_0_snapshot, myBundle2_0_0)); .symbolicName("snapshotbundle") .version("[1.0.0, 2.0.0)") .findAll(); assertEquals(result5, ImmutableList.of(snapshotBundle1_0_0_snapshot));
protected <T> Maybe<T> tryLoadFromBundleWhiteList(LoaderDispatcher<T> dispatcher, String className) { Framework framework = getFramework(); if (framework == null) { return Maybe.absentNull(); } List<Bundle> bundles = Osgis.bundleFinder(framework) .satisfying(createBundleMatchingPredicate()) .findAll(); for (Bundle b : bundles) { Maybe<T> item = dispatcher.tryLoadFrom(b, className); if (item.isPresent()) { return item; } } return Maybe.absentNull(); }
/** @deprecated since 0.7.0 use {@link #bundleFinder(Framework)} */ @Deprecated public static List<Bundle> getBundlesByName(Framework framework, String symbolicName) { return bundleFinder(framework).symbolicName(symbolicName).findAll(); }
@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)); }
/** @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(); }