use of org.osgi.framework.wiring.BundleRequirement in project rt.equinox.framework by eclipse.
the class ClassLoadingBundleTests method testBug370258_endException.
public void testBug370258_endException() {
final boolean[] endCalled = { false };
ResolverHookFactory endHook = new ResolverHookFactory() {
public ResolverHook begin(Collection triggers) {
return new ResolverHook() {
public void filterSingletonCollisions(BundleCapability singleton, Collection collisionCandidates) {
// Nothing
}
public void filterResolvable(Collection candidates) {
throw new RuntimeException("Error");
}
public void filterMatches(BundleRequirement requirement, Collection candidates) {
// Nothing
}
public void end() {
endCalled[0] = true;
}
};
}
};
ResolverHookFactory error = new ResolverHookFactory() {
public ResolverHook begin(Collection triggers) {
return new ResolverHook() {
public void filterSingletonCollisions(BundleCapability singleton, Collection collisionCandidates) {
// Nothing
}
public void filterResolvable(Collection candidates) {
// Nothing
}
public void filterMatches(BundleRequirement requirement, Collection candidates) {
// Nothing
}
public void end() {
throw new RuntimeException("Error");
}
};
}
};
ServiceRegistration errorReg = OSGiTestsActivator.getContext().registerService(ResolverHookFactory.class, error, null);
ServiceRegistration endReg = OSGiTestsActivator.getContext().registerService(ResolverHookFactory.class, endHook, null);
try {
// $NON-NLS-1$
Bundle test = installer.installBundle("test");
try {
test.start();
fail("Should not be able to start this bundle");
} catch (BundleException e) {
// expected
assertEquals("Wrong exception type.", BundleException.REJECTED_BY_HOOK, e.getType());
}
} catch (BundleException e) {
fail("Unexpected install fail", e);
} finally {
errorReg.unregister();
endReg.unregister();
}
assertTrue("end is not called", endCalled[0]);
}
use of org.osgi.framework.wiring.BundleRequirement in project rt.equinox.framework by eclipse.
the class ClassLoadingBundleTests method testBug348806.
public void testBug348806() {
ResolverHookFactory error = new ResolverHookFactory() {
public ResolverHook begin(Collection triggers) {
return new ResolverHook() {
public void filterSingletonCollisions(BundleCapability singleton, Collection collisionCandidates) {
// Nothing
}
public void filterResolvable(Collection candidates) {
// Nothing
}
public void filterMatches(BundleRequirement requirement, Collection candidates) {
// Nothing
}
public void end() {
throw new RuntimeException("Error");
}
};
}
};
ServiceRegistration reg = OSGiTestsActivator.getContext().registerService(ResolverHookFactory.class, error, null);
try {
// $NON-NLS-1$
Bundle test = installer.installBundle("test");
try {
test.start();
fail("Should not be able to start this bundle");
} catch (BundleException e) {
// expected
assertEquals("Wrong exception type.", BundleException.REJECTED_BY_HOOK, e.getType());
}
} catch (BundleException e) {
fail("Unexpected install fail", e);
} finally {
reg.unregister();
}
}
use of org.osgi.framework.wiring.BundleRequirement in project rt.equinox.framework by eclipse.
the class ClassLoadingBundleTests method testBug370258_beginException.
public void testBug370258_beginException() {
final boolean[] endCalled = { false };
ResolverHookFactory endHook = new ResolverHookFactory() {
public ResolverHook begin(Collection triggers) {
return new ResolverHook() {
public void filterSingletonCollisions(BundleCapability singleton, Collection collisionCandidates) {
// Nothing
}
public void filterResolvable(Collection candidates) {
throw new RuntimeException("Error");
}
public void filterMatches(BundleRequirement requirement, Collection candidates) {
// Nothing
}
public void end() {
endCalled[0] = true;
}
};
}
};
ResolverHookFactory error = new ResolverHookFactory() {
public ResolverHook begin(Collection triggers) {
throw new RuntimeException("Error");
}
};
ServiceRegistration endReg = OSGiTestsActivator.getContext().registerService(ResolverHookFactory.class, endHook, null);
ServiceRegistration errorReg = OSGiTestsActivator.getContext().registerService(ResolverHookFactory.class, error, null);
try {
// $NON-NLS-1$
Bundle test = installer.installBundle("test");
try {
test.start();
fail("Should not be able to start this bundle");
} catch (BundleException e) {
// expected
assertEquals("Wrong exception type.", BundleException.REJECTED_BY_HOOK, e.getType());
}
} catch (BundleException e) {
fail("Unexpected install fail", e);
} finally {
errorReg.unregister();
endReg.unregister();
}
assertTrue("end is not called", endCalled[0]);
}
use of org.osgi.framework.wiring.BundleRequirement in project rt.equinox.framework by eclipse.
the class MultiReleaseJarTests method doTestMultiReleaseBundleManifest.
private void doTestMultiReleaseBundleManifest(int rv) throws Exception {
if (rv < 9) {
System.setProperty("java.specification.version", "1." + rv);
} else {
System.setProperty("java.specification.version", Integer.toString(rv));
}
String expectedCap;
String expectedPkg;
if (rv < 9) {
expectedCap = "capbase";
expectedPkg = "pkgbase";
} else {
expectedCap = "cap" + rv;
expectedPkg = "pkg" + rv;
}
// $NON-NLS-1$
File config = OSGiTestsActivator.getContext().getDataFile(getName());
Equinox equinox = new Equinox(Collections.singletonMap(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath()));
try {
equinox.start();
BundleContext systemContext = equinox.getBundleContext();
Bundle mrBundle = systemContext.installBundle(mrJarBundle.toURI().toString());
mrBundle.start();
List<BundleWire> capWires = mrBundle.adapt(BundleWiring.class).getRequiredWires(expectedCap);
assertEquals("Wrong number of capability wires.", 1, capWires.size());
List<BundleRequirement> pkgReqs = mrBundle.adapt(BundleRevision.class).getDeclaredRequirements(PackageNamespace.PACKAGE_NAMESPACE);
assertEquals("Wrong number of package requiremens.", 1, pkgReqs.size());
String filter = pkgReqs.get(0).getDirectives().get(Namespace.REQUIREMENT_FILTER_DIRECTIVE);
assertTrue("Wrong package filter: " + filter, filter.contains(expectedPkg));
} finally {
try {
equinox.stop();
equinox.waitForStop(10000);
} catch (Exception e) {
// ignore;
}
}
}
use of org.osgi.framework.wiring.BundleRequirement in project rt.equinox.framework by eclipse.
the class MultiReleaseJarTests method doTestMultiReleaseBundleManifestChangeRuntime.
private void doTestMultiReleaseBundleManifestChangeRuntime(int rv, Map<String, String> configMap, String location) throws BundleException {
if (rv < 9) {
System.setProperty("java.specification.version", "1." + rv);
} else {
System.setProperty("java.specification.version", Integer.toString(rv));
}
String expectedCap;
String expectedPkg;
if (rv < 9) {
expectedCap = "capbase";
expectedPkg = "pkgbase";
} else {
expectedCap = "cap" + rv;
expectedPkg = "pkg" + rv;
}
Equinox equinox = new Equinox(configMap);
try {
equinox.start();
BundleContext systemContext = equinox.getBundleContext();
Bundle mrBundle = systemContext.getBundle(location);
assertNotNull("No mrBundle found: " + rv, mrBundle);
assertEquals("Wrong state of mrBundle: " + rv, Bundle.ACTIVE, mrBundle.getState());
List<BundleWire> capWires = mrBundle.adapt(BundleWiring.class).getRequiredWires(expectedCap);
assertEquals("Wrong number of capability wires: " + rv, 1, capWires.size());
List<BundleRequirement> pkgReqs = mrBundle.adapt(BundleRevision.class).getDeclaredRequirements(PackageNamespace.PACKAGE_NAMESPACE);
assertEquals("Wrong number of package requiremens: " + rv, 1, pkgReqs.size());
String filter = pkgReqs.get(0).getDirectives().get(Namespace.REQUIREMENT_FILTER_DIRECTIVE);
assertTrue("Wrong package filter: " + rv + " " + filter, filter.contains(expectedPkg));
} finally {
try {
equinox.stop();
equinox.waitForStop(10000);
} catch (Exception e) {
// ignore;
}
}
}
Aggregations