Search in sources :

Example 6 with Logger

use of org.apache.felix.utils.log.Logger in project felix by apache.

the class RepositoryImplTest method createRepositoryAdmin.

private RepositoryAdminImpl createRepositoryAdmin() throws Exception {
    BundleContext bundleContext = EasyMock.createMock(BundleContext.class);
    Bundle systemBundle = EasyMock.createMock(Bundle.class);
    BundleRevision systemBundleRevision = EasyMock.createMock(BundleRevision.class);
    Activator.setContext(bundleContext);
    EasyMock.expect(bundleContext.getProperty((String) EasyMock.anyObject())).andReturn(null).anyTimes();
    EasyMock.expect(bundleContext.getBundle(0)).andReturn(systemBundle);
    EasyMock.expect(systemBundle.getHeaders()).andReturn(new Hashtable());
    EasyMock.expect(systemBundle.getRegisteredServices()).andReturn(null);
    EasyMock.expect(new Long(systemBundle.getBundleId())).andReturn(new Long(0)).anyTimes();
    EasyMock.expect(systemBundle.getBundleContext()).andReturn(bundleContext);
    EasyMock.expect(systemBundleRevision.getCapabilities(null)).andReturn(Collections.<Capability>emptyList());
    EasyMock.expect(systemBundle.adapt(BundleRevision.class)).andReturn(systemBundleRevision);
    bundleContext.addBundleListener((BundleListener) EasyMock.anyObject());
    bundleContext.addServiceListener((ServiceListener) EasyMock.anyObject());
    EasyMock.expect(bundleContext.getBundles()).andReturn(new Bundle[] { systemBundle });
    EasyMock.expect(bundleContext.createFilter(null)).andReturn(new Filter() {

        public boolean match(ServiceReference reference) {
            return true;
        }

        public boolean match(Dictionary dictionary) {
            return true;
        }

        public boolean matchCase(Dictionary dictionary) {
            return true;
        }

        public boolean matches(Map<String, ?> map) {
            return true;
        }
    }).anyTimes();
    EasyMock.replay(new Object[] { bundleContext, systemBundle, systemBundleRevision });
    RepositoryAdminImpl repoAdmin = new RepositoryAdminImpl(bundleContext, new Logger(bundleContext));
    // force initialization && remove all initial repositories
    Repository[] repos = repoAdmin.listRepositories();
    for (int i = 0; repos != null && i < repos.length; i++) {
        repoAdmin.removeRepository(repos[i].getURI());
    }
    return repoAdmin;
}
Also used : Dictionary(java.util.Dictionary) Bundle(org.osgi.framework.Bundle) Hashtable(java.util.Hashtable) Logger(org.apache.felix.utils.log.Logger) ServiceReference(org.osgi.framework.ServiceReference) Repository(org.apache.felix.bundlerepository.Repository) Filter(org.osgi.framework.Filter) BundleRevision(org.osgi.framework.wiring.BundleRevision) Map(java.util.Map) BundleContext(org.osgi.framework.BundleContext)

Example 7 with Logger

use of org.apache.felix.utils.log.Logger in project felix by apache.

the class ResolverImplTest method createRepositoryAdmin.

