use of org.osgi.framework.wiring.BundleRevision in project aries by apache.
the class BundleRevisionResourceTest method testNoModellerServiceRequirements.
@Test
public void testNoModellerServiceRequirements() {
BundleRevision br = EasyMock.createNiceMock(BundleRevision.class);
expect(br.getRequirements(anyObject(String.class))).andReturn(Collections.<Requirement>emptyList());
expect(br.getCapabilities(anyObject(String.class))).andReturn(Collections.<Capability>emptyList());
replay(br);
BundleRevisionResource brr = new BundleRevisionResource(br);
assertEquals(0, brr.getRequirements("osgi.service").size());
}
use of org.osgi.framework.wiring.BundleRevision in project rt.equinox.framework by eclipse.
the class PackageAdminImpl method getBundleType.
public int getBundleType(Bundle bundle) {
Module module = StartLevelImpl.getModule(bundle);
if (module == null) {
return 0;
}
List<BundleRevision> revisions = module.getRevisions().getRevisions();
if (revisions.isEmpty()) {
return 0;
}
return (revisions.get(0).getTypes() & BundleRevision.TYPE_FRAGMENT) != 0 ? PackageAdmin.BUNDLE_TYPE_FRAGMENT : 0;
}
use of org.osgi.framework.wiring.BundleRevision in project rt.equinox.framework by eclipse.
the class ResolverImpl method resolve.
public synchronized void resolve(BundleDescription[] reRefresh, Dictionary<Object, Object>[] platformProperties) {
if (DEBUG)
// $NON-NLS-1$
ResolverImpl.log("*** BEGIN RESOLUTION ***");
if (state == null)
// $NON-NLS-1$
throw new IllegalStateException("RESOLVER_NO_STATE");
// set developmentMode each resolution
developmentMode = platformProperties.length == 0 ? false : StateImpl.DEVELOPMENT_MODE.equals(platformProperties[0].get(StateImpl.OSGI_RESOLVER_MODE));
// set uses timeout each resolution
usesTimeout = getUsesTimeout(platformProperties);
// set limit for constraints with multiple suppliers each resolution
usesMultipleSuppliersLimit = getMultipleSuppliersLimit(platformProperties);
hook = (state instanceof StateImpl) ? ((StateImpl) state).getResolverHook() : null;
if (!initialized) {
initialize();
}
try {
reRefresh = addDevConstraints(reRefresh);
// Unresolve all the supplied bundles and their dependents
if (reRefresh != null)
for (int i = 0; i < reRefresh.length; i++) {
ResolverBundle rb = bundleMapping.get(reRefresh[i]);
if (rb != null)
unresolveBundle(rb, false);
}
// reorder exports and bundles after unresolving the bundles
resolverExports.reorder();
resolverBundles.reorder();
reorderGenerics();
// always get the latest EEs
getCurrentEEs(platformProperties);
// $NON-NLS-1$//$NON-NLS-2$
boolean resolveOptional = platformProperties.length == 0 ? false : "true".equals(platformProperties[0].get("osgi.resolveOptional"));
ResolverBundle[] currentlyResolved = null;
if (resolveOptional) {
BundleDescription[] resolvedBundles = state.getResolvedBundles();
currentlyResolved = new ResolverBundle[resolvedBundles.length];
for (int i = 0; i < resolvedBundles.length; i++) currentlyResolved[i] = bundleMapping.get(resolvedBundles[i]);
}
// attempt to resolve all unresolved bundles
Collection<ResolverBundle> hookDisabled = Collections.EMPTY_LIST;
if (hook != null) {
List<ResolverBundle> resolvableBundles = new ArrayList<>(unresolvedBundles);
List<BundleRevision> resolvableRevisions = new ArrayList<>(resolvableBundles.size());
for (ResolverBundle bundle : resolvableBundles) resolvableRevisions.add(bundle.getBundleDescription());
ArrayMap<BundleRevision, ResolverBundle> resolvable = new ArrayMap<>(resolvableRevisions, resolvableBundles);
int size = resolvableBundles.size();
hook.filterResolvable(resolvable);
if (resolvable.size() < size) {
hookDisabled = new ArrayList<>(unresolvedBundles);
hookDisabled.removeAll(resolvableBundles);
}
}
usesCalculationTimeout = false;
List<ResolverBundle> toResolve = new ArrayList<>(unresolvedBundles);
// first resolve the system bundle to allow osgi.ee capabilities to be resolved
List<ResolverBundle> unresolvedSystemBundles = new ArrayList<>(1);
String systemBSN = getSystemBundle();
for (Iterator<ResolverBundle> iToResolve = toResolve.iterator(); iToResolve.hasNext(); ) {
ResolverBundle rb = iToResolve.next();
String symbolicName = rb.getName();
if (symbolicName != null && symbolicName.equals(systemBSN)) {
unresolvedSystemBundles.add(rb);
iToResolve.remove();
}
}
if (!unresolvedSystemBundles.isEmpty())
resolveBundles(unresolvedSystemBundles.toArray(new ResolverBundle[unresolvedSystemBundles.size()]), platformProperties, hookDisabled);
// Now resolve the rest
resolveBundles(toResolve.toArray(new ResolverBundle[toResolve.size()]), platformProperties, hookDisabled);
Collection<ResolverBundle> optionalResolved = resolveOptional ? resolveOptionalConstraints(currentlyResolved) : Collections.EMPTY_LIST;
ResolverHook current = hook;
if (current != null) {
hook = null;
current.end();
}
// set the resolved status of the bundles in the State
// Note this must be done after calling end above in case end throws errors
stateResolveBundles(bundleMapping.values().toArray(new ResolverBundle[bundleMapping.size()]));
for (ResolverBundle bundle : optionalResolved) {
state.resolveBundle(bundle.getBundleDescription(), false, null, null, null, null, null, null, null, null);
stateResolveBundle(bundle);
}
// reorder exports and bundles after resolving the bundles
resolverExports.reorder();
resolverBundles.reorder();
reorderGenerics();
if (resolveOptional)
resolveOptionalConstraints(currentlyResolved);
if (DEBUG)
// $NON-NLS-1$
ResolverImpl.log("*** END RESOLUTION ***");
} finally {
if (hook != null)
// need to make sure end is always called
hook.end();
hook = null;
}
}
use of org.osgi.framework.wiring.BundleRevision in project rt.equinox.framework by eclipse.
the class StateImpl method linkDynamicImport.
public ExportPackageDescription linkDynamicImport(BundleDescription importingBundle, String requestedPackage) {
if (resolver == null)
// $NON-NLS-1$
throw new IllegalStateException("no resolver set");
BundleDescriptionImpl importer = (BundleDescriptionImpl) importingBundle;
if (importer.getDynamicStamp(requestedPackage) == getTimeStamp())
return null;
fullyLoad();
synchronized (this.monitor) {
ResolverHook currentHook = null;
try {
resolving = true;
ResolverHookFactory currentFactory = hookFactory;
if (currentFactory != null) {
Collection<BundleRevision> triggers = new ArrayList<>(1);
triggers.add(importingBundle);
triggers = Collections.unmodifiableCollection(triggers);
currentHook = begin(triggers);
}
// ask the resolver to resolve our dynamic import
ExportPackageDescriptionImpl result = (ExportPackageDescriptionImpl) resolver.resolveDynamicImport(importingBundle, requestedPackage);
if (result == null)
importer.setDynamicStamp(requestedPackage, new Long(getTimeStamp()));
else {
// remove any cached timestamp
importer.setDynamicStamp(requestedPackage, null);
// need to add the result to the list of resolved imports
importer.addDynamicResolvedImport(result);
}
setDynamicCacheChanged(true);
return result;
} finally {
resolving = false;
if (currentHook != null)
currentHook.end();
}
}
}
use of org.osgi.framework.wiring.BundleRevision in project rt.equinox.framework by eclipse.
the class ClassLoadingBundleTests method testUninstallInUse01.
public void testUninstallInUse01() throws BundleException {
// $NON-NLS-1$
Bundle exporter1 = installer.installBundle("exporter.importer1");
BundleRevision iExporter1 = exporter1.adapt(BundleRevision.class);
// $NON-NLS-1$
Bundle exporter2 = installer.installBundle("exporter.importer2");
installer.resolveBundles(new Bundle[] { exporter1, exporter2 });
exporter1.uninstall();
// $NON-NLS-1$
Bundle importer = installer.installBundle("exporter.importer4");
installer.resolveBundles(new Bundle[] { importer });
BundleWiring importerWiring = importer.adapt(BundleWiring.class);
assertNotNull("Bundle b has no wiring.", importerWiring);
List<BundleWire> bImports = importerWiring.getRequiredWires(PackageNamespace.PACKAGE_NAMESPACE);
assertEquals("Wrong number of imported packages.", 1, bImports.size());
assertEquals("Wrong exporter.", iExporter1, bImports.get(0).getProvider());
}
Aggregations