use of org.osgi.service.indexer.Builder in project bnd by bndtools.
the class SCRAnalyzer method createRequirement.
private static Requirement createRequirement(VersionRange range) {
Builder builder = new Builder().setNamespace(Namespaces.NS_EXTENDER);
StringBuilder filter = new StringBuilder();
filter.append('(').append(Namespaces.NS_EXTENDER).append('=').append(Namespaces.EXTENDER_SCR).append(')');
filter.insert(0, "(&");
Util.addVersionFilter(filter, range, VersionKey.PackageVersion);
filter.append(')');
builder.addDirective(Namespaces.DIRECTIVE_FILTER, filter.toString()).addDirective(Namespaces.DIRECTIVE_EFFECTIVE, Namespaces.EFFECTIVE_ACTIVE);
Requirement requirement = builder.buildRequirement();
return requirement;
}
use of org.osgi.service.indexer.Builder in project bnd by bndtools.
the class BundleAnalyzer method doPlainJarIdentity.
private void doPlainJarIdentity(Resource resource, List<? super Capability> caps) {
String name = (String) resource.getProperties().get(Resource.NAME);
if (name.toLowerCase().endsWith(SUFFIX_JAR))
name = name.substring(0, name.length() - SUFFIX_JAR.length());
Version version = null;
int dashIndex = name.lastIndexOf('-');
if (dashIndex > 0) {
try {
String versionStr = name.substring(dashIndex + 1);
version = new Version(versionStr);
name = name.substring(0, dashIndex);
} catch (Exception e) {
version = null;
}
}
Builder builder = new Builder().setNamespace(Namespaces.NS_IDENTITY).addAttribute(Namespaces.NS_IDENTITY, name).addAttribute(Namespaces.ATTR_IDENTITY_TYPE, Namespaces.RESOURCE_TYPE_PLAIN_JAR);
if (version != null)
builder.addAttribute(Namespaces.ATTR_VERSION, version);
caps.add(builder.buildCapability());
}
use of org.osgi.service.indexer.Builder in project bnd by bndtools.
the class BundleAnalyzer method doBundleIdentity.
private void doBundleIdentity(Resource resource, MimeType mimeType, List<? super Capability> caps) throws Exception {
Manifest manifest = resource.getManifest();
if (manifest == null)
throw new IllegalArgumentException("Missing bundle manifest.");
String type;
switch(mimeType) {
case Bundle:
type = Namespaces.RESOURCE_TYPE_BUNDLE;
break;
case Fragment:
type = Namespaces.RESOURCE_TYPE_FRAGMENT;
break;
default:
type = Namespaces.RESOURCE_TYPE_PLAIN_JAR;
break;
}
SymbolicName bsn = Util.getSymbolicName(resource);
boolean singleton = Boolean.TRUE.toString().equalsIgnoreCase(bsn.getAttributes().get(Constants.SINGLETON_DIRECTIVE + ":"));
Version version = Util.getVersion(resource);
Builder builder = new Builder().setNamespace(Namespaces.NS_IDENTITY).addAttribute(Namespaces.NS_IDENTITY, bsn.getName()).addAttribute(Namespaces.ATTR_IDENTITY_TYPE, type).addAttribute(Namespaces.ATTR_VERSION, version);
if (singleton)
builder.addDirective(Namespaces.DIRECTIVE_SINGLETON, Boolean.TRUE.toString());
caps.add(builder.buildCapability());
}
use of org.osgi.service.indexer.Builder in project bnd by bndtools.
the class BundleAnalyzer method doImports.
private void doImports(Resource resource, List<? super Requirement> reqs) throws Exception {
Manifest manifest = resource.getManifest();
String importsStr = manifest.getMainAttributes().getValue(Constants.IMPORT_PACKAGE);
Map<String, Map<String, String>> imports = OSGiHeader.parseHeader(importsStr);
for (Entry<String, Map<String, String>> entry : imports.entrySet()) {
StringBuilder filter = new StringBuilder();
String pkgName = OSGiHeader.removeDuplicateMarker(entry.getKey());
filter.append("(osgi.wiring.package=").append(pkgName).append(")");
String versionStr = entry.getValue().get(Constants.VERSION_ATTRIBUTE);
if (versionStr != null) {
VersionRange version = new VersionRange(versionStr);
filter.insert(0, "(&");
Util.addVersionFilter(filter, version, VersionKey.PackageVersion);
filter.append(")");
}
Builder builder = new Builder().setNamespace(Namespaces.NS_WIRING_PACKAGE).addDirective(Namespaces.DIRECTIVE_FILTER, filter.toString());
copyAttribsAndDirectives(entry.getValue(), builder, Constants.VERSION_ATTRIBUTE, "specification-version");
reqs.add(builder.buildRequirement());
}
}
use of org.osgi.service.indexer.Builder in project bnd by bndtools.
the class BundleAnalyzer method doBREE.
private void doBREE(Resource resource, List<? super Requirement> reqs) throws Exception {
@SuppressWarnings("deprecation") String breeStr = resource.getManifest().getMainAttributes().getValue(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT);
Map<String, Map<String, String>> brees = OSGiHeader.parseHeader(breeStr);
final String filter;
if (!brees.isEmpty()) {
if (brees.size() == 1) {
String bree = brees.keySet().iterator().next();
filter = EE.parseBREE(bree).toFilter();
} else {
StringBuilder builder = new StringBuilder().append("(|");
for (String bree : brees.keySet()) {
bree = OSGiHeader.removeDuplicateMarker(bree);
builder.append(EE.parseBREE(bree).toFilter());
}
builder.append(')');
filter = builder.toString();
}
Requirement requirement = new Builder().setNamespace(Namespaces.NS_EE).addDirective(Namespaces.DIRECTIVE_FILTER, filter).buildRequirement();
reqs.add(requirement);
}
}
Aggregations