use of org.osgi.service.packageadmin.PackageAdmin in project sling by apache.
the class SlingFelixTest method test_Felix_getBundle_Class_from_PackageAdmin.
@SuppressWarnings("deprecation")
@Test
public void test_Felix_getBundle_Class_from_PackageAdmin() {
/*
* Tests whether the Felix.getBundle(Class) call from PackageAdmin
* is possible. This test should always succeed regardless of the
* SLING-2554 implementation because it uses regular Java call
* methodology.
*/
PackageAdmin pa = getService(framework, PackageAdmin.class);
assertNotNull(pa);
assertNull("Integer class provided by the VM not from a bundle", pa.getBundle(Integer.class));
assertEquals("BundleContext class must come from the framework", framework.getBundle(), pa.getBundle(BundleContext.class));
}
use of org.osgi.service.packageadmin.PackageAdmin in project rt.equinox.framework by eclipse.
the class SubstituteExportsBundleTests method testSubstituteExports13.
public void testSubstituteExports13() throws BundleException {
// $NON-NLS-1$
Bundle a = installer.installBundle("substitutes.a");
// $NON-NLS-1$
Bundle b = installer.installBundle("substitutes.b");
// $NON-NLS-1$
Bundle c = installer.installBundle("substitutes.c");
// $NON-NLS-1$
Bundle d = installer.installBundle("substitutes.d");
Bundle[] allBundles = new Bundle[] { a, b, c, d };
// $NON-NLS-1$
assertTrue("Bundles are not resolved", installer.resolveBundles(allBundles));
PackageAdmin pa = installer.getPackageAdmin();
// $NON-NLS-1$
ExportedPackage[] xPackages = pa.getExportedPackages("substitutes.x");
// $NON-NLS-1$
assertNotNull("xPackages is null", xPackages);
// $NON-NLS-1$
assertEquals("xPackages wrong number", 1, xPackages.length);
// $NON-NLS-1$
assertEquals("Wrong exporter", a, xPackages[0].getExportingBundle());
Bundle[] xImporters = xPackages[0].getImportingBundles();
// $NON-NLS-1$
assertNotNull("xImporters is null", xImporters);
// $NON-NLS-1$
assertEquals("Wrong number of xImporters", 3, xImporters.length);
// $NON-NLS-1$
ExportedPackage[] yPackages = pa.getExportedPackages("substitutes.y");
// $NON-NLS-1$
assertNotNull("yPackages is null", yPackages);
// $NON-NLS-1$
assertEquals("yPackages wrong number", 1, yPackages.length);
// $NON-NLS-1$
assertEquals("Wrong exporter", a, yPackages[0].getExportingBundle());
Bundle[] yImporters = yPackages[0].getImportingBundles();
// $NON-NLS-1$
assertNotNull("yImporters is null", yImporters);
// $NON-NLS-1$
assertEquals("Wrong number of yImporters", 3, yImporters.length);
Bundle[] expectedImporters = new Bundle[] { b, c, d };
for (int i = 0; i < expectedImporters.length; i++) {
// $NON-NLS-1$
contains("xPackages importers does not contain", xImporters, expectedImporters[i]);
// $NON-NLS-1$
contains("yPackages importers does not contain", yImporters, expectedImporters[i]);
}
}
use of org.osgi.service.packageadmin.PackageAdmin in project rt.equinox.framework by eclipse.
the class SubstituteExportsBundleTests method testSubstituteExports14.
public void testSubstituteExports14() throws BundleException {
// $NON-NLS-1$
Bundle iBundle = installer.installBundle("substitutes.i");
// $NON-NLS-1$
Bundle jBundle = installer.installBundle("substitutes.j");
// $NON-NLS-1$
Bundle kBundle = installer.installBundle("substitutes.k");
// $NON-NLS-1$
Bundle lBundle = installer.installBundle("substitutes.l");
// $NON-NLS-1$
Bundle mBundle = installer.installBundle("substitutes.m");
// $NON-NLS-1$
Bundle nBundle = installer.installBundle("substitutes.n");
// $NON-NLS-1$
Bundle pBundle = installer.installBundle("substitutes.p");
// $NON-NLS-1$
Bundle qBundle = installer.installBundle("substitutes.q");
// k and l do not depend on i
Bundle[] allBundles = new Bundle[] { iBundle, jBundle, kBundle, lBundle, mBundle, nBundle, pBundle, qBundle };
// $NON-NLS-1$
assertTrue("Bundles are not resolved", installer.resolveBundles(allBundles));
PackageAdmin pa = installer.getPackageAdmin();
// $NON-NLS-1$
ExportedPackage[] xPackages = pa.getExportedPackages("substitutes.x");
// $NON-NLS-1$
assertNotNull("xPackages is null", xPackages);
// $NON-NLS-1$
assertEquals("xPackages wrong number", 3, xPackages.length);
// $NON-NLS-1$
ExportedPackage[] yPackages = pa.getExportedPackages("substitutes.y");
// $NON-NLS-1$
assertNotNull("yPackages is null", yPackages);
// $NON-NLS-1$
assertEquals("yPackages wrong number", 3, yPackages.length);
Bundle[] expectedExporters = new Bundle[] { iBundle, kBundle, mBundle };
for (int i = 0; i < expectedExporters.length; i++) {
boolean found = false;
for (int j = 0; j < xPackages.length && !found; j++) {
found = expectedExporters[i] == xPackages[j].getExportingBundle();
if (found) {
Bundle[] importingBundles = xPackages[j].getImportingBundles();
Bundle[] expectedImporters = null;
String message = null;
if (expectedExporters[i] == iBundle) {
expectedImporters = new Bundle[] { jBundle, mBundle, nBundle, pBundle, qBundle };
// $NON-NLS-1$
message = "iBundle ";
} else if (expectedExporters[i] == kBundle) {
expectedImporters = new Bundle[] { lBundle, mBundle, nBundle, pBundle, qBundle };
// $NON-NLS-1$
message = "kBundle ";
} else if (expectedExporters[i] == mBundle) {
expectedImporters = new Bundle[] { nBundle, pBundle, qBundle };
// $NON-NLS-1$
message = "mBundle ";
}
assertEquals(message, expectedImporters.length, importingBundles.length);
for (int k = 0; k < expectedImporters.length; k++) contains(message, importingBundles, expectedImporters[k]);
}
}
}
}
use of org.osgi.service.packageadmin.PackageAdmin in project rt.equinox.framework by eclipse.
the class SystemBundleTests method testSystemBundle11.
public void testSystemBundle11() {
// test extra packages property
// $NON-NLS-1$
File config = OSGiTestsActivator.getContext().getDataFile("testSystemBundle11");
Map<String, Object> configuration = new HashMap<String, Object>();
configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
// $NON-NLS-1$
configuration.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, "test.pkg1, test.pkg2");
Equinox equinox = new Equinox(configuration);
try {
equinox.init();
equinox.start();
} catch (BundleException e) {
// $NON-NLS-1$
fail("Failed to start the framework", e);
}
// $NON-NLS-1$
assertEquals("Wrong state for SystemBundle", Bundle.ACTIVE, equinox.getState());
BundleContext systemContext = equinox.getBundleContext();
// $NON-NLS-1$
assertNotNull("SystemBundle context is null", systemContext);
PackageAdmin pa = (PackageAdmin) equinox.getBundleContext().getService(equinox.getBundleContext().getServiceReference(PackageAdmin.class.getName()));
// $NON-NLS-1$
ExportedPackage[] pkg1 = pa.getExportedPackages("test.pkg1");
assertNotNull(pkg1);
// $NON-NLS-1$
assertEquals("Wrong number of exports", 1, pkg1.length);
// $NON-NLS-1$ //$NON-NLS-2$
assertEquals("Wrong package name", "test.pkg1", pkg1[0].getName());
// $NON-NLS-1$
ExportedPackage[] pkg2 = pa.getExportedPackages("test.pkg2");
assertNotNull(pkg2);
// $NON-NLS-1$
assertEquals("Wrong number of exports", 1, pkg2.length);
// $NON-NLS-1$ //$NON-NLS-2$
assertEquals("Wrong package name", "test.pkg2", pkg2[0].getName());
try {
equinox.stop();
} catch (BundleException e) {
// $NON-NLS-1$
fail("Unexpected erorr stopping framework", e);
}
try {
equinox.waitForStop(10000);
} catch (InterruptedException e) {
// $NON-NLS-1$
fail("Unexpected interrupted exception", e);
}
// $NON-NLS-1$
assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState());
}
use of org.osgi.service.packageadmin.PackageAdmin in project rt.equinox.framework by eclipse.
the class BundleInstaller method refreshPackages.
public synchronized Bundle[] refreshPackages(Bundle[] refresh) {
if (bundles == null)
return null;
PackageAdmin pa = (PackageAdmin) packageAdmin.getService();
final boolean[] flag = new boolean[] { false };
FrameworkListener listener = new FrameworkListener() {
public void frameworkEvent(FrameworkEvent event) {
if (event.getType() == FrameworkEvent.PACKAGES_REFRESHED)
synchronized (flag) {
flag[0] = true;
flag.notifyAll();
}
}
};
context.addFrameworkListener(listener);
final HashSet refreshed = new HashSet();
BundleListener refreshBundleListener = new SynchronousBundleListener() {
public void bundleChanged(BundleEvent event) {
refreshed.add(event.getBundle());
}
};
context.addBundleListener(refreshBundleListener);
try {
pa.refreshPackages(refresh);
synchronized (flag) {
while (!flag[0]) {
try {
flag.wait(5000);
} catch (InterruptedException e) {
// do nothing
}
}
}
} finally {
context.removeFrameworkListener(listener);
context.removeBundleListener(refreshBundleListener);
}
return (Bundle[]) refreshed.toArray(new Bundle[refreshed.size()]);
}
Aggregations