use of org.osgi.service.indexer.Requirement in project bnd by bndtools.
the class TestBundleAnalyzer method testPackageImports.
public void testPackageImports() throws Exception {
BundleAnalyzer a = new BundleAnalyzer(new XNullLogSvc());
LinkedList<Capability> caps = new LinkedList<Capability>();
LinkedList<Requirement> reqs = new LinkedList<Requirement>();
a.analyzeResource(new JarResource(new File("testdata/05-import.jar")), caps, reqs);
Requirement pkgImport = findReqs("osgi.wiring.package", reqs).get(0);
assertEquals("(&(osgi.wiring.package=org.example.a)(version>=1.0.0)(!(version>=2.0.0)))", pkgImport.getDirectives().get("filter"));
}
use of org.osgi.service.indexer.Requirement in project bnd by bndtools.
the class TestIndexer method testLogErrorsFromAnalyzer.
public void testLogErrorsFromAnalyzer() throws Exception {
ResourceAnalyzer badAnalyzer = new ResourceAnalyzer() {
public void analyzeResource(Resource resource, List<Capability> capabilities, List<Requirement> requirements) throws Exception {
throw new Exception("Bang!");
}
};
ResourceAnalyzer goodAnalyzer = mock(ResourceAnalyzer.class);
LogService log = mock(LogService.class);
RepoIndex indexer = new RepoIndex(log);
indexer.addAnalyzer(badAnalyzer, null);
indexer.addAnalyzer(goodAnalyzer, null);
// Run the indexer
Map<String, String> props = new HashMap<String, String>();
props.put(ResourceIndexer.ROOT_URL, new File("testdata").getAbsoluteFile().toURI().toURL().toString());
StringWriter writer = new StringWriter();
indexer.indexFragment(Collections.singleton(new File("testdata/subdir/01-bsn+version.jar")), writer, props);
// The "good" analyzer should have been called
verify(goodAnalyzer).analyzeResource(any(Resource.class), anyListOf(Capability.class), anyListOf(Requirement.class));
// The log service should have been notified about the exception
ArgumentCaptor<Exception> exceptionCaptor = ArgumentCaptor.forClass(Exception.class);
verify(log).log(eq(LogService.LOG_ERROR), any(String.class), exceptionCaptor.capture());
assertEquals("Bang!", exceptionCaptor.getValue().getMessage());
}
use of org.osgi.service.indexer.Requirement in project bnd by bndtools.
the class SCRAnalyzer method analyzeResource.
public void analyzeResource(Resource resource, List<Capability> caps, List<Requirement> reqs) throws Exception {
String header = null;
Manifest manifest = resource.getManifest();
if (manifest != null)
header = manifest.getMainAttributes().getValue(ComponentConstants.SERVICE_COMPONENT);
if (header == null)
return;
StringTokenizer tokenizer = new StringTokenizer(header, ",");
Version highest = null;
while (tokenizer.hasMoreTokens()) {
String pattern = tokenizer.nextToken().trim();
List<String> paths = Util.findMatchingPaths(resource, pattern);
if (paths != null)
for (String path : paths) {
Version version = processScrXml(resource, path, caps, reqs);
if (version == null)
continue;
if (highest == null || (version.compareTo(highest) > 0))
highest = version;
}
}
if (highest != null) {
Version lower = new Version(highest.getMajor(), highest.getMinor(), 0);
Version upper = new Version(highest.getMajor() + 1, 0, 0);
Requirement requirement = createRequirement(new VersionRange(true, lower, upper, false));
reqs.add(requirement);
}
}
Aggregations