use of org.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.
the class SecurityManagerTests method testEnableSecurityManager03.
public void testEnableSecurityManager03() throws BundleException {
// $NON-NLS-1$
File config = OSGiTestsActivator.getContext().getDataFile("testEnableSecurityManager03");
Map<String, Object> configuration = new HashMap<String, Object>();
configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
configuration.put(Constants.FRAMEWORK_SECURITY, Constants.FRAMEWORK_SECURITY_OSGI);
Equinox equinox = new Equinox(configuration);
try {
equinox.init();
} catch (BundleException e) {
// $NON-NLS-1$
fail("Unexpected exception on init()", e);
}
// $NON-NLS-1$
assertNotNull("SecurityManager is null", System.getSecurityManager());
// 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 installing a bundle to tests bug
// $NON-NLS-1$
String locationSecurityA = installer.getBundleLocation("security.a");
// set the security for the bundle
ConditionalPermissionAdmin ca = (ConditionalPermissionAdmin) systemContext.getService(systemContext.getServiceReference(ConditionalPermissionAdmin.class.getName()));
ConditionalPermissionUpdate update = ca.newConditionalPermissionUpdate();
List rows = update.getConditionalPermissionInfos();
rows.add(ca.newConditionalPermissionInfo(null, null, new PermissionInfo[] { hostFragmentPermission, importPackagePermission }, ConditionalPermissionInfo.ALLOW));
// $NON-NLS-1$
assertTrue("Cannot commit rows", update.commit());
Bundle securityA = systemContext.installBundle(locationSecurityA);
equinox.start();
PackageAdmin pa = (PackageAdmin) systemContext.getService(systemContext.getServiceReference(PackageAdmin.class.getName()));
try {
assertTrue(pa.resolveBundles(new Bundle[] { securityA }));
ExportedPackage[] eps = pa.getExportedPackages(securityA);
// $NON-NLS-1$
assertNull("Found unexpected exports", eps);
RequiredBundle[] rbs = pa.getRequiredBundles(securityA.getSymbolicName());
// $NON-NLS-1$
assertNull("Found unexpected required bundle", rbs);
// grant export permission
update = ca.newConditionalPermissionUpdate();
rows = update.getConditionalPermissionInfos();
rows.clear();
rows.add(ca.newConditionalPermissionInfo(null, null, new PermissionInfo[] { hostFragmentProvidePermission, allPackagePermission }, ConditionalPermissionInfo.ALLOW));
// $NON-NLS-1$
assertTrue("Cannot commit rows", update.commit());
securityA.uninstall();
securityA = systemContext.installBundle(locationSecurityA);
assertTrue(pa.resolveBundles(new Bundle[] { securityA }));
eps = pa.getExportedPackages(securityA);
// $NON-NLS-1$
assertNotNull("Did not find expected exports", eps);
// $NON-NLS-1$
assertEquals("Wrong number of exports found", 1, eps.length);
rbs = pa.getRequiredBundles(securityA.getSymbolicName());
// $NON-NLS-1$
assertNotNull("Did not find required bundle", eps);
// $NON-NLS-1$
assertEquals("Wrong number of required bundles found", 1, rbs.length);
} finally {
// put the framework back to the RESOLVED state
equinox.stop();
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$
assertNull("SecurityManager is not null", System.getSecurityManager());
}
use of org.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.
the class BasicLocationTests method testSchemes.
public void testSchemes() throws Exception {
Map<String, String> fwkConfig = new HashMap<String, String>();
fwkConfig.put(EquinoxLocations.PROP_CONFIG_AREA + EquinoxLocations.READ_ONLY_AREA_SUFFIX, "true");
fwkConfig.put(EquinoxLocations.PROP_USER_AREA, "http://example.com/a");
fwkConfig.put(EquinoxLocations.PROP_INSTANCE_AREA, "ftp://example.com/c/d");
fwkConfig.put(EquinoxLocations.PROP_CONFIG_AREA, "platform:/base/e/f");
fwkConfig.put(EquinoxLocations.PROP_INSTALL_AREA, "file:" + prefix + "/g");
Equinox equinox = new Equinox(fwkConfig);
equinox.init();
try {
Map<String, Location> locations = getLocations(equinox);
checkSlashes(locations);
checkLocation(locations.get(Location.USER_FILTER), true, true, "http");
checkLocation(locations.get(Location.INSTANCE_FILTER), true, true, "ftp");
checkLocation(locations.get(Location.CONFIGURATION_FILTER), true, true, "platform");
checkLocation(locations.get(Location.INSTALL_FILTER), true, true, "file");
} finally {
equinox.stop();
}
}
use of org.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.
the class BasicLocationTests method testSlashes.
public void testSlashes() throws BundleException, InvalidSyntaxException {
Map<String, String> fwkConfig = new HashMap<String, String>();
fwkConfig.put(EquinoxLocations.PROP_CONFIG_AREA + EquinoxLocations.READ_ONLY_AREA_SUFFIX, "true");
fwkConfig.put(EquinoxLocations.PROP_USER_AREA, prefix + "/a");
fwkConfig.put(EquinoxLocations.PROP_INSTANCE_AREA, prefix + "/c/d");
fwkConfig.put(EquinoxLocations.PROP_CONFIG_AREA, prefix + "/e/f");
fwkConfig.put(EquinoxLocations.PROP_INSTALL_AREA, "file:" + prefix + "/g");
Equinox equinox = new Equinox(fwkConfig);
equinox.init();
try {
checkSlashes(getLocations(equinox));
} finally {
equinox.stop();
}
}
use of org.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.
the class BasicLocationTests method testUserDir.
public void testUserDir() throws Exception {
Map<String, String> fwkConfig = new HashMap<String, String>();
fwkConfig.put(EquinoxLocations.PROP_USER_AREA, "@user.dir");
fwkConfig.put(EquinoxLocations.PROP_CONFIG_AREA + EquinoxLocations.READ_ONLY_AREA_SUFFIX, "true");
fwkConfig.put(EquinoxLocations.PROP_INSTANCE_AREA, "@user.dir");
fwkConfig.put(EquinoxLocations.PROP_CONFIG_AREA, "@user.dir");
fwkConfig.put(EquinoxLocations.PROP_INSTALL_AREA, "file:" + prefix + "/g");
Equinox equinox = new Equinox(fwkConfig);
equinox.init();
try {
Map<String, Location> locations = getLocations(equinox);
checkLocation(locations.get(Location.USER_FILTER), true, true, "file");
checkLocation(locations.get(Location.INSTANCE_FILTER), true, true, "file");
checkLocation(locations.get(Location.CONFIGURATION_FILTER), true, true, "file");
checkLocation(locations.get(Location.INSTALL_FILTER), true, true, "file");
} finally {
equinox.stop();
}
}
use of org.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.
the class BasicLocationTests method testNone.
public void testNone() throws Exception {
Map<String, String> fwkConfig = new HashMap<String, String>();
fwkConfig.put(EquinoxLocations.PROP_CONFIG_AREA + EquinoxLocations.READ_ONLY_AREA_SUFFIX, "true");
fwkConfig.put(EquinoxLocations.PROP_USER_AREA, "@none");
fwkConfig.put(EquinoxLocations.PROP_INSTANCE_AREA, "@none");
// TODO framework does not handle no config area well
// fwkConfig.put(EquinoxLocations.PROP_CONFIG_AREA, "@none");
fwkConfig.put(EquinoxLocations.PROP_INSTALL_AREA, "file:" + prefix + "/g");
Equinox equinox = new Equinox(fwkConfig);
equinox.init();
try {
Map<String, Location> locations = getLocations(equinox);
assertNull("User location should be null", locations.get(Location.USER_FILTER));
assertNull("Instance location should be null", locations.get(Location.INSTANCE_FILTER));
// TODO assertNull("Configuration location should be null", locations.get(Location.CONFIGURATION_FILTER));
} finally {
equinox.stop();
}
}
Aggregations