use of org.osgi.service.indexer.Builder in project bnd by bndtools.
the class BundleAnalyzer method doBundleNativeCode.
private void doBundleNativeCode(Resource resource, final List<? super Requirement> reqs) throws IOException {
String nativeHeaderStr = resource.getManifest().getMainAttributes().getValue(Constants.BUNDLE_NATIVECODE);
if (nativeHeaderStr == null)
return;
boolean optional = false;
List<String> options = new LinkedList<String>();
Map<String, Map<String, String>> nativeHeader = OSGiHeader.parseHeader(nativeHeaderStr);
for (Entry<String, Map<String, String>> entry : nativeHeader.entrySet()) {
String name = entry.getKey();
if ("*".equals(name)) {
optional = true;
continue;
}
StringBuilder builder = new StringBuilder().append("(&");
Map<String, String> attribs = entry.getValue();
String osnamesFilter = buildFilter(attribs, Constants.BUNDLE_NATIVECODE_OSNAME, Namespaces.ATTR_NATIVE_OSNAME);
if (osnamesFilter != null)
builder.append(osnamesFilter);
String versionRangeStr = attribs.get(Constants.BUNDLE_NATIVECODE_OSVERSION);
if (versionRangeStr != null)
Util.addVersionFilter(builder, new VersionRange(versionRangeStr), VersionKey.NativeOsVersion);
String processorFilter = buildFilter(attribs, Constants.BUNDLE_NATIVECODE_PROCESSOR, Namespaces.ATTR_NATIVE_PROCESSOR);
if (processorFilter != null)
builder.append(processorFilter);
String languageFilter = buildFilter(attribs, Constants.BUNDLE_NATIVECODE_LANGUAGE, Namespaces.ATTR_NATIVE_LANGUAGE);
if (languageFilter != null)
builder.append(languageFilter);
String selectionFilter = attribs.get(Constants.SELECTION_FILTER_ATTRIBUTE);
if (selectionFilter != null)
builder.append(selectionFilter);
builder.append(")");
options.add(builder.toString());
}
if (options.isEmpty())
return;
String filter;
if (options.size() == 1)
filter = options.get(0);
else {
StringBuilder builder = new StringBuilder();
builder.append("(|");
for (String option : options) builder.append(option);
builder.append(")");
filter = builder.toString();
}
Builder builder = new Builder().setNamespace(Namespaces.NS_NATIVE).addDirective(Namespaces.DIRECTIVE_FILTER, filter);
if (optional)
builder.addDirective(Namespaces.DIRECTIVE_RESOLUTION, Namespaces.RESOLUTION_OPTIONAL);
reqs.add(builder.buildRequirement());
}
use of org.osgi.service.indexer.Builder in project bnd by bndtools.
the class BlueprintAnalyzer method createRequirement.
private Requirement createRequirement() {
Builder builder = new Builder().setNamespace(Namespaces.NS_EXTENDER);
String filter = String.format("(&(%s=%s)(version>=1.0.0)(!(version>=2.0.0)))", Namespaces.NS_EXTENDER, Namespaces.EXTENDER_BLUEPRINT);
builder.addDirective(Namespaces.DIRECTIVE_FILTER, filter).addDirective(Namespaces.DIRECTIVE_EFFECTIVE, Namespaces.EFFECTIVE_ACTIVE);
return builder.buildRequirement();
}
use of org.osgi.service.indexer.Builder in project bnd by bndtools.
the class BundleAnalyzer method doRequireBundles.
private void doRequireBundles(Resource resource, List<? super Requirement> reqs) throws Exception {
Manifest manifest = resource.getManifest();
String requiresStr = manifest.getMainAttributes().getValue(Constants.REQUIRE_BUNDLE);
if (requiresStr == null)
return;
Map<String, Map<String, String>> requires = OSGiHeader.parseHeader(requiresStr);
for (Entry<String, Map<String, String>> entry : requires.entrySet()) {
StringBuilder filter = new StringBuilder();
String bsn = OSGiHeader.removeDuplicateMarker(entry.getKey());
filter.append("(osgi.wiring.bundle=").append(bsn).append(")");
String versionStr = entry.getValue().get(Constants.BUNDLE_VERSION_ATTRIBUTE);
if (versionStr != null) {
VersionRange version = new VersionRange(versionStr);
filter.insert(0, "(&");
Util.addVersionFilter(filter, version, VersionKey.BundleVersion);
filter.append(")");
}
Builder builder = new Builder().setNamespace(Namespaces.NS_WIRING_BUNDLE).addDirective(Namespaces.DIRECTIVE_FILTER, filter.toString());
copyAttribsAndDirectives(entry.getValue(), builder, Constants.BUNDLE_VERSION_ATTRIBUTE);
reqs.add(builder.buildRequirement());
}
}
use of org.osgi.service.indexer.Builder in project bnd by bndtools.
the class BundleAnalyzer method doContent.
private void doContent(Resource resource, MimeType mimeType, List<? super Capability> capabilities) throws Exception {
String sha = calculateSHA(resource);
List<String> locations = calculateLocation(resource);
for (String location : locations) {
Builder builder = new Builder().setNamespace(Namespaces.NS_CONTENT);
builder.addAttribute(Namespaces.NS_CONTENT, sha);
builder.addAttribute(Namespaces.ATTR_CONTENT_URL, location);
long size = resource.getSize();
if (size > 0L)
builder.addAttribute(Namespaces.ATTR_CONTENT_SIZE, size);
builder.addAttribute(Namespaces.ATTR_CONTENT_MIME, mimeType.toString());
capabilities.add(builder.buildCapability());
}
}
use of org.osgi.service.indexer.Builder in project bnd by bndtools.
the class BundleAnalyzer method doImportService.
private void doImportService(Resource resource, List<? super Requirement> reqs) throws Exception {
@SuppressWarnings("deprecation") String importsStr = resource.getManifest().getMainAttributes().getValue(Constants.IMPORT_SERVICE);
Map<String, Map<String, String>> imports = OSGiHeader.parseHeader(importsStr);
for (Entry<String, Map<String, String>> imp : imports.entrySet()) {
String service = OSGiHeader.removeDuplicateMarker(imp.getKey());
Map<String, String> attribs = imp.getValue();
boolean optional = false;
String availabilityStr = attribs.get(IMPORT_SERVICE_AVAILABILITY);
if (Constants.RESOLUTION_OPTIONAL.equals(availabilityStr))
optional = true;
StringBuilder filter = new StringBuilder();
filter.append('(').append(Constants.OBJECTCLASS).append('=').append(service).append(')');
Builder builder = new Builder().setNamespace(Namespaces.NS_SERVICE).addDirective(Namespaces.DIRECTIVE_FILTER, filter.toString()).addDirective(Namespaces.DIRECTIVE_EFFECTIVE, Namespaces.EFFECTIVE_ACTIVE);
if (optional)
builder.addDirective(Namespaces.DIRECTIVE_RESOLUTION, Constants.RESOLUTION_OPTIONAL);
reqs.add(builder.buildRequirement());
}
}
Aggregations