use of org.osgi.framework.wiring.BundleRevision in project rt.equinox.framework by eclipse.
the class TestModuleContainer method testSingleton04.
@Test
public void testSingleton04() throws BundleException, IOException {
final Collection<BundleRevision> disabled = new ArrayList<BundleRevision>();
ResolverHookFactory resolverHookFactory = new ResolverHookFactory() {
@Override
public ResolverHook begin(Collection<BundleRevision> triggers) {
return new ResolverHook() {
@Override
public void filterSingletonCollisions(BundleCapability singleton, Collection<BundleCapability> collisionCandidates) {
// nothing
}
@Override
public void filterResolvable(Collection<BundleRevision> candidates) {
candidates.removeAll(disabled);
}
@Override
public void filterMatches(BundleRequirement requirement, Collection<BundleCapability> candidates) {
// nothing
}
@Override
public void end() {
// nothing
}
};
}
};
DummyContainerAdaptor adaptor = new DummyContainerAdaptor(new DummyCollisionHook(false), Collections.<String, String>emptyMap(), resolverHookFactory);
ModuleContainer container = adaptor.getContainer();
Module s1_v1 = installDummyModule("singleton1_v1.MF", "s1_v1", container);
Module s1_v2 = installDummyModule("singleton1_v2.MF", "s1_v2", container);
Module s1_v3 = installDummyModule("singleton1_v3.MF", "s1_v3", container);
Module s2_v1 = installDummyModule("singleton2_v1.MF", "s1_v1", container);
Module s2_v2 = installDummyModule("singleton2_v2.MF", "s1_v2", container);
Module s2_v3 = installDummyModule("singleton2_v3.MF", "s1_v3", container);
container.resolve(null, false);
Assert.assertFalse("Singleton v1 is resolved.", Module.RESOLVED_SET.contains(s1_v1.getState()));
Assert.assertFalse("Singleton v2 is resolved.", Module.RESOLVED_SET.contains(s1_v2.getState()));
Assert.assertTrue("Singleton v3 is not resolved.", Module.RESOLVED_SET.contains(s1_v3.getState()));
Assert.assertFalse("client v1 is resolved.", Module.RESOLVED_SET.contains(s2_v1.getState()));
Assert.assertFalse("client v2 is resolved.", Module.RESOLVED_SET.contains(s2_v2.getState()));
Assert.assertTrue("client v3 is not resolved.", Module.RESOLVED_SET.contains(s2_v3.getState()));
// now disable s1_v3
disabled.add(s1_v3.getCurrentRevision());
container.refresh(Arrays.asList(s1_v3));
Assert.assertFalse("Singleton v1 is resolved.", Module.RESOLVED_SET.contains(s1_v1.getState()));
Assert.assertTrue("Singleton v2 is not resolved.", Module.RESOLVED_SET.contains(s1_v2.getState()));
Assert.assertFalse("Singleton v3 is resolved.", Module.RESOLVED_SET.contains(s1_v3.getState()));
Assert.assertFalse("client v1 is resolved.", Module.RESOLVED_SET.contains(s2_v1.getState()));
Assert.assertTrue("client v2 is not resolved.", Module.RESOLVED_SET.contains(s2_v2.getState()));
Assert.assertFalse("client v3 is resolved.", Module.RESOLVED_SET.contains(s2_v3.getState()));
// now disable s1_v2
disabled.add(s1_v2.getCurrentRevision());
container.refresh(Arrays.asList(s1_v2));
Assert.assertTrue("Singleton v1 is not resolved.", Module.RESOLVED_SET.contains(s1_v1.getState()));
Assert.assertFalse("Singleton v2 is resolved.", Module.RESOLVED_SET.contains(s1_v2.getState()));
Assert.assertFalse("Singleton v3 is resolved.", Module.RESOLVED_SET.contains(s1_v3.getState()));
Assert.assertTrue("client v1 is not resolved.", Module.RESOLVED_SET.contains(s2_v1.getState()));
Assert.assertFalse("client v2 is resolved.", Module.RESOLVED_SET.contains(s2_v2.getState()));
Assert.assertFalse("client v3 is resolved.", Module.RESOLVED_SET.contains(s2_v3.getState()));
}
use of org.osgi.framework.wiring.BundleRevision in project rt.equinox.framework by eclipse.
the class SystemBundleTests method testBug413879.
public void testBug413879() {
// $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);
}
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);
ServiceRegistration<ResolverHookFactory> resolverHookReg = systemContext.registerService(ResolverHookFactory.class, new ResolverHookFactory() {
@Override
public ResolverHook begin(Collection<BundleRevision> triggers) {
// just trying to delay the resolve so that we get two threads trying to apply off the same snapshot
try {
Thread.sleep(500);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException(e);
}
return null;
}
}, null);
final Set<Throwable> errors = Collections.newSetFromMap(new ConcurrentHashMap<Throwable, Boolean>());
try {
Runnable dynamicLoadClass = new Runnable() {
@Override
public void run() {
try {
testFinal1.loadClass("substitutes.x.Ax");
testFinal1.loadClass("org.osgi.framework.hooks.bundle.FindHook");
} catch (Throwable t) {
errors.add(t);
}
}
};
Thread t1 = new Thread(dynamicLoadClass, getName() + "-1");
Thread t2 = new Thread(dynamicLoadClass, getName() + "-2");
t1.start();
t2.start();
t1.join();
t2.join();
} catch (Throwable t) {
fail("Unexpected testing bundle", t);
} finally {
reg.unregister();
resolverHookReg.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);
}
if (!errors.isEmpty()) {
fail("Failed to resolve dynamic", errors.iterator().next());
}
}
use of org.osgi.framework.wiring.BundleRevision in project karaf by apache.
the class BundleServiceImpl method getUnsatisfiedRequirements.
@Override
public List<BundleRequirement> getUnsatisfiedRequirements(Bundle bundle, String namespace) {
List<BundleRequirement> result = new ArrayList<>();
BundleRevision rev = bundle.adapt(BundleRevision.class);
if (rev != null) {
List<BundleRequirement> reqs = rev.getDeclaredRequirements(namespace);
for (BundleRequirement req : reqs) {
if (!canBeSatisfied(req)) {
result.add(req);
}
}
}
return result;
}
use of org.osgi.framework.wiring.BundleRevision in project karaf by apache.
the class BundleInfoImpl method populateRevisions.
private String populateRevisions(Bundle bundle) {
String ret = "";
BundleRevisions revisions = bundle.adapt(BundleRevisions.class);
if (revisions == null) {
return ret;
}
for (BundleRevision revision : revisions.getRevisions()) {
ret = ret + "[" + revision + "]" + " ";
}
return ret;
}
use of org.osgi.framework.wiring.BundleRevision in project karaf by apache.
the class PackageServiceImpl method getImports.
@Override
public List<PackageRequirement> getImports() {
Bundle[] bundles = bundleContext.getBundles();
SortedMap<String, PackageRequirement> requirements = new TreeMap<>();
for (Bundle bundle : bundles) {
BundleRevision rev = bundle.adapt(BundleRevision.class);
if (rev != null) {
List<BundleRequirement> reqs = rev.getDeclaredRequirements(BundleRevision.PACKAGE_NAMESPACE);
for (BundleRequirement req : reqs) {
PackageRequirement preq = create(req, bundle);
requirements.put(preq.getPackageName() + "|" + preq.getFilter() + "|" + preq.getBundle().getBundleId(), preq);
}
}
}
return new ArrayList<>(requirements.values());
}
Aggregations