use of org.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.
the class SystemBundleTests method testWeavingPersistence.
public void testWeavingPersistence() {
// $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);
}
long testID1 = test1.getBundleId();
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);
try {
testFinal1.loadClass("substitutes.x.Ax");
testFinal1.loadClass("org.osgi.framework.hooks.bundle.FindHook");
} catch (Throwable t) {
fail("Unexpected testing bundle", t);
} finally {
reg.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);
}
try {
equinox.start();
} catch (BundleException e) {
// $NON-NLS-1$
fail("Unexpected exception in start()", e);
}
systemContext = equinox.getBundleContext();
test1 = systemContext.getBundle(testID1);
Bundle test2 = null;
try {
test2 = systemContext.installBundle(installer.getBundleLocation("exporter.importer1"));
} catch (BundleException e) {
// $NON-NLS-1$
fail("Unexpected error installing bundle", e);
}
long testID2 = test2.getBundleId();
final Bundle testFinal2 = test2;
reg = systemContext.registerService(WeavingHook.class, new WeavingHook() {
public void weave(WovenClass wovenClass) {
if (!testFinal2.equals(wovenClass.getBundleWiring().getBundle()))
return;
if (!"exporter.importer.test.Test1".equals(wovenClass.getClassName()))
return;
List dynamicImports = wovenClass.getDynamicImports();
dynamicImports.add("*");
}
}, null);
try {
testFinal2.loadClass("exporter.importer.test.Test1");
testFinal2.loadClass("org.osgi.framework.hooks.service.FindHook");
} catch (Throwable t) {
fail("Unexpected testing bundle", t);
} finally {
reg.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);
}
try {
equinox.start();
} catch (BundleException e) {
// $NON-NLS-1$
fail("Unexpected exception in start()", e);
}
systemContext = equinox.getBundleContext();
test1 = systemContext.getBundle(testID1);
test2 = systemContext.getBundle(testID2);
BundleRevision rev1 = test1.adapt(BundleRevision.class);
BundleRevision rev2 = test2.adapt(BundleRevision.class);
BundleWiring wiring1 = rev1.getWiring();
BundleWiring wiring2 = rev2.getWiring();
assertNotNull("wiring1 is null", wiring1);
assertNotNull("wiring2 is null", wiring2);
List packages1 = wiring1.getRequiredWires(BundleRevision.PACKAGE_NAMESPACE);
List packages2 = wiring2.getRequiredWires(BundleRevision.PACKAGE_NAMESPACE);
// could make this a more complete check, but with the bug the dynamic wires
// are missing altogether because we fail to save the resolver state cache.
assertEquals("Wrong number of wires for wiring1", 1, packages1.size());
assertEquals("Wrong number of wires for wiring2", 1, packages2.size());
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);
}
}
use of org.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.
the class SystemBundleTests method testAllNullConfigurationValues.
public void testAllNullConfigurationValues() throws BundleException {
Collection<String> requiredProperties = // prevent bad formatting...
Arrays.asList(//
Constants.FRAMEWORK_EXECUTIONENVIRONMENT, //
Constants.FRAMEWORK_LANGUAGE, //
Constants.FRAMEWORK_OS_NAME, //
Constants.FRAMEWORK_OS_VERSION, //
Constants.FRAMEWORK_PROCESSOR, //
Constants.FRAMEWORK_STORAGE, //
Constants.FRAMEWORK_SYSTEMCAPABILITIES, //
Constants.FRAMEWORK_SYSTEMPACKAGES, //
Constants.FRAMEWORK_UUID, //
Constants.FRAMEWORK_VENDOR, //
Constants.FRAMEWORK_VERSION, //
Constants.SUPPORTS_FRAMEWORK_EXTENSION, //
Constants.SUPPORTS_FRAMEWORK_FRAGMENT, //
Constants.SUPPORTS_FRAMEWORK_REQUIREBUNDLE, //
EquinoxConfiguration.PROP_FRAMEWORK, //
EquinoxConfiguration.PROP_OSGI_ARCH, //
EquinoxConfiguration.PROP_OSGI_OS, //
EquinoxConfiguration.PROP_OSGI_WS, //
EquinoxConfiguration.PROP_OSGI_WS, //
EquinoxConfiguration.PROP_OSGI_NL, //
EquinoxConfiguration.PROP_STATE_SAVE_DELAY_INTERVAL, //
EquinoxConfiguration.PROP_INIT_UUID, //
"gosh.args", //
EquinoxLocations.PROP_HOME_LOCATION_AREA, //
EquinoxLocations.PROP_CONFIG_AREA, //
EquinoxLocations.PROP_INSTALL_AREA, //
EclipseStarter.PROP_LOGFILE);
Properties systemProperties = (Properties) System.getProperties().clone();
Map<String, Object> configuration = new HashMap<String, Object>();
for (Object key : systemProperties.keySet()) {
configuration.put((String) key, null);
}
// $NON-NLS-1$
File config = OSGiTestsActivator.getContext().getDataFile(getName());
configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
Equinox equinox = new Equinox(configuration);
equinox.start();
for (Object key : systemProperties.keySet()) {
String property = (String) key;
String value = equinox.getBundleContext().getProperty(property);
if (requiredProperties.contains(property)) {
assertNotNull(property + " is null", value);
} else {
assertNull(property + " is not null", value);
}
String systemValue = System.getProperty(property);
assertEquals("Wrong system value for " + property, systemProperties.getProperty(property), systemValue);
}
assertEquals(systemProperties, System.getProperties());
equinox.stop();
}
use of org.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.
the class SecurityAdminUnitTests method setUp.
protected void setUp() throws Exception {
previousPolicy = Policy.getPolicy();
final Permission allPermission = new AllPermission();
final PermissionCollection allPermissions = new PermissionCollection() {
private static final long serialVersionUID = 3258131349494708277L;
// A simple PermissionCollection that only has AllPermission
public void add(Permission permission) {
// no adding to this policy
}
public boolean implies(Permission permission) {
return true;
}
public Enumeration elements() {
return new Enumeration() {
int cur = 0;
public boolean hasMoreElements() {
return cur < 1;
}
public Object nextElement() {
if (cur == 0) {
cur = 1;
return allPermission;
}
throw new NoSuchElementException();
}
};
}
};
Policy.setPolicy(new Policy() {
public PermissionCollection getPermissions(CodeSource codesource) {
return allPermissions;
}
public void refresh() {
// nothing
}
});
// $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(Constants.FRAMEWORK_SECURITY, Constants.FRAMEWORK_SECURITY_OSGI);
equinox = new Equinox(configuration);
try {
equinox.init();
} catch (BundleException e) {
// $NON-NLS-1$
fail("Unexpected exception on init()", e);
}
cpa = equinox.getBundleContext().getService(equinox.getBundleContext().getServiceReference(ConditionalPermissionAdmin.class));
pa = equinox.getBundleContext().getService(equinox.getBundleContext().getServiceReference(PermissionAdmin.class));
super.setUp();
}
use of org.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.
the class SecurityManagerTests method testEnableSecurityManager05.
public void testEnableSecurityManager05() 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(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 locationLinkA = installer.getBundleLocation("test.link.a");
// $NON-NLS-1$
String locationLinkAClient = installer.getBundleLocation("test.link.a.client");
Bundle linkA = systemContext.installBundle(locationLinkA);
Bundle linkAClient = systemContext.installBundle(locationLinkAClient);
equinox.start();
try {
PackageAdmin pa = (PackageAdmin) systemContext.getService(systemContext.getServiceReference(PackageAdmin.class.getName()));
assertTrue(pa.resolveBundles(new Bundle[] { linkA, linkAClient }));
linkA.uninstall();
linkAClient.uninstall();
linkA = systemContext.installBundle(locationLinkA);
linkAClient = systemContext.installBundle(locationLinkAClient);
assertTrue(pa.resolveBundles(new Bundle[] { linkA, linkAClient }));
} 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 SecurityManagerTests method testLocalization01.
public void testLocalization01() throws BundleException {
// create/start/stop/start/stop test
// $NON-NLS-1$
File config = OSGiTestsActivator.getContext().getDataFile("testLocalization01");
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 host and fragment to test bug 245678
// $NON-NLS-1$
String locationSecurityA = installer.getBundleLocation("security.a");
// $NON-NLS-1$
String locationSecurityAFragA = installer.getBundleLocation("security.a.frag.a");
// set the security for the host and fragment
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, allPackagePermission }, ConditionalPermissionInfo.ALLOW));
// $NON-NLS-1$
assertTrue("Cannot commit rows", update.commit());
Bundle securityA = systemContext.installBundle(locationSecurityA);
systemContext.installBundle(locationSecurityAFragA);
equinox.start();
try {
securityA.start();
// $NON-NLS-1$
Dictionary headers = securityA.getHeaders("en_US");
String name = (String) headers.get(Constants.BUNDLE_NAME);
// $NON-NLS-1$ //$NON-NLS-2$
assertEquals("Wrong Bundle-Name", "en_US", name);
// $NON-NLS-1$
headers = securityA.getHeaders("en");
name = (String) headers.get(Constants.BUNDLE_NAME);
// $NON-NLS-1$ //$NON-NLS-2$
assertEquals("Wrong Bundle-Name", "default", name);
} catch (BundleException e) {
// $NON-NLS-1$
fail("Failed to start securityA", e);
} 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());
}
Aggregations