use of org.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.
the class SecurityManagerTests method testDynamicImportWithSecurity.
public void testDynamicImportWithSecurity() throws BundleException {
File config = OSGiTestsActivator.getContext().getDataFile(getName());
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.start();
} catch (BundleException e) {
// $NON-NLS-1$
fail("Failed to start the framework", e);
}
BundleContext systemContext = equinox.getBundleContext();
// register a no-op resolver hook to test security
ResolverHookFactory dummyHook = new ResolverHookFactory() {
@Override
public ResolverHook begin(Collection<BundleRevision> triggers) {
return new ResolverHook() {
@Override
public void filterResolvable(Collection<BundleRevision> candidates) {
// nothing
}
@Override
public void filterSingletonCollisions(BundleCapability singleton, Collection<BundleCapability> collisionCandidates) {
// nothing
}
@Override
public void filterMatches(BundleRequirement requirement, Collection<BundleCapability> candidates) {
// always remove candidates for dynamic import
if (PackageNamespace.RESOLUTION_DYNAMIC.equals(requirement.getDirectives().get(Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE))) {
candidates.clear();
}
}
@Override
public void end() {
// nothing
}
};
}
};
systemContext.registerService(ResolverHookFactory.class, dummyHook, null);
// $NON-NLS-1$
assertNotNull("System context is null", systemContext);
// try installing host and fragment to test bug 245678
// $NON-NLS-1$
String testDynamicImportLocation = installer.getBundleLocation("test.dynamicimport");
// 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[] { allPackagePermission }, ConditionalPermissionInfo.ALLOW));
// $NON-NLS-1$
assertTrue("Cannot commit rows", update.commit());
Bundle testDynamicImport = systemContext.installBundle(testDynamicImportLocation);
try {
testDynamicImport.start();
} catch (BundleException e) {
fail("Did not start test bundle successfully.", e);
}
// 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);
}
// $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 SecurityManagerTests method testEnableSecurityManager01.
public void testEnableSecurityManager01() {
// $NON-NLS-1$
File config = OSGiTestsActivator.getContext().getDataFile("testEnableSecurityManager01");
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());
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());
// put the framework back to the RESOLVED state
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$
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 testUNC.
public void testUNC() throws Exception {
if (!windows)
return;
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, "//server/share/a");
fwkConfig.put(EquinoxLocations.PROP_INSTANCE_AREA, "//server/share/b");
fwkConfig.put(EquinoxLocations.PROP_CONFIG_AREA, "//server/share/c");
fwkConfig.put(EquinoxLocations.PROP_INSTALL_AREA, "file://server/share/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 testDebugLogOnGetURL.
public void testDebugLogOnGetURL() throws Exception {
Properties debugOptions = new Properties();
debugOptions.put("org.eclipse.osgi/debug/location", "true");
File debugOptionsFile = OSGiTestsActivator.getContext().getDataFile(getName() + ".options");
debugOptions.store(new FileOutputStream(debugOptionsFile), getName());
Map<String, String> fwkConfig = new HashMap<String, String>();
fwkConfig.put(EquinoxLocations.PROP_CONFIG_AREA + EquinoxLocations.READ_ONLY_AREA_SUFFIX, "true");
fwkConfig.put(EquinoxLocations.PROP_INSTALL_AREA, "file:" + prefix + "/g");
fwkConfig.put(EquinoxConfiguration.PROP_DEBUG, debugOptionsFile.getAbsolutePath());
fwkConfig.put("eclipse.consoleLog", "true");
Equinox equinox = new Equinox(fwkConfig);
equinox.init();
try {
final List<LogEntry> logEntries = new ArrayList<LogEntry>();
LogReaderService logReaderService = getLogReaderService(equinox);
LogListener logListener = new SynchronousLogListener() {
@Override
public void logged(LogEntry entry) {
logEntries.add(entry);
}
};
logReaderService.addLogListener(logListener);
Map<String, Location> locations = getLocations(equinox);
Location userLocation = locations.get(Location.USER_FILTER);
Location instanceLocation = locations.get(Location.INSTANCE_FILTER);
assertNotNull("User locatoin is not null.", userLocation.getURL());
assertNotNull("Instance location is not null.", instanceLocation.getURL());
assertEquals("Wrong number of log entries", 2, logEntries.size());
} finally {
equinox.stop();
}
}
use of org.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.
the class BasicLocationTests method testUserHome.
public void testUserHome() 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, "@user.home");
fwkConfig.put(EquinoxLocations.PROP_INSTANCE_AREA, "@user.home");
fwkConfig.put(EquinoxLocations.PROP_CONFIG_AREA, "@user.home");
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();
}
}
Aggregations