Search in sources :

Example 6 with LogService

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);
}
Also used : LogService(org.osgi.service.log.LogService)

Example 7 with LogService

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");
}
Also used : XmlTester(aQute.bnd.test.XmlTester) Builder(aQute.bnd.osgi.Builder) Attributes(java.util.jar.Attributes) Resource(aQute.bnd.osgi.Resource) Jar(aQute.bnd.osgi.Jar) File(java.io.File) LogService(org.osgi.service.log.LogService)

Example 8 with LogService

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");
}
Also used : XmlTester(aQute.bnd.test.XmlTester) Builder(aQute.bnd.osgi.Builder) Attributes(java.util.jar.Attributes) Resource(aQute.bnd.osgi.Resource) Jar(aQute.bnd.osgi.Jar) File(java.io.File) LogService(org.osgi.service.log.LogService)

Example 9 with LogService

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);
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ResourceIndexer(org.osgi.service.indexer.ResourceIndexer) ServiceReference(org.osgi.framework.ServiceReference) StringWriter(java.io.StringWriter) File(java.io.File) Utils.copyToTempFile(org.example.tests.utils.Utils.copyToTempFile) RepoIndex(org.osgi.service.indexer.impl.RepoIndex) LogService(org.osgi.service.log.LogService)

Example 10 with LogService

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);
    }
}
Also used : PrintStream(java.io.PrintStream) LogService(org.osgi.service.log.LogService) Date(java.util.Date)

Aggregations

LogService (org.osgi.service.log.LogService)14 File (java.io.File)10 StringWriter (java.io.StringWriter)5 HashMap (java.util.HashMap)5 Builder (aQute.bnd.osgi.Builder)4 Jar (aQute.bnd.osgi.Jar)4 Resource (aQute.bnd.osgi.Resource)4 XmlTester (aQute.bnd.test.XmlTester)4 Attributes (java.util.jar.Attributes)4 Matchers.anyString (org.mockito.Matchers.anyString)4 PrintStream (java.io.PrintStream)2 List (java.util.List)2 Utils.copyToTempFile (org.example.tests.utils.Utils.copyToTempFile)2 ServiceReference (org.osgi.framework.ServiceReference)2 Resource (org.osgi.service.indexer.Resource)2 ResourceAnalyzer (org.osgi.service.indexer.ResourceAnalyzer)2 ResourceIndexer (org.osgi.service.indexer.ResourceIndexer)2 Run (aQute.bnd.build.Run)1 Workspace (aQute.bnd.build.Workspace)1 IOException (java.io.IOException)1