org.osgi.framework.wiring.BundleWiring Java Examples
The following examples show how to use
org.osgi.framework.wiring.BundleWiring.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BundleWiringTestSuite.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void runTest() throws Throwable { buB = Util.installBundle(bc, "bundleB_test-1.0.0.jar"); assertNotNull(buB); FrameworkWiring fw = bc.getBundle(0).adapt(FrameworkWiring.class); assertNotNull(fw); fw.resolveBundles(Collections.singleton(buB)); BundleWiring wiring = buB.adapt(BundleWiring.class); assertNotNull(wiring); Collection resources = wiring.listResources("/", "*.class", 0); assertEquals("Class files in top of bundleB_test", 0, resources.size()); resources = wiring.listResources("/org/knopflerfish/bundle", "*.class", BundleWiring.FINDENTRIES_RECURSE); assertEquals("Class files in bundleB_test", 2, resources.size()); resources = wiring.listResources("/", "*.class", BundleWiring.FINDENTRIES_RECURSE + BundleWiring.LISTRESOURCES_LOCAL); assertEquals("Class files in bundleB_test", 3, resources.size()); resources = wiring.listResources("org/", null, BundleWiring.FINDENTRIES_RECURSE + BundleWiring.LISTRESOURCES_LOCAL); assertEquals("All entires in bundleB_test org", 8, resources.size()); out.println("### framework test bundle :FRAME700A:PASS"); }
Example #2
Source File: WiringHTMLDisplayer.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override String getReqName(final BundleRequirement requirement) { final StringBuffer sb = new StringBuffer(50); final String filter = requirement.getDirectives().get("filter"); final String eeName = getFilterValue(filter, ExecutionEnvironmentNamespace.EXECUTION_ENVIRONMENT_NAMESPACE); if (eeName != null) { sb.append(eeName); appendVersion(sb, requirement); } else { // Filter too complex to extract info from... sb.append(filter); } final BundleWiring reqWiring = requirement.getRevision().getWiring(); appendPendingRemovalOnRefresh(sb, reqWiring); return sb.toString(); }
Example #3
Source File: AbstractBundle.java From concierge with Eclipse Public License 1.0 | 6 votes |
protected final BundleWiringDTO getBundleWiringDTO(BundleRevision revision){ BundleWiringDTO dto = new BundleWiringDTO(); dto.bundle = revision.getBundle().getBundleId(); BundleWiring wiring = revision.getWiring(); // TODO what is root dto.root = wiring.hashCode(); dto.resources = new HashSet<BundleRevisionDTO>(); dto.resources.add(getBundleRevisionDTO(revision)); dto.nodes = new HashSet<BundleWiringDTO.NodeDTO>(); addBundleWiringNodeDTO(wiring, dto.resources, dto.nodes); return dto; }
Example #4
Source File: WiringHTMLDisplayer.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override String getReqName(final BundleRequirement requirement) { final StringBuffer sb = new StringBuffer(50); final String filter = requirement.getDirectives().get("filter"); final String hostName = getFilterValue(filter, BundleRevision.HOST_NAMESPACE); if (hostName != null) { sb.append(hostName); appendVersion(sb, requirement); } else { // Filter too complex to extract info from... sb.append(filter); } final BundleWiring reqWiring = requirement.getRevision().getWiring(); appendPendingRemovalOnRefresh(sb, reqWiring); return sb.toString(); }
Example #5
Source File: WiringHTMLDisplayer.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override String getReqName(final BundleRequirement requirement) { final StringBuffer sb = new StringBuffer(50); final String filter = requirement.getDirectives().get("filter"); final String idName = getFilterValue(filter, IdentityNamespace.IDENTITY_NAMESPACE); if (idName != null) { sb.append(idName); appendVersionAndType(sb, requirement); } else { // Filter too complex to extract info from... sb.append(filter); } final BundleWiring reqWiring = requirement.getRevision().getWiring(); appendPendingRemovalOnRefresh(sb, reqWiring); return sb.toString(); }
Example #6
Source File: PackageAdminImpl.java From concierge with Eclipse Public License 1.0 | 6 votes |
/** * @see org.osgi.service.packageadmin.ExportedPackage#getImportingBundles() */ public Bundle[] getImportingBundles() { final ArrayList<Bundle> result = new ArrayList<Bundle>(); final BundleWiring wiring = cap.getResource().getWiring(); if (wiring != null) { final List<BundleWire> wires = wiring.getProvidedWires(PackageNamespace.PACKAGE_NAMESPACE); for (final BundleWire wire : wires) { if (wire.getCapability().equals(cap)) { final Bundle b = wire.getRequirer().getBundle(); if (b != cap.getResource().getBundle()) { result.add(wire.getRequirer().getBundle()); } } } addRequiringBundles(wiring, result); } return toArrayOrNull(result, Bundle.class); }
Example #7
Source File: PackageAdminImpl.java From concierge with Eclipse Public License 1.0 | 6 votes |
/** * @see org.osgi.service.packageadmin.PackageAdmin#getHosts(org.osgi.framework.Bundle) */ public Bundle[] getHosts(final Bundle bundle) { final BundleWiring wiring = bundle.adapt(BundleWiring.class); if (wiring == null) { return null; } final List<BundleWire> wires = wiring.getRequiredWires(HostNamespace.HOST_NAMESPACE); final ArrayList<Bundle> result = new ArrayList<Bundle>(); for (final BundleWire wire : wires) { if (wire.getRequirer().getBundle() == bundle) { result.add(wire.getProvider().getBundle()); } } return toArrayOrNull(result, Bundle.class); }
Example #8
Source File: Activator.java From logging-log4j2 with Apache License 2.0 | 6 votes |
@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(); }
Example #9
Source File: WiringHTMLDisplayer.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Present a generic requirement by showing its filter. * * @param requirement The requirement to present. * @return string presentation of the requirement. */ String getReqName(BundleRequirement requirement) { final StringBuffer sb = new StringBuffer(50); final String filter = requirement.getDirectives().get("filter"); if (filter != null) { sb.append(filter); } else { sb.append(" &emdash; "); } final BundleWiring reqWiring = requirement.getRevision().getWiring(); appendPendingRemovalOnRefresh(sb, reqWiring); return sb.toString(); }
Example #10
Source File: PackageAdminImpl.java From concierge with Eclipse Public License 1.0 | 6 votes |
private void getExportedPackages0(final Bundle bundle, final String name, final ArrayList<ExportedPackage> result) { if (bundle == null) { throw new IllegalArgumentException("bundle==null"); } if (result == null) { throw new IllegalArgumentException("result==null"); } final List<BundleRevision> revs = bundle.adapt(BundleRevisions.class).getRevisions(); if (revs.isEmpty()) { return; } for (final BundleRevision r : revs) { final BundleWiring wiring = r.getWiring(); if (wiring != null && wiring.isInUse()) { for (final Capability cap : wiring.getCapabilities(PackageNamespace.PACKAGE_NAMESPACE)) { if (name == null || name.equals(cap.getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE))) { result.add(new ExportedPackageImpl((BundleCapability) cap)); } } } } }
Example #11
Source File: WiringHTMLDisplayer.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override String getReqName(final BundleRequirement requirement) { final StringBuffer sb = new StringBuffer(50); final String filter = requirement.getDirectives().get("filter"); final String bundleName = getFilterValue(filter, BundleRevision.BUNDLE_NAMESPACE); if (bundleName != null) { sb.append(bundleName); appendVersion(sb, requirement); } else { // Filter too complex to extract info from... sb.append(filter); } final BundleWiring reqWiring = requirement.getRevision().getWiring(); appendPendingRemovalOnRefresh(sb, reqWiring); return sb.toString(); }
Example #12
Source File: Concierge.java From concierge with Eclipse Public License 1.0 | 6 votes |
/** * @see org.osgi.framework.wiring.FrameworkWiring#getRemovalPendingBundles() * @category FrameworkWiring */ public Collection<Bundle> getRemovalPendingBundles() { final ArrayList<Bundle> removalPending = new ArrayList<Bundle>(); bundleLoop: for (final AbstractBundle bundle : bundles) { if (bundle instanceof BundleImpl) { final List<BundleRevision> revisions = bundle.getRevisions(); for (final BundleRevision rev : revisions) { final BundleWiring wiring = rev.getWiring(); if (wiring != null && !wiring.isCurrent() && wiring.isInUse()) { removalPending.add(bundle); continue bundleLoop; } } } } return removalPending; }
Example #13
Source File: WiringHTMLDisplayer.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override String getReqName(final BundleRequirement requirement) { final StringBuffer sb = new StringBuffer(50); final String filter = requirement.getDirectives().get("filter"); final String pkgName = getFilterValue(filter, BundleRevision.PACKAGE_NAMESPACE); if (pkgName != null) { sb.append(pkgName); appendVersionAndResolutionDirective(sb, requirement); } else { sb.append(filter); } final BundleWiring reqWiring = requirement.getRevision().getWiring(); appendPendingRemovalOnRefresh(sb, reqWiring); return sb.toString(); }
Example #14
Source File: ConciergeJvmOptions.java From concierge with Eclipse Public License 1.0 | 6 votes |
/** * Test if startup of framework does work when java.specification.name is * NOT null. This is the standard case for JavaSE 7/8 etc JVMs. */ @Test public void testJavaSpecificationNameNotNull() throws Exception { String propName = "java.specification.name"; String propValue = System.getProperty(propName); Assert.assertNotNull(propValue); try { startFramework(); Assert.assertEquals(0, framework.getBundleId()); BundleWiring w = framework.adapt(BundleWiring.class); List<BundleCapability> caps = w.getCapabilities("osgi.ee"); checkEECaps(caps); } finally { stopFramework(); } }
Example #15
Source File: ConciergeJvmOptions.java From concierge with Eclipse Public License 1.0 | 6 votes |
/** * Test if startup of framework does work when java.specification.name IS * null. This will for example happen when running on CEE-J. */ @Test public void testJavaSpecificationNameNull() throws Exception { String propName = "java.specification.name"; String savedPropValue = System.getProperty(propName); try { System.clearProperty(propName); String propValue = System.getProperty(propName); Assert.assertNull(propValue); startFramework(); Assert.assertEquals(0, framework.getBundleId()); BundleWiring w = framework.adapt(BundleWiring.class); List<BundleCapability> caps = w.getCapabilities("osgi.ee"); checkEECaps(caps); } finally { stopFramework(); System.setProperty(propName, savedPropValue); } }
Example #16
Source File: Activator.java From logging-log4j2 with Apache License 2.0 | 6 votes |
private void loadProvider(final BundleContext bundleContext, final BundleWiring bundleWiring) { final String filter = "(APIVersion>=2.6.0)"; try { final Collection<ServiceReference<Provider>> serviceReferences = bundleContext.getServiceReferences(Provider.class, filter); Provider maxProvider = null; for (final ServiceReference<Provider> serviceReference : serviceReferences) { final Provider provider = bundleContext.getService(serviceReference); if (maxProvider == null || provider.getPriority() > maxProvider.getPriority()) { maxProvider = provider; } } if (maxProvider != null) { ProviderUtil.addProvider(maxProvider); } } catch (final InvalidSyntaxException ex) { LOGGER.error("Invalid service filter: " + filter, ex); } final List<URL> urls = bundleWiring.findEntries("META-INF", "log4j-provider.properties", 0); for (final URL url : urls) { ProviderUtil.loadProvider(url, bundleWiring.getClassLoader()); } }
Example #17
Source File: HandlersConfigurerDi.java From vespa with Apache License 2.0 | 6 votes |
@Override public BundleClasses getBundleClasses(ComponentSpecification bundleSpec, Set<String> packagesToScan) { //Temporary hack: Using class name since ClassLoaderOsgiFramework is not available at compile time in this bundle. if (osgiFramework.getClass().getName().equals("com.yahoo.application.container.impl.ClassLoaderOsgiFramework")) { Bundle syntheticClassPathBundle = first(osgiFramework.bundles()); ClassLoader classLoader = syntheticClassPathBundle.adapt(BundleWiring.class).getClassLoader(); return new BundleClasses( syntheticClassPathBundle, OsgiUtil.getClassEntriesForBundleUsingProjectClassPathMappings(classLoader, bundleSpec, packagesToScan)); } else { Bundle bundle = getBundle(bundleSpec); if (bundle == null) throw new RuntimeException("No bundle matching " + quote(bundleSpec)); return new BundleClasses(bundle, OsgiUtil.getClassEntriesInBundleClassPath(bundle, packagesToScan)); } }
Example #18
Source File: NetbinoxHooks.java From netbeans with Apache License 2.0 | 6 votes |
@Override public byte[] processClass(String className, byte[] bytes, ClasspathEntry ce, BundleEntry be, ClasspathManager cm) { final BaseData bd = ce.getBaseData(); if (bd == null) { return bytes; } final Bundle b = bd.getBundle(); if (b == null) { return bytes; } BundleWiring w = b.adapt(org.osgi.framework.wiring.BundleWiring.class); if (w == null) { return bytes; } ClassLoader loader = w.getClassLoader(); return archive.patchByteCode(loader, className, ce.getDomain(), bytes); }
Example #19
Source File: NexusBundleTracker.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
private void prepareDependencies(final Bundle bundle) { final BundleWiring wiring = bundle.adapt(BundleWiring.class); final List<BundleWire> wires = wiring.getRequiredWires(BundleRevision.PACKAGE_NAMESPACE); if (wires != null) { for (final BundleWire wire : wires) { try { final Bundle dependency = wire.getProviderWiring().getBundle(); if (!visited.contains(dependency.getSymbolicName()) && hasComponents(dependency)) { if (!live(dependency)) { dependency.start(); } if (live(dependency)) { // pseudo-event to trigger bundle activation addingBundle(dependency, null /* unused */); } } } catch (final Exception e) { log.warn("MISSING {}", wire, e); } } } }
Example #20
Source File: SiddhiExtensionLoader.java From siddhi with Apache License 2.0 | 6 votes |
private void removeExtensions(Bundle bundle) { bundleExtensions.entrySet().stream().filter(entry -> entry.getValue() == bundle.getBundleId()).forEachOrdered(entry -> { siddhiExtensionsMap.remove(entry.getKey()); }); bundleExtensions.entrySet().removeIf(entry -> entry.getValue() == bundle.getBundleId()); BundleWiring bundleWiring = bundle.adapt(BundleWiring.class); if (bundleWiring != null) { ClassLoader classLoader = bundleWiring.getClassLoader(); Iterable<Class<?>> extensions = ClassIndex.getAnnotated(Extension.class, classLoader); for (Class extension : extensions) { Extension siddhiExtensionAnnotation = (Extension) extension.getAnnotation(Extension.class); if (!siddhiExtensionAnnotation.namespace().isEmpty()) { String key = siddhiExtensionAnnotation.namespace() + SiddhiConstants.EXTENSION_SEPARATOR + siddhiExtensionAnnotation.name(); removeFromExtensionHolderMap(key, extension, extensionHolderConcurrentHashMap); } } } }
Example #21
Source File: ClassPatcher.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
public byte[] patch(String className, byte[] classBytes) { if(wrappers.size() == 0) { return classBytes; } matchProps.put(PROP_CLASSNAME, className); if(patchesFilter != null) { boolean b = patchesFilter.match(matchProps); if(!b) { return classBytes; } } try { ClassReader cr = new ClassReader(classBytes); ClassWriter cw = new BundleClassWriter(ClassWriter.COMPUTE_MAXS, patchedBundle.adapt(BundleWiring.class).getClassLoader()); ClassAdapter trans = new ClassAdapterPatcher(cw, className.replace('.', '/'), patchedBundle.adapt(BundleWiring.class).getClassLoader(), patchedBundle.getBundleId(), this); cr.accept(trans, 0); byte[] newBytes = cw.toByteArray(); if(bDumpClasses) { dumpClassBytes(className, newBytes); } classBytes = newBytes; } catch (Exception e) { throw new RuntimeException("Failed to patch " + className + "/" + patchedBundle.adapt(BundleWiring.class).getClassLoader() +": " +e); } return classBytes; }
Example #22
Source File: HostApplication.java From SimpleFlatMapper with MIT License | 5 votes |
private void debugBundle(Bundle b) { BundleRevision br = b.adapt(BundleRevision.class); br.getCapabilities(null).forEach(System.out::println); b.adapt(BundleWiring.class).getProvidedWires(null).forEach(System.out::println); ; }
Example #23
Source File: Jsr107OsgiTest.java From ehcache3 with Apache License 2.0 | 5 votes |
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]))); }
Example #24
Source File: ClusteredOsgiTest.java From ehcache3 with Apache License 2.0 | 5 votes |
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]))); }
Example #25
Source File: WiringHTMLDisplayer.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Append information about provided capabilities. * * @param sb Output buffer. * @param nameSpace The name space that we present capabilities for. * @param wiring The wiring that we present capabilities for. */ private void appendProvidedCapabilities(final StringBuffer sb, final String nameSpace, final BundleWiring wiring) { WireFormatter wf; if (BundleRevision.PACKAGE_NAMESPACE.equals(nameSpace)) { wf = new WireFormatterPackage(nameSpace, wiring); } else if (ExecutionEnvironmentNamespace.EXECUTION_ENVIRONMENT_NAMESPACE.equals(nameSpace)) { wf = new WireFormatterEE(nameSpace, wiring); } else if (BundleRevision.HOST_NAMESPACE.equals(nameSpace)) { wf = new WireFormatterHost(nameSpace, wiring); } else if (BundleRevision.BUNDLE_NAMESPACE.equals(nameSpace)) { wf = new WireFormatterBundle(nameSpace, wiring); } else if (IdentityNamespace.IDENTITY_NAMESPACE.equals(nameSpace)) { wf = new WireFormatterID(nameSpace, wiring); } else { wf = new WireFormatter(nameSpace, wiring); } // Mapping from capability title to (string) to requesters (strings) final Map<String,List<String>> cap2requesters = new TreeMap<String, List<String>>(); wf.providedCapabilitiesView(cap2requesters); appendCapabilityInfo(sb, cap2requesters); }
Example #26
Source File: WiringHTMLDisplayer.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Get a HTML-formated presentation string for the owner of a wiring. * E.g., for the provide or requester of a capability. * * @param bw the bundle wiring to present. * @param link if true return a bundle selection link. * @return bundle name as a bundle selection link. */ String getWiringName(BundleWiring bw, boolean link) { if (bw == null) { return "—?—"; } final BundleRevision br = bw.getRevision(); final Bundle b = br.getBundle(); if (link) { final StringBuffer sb = new StringBuffer(50); Util.bundleLink(sb, b); return sb.toString(); } return Util.getBundleName(b); }
Example #27
Source File: WiringHTMLDisplayer.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Get a HTML-formated presentation string for the capability described by * the given {@code capability}. * @param capability capability to be named. * @return */ String getCapName(final BundleCapability capability) { final StringBuffer sb = new StringBuffer(50); sb.append(capability.getAttributes()); final BundleWiring capWiring = capability.getRevision().getWiring(); appendPendingRemovalOnRefresh(sb, capWiring); return sb.toString(); }
Example #28
Source File: WiringHTMLDisplayer.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
static void appendPendingRemovalOnRefresh(final StringBuffer sb, final BundleWiring wiring) { if (wiring!=null && !wiring.isCurrent()) { sb.append(" <i>pending removal on "); new WiringUrl(wiring.getBundle()).refreshLink(sb, "refresh"); sb.append("</i>"); } }
Example #29
Source File: WiringHTMLDisplayer.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Append information about required capabilities. * * @param sb Output buffer. * @param nameSpace The name-space that we present requirements for. * @param wiring The wiring that we present requirements for. */ private void appendRequiredCapabilities(final StringBuffer sb, final String nameSpace, final BundleWiring wiring) { WireFormatter wf; if (BundleRevision.PACKAGE_NAMESPACE.equals(nameSpace)) { wf = new WireFormatterPackage(nameSpace, wiring); } else if (ExecutionEnvironmentNamespace.EXECUTION_ENVIRONMENT_NAMESPACE.equals(nameSpace)) { wf = new WireFormatterEE(nameSpace, wiring); } else if (BundleRevision.HOST_NAMESPACE.equals(nameSpace)) { wf = new WireFormatterHost(nameSpace, wiring); } else if (BundleRevision.BUNDLE_NAMESPACE.equals(nameSpace)) { wf = new WireFormatterBundle(nameSpace, wiring); } else if (IdentityNamespace.IDENTITY_NAMESPACE.equals(nameSpace)) { wf = new WireFormatterID(nameSpace, wiring); } else { wf = new WireFormatter(nameSpace, wiring); } // Mapping from capability title to (string) to provider (strings) final Map<String,List<String>> cap2providers = new TreeMap<String, List<String>>(); wf.requiredCapabilitiesView(cap2providers); appendCapabilityInfo(sb, cap2providers); }
Example #30
Source File: WiringHTMLDisplayer.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Creates a wire formatter for a name-space. * @param nameSpace The name-space to present info for. * @param wiring The wiring to present info for. */ WireFormatter(final String nameSpace, final BundleWiring wiring) { this.wiring = wiring; this.nameSpace = nameSpace; }