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);
}
use of org.osgi.service.log.LogService in project bnd by bndtools.
the class DSAnnotationTest method testInheritance.
public void testInheritance(String key, String value, String extender) throws Exception {
Builder b = new Builder();
b.setProperty(Constants.DSANNOTATIONS, "test.component.DSAnnotationTest*Bottom");
b.setProperty(key, value);
b.setProperty("Private-Package", "test.component");
b.addClasspath(new File("bin"));
Jar jar = b.build();
assertOk(b);
Attributes a = getAttr(jar);
checkProvides(a);
checkRequires(a, extender, LogService.class.getName());
Resource r = jar.getResource("OSGI-INF/bottom.xml");
assertNotNull(r);
r.write(System.err);
XmlTester xt = new XmlTester(r.openInputStream(), "scr", "http://www.osgi.org/xmlns/scr/v1.3.0");
xt.assertAttribute("LogService", "scr:component/reference[1]/@name");
xt.assertAttribute("setLogService", "scr:component/reference[1]/@bind");
xt.assertAttribute("unsetLogService", "scr:component/reference[1]/@unbind");
xt.assertAttribute("updatedLogService", "scr:component/reference[1]/@updated");
xt.assertAttribute("PrivateLogService", "scr:component/reference[2]/@name");
xt.assertAttribute("setPrivateLogService", "scr:component/reference[2]/@bind");
xt.assertAttribute("unsetPrivateLogService", "scr:component/reference[2]/@unbind");
// is private in super class
xt.assertAttribute("", "scr:component/reference[2]/@updated");
}
use of org.osgi.service.log.LogService in project bnd by bndtools.
the class DSAnnotationTest method testBinds.
public void testBinds(String extender) throws Exception {
Builder b = new Builder();
b.setProperty(Constants.DSANNOTATIONS, "test.component.DSAnnotationTest*CheckBinds");
if (extender != null)
b.setProperty(Constants.DSANNOTATIONS_OPTIONS, "extender");
b.setProperty(Constants.DSANNOTATIONS_OPTIONS + ".min", "version;minimum=1.2.0");
b.setProperty("Private-Package", "test.component");
b.addClasspath(new File("bin"));
Jar jar = b.build();
assertOk(b);
Attributes a = getAttr(jar);
checkProvides(a);
checkRequires(a, extender, LogService.class.getName());
Resource r = jar.getResource("OSGI-INF/prototypes.xml");
assertNotNull(r);
r.write(System.err);
XmlTester xt = new XmlTester(r.openInputStream(), "scr", "http://www.osgi.org/xmlns/scr/v1.2.0");
xt.assertAttribute("LogService", "scr:component/reference[1]/@name");
xt.assertAttribute("bindLogService", "scr:component/reference[1]/@bind");
xt.assertAttribute("unbindLogService", "scr:component/reference[1]/@unbind");
xt.assertAttribute("updatedLogService", "scr:component/reference[1]/@updated");
}
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 bnd by bndtools.
the class LogTracker method log.
public void log(ServiceReference sr, int level, String message, Throwable exception) {
LogService log = getService();
if (log != null)
log.log(sr, level, message, exception);
else {
PrintStream stream = (level <= LogService.LOG_WARNING) ? System.err : System.out;
if (message == null)
message = "";
Date now = new Date();
stream.println(String.format("[%-7s] %tF %tT: %s", LogUtils.formatLogLevel(level), now, now, message));
if (exception != null)
exception.printStackTrace(stream);
}
}
Aggregations