use of org.osgi.framework.wiring.BundleCapability in project rt.equinox.framework by eclipse.
the class PackageAdminImpl method getRequiredBundles.
public RequiredBundle[] getRequiredBundles(String symbolicName) {
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$//$NON-NLS-4$
String filter = "(" + BundleNamespace.BUNDLE_NAMESPACE + "=" + (symbolicName == null ? "*" : symbolicName) + ")";
Map<String, String> directives = Collections.<String, String>singletonMap(Namespace.REQUIREMENT_FILTER_DIRECTIVE, filter);
Map<String, Boolean> attributes = Collections.singletonMap(Capabilities.SYNTHETIC_REQUIREMENT, Boolean.TRUE);
Requirement bundleReq = ModuleContainer.createRequirement(BundleNamespace.BUNDLE_NAMESPACE, directives, attributes);
Collection<BundleCapability> bundleCaps = container.getFrameworkWiring().findProviders(bundleReq);
InternalUtils.filterCapabilityPermissions(bundleCaps);
Collection<RequiredBundle> result = new ArrayList<>();
for (BundleCapability capability : bundleCaps) {
BundleWiring wiring = capability.getRevision().getWiring();
if (wiring != null) {
result.add(new RequiredBundleImpl(capability, wiring));
}
}
return result.isEmpty() ? null : result.toArray(new RequiredBundle[result.size()]);
}
use of org.osgi.framework.wiring.BundleCapability 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.osgi.framework.wiring.BundleCapability 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.BundleCapability 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.BundleCapability 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]);
}
Aggregations