private RepositoryAdminImpl createRepositoryAdmin() throws Exception {
    BundleContext bundleContext = EasyMock.createMock(BundleContext.class);
    Bundle systemBundle = EasyMock.createMock(Bundle.class);
    BundleRevision systemBundleRevision = EasyMock.createMock(BundleRevision.class);
    Activator.setContext(bundleContext);
    EasyMock.expect(bundleContext.getProperty(RepositoryAdminImpl.REPOSITORY_URL_PROP)).andReturn(getClass().getResource("/referred.xml").toExternalForm());
    EasyMock.expect(bundleContext.getProperty((String) EasyMock.anyObject())).andReturn(null).anyTimes();
    EasyMock.expect(bundleContext.getBundle(0)).andReturn(systemBundle);
    EasyMock.expect(bundleContext.installBundle((String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(systemBundle);
    EasyMock.expect(systemBundle.getHeaders()).andReturn(new Hashtable()).anyTimes();
    systemBundle.start();
    EasyMock.expectLastCall().anyTimes();
    EasyMock.expect(systemBundle.getRegisteredServices()).andReturn(null);
    EasyMock.expect(new Long(systemBundle.getBundleId())).andReturn(new Long(0)).anyTimes();
    EasyMock.expect(systemBundle.getBundleContext()).andReturn(bundleContext);
    EasyMock.expect(systemBundleRevision.getCapabilities(null)).andReturn(Collections.<Capability>emptyList());
    EasyMock.expect(systemBundle.adapt(BundleRevision.class)).andReturn(systemBundleRevision);
    bundleContext.addBundleListener((BundleListener) EasyMock.anyObject());
    bundleContext.addServiceListener((ServiceListener) EasyMock.anyObject());
    EasyMock.expect(bundleContext.getBundles()).andReturn(new Bundle[] { systemBundle });
    final Capture c = new Capture();
    EasyMock.expect(bundleContext.createFilter((String) capture(c))).andAnswer(new IAnswer() {

        public Object answer() throws Throwable {
            return FilterImpl.newInstance((String) c.getValue());
        }
    }).anyTimes();
    EasyMock.replay(new Object[] { bundleContext, systemBundle, systemBundleRevision });
    RepositoryAdminImpl repoAdmin = new RepositoryAdminImpl(bundleContext, new Logger(bundleContext));
    // force initialization && remove all initial repositories
    Repository[] repos = repoAdmin.listRepositories();
    for (int i = 0; repos != null && i < repos.length; i++) {
        repoAdmin.removeRepository(repos[i].getURI());
    }
    return repoAdmin;
}
Also used : Hashtable(java.util.Hashtable) Logger(org.apache.felix.utils.log.Logger) Capture(org.easymock.Capture) IAnswer(org.easymock.IAnswer) BundleRevision(org.osgi.framework.wiring.BundleRevision)

Example 8 with Logger

use of org.apache.felix.utils.log.Logger in project felix by apache.

the class ResolverImplTest method testFindUpdatableLocalResource.

public void testFindUpdatableLocalResource() throws Exception {
    LocalResource resource = EasyMock.createMock(LocalResource.class);
    EasyMock.expect(resource.getSymbolicName()).andReturn("com.test.bundleA").anyTimes();
    EasyMock.expect(resource.getRequirements()).andReturn(null).anyTimes();
    EasyMock.expect(resource.getCapabilities()).andReturn(null).anyTimes();
    EasyMock.expect(resource.getURI()).andReturn("http://test.com").anyTimes();
    EasyMock.expect(resource.isLocal()).andReturn(true).anyTimes();
    Repository localRepo = EasyMock.createMock(Repository.class);
    Repository[] localRepos = { localRepo };
    final LocalResource[] localResources = { resource };
    EasyMock.expect(localRepo.getResources()).andReturn(localResources).anyTimes();
    EasyMock.expect(localRepo.getURI()).andReturn(Repository.LOCAL).anyTimes();
    EasyMock.expect(localRepo.getLastModified()).andReturn(System.currentTimeMillis()).anyTimes();
    BundleContext bundleContext = EasyMock.createMock(BundleContext.class);
    EasyMock.replay(resource, localRepo);
    ResolverImpl resolver = new ResolverImpl(bundleContext, localRepos, new Logger(bundleContext)) {

        @Override
        public LocalResource[] getLocalResources() {
            return localResources;
        }
    };
    resolver.add(resource);
    boolean exceptionThrown = false;
    try {
        resolver.resolve();
        resolver.deploy(Resolver.START);
    } catch (Exception e) {
        e.printStackTrace();
        exceptionThrown = true;
    }
    assertFalse(exceptionThrown);
}
Also used : Logger(org.apache.felix.utils.log.Logger)

Example 9 with Logger

use of org.apache.felix.utils.log.Logger in project felix by apache.

the class Activator method start.

public void start(BundleContext context) {
    Activator.context = context;
    Activator.logger = new Logger(context);
    // Register bundle repository service.
    m_repoAdmin = new RepositoryAdminImpl(context, logger);
    context.registerService(RepositoryAdmin.class.getName(), m_repoAdmin, null);
    // Register the OSGi Repository-spec compliant facade
    context.registerService(Repository.class.getName(), new OSGiRepositoryImpl(m_repoAdmin), null);
    try {
        context.registerService(org.osgi.service.obr.RepositoryAdmin.class.getName(), Wrapper.wrap(m_repoAdmin), null);
    } catch (Throwable th) {
    // Ignore
    }
    // the exception when we try to register the command service.
    try {
        // Register "obr" impl command service as a
        // wrapper for the bundle repository service.
        context.registerService(org.apache.felix.shell.Command.class.getName(), new ObrCommandImpl(Activator.context, m_repoAdmin), null);
    } catch (Throwable th) {
    // Ignore.
    }
    try {
        Hashtable dict = new Hashtable();
        dict.put("osgi.command.scope", "obr");
        dict.put("osgi.command.function", new String[] { "deploy", "info", "javadoc", "list", "repos", "source" });
        context.registerService(ObrGogoCommand.class.getName(), new ObrGogoCommand(Activator.context, m_repoAdmin), dict);
    } catch (Throwable th) {
    // Ignore
    }
    try {
        Hashtable dict = new Hashtable();
        dict.put(URLConstants.URL_HANDLER_PROTOCOL, "obr");
        context.registerService(URLStreamHandlerService.class.getName(), new ObrURLStreamHandlerService(Activator.context, m_repoAdmin), dict);
    } catch (Exception e) {
        throw new RuntimeException("could not register obr url handler");
    }
}
Also used : RepositoryAdmin(org.apache.felix.bundlerepository.RepositoryAdmin) URLStreamHandlerService(org.osgi.service.url.URLStreamHandlerService) Hashtable(java.util.Hashtable) Logger(org.apache.felix.utils.log.Logger) Repository(org.osgi.service.repository.Repository)

Aggregations

Logger (org.apache.felix.utils.log.Logger)9 BundleRevision (org.osgi.framework.wiring.BundleRevision)6 Hashtable (java.util.Hashtable)5 Bundle (org.osgi.framework.Bundle)5 BundleContext (org.osgi.framework.BundleContext)5 Repository (org.apache.felix.bundlerepository.Repository)3 Capture (org.easymock.Capture)3 IAnswer (org.easymock.IAnswer)3 Dictionary (java.util.Dictionary)1 Map (java.util.Map)1 RepositoryAdmin (org.apache.felix.bundlerepository.RepositoryAdmin)1 Filter (org.osgi.framework.Filter)1 ServiceReference (org.osgi.framework.ServiceReference)1 Capability (org.osgi.resource.Capability)1 Activate (org.osgi.service.component.annotations.Activate)1 Repository (org.osgi.service.repository.Repository)1 URLStreamHandlerService (org.osgi.service.url.URLStreamHandlerService)1