Search in sources :

Example 96 with Bundle

use of org.osgi.framework.Bundle in project sling by apache.

the class SlingTldLocationsCache method printConfiguration.

public void printConfiguration(final PrintWriter pw) {
    pw.println("Currently available JSP Taglibs:");
    final SortedMap<String, String> taglibs = new TreeMap<String, String>();
    for (final Map.Entry<String, TldLocationEntry> entry : tldLocations.entrySet()) {
        final long bundleId = entry.getValue().getBundleId();
        final Bundle bundle = bundleContext.getBundle(bundleId);
        if (bundle != null) {
            taglibs.put(entry.getKey(), String.format("%s (%s)", bundle.getSymbolicName(), bundleId));
        } else {
            // really shouldn't happen
            taglibs.put(entry.getKey(), String.format("INVALID BUNDLE ID: %s", bundleId));
        }
    }
    for (final Map.Entry<String, String> entry : taglibs.entrySet()) {
        pw.printf("  %s - %s\n", entry.getKey(), entry.getValue());
    }
}
Also used : Bundle(org.osgi.framework.Bundle) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) SortedMap(java.util.SortedMap)

Example 97 with Bundle

use of org.osgi.framework.Bundle in project sling by apache.

the class LogSupportTest method prepare.

@Before
@SuppressWarnings("unchecked")
public void prepare() throws Exception {
    bundle = Mockito.mock(Bundle.class);
    Mockito.when(bundle.getSymbolicName()).thenReturn("foo.bundle");
    Mockito.when(bundle.getBundleId()).thenReturn(42L);
    StartLevel startLevel = Mockito.mock(StartLevel.class);
    logSupport = new LogSupport(startLevel);
    Field loggerField = LogSupport.class.getDeclaredField("loggers");
    loggerField.setAccessible(true);
    Map<Long, Logger> loggers = (Map<Long, Logger>) loggerField.get(logSupport);
    testLogger = getMockInfoLogger();
    loggers.put(bundle.getBundleId(), testLogger);
}
Also used : Field(java.lang.reflect.Field) Bundle(org.osgi.framework.Bundle) StartLevel(org.osgi.service.startlevel.StartLevel) Logger(org.slf4j.Logger) HashMap(java.util.HashMap) Map(java.util.Map) Before(org.junit.Before)

Example 98 with Bundle

use of org.osgi.framework.Bundle in project sling by apache.

the class BundleBundleVersionInfoTest method testSnapshot.

@Test
public void testSnapshot() {
    final String name = "some.bundle";
    final Version version = new Version("1.0.4.SNAPSHOT");
    final long lastMod = 0;
    final Bundle b = getMockBundle(name, version, lastMod);
    BundleVersionInfo<?> vi = new BundleBundleVersionInfo(b);
    assertEquals("Symbolic name matches", name, vi.getBundleSymbolicName());
    assertEquals("Version matches", version, vi.getVersion());
    assertTrue("isBundle", vi.isBundle());
    assertTrue("Bundle is a snapshot", vi.isSnapshot());
    assertEquals("Last-Modified matches", BundleVersionInfo.BND_LAST_MODIFIED_MISSING, vi.getBundleLastModified());
    assertTrue("Bundle is stored as source", vi.getSource() == b);
}
Also used : Version(org.osgi.framework.Version) Bundle(org.osgi.framework.Bundle) Test(org.junit.Test)

Example 99 with Bundle

use of org.osgi.framework.Bundle in project sling by apache.

the class Activator method start.

public void start(BundleContext bundleContext) {
    // install handler for uncaught exceptions
    oldHandler = Thread.getDefaultUncaughtExceptionHandler();
    Thread.setDefaultUncaughtExceptionHandler(this);
    // install thread handler shell command
    register(bundleContext, new String[] { "org.apache.felix.shell.Command" }, new ServiceFactory() {

        public void ungetService(final Bundle bundle, final ServiceRegistration reg, final Object consoleObject) {
        // nothing to do
        }

        public Object getService(final Bundle bundle, final ServiceRegistration reg) {
            return new ThreadDumpCommand();
        }
    }, null);
    // install Web Console configuration printer
    final Dictionary<String, Object> props = new Hashtable<String, Object>();
    props.put("felix.webconsole.label", "slingthreads");
    props.put("felix.webconsole.title", "Threads");
    props.put("felix.webconsole.configprinter.modes", "always");
    final ThreadDumperPanel tdp = new ThreadDumperPanel();
    register(bundleContext, new String[] { tdp.getClass().getName() }, tdp, props);
}
Also used : ServiceFactory(org.osgi.framework.ServiceFactory) Bundle(org.osgi.framework.Bundle) Hashtable(java.util.Hashtable) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 100 with Bundle

use of org.osgi.framework.Bundle in project sling by apache.

the class AdapterManagerTest method createBundle.

/**
     * Helper method to create a mock bundle
     */
protected Bundle createBundle(String name) {
    final Bundle bundle = this.context.mock(Bundle.class, name);
    this.context.checking(new Expectations() {

        {
            allowing(bundle).getBundleId();
            will(returnValue(1L));
        }
    });
    return bundle;
}
Also used : Expectations(org.jmock.Expectations) Bundle(org.osgi.framework.Bundle)

Aggregations

Bundle (org.osgi.framework.Bundle)2490 Test (org.junit.Test)659 URL (java.net.URL)388 BundleContext (org.osgi.framework.BundleContext)311 File (java.io.File)298 ArrayList (java.util.ArrayList)292 IOException (java.io.IOException)278 BundleException (org.osgi.framework.BundleException)270 HashMap (java.util.HashMap)149 ServiceReference (org.osgi.framework.ServiceReference)145 Path (org.eclipse.core.runtime.Path)126 Hashtable (java.util.Hashtable)124 HashSet (java.util.HashSet)95 InputStream (java.io.InputStream)94 IStatus (org.eclipse.core.runtime.IStatus)86 Status (org.eclipse.core.runtime.Status)82 List (java.util.List)80 Map (java.util.Map)74 BundleWiring (org.osgi.framework.wiring.BundleWiring)74 Version (org.osgi.framework.Version)73