use of org.osgi.service.indexer.Requirement 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);
}
}
use of org.osgi.service.indexer.Requirement in project bnd by bndtools.
the class RepoIndex method generateResource.
private Tag generateResource(File file, Map<String, String> config) throws Exception {
JarResource resource = new JarResource(file);
List<Capability> caps = new AddOnlyList<Capability>(new LinkedList<Capability>());
List<Requirement> reqs = new AddOnlyList<Requirement>(new LinkedList<Requirement>());
Tag resourceTag = new Tag(Schema.ELEM_RESOURCE);
try {
// Read config settings and save in thread local state
if (config != null) {
URL rootURL;
String rootURLStr = config.get(ResourceIndexer.ROOT_URL);
if (rootURLStr != null) {
File rootDir = new File(rootURLStr);
if (rootDir.isDirectory())
rootURL = rootDir.toURI().toURL();
else
rootURL = new URL(rootURLStr);
} else
rootURL = new File(System.getProperty("user.dir")).toURI().toURL();
String urlTemplate = config.get(ResourceIndexer.URL_TEMPLATE);
bundleAnalyzer.setStateLocal(new GeneratorState(rootURL.toURI().normalize(), urlTemplate, resolvers));
} else {
bundleAnalyzer.setStateLocal(null);
}
// Iterate over the analyzers
try {
synchronized (analyzers) {
for (Pair<ResourceAnalyzer, Filter> entry : analyzers) {
ResourceAnalyzer analyzer = entry.getFirst();
Filter filter = entry.getSecond();
if (filter == null || filter.match(resource.getProperties())) {
try {
analyzer.analyzeResource(resource, caps, reqs);
} catch (Exception e) {
log(LogService.LOG_ERROR, MessageFormat.format("Error calling analyzer \"{0}\" on resource {1}.", analyzer.getClass().getName(), resource.getLocation()), e);
StringWriter writer = new StringWriter();
Formatter comment = new Formatter(writer);
comment.format("Error calling analyzer \"%s\" on resource %s with message %s and stack: ", analyzer.getClass().getName(), resource.getLocation(), e);
comment.close();
e.printStackTrace(new PrintWriter(writer));
resourceTag.addComment(writer.toString());
}
}
}
}
} finally {
bundleAnalyzer.setStateLocal(null);
}
} finally {
resource.close();
}
for (Capability cap : caps) {
Tag capTag = new Tag(Schema.ELEM_CAPABILITY);
capTag.addAttribute(Schema.ATTR_NAMESPACE, cap.getNamespace());
appendAttributeAndDirectiveTags(capTag, cap.getAttributes(), cap.getDirectives());
resourceTag.addContent(capTag);
}
for (Requirement req : reqs) {
Tag reqTag = new Tag(Schema.ELEM_REQUIREMENT);
reqTag.addAttribute(Schema.ATTR_NAMESPACE, req.getNamespace());
appendAttributeAndDirectiveTags(reqTag, req.getAttributes(), req.getDirectives());
resourceTag.addContent(reqTag);
}
return resourceTag;
}
use of org.osgi.service.indexer.Requirement in project bnd by bndtools.
the class TestOSGiFrameworkAnalyzer method testOsgiFrameworkSpecificationVersions.
public void testOsgiFrameworkSpecificationVersions() throws Exception {
LinkedList<Capability> caps;
LinkedList<Requirement> reqs;
caps = new LinkedList<Capability>();
reqs = new LinkedList<Requirement>();
JarResource inputResource = new JarResource(new File("testdata/org.apache.felix.framework-4.0.2.jar"));
new BundleAnalyzer(new XNullLogSvc()).analyzeResource(inputResource, caps, reqs);
new OSGiFrameworkAnalyzer(new XNullLogSvc()).analyzeResource(inputResource, caps, reqs);
assertEquals(new Version("4.3.0"), findCaps("osgi.contract", caps).get(0).getAttributes().get("version"));
caps = new LinkedList<Capability>();
reqs = new LinkedList<Requirement>();
inputResource = new JarResource(new File("testdata/org.eclipse.osgi_3.7.2.v20120110-1415.jar"));
new BundleAnalyzer(new XNullLogSvc()).analyzeResource(inputResource, caps, reqs);
new OSGiFrameworkAnalyzer(new XNullLogSvc()).analyzeResource(inputResource, caps, reqs);
assertEquals(new Version("4.3.0"), findCaps("osgi.contract", caps).get(0).getAttributes().get("version"));
caps = new LinkedList<Capability>();
reqs = new LinkedList<Requirement>();
inputResource = new JarResource(new File("testdata/org.apache.felix.framework-3.2.2.jar"));
new BundleAnalyzer(new XNullLogSvc()).analyzeResource(inputResource, caps, reqs);
new OSGiFrameworkAnalyzer(new XNullLogSvc()).analyzeResource(inputResource, caps, reqs);
assertEquals(new Version("4.2.0"), findCaps("osgi.contract", caps).get(0).getAttributes().get("version"));
caps = new LinkedList<Capability>();
reqs = new LinkedList<Requirement>();
inputResource = new JarResource(new File("testdata/org.eclipse.osgi_3.6.2.R36x_v20110210.jar"));
new BundleAnalyzer(new XNullLogSvc()).analyzeResource(inputResource, caps, reqs);
new OSGiFrameworkAnalyzer(new XNullLogSvc()).analyzeResource(inputResource, caps, reqs);
assertEquals(new Version("4.2.0"), findCaps("osgi.contract", caps).get(0).getAttributes().get("version"));
}
use of org.osgi.service.indexer.Requirement in project bnd by bndtools.
the class TestOSGiFrameworkAnalyzer method testOsgiFramework.
public void testOsgiFramework() throws Exception {
LinkedList<Capability> caps = new LinkedList<Capability>();
LinkedList<Requirement> reqs = new LinkedList<Requirement>();
JarResource input = new JarResource(new File("testdata/org.apache.felix.framework-4.0.2.jar"));
new BundleAnalyzer(new XNullLogSvc()).analyzeResource(input, caps, reqs);
new OSGiFrameworkAnalyzer(new XNullLogSvc()).analyzeResource(input, caps, reqs);
List<Capability> fwkCaps = findCaps("osgi.contract", caps);
assertNotNull(fwkCaps);
assertEquals(1, fwkCaps.size());
Capability fwkCap = fwkCaps.get(0);
assertEquals("OSGiFramework", fwkCap.getAttributes().get("osgi.contract"));
assertEquals(new Version("4.3.0"), fwkCap.getAttributes().get("version"));
assertEquals("org.osgi.framework.startlevel,org.osgi.framework.wiring,org.osgi.framework.hooks.bundle,org.osgi.framework.hooks.service,org.osgi.framework.hooks.resolver,org.osgi.framework.launch,org.osgi.framework,org.osgi.framework.hooks.weaving,org.osgi.service.packageadmin,org.osgi.service.url,org.osgi.service.startlevel,org.osgi.util.tracker", fwkCap.getDirectives().get("uses"));
}
use of org.osgi.service.indexer.Requirement 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;
}
Aggregations