use of org.osgi.service.indexer.Capability 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.Capability 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());
}
Aggregations