org.osgi.resource.Namespace Java Examples
The following examples show how to use
org.osgi.resource.Namespace.
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: BundleUtils.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
private static Bundle[] getBundles(String symbolicName, FrameworkWiring fwkWiring) { BundleContext context = fwkWiring.getBundle().getBundleContext(); if (Constants.SYSTEM_BUNDLE_SYMBOLICNAME.equals(symbolicName)) { symbolicName = context.getBundle(Constants.SYSTEM_BUNDLE_LOCATION).getSymbolicName(); } StringBuilder filter = new StringBuilder(); filter.append('(') .append(IdentityNamespace.IDENTITY_NAMESPACE) .append('=') .append(symbolicName) .append(')'); Map<String, String> directives = Collections.singletonMap(Namespace.REQUIREMENT_FILTER_DIRECTIVE, filter.toString()); Collection<BundleCapability> matchingBundleCapabilities = fwkWiring.findProviders(ModuleContainer.createRequirement(IdentityNamespace.IDENTITY_NAMESPACE, directives, Collections.emptyMap())); if (matchingBundleCapabilities.isEmpty()) { return null; } Bundle[] results = matchingBundleCapabilities.stream().map(c -> c.getRevision().getBundle()) // Remove all the bundles that are uninstalled .filter(bundle -> (bundle.getState() & (Bundle.UNINSTALLED)) == 0) .sorted((b1, b2) -> b2.getVersion().compareTo(b1.getVersion())) // highest version first .toArray(Bundle[]::new); return results.length > 0 ? results : null; }
Example #2
Source File: Concierge.java From concierge with Eclipse Public License 1.0 | 6 votes |
protected List<Capability> findProviders(Requirement requirement){ final String filterStr = requirement.getDirectives() .get(Namespace.REQUIREMENT_FILTER_DIRECTIVE); final List<Capability> providers; if (filterStr == null) { providers = capabilityRegistry .getAll(requirement.getNamespace()); } else { try { providers = RFC1960Filter.filterWithIndex( requirement, filterStr, capabilityRegistry); } catch (final InvalidSyntaxException ise) { // TODO: debug output ise.printStackTrace(); return Collections.emptyList(); } } return providers; }
Example #3
Source File: Concierge.java From concierge with Eclipse Public License 1.0 | 6 votes |
static boolean matches0(final String namespace, final Requirement req, final Capability cap, final String filterStr) { if (!namespace.startsWith("osgi.wiring.")) { return true; } final String mandatory = cap.getDirectives() .get(Namespace.RESOLUTION_MANDATORY); if (mandatory == null) { return true; } final Set<String> mandatoryAttributes = new HashSet<String>( Arrays.asList(Utils.splitString( Utils.unQuote(mandatory).toLowerCase(), ','))); final Matcher matcher = FILTER_ASSERT_MATCHER .matcher(filterStr == null ? "" : filterStr); while (matcher.find()) { mandatoryAttributes.remove(matcher.group(1)); } return mandatoryAttributes.isEmpty(); }
Example #4
Source File: ResolveContextImpl.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
private void addToProvidersIfMatching(Resource res, List<Capability> providers, Requirement req) { String f = req.getDirectives().get(Namespace.REQUIREMENT_FILTER_DIRECTIVE); Filter filter = null; if(f != null) { try { filter = bc.createFilter(f); } catch (InvalidSyntaxException e) { // TODO log filter failure, skip System.err.println("Failed, " + f + ". " + e); return; } } for(Capability c : res.getCapabilities(req.getNamespace())) { if(filter != null && !filter.matches(c.getAttributes())) { continue; } providers.add(c); } }
Example #5
Source File: BundleImpl.java From concierge with Eclipse Public License 1.0 | 5 votes |
void refresh() { // iterate over old and current revisions for (final BundleRevision brev : revisions) { final Revision rev = (Revision) brev; if (rev.wiring != null) { rev.wiring.cleanup(); rev.wiring = null; } } revisions.clear(); if (currentRevision != null) { revisions.add(currentRevision); // detach fragments (if any) and reset classloader currentRevision.refresh(); // remove from framework wirings framework.wirings.remove(currentRevision); // clear and restore dynamic imports currentRevision.dynamicImports.clear(); for (final BundleRequirement req : currentRevision.requirements .lookup(PackageNamespace.PACKAGE_NAMESPACE)) { if (PackageNamespace.RESOLUTION_DYNAMIC .equals(req.getDirectives().get( Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE))) { currentRevision.dynamicImports.add(req); } } } }
Example #6
Source File: Concierge.java From concierge with Eclipse Public License 1.0 | 5 votes |
static boolean matches(final Requirement req, final Capability cap) { final String reqNamespace = req.getNamespace(); final String capNamespace = cap.getNamespace(); if (!reqNamespace.equals(capNamespace)) { return false; } /* * final String effective = req.getDirectives().get( * Namespace.REQUIREMENT_EFFECTIVE_DIRECTIVE); if (!(effective == null * || effective .equals(Namespace.EFFECTIVE_RESOLVE))) { return false; } */ final String filter = req.getDirectives() .get(Namespace.REQUIREMENT_FILTER_DIRECTIVE); try { if (!(filter == null || RFC1960Filter.fromString(filter) .matches(cap.getAttributes()))) { return false; } return matches0(capNamespace, req, cap, filter); } catch (final InvalidSyntaxException e) { // TODO: to log e.printStackTrace(); return false; } }
Example #7
Source File: DownloadableBundleRequirement.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
public DownloadableBundleRequirement() { final String filter = "(|(" + ContentNamespace.CAPABILITY_MIME_ATTRIBUTE + "=" + MIME_BUNDLE + ")(" + ContentNamespace.CAPABILITY_MIME_ATTRIBUTE + "=" + MIME_BUNDLE_ALT + "))"; directives.put(Namespace.REQUIREMENT_FILTER_DIRECTIVE, filter); }
Example #8
Source File: BundleImpl.java From concierge with Eclipse Public License 1.0 | 4 votes |
WovenClassImpl(final String clazzName, final byte[] bytes, final Revision revision, final ProtectionDomain domain) { this.bytes = bytes; this.clazzName = clazzName; this.dynamicImportRequirements = new ArrayList<BundleRequirement>(); this.dynamicImports = new ArrayList<String>() { /** * */ private static final long serialVersionUID = 975783807443126126L; @Override public boolean add(final String dynImport) { checkDynamicImport(dynImport); return super.add(dynImport); } @Override public boolean addAll( final Collection<? extends String> c) { for (final String dynImport : c) { checkDynamicImport(dynImport); } return super.addAll(c); } private void checkDynamicImport(final String dynImport) throws IllegalArgumentException { try { final String[] literals = Utils .splitString(dynImport, ';'); if (literals[0].contains(";")) { throw new IllegalArgumentException(dynImport); } final ParseResult parseResult = Utils .parseLiterals(literals, 1); final HashMap<String, String> dirs = parseResult .getDirectives(); dirs.put(Namespace.REQUIREMENT_FILTER_DIRECTIVE, Utils.createFilter( PackageNamespace.PACKAGE_NAMESPACE, literals[0], parseResult.getLatter())); dirs.put(Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE, PackageNamespace.RESOLUTION_DYNAMIC); dirs.put(Concierge.DIR_INTERNAL, literals[0]); final BundleRequirement req = new BundleRequirementImpl( revision, PackageNamespace.PACKAGE_NAMESPACE, dirs, null, Constants.DYNAMICIMPORT_PACKAGE + ' ' + dynImport); dynamicImportRequirements.add(req); } catch (final BundleException be) { throw new IllegalArgumentException( "Unvalid dynamic import " + dynImport); } } }; this.domain = domain; }
Example #9
Source File: ResolveContextImpl.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public boolean isEffective(Requirement requirement) { String ed = requirement.getDirectives().get(Namespace.REQUIREMENT_EFFECTIVE_DIRECTIVE); return ed == null || Namespace.EFFECTIVE_RESOLVE.equals(ed); }