use of org.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.
the class DiscardBundleTests method doTest.
private void doTest(Map<String, ?> configuration, boolean discard, File bundleFile) throws Exception {
Equinox equinox = new Equinox(configuration);
initAndStart(equinox);
try {
String location = REFERENCE_PROTOCOL + bundleFile.toURI();
equinox.getBundleContext().installBundle(location);
try {
equinox = restart(equinox, configuration);
assertNotDiscarded(location, equinox);
// Attempting to touch the file with equinox still running
// will sometimes result in failure presumably due to a locked
// file.
stop(equinox);
touchFile(bundleFile);
equinox = restart(equinox, configuration);
if (discard)
assertDiscarded(location, equinox);
else
assertNotDiscarded(location, equinox);
} finally {
try {
equinox.getBundleContext().getBundle(location).uninstall();
} catch (Exception e) {
// Ignore
}
}
} finally {
stopQuietly(equinox);
}
}
use of org.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.
the class DiscardBundleTests method restart.
private Equinox restart(Equinox equinox, Map<String, ?> configuration) throws BundleException, InterruptedException {
stop(equinox);
equinox = new Equinox(configuration);
initAndStart(equinox);
return equinox;
}
use of org.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.
the class DiscardBundleTests method doTestDiscardDeletedBundleFile.
private void doTestDiscardDeletedBundleFile(File bundleFile) throws Exception {
Map<String, Object> configuration = createConfiguration();
Equinox equinox = new Equinox(configuration);
initAndStart(equinox);
try {
String location = REFERENCE_PROTOCOL + bundleFile.toURI();
equinox.getBundleContext().installBundle(location);
equinox = restart(equinox, configuration);
assertNotDiscarded(location, equinox);
// Attempting to delete the file with equinox still running
// will sometimes result in failure presumably due to a locked
// file.
stop(equinox);
rm(bundleFile);
equinox = restart(equinox, configuration);
assertDiscarded(location, equinox);
} finally {
stopQuietly(equinox);
}
}
use of org.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.
the class ImportJavaSEPackagesTests method doSystemPackages.
public void doSystemPackages(int rv, int expectedPackages) throws Exception {
if (rv < 9) {
System.setProperty("java.specification.version", "1." + rv);
} else {
System.setProperty("java.specification.version", Integer.toString(rv));
}
File config = OSGiTestsActivator.getContext().getDataFile(getName());
Map<String, String> headers = new HashMap<String, String>();
headers.put(Constants.BUNDLE_MANIFESTVERSION, "2");
headers.put(Constants.BUNDLE_SYMBOLICNAME, getName());
config.mkdirs();
File bundle = SystemBundleTests.createBundle(config, getName(), headers);
Equinox equinox = new Equinox(Collections.singletonMap(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath()));
try {
equinox.start();
BundleContext systemContext = equinox.getBundleContext();
Dictionary<String, String> testHeaders = equinox.getHeaders();
assertTrue(Constants.EXPORT_PACKAGE + " does not contain the java.* package", testHeaders.get(Constants.EXPORT_PACKAGE).contains(JAVA_LANG));
assertTrue(Constants.EXPORT_PACKAGE + " does not contain the java.* package", testHeaders.get(Constants.EXPORT_PACKAGE).contains(JAVA_UTIL));
List<BundleCapability> capabilities = equinox.adapt(BundleWiring.class).getCapabilities(PackageNamespace.PACKAGE_NAMESPACE);
int count = 0;
for (BundleCapability cap : capabilities) {
if (cap.getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE).toString().startsWith("java.")) {
count++;
}
}
assertEquals("Wrong number of java.* packages for version " + rv, expectedPackages, count);
Bundle testBundle = systemContext.installBundle(bundle.toURI().toString());
testBundle.start();
String systemPackages = testBundle.getBundleContext().getProperty(Constants.FRAMEWORK_SYSTEMPACKAGES);
assertTrue("System packages should include java.* packages", systemPackages.contains(JAVA_LANG));
assertTrue("System packages should include java.* packages", systemPackages.contains(JAVA_UTIL));
} catch (BundleException e) {
fail("Failed to test System packages");
} finally {
try {
equinox.stop();
equinox.waitForStop(10000);
} catch (Exception e) {
// do nothing
}
}
}
use of org.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.
the class MultiReleaseJarTests method doTestMultiReleaseClassLoad.
private void doTestMultiReleaseClassLoad(int rv) throws Exception {
if (rv < 9) {
System.setProperty("java.specification.version", "1." + rv);
} else {
System.setProperty("java.specification.version", Integer.toString(rv));
}
// $NON-NLS-1$
File config = OSGiTestsActivator.getContext().getDataFile(getName());
Equinox equinox = new Equinox(Collections.singletonMap(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath()));
try {
equinox.start();
BundleContext systemContext = equinox.getBundleContext();
Bundle mrBundle = systemContext.installBundle(mrJarBundle.toURI().toString());
mrBundle.start();
assertEquals("Wrong class.", "BASEXX", loadClass("multi.release.test.TestClassBase", mrBundle, false));
assertEquals("Wrong class.", "BASEXX", loadClass("multi.release.test.TestClass8", mrBundle, false));
assertEquals("Wrong class.", CNFE, loadClass("multi.release.test.TestClassAdd8", mrBundle, true));
assertEquals("Wrong class.", (rv >= 9) ? "BASE09" : "BASEXX", loadClass("multi.release.test.TestClass9", mrBundle, false));
assertEquals("Wrong class.", (rv >= 9) ? "ADD09" : CNFE, loadClass("multi.release.test.TestClassAdd9", mrBundle, true));
assertEquals("Wrong class.", (rv >= 10) ? "BASE10" : "BASEXX", loadClass("multi.release.test.TestClass10", mrBundle, false));
assertEquals("Wrong class.", (rv >= 10) ? "ADD10" : CNFE, loadClass("multi.release.test.TestClassAdd10", mrBundle, true));
assertEquals("Wrong class.", (rv >= 11) ? "BASE11" : "BASEXX", loadClass("multi.release.test.TestClass11", mrBundle, false));
assertEquals("Wrong class.", (rv >= 11) ? "ADD11" : CNFE, loadClass("multi.release.test.TestClassAdd11", mrBundle, true));
assertEquals("Wrong class.", "BASEXX", loadClass("multi.release.test.sub.TestClassBase", mrBundle, false));
assertEquals("Wrong class.", "BASEXX", loadClass("multi.release.test.sub.TestClass8", mrBundle, false));
assertEquals("Wrong class.", CNFE, loadClass("multi.release.test.TestClassAdd8", mrBundle, true));
assertEquals("Wrong class.", (rv >= 9) ? "BASE09" : "BASEXX", loadClass("multi.release.test.sub.TestClass9", mrBundle, false));
assertEquals("Wrong class.", (rv >= 9) ? "ADD09" : CNFE, loadClass("multi.release.test.sub.TestClassAdd9", mrBundle, true));
assertEquals("Wrong class.", (rv >= 10) ? "BASE10" : "BASEXX", loadClass("multi.release.test.sub.TestClass10", mrBundle, false));
assertEquals("Wrong class.", (rv >= 10) ? "ADD10" : CNFE, loadClass("multi.release.test.sub.TestClassAdd10", mrBundle, true));
assertEquals("Wrong class.", (rv >= 11) ? "BASE11" : "BASEXX", loadClass("multi.release.test.sub.TestClass11", mrBundle, false));
assertEquals("Wrong class.", (rv >= 11) ? "ADD11" : CNFE, loadClass("multi.release.test.sub.TestClassAdd11", mrBundle, true));
assertEquals("Wrong class.", "BASEXX", loadClass("multi.release.test.sub2.TestClassBase", mrBundle, false));
assertEquals("Wrong class.", "BASEXX", loadClass("multi.release.test.sub2.TestClass8", mrBundle, false));
assertEquals("Wrong class.", CNFE, loadClass("multi.release.test.TestClassAdd8", mrBundle, true));
assertEquals("Wrong class.", (rv >= 9) ? "BASE09" : "BASEXX", loadClass("multi.release.test.sub2.TestClass9", mrBundle, false));
assertEquals("Wrong class.", (rv >= 9) ? "ADD09" : CNFE, loadClass("multi.release.test.sub2.TestClassAdd9", mrBundle, true));
assertEquals("Wrong class.", (rv >= 10) ? "BASE10" : "BASEXX", loadClass("multi.release.test.sub2.TestClass10", mrBundle, false));
assertEquals("Wrong class.", (rv >= 10) ? "ADD10" : CNFE, loadClass("multi.release.test.sub2.TestClassAdd10", mrBundle, true));
assertEquals("Wrong class.", (rv >= 11) ? "BASE11" : "BASEXX", loadClass("multi.release.test.sub2.TestClass11", mrBundle, false));
assertEquals("Wrong class.", (rv >= 11) ? "ADD11" : CNFE, loadClass("multi.release.test.sub2.TestClassAdd11", mrBundle, true));
} finally {
try {
equinox.stop();
equinox.waitForStop(10000);
} catch (Exception e) {
// ignore;
}
}
}
Aggregations