use of org.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.
the class SystemBundleTests method testLogOrderMultipleListeners.
public void testLogOrderMultipleListeners() throws InterruptedException {
// $NON-NLS-1$
File config = OSGiTestsActivator.getContext().getDataFile(getName());
Map configuration = new HashMap();
configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
Equinox equinox = null;
try {
equinox = new Equinox(configuration);
equinox.start();
doLoggingOnMultipleListeners(equinox);
equinox.stop();
equinox.waitForStop(1000);
equinox.start();
doLoggingOnMultipleListeners(equinox);
} catch (BundleException e) {
fail("Failed init", e);
} finally {
try {
if (equinox != null) {
equinox.stop();
equinox.waitForStop(1000);
}
} catch (BundleException e) {
fail("Failed to stop framework.", e);
} catch (InterruptedException e) {
fail("Failed to stop framework.", e);
}
}
}
use of org.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.
the class SystemBundleTests method testBug405919.
public void testBug405919() throws Exception {
File config = OSGiTestsActivator.getContext().getDataFile(getName());
config.mkdirs();
Map<String, Object> configuration = new HashMap<String, Object>();
configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
configuration.put("osgi.framework", "boo");
// Initialize and start a framework specifying an invalid osgi.framework configuration value.
Equinox equinox = null;
try {
equinox = new Equinox(configuration);
equinox.start();
} catch (NullPointerException e) {
fail("failed to accept an invalid value for osgi.framework", e);
}
try {
// Make sure the framework can install and start a bundle.
BundleContext systemContext = equinox.getBundleContext();
try {
Bundle tb1 = systemContext.installBundle(installer.getBundleLocation("test.bug375784"));
tb1.start();
} catch (BundleException e) {
fail("failed to install and start test bundle", e);
}
// Check the capabilities and requirements of the system bundle.
BundleRevision inner = systemContext.getBundle().adapt(BundleRevision.class);
BundleRevision outer = getContext().getBundle(0).adapt(BundleRevision.class);
// Capabilities.
List<Capability> innerCaps = inner.getCapabilities(null);
List<Capability> outerCaps = outer.getCapabilities(null);
assertEquals("Number of capabilities differ", outerCaps.size(), innerCaps.size());
for (int i = 0; i < innerCaps.size(); i++) {
Capability innerCap = innerCaps.get(i);
Capability outerCap = innerCaps.get(i);
assertEquals("Capability namespaces differ: " + outerCap.getNamespace(), outerCap.getNamespace(), innerCap.getNamespace());
String namespace = outerCap.getNamespace();
if (NativeNamespace.NATIVE_NAMESPACE.equals(namespace) || "eclipse.platform".equals(namespace)) {
// Ignore these because they are known to differ.
continue;
}
assertEquals("Capability attributes differ: " + outerCap.getNamespace(), outerCap.getAttributes(), innerCap.getAttributes());
assertEquals("Capability directives differ: " + outerCap.getNamespace(), outerCap.getDirectives(), innerCap.getDirectives());
}
// Requirements.
List<Requirement> innerReqs = inner.getRequirements(null);
List<Requirement> outerReqs = outer.getRequirements(null);
assertEquals("Number of requirements differ", outerReqs.size(), innerReqs.size());
for (int i = 0; i < innerReqs.size(); i++) {
Requirement innerReq = innerReqs.get(i);
Requirement outerReq = innerReqs.get(i);
assertEquals("Requirement namespaces differ: " + outerReq.getNamespace(), outerReq.getNamespace(), innerReq.getNamespace());
assertEquals("Requirement attributes differ: " + outerReq.getNamespace(), outerReq.getAttributes(), innerReq.getAttributes());
assertEquals("Requirement directives differ: " + outerReq.getNamespace(), outerReq.getDirectives(), innerReq.getDirectives());
}
} finally {
equinox.stop();
equinox.waitForStop(5000);
}
}
use of org.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.
the class SystemBundleTests method testSystemBundle07.
public void testSystemBundle07() {
// test init twice
// $NON-NLS-1$
File config = OSGiTestsActivator.getContext().getDataFile("testSystemBundle07_01");
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);
}
try {
equinox.init();
} catch (Exception e) {
// $NON-NLS-1$
fail("Unexpected exception in init()", e);
}
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());
BundleContext systemContext = equinox.getBundleContext();
// $NON-NLS-1$
assertNotNull("SystemBundle context is null", systemContext);
try {
equinox.init();
} catch (Exception e) {
// $NON-NLS-1$
fail("Unexpected exception in init()", e);
}
ServiceReference[] refs = null;
try {
// $NON-NLS-1$
refs = systemContext.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) systemContext.getService(refs[0]);
URL configURL = configLocation.getURL();
// $NON-NLS-1$ //$NON-NLS-2$
assertTrue("incorrect configuration location", configURL.toExternalForm().endsWith("testSystemBundle07_01/"));
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 doTestBug351519Refresh.
private void doTestBug351519Refresh(Boolean refreshDuplicates) {
// Create a framework with equinox.refresh.duplicate.bsn=false configuration
// $NON-NLS-1$
File config = OSGiTestsActivator.getContext().getDataFile(getName());
Map<String, Object> configuration = new HashMap<String, Object>();
configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
if (refreshDuplicates != null) {
configuration.put("equinox.refresh.duplicate.bsn", refreshDuplicates.toString());
} else {
// we default to false now
refreshDuplicates = Boolean.FALSE;
}
Equinox equinox = new Equinox(configuration);
try {
equinox.start();
} catch (BundleException e) {
// $NON-NLS-1$
fail("Unexpected exception in init()", e);
}
BundleContext systemContext = equinox.getBundleContext();
systemContext.registerService(ResolverHookFactory.class, new ResolverHookFactory() {
public ResolverHook begin(Collection triggers) {
return new ResolverHook() {
public void filterResolvable(Collection candidates) {
// nothing
}
public void filterSingletonCollisions(BundleCapability singleton, Collection collisionCandidates) {
// resolve all singletons
collisionCandidates.clear();
}
public void filterMatches(BundleRequirement requirement, Collection candidates) {
// nothing
}
public void end() {
// nothing
}
};
}
}, null);
BundleInstaller testBundleInstaller = null;
BundleInstaller testBundleResolver = null;
try {
testBundleResolver = new BundleInstaller(OSGiTestsActivator.TEST_FILES_ROOT + "wiringTests/bundles", systemContext);
testBundleInstaller = new BundleInstaller(OSGiTestsActivator.TEST_FILES_ROOT + "wiringTests/bundles", getContext());
} catch (InvalidSyntaxException e) {
fail("Failed to create installers.", e);
}
// $NON-NLS-1$
assertNotNull("System context is null", systemContext);
// try installing a bundle before starting
Bundle tb1v1 = null, tb1v2 = null;
try {
// $NON-NLS-1$
tb1v1 = systemContext.installBundle(testBundleInstaller.getBundleLocation("singleton.tb1v1"));
// $NON-NLS-1$
tb1v2 = systemContext.installBundle(testBundleInstaller.getBundleLocation("singleton.tb1v2"));
} catch (BundleException e1) {
// $NON-NLS-1$
fail("failed to install a bundle", e1);
}
assertTrue("Could not resolve test bundles", testBundleResolver.resolveBundles(new Bundle[] { tb1v1, tb1v2 }));
Bundle[] refreshed = testBundleResolver.refreshPackages(new Bundle[] { tb1v1 });
if (refreshDuplicates) {
List refreshedList = Arrays.asList(refreshed);
assertEquals("Wrong number of refreshed bundles", 2, refreshed.length);
assertTrue("Refreshed bundles does not include v1", refreshedList.contains(tb1v1));
assertTrue("Refreshed bundles does not include v2", refreshedList.contains(tb1v2));
} else {
assertEquals("Wrong number of refreshed bundles", 1, refreshed.length);
assertEquals("Refreshed bundles does not include v1", refreshed[0], tb1v1);
}
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 testBug412228.
public void testBug412228() 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());
Equinox equinox = new Equinox(configuration);
equinox.init();
BundleContext systemContext = equinox.getBundleContext();
Bundle b = systemContext.installBundle(installer.getBundleLocation("test.bug412228"));
b.start();
equinox.start();
long startTime = System.currentTimeMillis();
equinox.stop();
try {
equinox.waitForStop(500);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
fail("Unexpected interruption.", e);
}
long stopTime = System.currentTimeMillis() - startTime;
if (stopTime > 2000) {
fail("waitForStop time took too long: " + stopTime);
}
}
Aggregations