use of org.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.
the class SystemBundleTests method testInitialBundleUpdate.
public void testInitialBundleUpdate() throws IOException {
// test installing bundle with empty manifest
File config = OSGiTestsActivator.getContext().getDataFile(getName());
Map<String, Object> configuration = new HashMap<String, Object>();
configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
Equinox equinox = new Equinox(configuration);
try {
equinox.init();
} catch (BundleException e) {
// $NON-NLS-1$
fail("Unexpected exception in init()", e);
}
// should be in the STARTING state
// $NON-NLS-1$
assertEquals("Wrong state for SystemBundle", Bundle.STARTING, equinox.getState());
BundleContext systemContext = equinox.getBundleContext();
// $NON-NLS-1$
assertNotNull("System context is null", systemContext);
try {
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());
File bundleFile = null;
try {
File baseDir = new File(config, "bundles");
baseDir.mkdirs();
bundleFile = createBundle(baseDir, getName(), true, true);
} catch (IOException e) {
fail("Unexpected error creating bundles.", e);
}
Bundle testBundle = null;
try {
String location = "reference:file:///" + bundleFile.getAbsolutePath();
URL url = new URL(null, location, new Handler(systemContext.getProperty(EquinoxLocations.PROP_INSTALL_AREA)));
// $NON-NLS-1$
testBundle = systemContext.installBundle("initial@" + location, url.openStream());
} catch (BundleException e) {
// $NON-NLS-1$
fail("Unexpected install error", e);
}
try {
testBundle.update();
} catch (BundleException e) {
// $NON-NLS-1$
fail("Unexpected update error", e);
}
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.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.
the class SystemBundleTests method testBug413879.
public void testBug413879() {
// $NON-NLS-1$
File config = OSGiTestsActivator.getContext().getDataFile(getName());
Map<String, Object> configuration = new HashMap<String, Object>();
configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
Equinox equinox = new Equinox(configuration);
try {
equinox.start();
} catch (BundleException e) {
// $NON-NLS-1$
fail("Unexpected exception in start()", e);
}
BundleContext systemContext = equinox.getBundleContext();
// $NON-NLS-1$
assertNotNull("System context is null", systemContext);
Bundle test1 = null;
try {
test1 = systemContext.installBundle(installer.getBundleLocation("substitutes.a"));
} catch (BundleException e) {
// $NON-NLS-1$
fail("Unexpected error installing bundle", e);
}
final Bundle testFinal1 = test1;
ServiceRegistration reg = systemContext.registerService(WeavingHook.class, new WeavingHook() {
public void weave(WovenClass wovenClass) {
if (!testFinal1.equals(wovenClass.getBundleWiring().getBundle()))
return;
if (!"substitutes.x.Ax".equals(wovenClass.getClassName()))
return;
List dynamicImports = wovenClass.getDynamicImports();
dynamicImports.add("*");
}
}, null);
ServiceRegistration<ResolverHookFactory> resolverHookReg = systemContext.registerService(ResolverHookFactory.class, new ResolverHookFactory() {
@Override
public ResolverHook begin(Collection<BundleRevision> triggers) {
// just trying to delay the resolve so that we get two threads trying to apply off the same snapshot
try {
Thread.sleep(500);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException(e);
}
return null;
}
}, null);
final Set<Throwable> errors = Collections.newSetFromMap(new ConcurrentHashMap<Throwable, Boolean>());
try {
Runnable dynamicLoadClass = new Runnable() {
@Override
public void run() {
try {
testFinal1.loadClass("substitutes.x.Ax");
testFinal1.loadClass("org.osgi.framework.hooks.bundle.FindHook");
} catch (Throwable t) {
errors.add(t);
}
}
};
Thread t1 = new Thread(dynamicLoadClass, getName() + "-1");
Thread t2 = new Thread(dynamicLoadClass, getName() + "-2");
t1.start();
t2.start();
t1.join();
t2.join();
} catch (Throwable t) {
fail("Unexpected testing bundle", t);
} finally {
reg.unregister();
resolverHookReg.unregister();
}
// put the framework back to the RESOLVED state
try {
equinox.stop();
} catch (BundleException e) {
// $NON-NLS-1$
fail("Unexpected error stopping framework", e);
}
try {
equinox.waitForStop(10000);
} catch (InterruptedException e) {
// $NON-NLS-1$
fail("Unexpected interrupted exception", e);
}
if (!errors.isEmpty()) {
fail("Failed to resolve dynamic", errors.iterator().next());
}
}
use of org.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.
the class SystemBundleTests method testDynamicSecurityManager.
public void testDynamicSecurityManager() throws BundleException {
SecurityManager sm = System.getSecurityManager();
assertNull("SecurityManager must be null to test.", sm);
try {
// $NON-NLS-1$
File config = OSGiTestsActivator.getContext().getDataFile(getName());
Map<String, Object> configuration = new HashMap<String, Object>();
configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
Equinox equinox = new Equinox(configuration);
try {
equinox.start();
} catch (BundleException e) {
// $NON-NLS-1$
fail("Unexpected exception in start()", e);
}
Bundle substitutesA = null;
try {
// $NON-NLS-1$
substitutesA = equinox.getBundleContext().installBundle(installer.getBundleLocation("substitutes.a"));
} catch (BundleException e1) {
// $NON-NLS-1$
fail("failed to install a bundle", e1);
}
assertTrue("BundleCould not resolve.", equinox.adapt(FrameworkWiring.class).resolveBundles(Collections.singleton(substitutesA)));
substitutesA.adapt(BundleWiring.class).findEntries("/", null, 0);
// set security manager after resolving
System.setSecurityManager(new SecurityManager() {
@Override
public void checkPermission(Permission perm, Object context) {
// do nothing
}
@Override
public void checkPermission(Permission perm) {
// do nothing
}
});
equinox.stop();
try {
FrameworkEvent event = equinox.waitForStop(10000);
assertEquals("Wrong event.", FrameworkEvent.STOPPED, event.getType());
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
fail("Unexpected interruption.", e);
}
// $NON-NLS-1$
assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState());
} finally {
System.setSecurityManager(null);
}
}
use of org.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.
the class SystemBundleTests method testProvideOSGiEEandNative.
public void testProvideOSGiEEandNative() throws BundleException {
// $NON-NLS-1$
File config = OSGiTestsActivator.getContext().getDataFile(getName());
Map<String, Object> configuration = new HashMap<String, Object>();
configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
configuration.put("osgi.equinox.allow.restricted.provides", "true");
Equinox equinox = new Equinox(configuration);
equinox.start();
BundleContext systemContext = equinox.getBundleContext();
Bundle testBundle = systemContext.installBundle(installer.getBundleLocation("test.bug449484"));
equinox.adapt(FrameworkWiring.class).resolveBundles(Collections.singleton(testBundle));
assertEquals("Wrong bundle state", Bundle.RESOLVED, testBundle.getState());
testBundle.uninstall();
equinox.stop();
configuration.remove("osgi.equinox.allow.restricted.provides");
equinox = new Equinox(configuration);
equinox.start();
systemContext = equinox.getBundleContext();
try {
testBundle = systemContext.installBundle(installer.getBundleLocation("test.bug449484"));
testBundle.uninstall();
fail("Expected to fail to install bundle with restricted provide capabilities.");
} catch (BundleException e) {
// expected
}
equinox.stop();
configuration.put("osgi.equinox.allow.restricted.provides", "false");
equinox = new Equinox(configuration);
equinox.start();
systemContext = equinox.getBundleContext();
try {
testBundle = systemContext.installBundle(installer.getBundleLocation("test.bug449484"));
testBundle.uninstall();
fail("Expected to fail to install bundle with restricted provide capabilities.");
} catch (BundleException e) {
// expected
}
equinox.stop();
}
use of org.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.
the class SystemBundleTests method testSystemBundle08.
public void testSystemBundle08() {
// create/start/stop/start/stop test
// $NON-NLS-1$
File config = OSGiTestsActivator.getContext().getDataFile("testSystemBundle08_1");
Map<String, Object> configuration = new HashMap<String, Object>();
configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
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());
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());
// $NON-NLS-1$
config = OSGiTestsActivator.getContext().getDataFile("testSystemBundle08_2");
configuration = new HashMap<String, Object>();
configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
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());
ServiceReference[] refs = null;
try {
// $NON-NLS-1$
refs = equinox.getBundleContext().getServiceReferences(Location.class.getName(), "(type=osgi.configuration.area)");
} catch (InvalidSyntaxException e) {
// $NON-NLS-1$
fail("Unexpected syntax error", e);
}
// $NON-NLS-1$
assertNotNull("Configuration Location refs is null", refs);
// $NON-NLS-1$
assertEquals("config refs length is wrong", 1, refs.length);
Location configLocation = (Location) equinox.getBundleContext().getService(refs[0]);
URL configURL = configLocation.getURL();
// $NON-NLS-1$ //$NON-NLS-2$
assertTrue("incorrect configuration location", configURL.toExternalForm().endsWith("testSystemBundle08_2/"));
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());
}
Aggregations