Search in sources :

Example 56 with Bundle

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

the class BundlesMBeanImpl method restart.

public void restart(String bundleId) throws MBeanException {
    try {
        List<Bundle> bundles = selectBundles(bundleId);
        for (Bundle bundle : bundles) {
            bundle.stop();
            bundle.start();
        }
    } catch (Exception e) {
        throw new MBeanException(null, e.toString());
    }
}
Also used : Bundle(org.osgi.framework.Bundle) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MBeanException(javax.management.MBeanException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MBeanException(javax.management.MBeanException)

Example 57 with Bundle

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

the class TestBundleFactory method createBundle.

Bundle createBundle(long id, String name) {
    Bundle bundle = createMock(Bundle.class);
    expect(bundle.getBundleId()).andReturn(id).anyTimes();
    Dictionary<String, String> headers = new Hashtable<>();
    headers.put(Constants.BUNDLE_NAME, name);
    expect(bundle.getHeaders()).andReturn(headers).anyTimes();
    return bundle;
}
Also used : Bundle(org.osgi.framework.Bundle) Hashtable(java.util.Hashtable)

Example 58 with Bundle

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

the class TestBundleFactory method createBundleContext.

public BundleContext createBundleContext() {
    BundleContext bundleContext = createMock(BundleContext.class);
    Bundle[] bundles = createBundles();
    expect(bundleContext.getProperty("karaf.systemBundlesStartLevel")).andReturn(Integer.toString(50)).anyTimes();
    expect(bundleContext.getBundles()).andReturn(bundles).anyTimes();
    expect(bundleContext.getBundle(0)).andReturn(null).anyTimes();
    expect(bundleContext.getBundle(1)).andReturn(bundles[0]).anyTimes();
    expect(bundleContext.getBundle(2)).andReturn(bundles[1]).anyTimes();
    replay(bundleContext);
    return bundleContext;
}
Also used : Bundle(org.osgi.framework.Bundle) BundleContext(org.osgi.framework.BundleContext)

Example 59 with Bundle

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

the class BundleSelectorImpl method getBundlesByLocation.

private List<Bundle> getBundlesByLocation(String url) {
    Bundle[] bundles = bundleContext.getBundles();
    ArrayList<Bundle> result = new ArrayList<>();
    Pattern locationPattern = Pattern.compile(url);
    for (Bundle bundle : bundles) {
        Matcher locationMatcher = locationPattern.matcher(bundle.getLocation());
        if (locationMatcher.matches()) {
            result.add(bundle);
        }
    }
    return result;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList)

Example 60 with Bundle

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

the class MetaCompleter method updateMeta.

private synchronized void updateMeta() {
    List<String> pids = MetaServiceCaller.withMetaTypeService(context, metatypeService -> {
        List<String> pids1 = new ArrayList<>();
        Bundle[] bundles = context.getBundles();
        for (Bundle bundle : bundles) {
            MetaTypeInformation info = metatypeService.getMetaTypeInformation(bundle);
            if (info == null) {
                continue;
            }
            if (info.getFactoryPids() != null) {
                pids1.addAll(Arrays.asList(info.getFactoryPids()));
            }
            if (info.getPids() != null) {
                pids1.addAll(Arrays.asList(info.getPids()));
            }
        }
        return pids1;
    });
    if (pids != null) {
        delegate.getStrings().clear();
        delegate.getStrings().addAll(pids);
    }
}
Also used : Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) MetaTypeInformation(org.osgi.service.metatype.MetaTypeInformation)

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