use of org.osgi.service.log.LogService 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.log.LogService in project bnd by bndtools.
the class TestIndexer method testBundleOutsideRootDirectory.
public void testBundleOutsideRootDirectory() throws Exception {
LogService log = mock(LogService.class);
RepoIndex indexer = new RepoIndex(log);
Map<String, String> props = new HashMap<String, String>();
props.put(ResourceIndexer.ROOT_URL, new File("testdata/subdir").getAbsoluteFile().toURI().toURL().toString());
StringWriter writer = new StringWriter();
indexer.indexFragment(Collections.singleton(new File("testdata/01-bsn+version.jar")), writer, props);
verify(log).log(eq(LogService.LOG_ERROR), anyString(), isA(IllegalArgumentException.class));
}
use of org.osgi.service.log.LogService in project bnd by bndtools.
the class TestIndexer method testFragmentPlainJar.
public void testFragmentPlainJar() throws Exception {
LogService mockLog = Mockito.mock(LogService.class);
RepoIndex indexer = new RepoIndex(mockLog);
indexer.addAnalyzer(new KnownBundleAnalyzer(), FrameworkUtil.createFilter("(name=*)"));
assertFragmentMatch(indexer, "testdata/fragment-plainjar.txt", "testdata/jcip-annotations.jar");
Mockito.verifyZeroInteractions(mockLog);
}
use of org.osgi.service.log.LogService in project bnd by bndtools.
the class TestStandaloneLibrary method assertIndexPath.
private void assertIndexPath(String root, String file, String dest) throws Exception {
File tempDir = IO.getFile(root);
tempDir.mkdirs();
final List<String> errors = new ArrayList<>();
final List<String> warnings = new ArrayList<>();
File target = IO.getFile(tempDir, dest);
target.getParentFile().mkdirs();
try {
IO.copy(IO.getFile("src/testdata/01-bsn+version.jar"), target);
ResourceIndexer indexer = new RepoIndex(new LogService() {
@Override
public void log(ServiceReference sr, int level, String message, Throwable exception) {
log(level, message + " " + exception);
}
@Override
public void log(ServiceReference sr, int level, String message) {
log(level, message);
}
@Override
public void log(int level, String message, Throwable exception) {
log(level, message + " " + exception);
}
@Override
public void log(int level, String message) {
switch(level) {
case LogService.LOG_ERROR:
errors.add(message);
break;
case LogService.LOG_WARNING:
warnings.add(message);
break;
default:
break;
}
}
});
StringWriter writer = new StringWriter();
String osRootPath = root.replace('/', File.separatorChar);
String rootURI = new File(osRootPath).toURI().toString();
File osFile = new File(file.replace('/', File.separatorChar));
assertTrue(osFile + " does not exist", osFile.isFile());
Map<String, String> config = new HashMap<String, String>();
config.put(ResourceIndexer.ROOT_URL, rootURI);
indexer.indexFragment(Collections.singleton(osFile), writer, config);
assertEquals(0, errors.size());
assertEquals(0, warnings.size());
} finally {
deleteWithException(tempDir);
}
}
use of org.osgi.service.log.LogService in project sling by apache.
the class OsgiInstallerTestBase method log.
protected void log(int level, String msg) {
final LogService log = getService(LogService.class);
log.log(level, msg);
}
Aggregations