Refine search
/** * Caches the package capabilities that are needed for a set of interface classes * * @param classes interfaces we want to track */ private void cachePackageCapabilities(Class<?> ... classes) { BundleWiring ourWiring = bundleContext.getBundle().adapt(BundleWiring.class); Set<String> packageNames = new HashSet<String>(); for (Class<?> clazz: classes) { packageNames.add(clazz.getPackage().getName()); } List<BundleCapability> ourExports = ourWiring.getCapabilities(PACKAGE_NAMESPACE); for (BundleCapability ourExport : ourExports) { String ourPkgName = (String) ourExport.getAttributes().get(PACKAGE_NAMESPACE); if (packageNames.contains(ourPkgName)) { packageCapabilities.add(ourExport); } } }
public BundleCapabilityImpl(BundleCapability bc, BundleGeneration bg) { gen = bg; owner = ((BundleCapabilityImpl)bc).owner; nameSpace = bc.getNamespace(); attributes = bc.getAttributes(); directives = bc.getDirectives(); }
BundleWiring bundleWiring = bundle.adapt(BundleWiring.class); if (bundleWiring == null) { LOG.error("BundleWiring is null for: " + bundle); List<BundleWire> requiredWires = bundleWiring.getRequiredWires(null); for (BundleWire bundleWire : requiredWires) { Bundle exportingBundle = bundleWire.getCapability().getRevision() .getBundle(); if (exportingBundle.getBundleId() == 0) { continue; // system bundle is skipped this one isn't needed while (bundleIterator.hasNext()) { Bundle auxBundle = bundleIterator.next(); if (auxBundle.getState() == Bundle.UNINSTALLED) { bundleIterator.remove();
public WrappingTransformer(ClassTransformer delegate, ServiceReference<?> persistenceProvider) { validate(delegate, persistenceProvider); this.delegate = delegate; Object packages = persistenceProvider.getProperty("org.apache.aries.jpa.container.weaving.packages"); if (packages instanceof String[]) { for (String s : (String[])packages) { packageImportsToAdd.add(s); } } else { Bundle provider = persistenceProvider.getBundle(); String suffix = ";" + Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE + "=" + provider.getSymbolicName() + ";" + Constants.BUNDLE_VERSION_ATTRIBUTE + "=" + provider.getVersion(); BundleRevision br = provider.adapt(BundleWiring.class).getRevision(); for (BundleCapability bc : br.getDeclaredCapabilities(BundleRevision.PACKAGE_NAMESPACE)) { packageImportsToAdd.add(bc.getAttributes().get(BundleRevision.PACKAGE_NAMESPACE) + suffix); } } }
public Map<String, Bundle> getWiredBundles(Bundle bundle) { // the set of bundles from which the bundle imports packages Map<String, Bundle> exporters = new HashMap<>(); for (BundleRevision revision : bundle.adapt(BundleRevisions.class).getRevisions()) { BundleWiring wiring = revision.getWiring(); if (wiring != null) { List<BundleWire> wires = wiring.getRequiredWires(BundleRevision.PACKAGE_NAMESPACE); if (wires != null) { for (BundleWire wire : wires) { if (wire.getProviderWiring().getBundle().getBundleId() != 0) { exporters.put(wire.getCapability().getAttributes().get(BundleRevision.PACKAGE_NAMESPACE).toString(), wire.getProviderWiring().getBundle()); } } } } } return exporters; }
private String getCapabilityId(BundleCapability capability) { StringBuilder sb = new StringBuilder(64); sb.append(capability.getRevision().getBundle().getBundleId()); Object v = capability.getAttributes().get(Constants.VERSION_ATTRIBUTE); if (v != null) { sb.append("; version=").append(v.toString()); } return sb.toString(); } }
private boolean isBundleLazyActivationPolicyUsed(BundleContext context) { if (context.getBundle().adapt(BundleStartLevel.class).isActivationPolicyUsed()) { // checking for lazy capability; NOTE this is equinox specific // but we fall back to header lookup for other frameworks List<BundleCapability> moduleData = context.getBundle().adapt(BundleRevision.class).getDeclaredCapabilities("equinox.module.data"); //$NON-NLS-1$ String activationPolicy = null; if (moduleData.isEmpty()) { activationPolicy = context.getBundle().getHeaders("").get(Constants.BUNDLE_ACTIVATIONPOLICY); //$NON-NLS-1$ } else { activationPolicy = (String) moduleData.get(0).getAttributes().get("activation.policy"); //$NON-NLS-1$ } return activationPolicy == null ? false : activationPolicy.startsWith(Constants.ACTIVATION_LAZY); } return false; }
private boolean checkRemove(String cap, BundleCapability cand) { return cap != null && !cap.equals(getCapabilityId(cand)) || cap == null && cand.getRevision().getBundle().getBundleId() != this.bundleId; }
/** * Load the Class of name <code>klassName</code>. * TODO : handle class version * * @param context The BundleContext * @param klassName The Class name * @return The Class of name <code>klassName</code> * @throws ClassNotFoundException if we can't load the Class of name <code>klassName</code> */ public static Class<?> loadClassNew(BundleContext context, String klassName) throws ClassNotFoundException { // extract package String packageName = klassName.substring(0, klassName.lastIndexOf('.')); BundleCapability exportedPackage = getExportedPackage(context, packageName); if (exportedPackage == null) { throw new ClassNotFoundException("No package found with name " + packageName + " while trying to load the class " + klassName + "."); } return exportedPackage.getRevision().getBundle().loadClass(klassName); }
private List<String> getExports(Bundle bundle) throws Exception { List<String> exports = new ArrayList<>(); BundleRevision rev = bundle.adapt(BundleRevision.class); List<BundleCapability> caps = rev.getDeclaredCapabilities(BundleRevision.PACKAGE_NAMESPACE); for (BundleCapability cap : caps) { Map<String, Object> attr = cap.getAttributes(); String packageName = (String)attr.get(BundleRevision.PACKAGE_NAMESPACE); exports.add(packageName); } return exports; }
/** * TODO Copied from BeanBundles.isBeanBundle(). Using that method from pax-cdi-spi * causes a ClassCircularityError. Is there a better way to avoid this? * @param candidate * @return */ private static boolean isBeanBundle(Bundle candidate) { List<BundleWire> wires = candidate.adapt(BundleWiring.class).getRequiredWires( Constants.EXTENDER_CAPABILITY); for (BundleWire wire : wires) { Object object = wire.getCapability().getAttributes().get(Constants.EXTENDER_CAPABILITY); if (object instanceof String) { String extender = (String) object; if (extender.equals(Constants.CDI_EXTENDER)) { return true; } } } return false; }
/** * Finds the CDI extension bundles wired to this given bundle. This method recursively calls * itself to track examine wirings of wired bundles. * * @param bundle * bean bundle * @param extensions * set of found extension bundles. */ public static void findExtensions(Bundle bundle, Set<Bundle> extensions) { List<BundleWire> wires = bundle.adapt(BundleWiring.class).getRequiredWires(null); if (wires != null) { for (BundleWire wire : wires) { String ns = wire.getCapability().getNamespace(); if (CDI_EXTENSION_CAPABILITY.equals(ns) || PAX_CDI_EXTENSION_CAPABILITY.equals(ns)) { Bundle b = wire.getProviderWiring().getBundle(); extensions.add(b); findExtensions(b, extensions); } } } } }
private void updateContext(Bundle currentContext, String className) { Bundle contextToSet = (currentContext == null) ? bundle : currentContext; int idx = className.lastIndexOf('.'); String packageName = (idx == -1) ? "" : className.substring(0, idx); BundleWiring wiring = contextToSet.adapt(BundleWiring.class); for (BundleWire wire : wiring.getRequiredWires(BundleRevision.PACKAGE_NAMESPACE)) { if (wire.getCapability().getAttributes().get(BundleRevision.PACKAGE_NAMESPACE).equals(packageName)) { contextToSet = wire.getProviderWiring().getBundle(); break; } } currentLoadingBundle.get().push(contextToSet); }
private boolean incompatibleExtender(Bundle bundle) { List<BundleWire> requiredWires = bundle.adapt(BundleWiring.class) .getRequiredWires(OSGI_EXTENDER_NS); for(BundleWire bw : requiredWires) { BundleCapability capability = bw.getCapability(); if(EntityManagerFactoryBuilder.JPA_CAPABILITY_NAME.equals( capability.getAttributes().get(OSGI_EXTENDER_NS))) { // If the persistence bundle requires a different revision for the // JPA extender then we are incompatible, otherwise we are return !capability.getRevision().equals(wiring.getRevision()); } } // If there is no requirement then we must assume that it's safe return false; }
List<BundleRevision> revisions = bundle.adapt(BundleRevisions.class).getRevisions(); for (BundleRevision revision : revisions) BundleWiring wiring = revision.getWiring(); if (wiring != null) for (BundleWire bw : wiring.getRequiredWires(null)) if (HostNamespace.HOST_NAMESPACE.equals(bw.getCapability().getNamespace())) result.add(bw.getProvider().getBundle()); result.add(dependentWire.getRequirer().getBundle());
final String schemaExpression) { BundleWiring bundleWiring = currentBundle.adapt(BundleWiring.class); List<BundleWire> wires = bundleWiring.getRequiredWires(LiquibaseEOSGiConstants.CAPABILITY_NS_LIQUIBASE_CHANGELOG); BundleCapability capability = wire.getCapability(); Map<String, Object> capabilityAttributes = capability.getAttributes(); if (capabilityFilter.matches(capabilityAttributes)) { Object schemaResourceAttr = capabilityAttributes.get(LiquibaseEOSGiConstants.CAPABILITY_ATTR_RESOURCE); if (schemaResourceAttr != null) { bundleResource = new BundleResource(capability.getRevision().getBundle(), String.valueOf(schemaResourceAttr), capabilityAttributes); } else {
public Bundle[] getRequiringBundles() { Set<Bundle> set = new HashSet<Bundle>(); for (BundleWire wire : m_bundle.adapt(BundleWiring.class).getProvidedWires(null)) { if (BundleNamespace.BUNDLE_NAMESPACE.equals(wire.getCapability().getNamespace())) { set.add(wire.getRequirer().getBundle()); } } return set.toArray(new Bundle[set.size()]); }
private void printDuplicatePackages(Tree<Bundle> tree) { Set<Bundle> bundles = tree.flatten(); Map<String, Set<Bundle>> exports = new HashMap<>(); for (Bundle bundle : bundles) { for (BundleRevision revision : bundle.adapt(BundleRevisions.class).getRevisions()) { BundleWiring wiring = revision.getWiring(); if (wiring != null) { List<BundleWire> wires = wiring.getProvidedWires(BundleRevision.PACKAGE_NAMESPACE); if (wires != null) { for (BundleWire wire : wires) { String name = wire.getCapability().getAttributes().get(BundleRevision.PACKAGE_NAMESPACE).toString(); exports.computeIfAbsent(name, k -> new HashSet<>()).add(bundle); } } } } } for(Map.Entry<String, Set<Bundle>> entry : exports.entrySet()) { Set<Bundle> bundlesExportingPkg = entry.getValue(); if(bundlesExportingPkg.size() > 1) { System.out.printf("%n"); System.out.printf("WARNING: multiple bundles are exporting package %s%n", entry.getKey()); for (Bundle bundle : bundlesExportingPkg) { System.out.printf("- %s%n", bundle); } } } }
.adapt(FrameworkWiring.class).findProviders(req); Collection<BundleWiring> result = new ArrayList<BundleWiring>(1); // normally BundleRevision revision = identity.getRevision(); BundleWiring wiring = revision.getWiring(); if (wiring != null) { if ((revision.getTypes() & BundleRevision.TYPE_FRAGMENT) != 0) { wiring = wiring.getRequiredWires(HostNamespace.HOST_NAMESPACE).get(0).getProviderWiring();
exportCap.getAttributes().get(BundleRevision.PACKAGE_NAMESPACE); for (BundleRevision revision : exporter.adapt(BundleRevisions.class).getRevisions()) if ((cap.getNamespace().equals(BundleRevision.PACKAGE_NAMESPACE) && cap.getAttributes().get(BundleRevision.PACKAGE_NAMESPACE) .equals(pkgName)) || cap.getNamespace().equals(BundleRevision.BUNDLE_NAMESPACE)) result.add(dependentWire.getRequirer().getBundle());