use of org.eclipse.osgi.report.resolution.ResolutionReport in project rt.equinox.framework by eclipse.
the class TestModuleContainer method testBug483849.
@Test
public void testBug483849() throws BundleException, IOException {
DummyContainerAdaptor adaptor = createDummyAdaptor();
ModuleContainer container = adaptor.getContainer();
// install and resolve host bundle
Module host = installDummyModule("bug483849.host.MF", "host", container);
ResolutionReport report = container.resolve(Arrays.asList(host), true);
Assert.assertNull("Failed to resolve host.", report.getResolutionException());
// install and dynamically attach a fragment that exports a package and resolve an importer
Module frag = installDummyModule("bug483849.frag.MF", "frag", container);
Module importer = installDummyModule("bug483849.importer.MF", "importer", container);
report = container.resolve(Arrays.asList(frag, importer), true);
Assert.assertNull("Failed to resolve test fragment and importer.", report.getResolutionException());
// get the count of package exports
ModuleWiring wiring = host.getCurrentRevision().getWiring();
int originalPackageCnt = wiring.getCapabilities(PackageNamespace.PACKAGE_NAMESPACE).size();
// update the host to generate a new revision
Map<String, String> updateManifest = getManifest("bug483849.host.MF");
ModuleRevisionBuilder updateBuilder = OSGiManifestBuilderFactory.createBuilder(updateManifest);
container.update(host, updateBuilder, null);
// refresh host which should force the importer to re-resolve to the new revision
report = container.refresh(Collections.singleton(host));
ModuleWiring importerWiring = importer.getCurrentRevision().getWiring();
Assert.assertNotNull("No wiring for importer.", importerWiring);
List<ModuleWire> importerPackageWires = importerWiring.getRequiredModuleWires(PackageNamespace.PACKAGE_NAMESPACE);
Assert.assertEquals("Wrong number of importer package Wires.", 1, importerPackageWires.size());
Assert.assertEquals("Wrong provider wiring.", host.getCurrentRevision().getWiring(), importerPackageWires.iterator().next().getProviderWiring());
Assert.assertEquals("Wrong provider revision.", host.getCurrentRevision(), importerPackageWires.iterator().next().getProviderWiring().getRevision());
wiring = host.getCurrentRevision().getWiring();
List<BundleCapability> packages = wiring.getCapabilities(PackageNamespace.PACKAGE_NAMESPACE);
Assert.assertEquals("Wrong number of host packages.", originalPackageCnt, packages.size());
}
use of org.eclipse.osgi.report.resolution.ResolutionReport in project rt.equinox.framework by eclipse.
the class TestModuleContainer method testSplitPackageUses01.
@Test
public void testSplitPackageUses01() throws BundleException {
DummyContainerAdaptor adaptor = createDummyAdaptor();
ModuleContainer container = adaptor.getContainer();
// install a split exporter core that substitutes
Map<String, String> coreManifest = new HashMap<String, String>();
coreManifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
coreManifest.put(Constants.BUNDLE_SYMBOLICNAME, "core");
coreManifest.put(Constants.EXPORT_PACKAGE, "pkg1; core=split; mandatory:=core");
coreManifest.put(Constants.IMPORT_PACKAGE, "pkg1; core=split");
// install a split exporter misc that requires core and substitutes
Map<String, String> miscManifest = new HashMap<String, String>();
miscManifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
miscManifest.put(Constants.BUNDLE_SYMBOLICNAME, "misc");
miscManifest.put(Constants.EXPORT_PACKAGE, "pkg1; misc=split; mandatory:=misc");
miscManifest.put(Constants.REQUIRE_BUNDLE, "core");
// install a bundle that imports core and exports pkg2 that uses pkg1 from core
Map<String, String> importsCoreManifest = new HashMap<String, String>();
importsCoreManifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
importsCoreManifest.put(Constants.BUNDLE_SYMBOLICNAME, "importsCore");
importsCoreManifest.put(Constants.EXPORT_PACKAGE, "pkg2; uses:=pkg1");
importsCoreManifest.put(Constants.IMPORT_PACKAGE, "pkg1; core=split");
// install a bundle that imports pkg2, but requires misc
Map<String, String> requiresMiscManifest = new HashMap<String, String>();
requiresMiscManifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
requiresMiscManifest.put(Constants.BUNDLE_SYMBOLICNAME, "requiresMisc");
requiresMiscManifest.put(Constants.IMPORT_PACKAGE, "pkg2");
requiresMiscManifest.put(Constants.REQUIRE_BUNDLE, "misc");
installDummyModule(coreManifest, "core", container);
installDummyModule(miscManifest, "misc", container);
installDummyModule(importsCoreManifest, "importsCore", container);
Module requireMisc = installDummyModule(requiresMiscManifest, "requireMisc", container);
ResolutionReport report = container.resolve(Arrays.asList(requireMisc), true);
Assert.assertNull("Failed to resolve test.", report.getResolutionException());
// now test by resolving the split exporters first
adaptor = createDummyAdaptor();
container = adaptor.getContainer();
installDummyModule(coreManifest, "core", container);
Module misc = installDummyModule(miscManifest, "misc", container);
report = container.resolve(Arrays.asList(misc), true);
Assert.assertNull("Failed to resolve test.", report.getResolutionException());
installDummyModule(importsCoreManifest, "importsCore", container);
requireMisc = installDummyModule(requiresMiscManifest, "requireMisc", container);
report = container.resolve(Arrays.asList(requireMisc), true);
Assert.assertNull("Failed to resolve test.", report.getResolutionException());
// now test by resolving the split exporters first with a real substitution
adaptor = createDummyAdaptor();
container = adaptor.getContainer();
// install a exporter that substitutes core's export
Map<String, String> substitutesCoreManifest = new HashMap<String, String>();
substitutesCoreManifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
substitutesCoreManifest.put(Constants.BUNDLE_SYMBOLICNAME, "substitutesCore");
substitutesCoreManifest.put(Constants.EXPORT_PACKAGE, "pkg1; substitutesCore=true; mandatory:=substitutesCore");
// change core's import to force it to the substitute
coreManifest.put(Constants.IMPORT_PACKAGE, "pkg1; substitutesCore=true");
importsCoreManifest.put(Constants.IMPORT_PACKAGE, "pkg1; substitutesCore=true");
installDummyModule(substitutesCoreManifest, "substitutesCore", container);
installDummyModule(coreManifest, "core", container);
misc = installDummyModule(miscManifest, "misc", container);
report = container.resolve(Arrays.asList(misc), true);
Assert.assertNull("Failed to resolve test.", report.getResolutionException());
installDummyModule(importsCoreManifest, "importsCore", container);
requireMisc = installDummyModule(requiresMiscManifest, "requireMisc", container);
report = container.resolve(Arrays.asList(requireMisc), true);
Assert.assertNull("Failed to resolve test.", report.getResolutionException());
// not test by doing a full resolve with real substitution
adaptor = createDummyAdaptor();
container = adaptor.getContainer();
installDummyModule(substitutesCoreManifest, "substitutesCore", container);
installDummyModule(coreManifest, "core", container);
installDummyModule(miscManifest, "misc", container);
installDummyModule(importsCoreManifest, "importsCore", container);
requireMisc = installDummyModule(requiresMiscManifest, "requireMisc", container);
report = container.resolve(Arrays.asList(requireMisc), true);
Assert.assertNull("Failed to resolve test.", report.getResolutionException());
}
use of org.eclipse.osgi.report.resolution.ResolutionReport in project rt.equinox.framework by eclipse.
the class TestModuleContainer method createContainerWithSystemBundle.
private Module createContainerWithSystemBundle(boolean resolveSystemBundle) throws BundleException, IOException {
DummyContainerAdaptor adaptor = createDummyAdaptor();
ModuleContainer container = adaptor.getContainer();
// install the system.bundle
String systemCapability = "osgi.ee; osgi.ee=\"JavaSE\"; version:List<Version>=\"1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6\", equinox.test; equinox.test=system, osgi.native; osgi.native.osname=test";
Module systemBundle = installDummyModule("system.bundle.MF", Constants.SYSTEM_BUNDLE_LOCATION, Constants.SYSTEM_BUNDLE_SYMBOLICNAME, null, systemCapability, container);
if (resolveSystemBundle) {
ResolutionReport report = container.resolve(Collections.singleton(systemBundle), true);
Assert.assertNull("Found resolution exception.", report.getResolutionException());
Assert.assertEquals("System is not resolved.", State.RESOLVED, systemBundle.getState());
}
return systemBundle;
}
use of org.eclipse.osgi.report.resolution.ResolutionReport in project rt.equinox.framework by eclipse.
the class TestModuleContainer method testSystemBundleFragmentRequiresOtherFragmentFailResolution.
@Test
public void testSystemBundleFragmentRequiresOtherFragmentFailResolution() throws BundleException, IOException {
// install the system.bundle
Module systemBundle = createContainerWithSystemBundle(true);
ModuleContainer container = systemBundle.getContainer();
// install an system.bundle fragment that provides a capability
Map<String, String> systemFragManifest1 = new HashMap<String, String>();
systemFragManifest1.put(Constants.BUNDLE_MANIFESTVERSION, "2");
systemFragManifest1.put(Constants.BUNDLE_SYMBOLICNAME, "systemFrag1");
systemFragManifest1.put(Constants.FRAGMENT_HOST, Constants.SYSTEM_BUNDLE_SYMBOLICNAME);
systemFragManifest1.put(Constants.PROVIDE_CAPABILITY, "fragment.capability; fragment.capability=test1");
Module systemFrag1 = installDummyModule(systemFragManifest1, "systemFrag1", container);
// install an system.bundle fragment that requires a fragment capability, but fails to match
Map<String, String> systemFragManifest2 = new HashMap<String, String>();
systemFragManifest2.put(Constants.BUNDLE_MANIFESTVERSION, "2");
systemFragManifest2.put(Constants.BUNDLE_SYMBOLICNAME, "systemFrag2");
systemFragManifest2.put(Constants.FRAGMENT_HOST, Constants.SYSTEM_BUNDLE_SYMBOLICNAME);
systemFragManifest2.put(Constants.REQUIRE_CAPABILITY, "fragment.capability; filter:=\"(fragment.capability=test4)\"");
systemFragManifest2.put(Constants.PROVIDE_CAPABILITY, "fragment.capability; fragment.capability=test2");
Module systemFrag2 = installDummyModule(systemFragManifest2, "systemFrag2", container);
// install an system.bundle fragment that requires a fragment capability from a fragment that fails to resolve
Map<String, String> systemFragManifest3 = new HashMap<String, String>();
systemFragManifest3.put(Constants.BUNDLE_MANIFESTVERSION, "2");
systemFragManifest3.put(Constants.BUNDLE_SYMBOLICNAME, "systemFrag3");
systemFragManifest3.put(Constants.FRAGMENT_HOST, Constants.SYSTEM_BUNDLE_SYMBOLICNAME);
systemFragManifest3.put(Constants.REQUIRE_CAPABILITY, "fragment.capability; filter:=\"(fragment.capability=test2)\"");
systemFragManifest3.put(Constants.PROVIDE_CAPABILITY, "fragment.capability; fragment.capability=test3");
Module systemFrag3 = installDummyModule(systemFragManifest3, "systemFrag3", container);
ResolutionReport report = container.resolve(Arrays.asList(systemFrag3), true);
Assert.assertNotNull("Expected failure message", report.getResolutionException());
List<ModuleWire> hostWires = systemBundle.getCurrentRevision().getWiring().getProvidedModuleWires(HostNamespace.HOST_NAMESPACE);
assertEquals("Wrong number of fragments.", 1, hostWires.size());
List<ModuleWire> systemFrag1HostWires = systemFrag1.getCurrentRevision().getWiring().getRequiredModuleWires(HostNamespace.HOST_NAMESPACE);
assertWires(systemFrag1HostWires, hostWires);
// install a bundle that can satisfy the failed requirement, but it should not be allowed since it is not a fragment
Map<String, String> provideCapabilityManifest1 = new HashMap<String, String>();
provideCapabilityManifest1.put(Constants.BUNDLE_MANIFESTVERSION, "2");
provideCapabilityManifest1.put(Constants.BUNDLE_SYMBOLICNAME, "provideCapabilityBundle1");
provideCapabilityManifest1.put(Constants.PROVIDE_CAPABILITY, "fragment.capability; fragment.capability=test4");
installDummyModule(provideCapabilityManifest1, "provideCapabilityBundle1", container);
hostWires = systemBundle.getCurrentRevision().getWiring().getProvidedModuleWires(HostNamespace.HOST_NAMESPACE);
assertEquals("Wrong number of fragments.", 1, hostWires.size());
systemFrag1HostWires = systemFrag1.getCurrentRevision().getWiring().getRequiredModuleWires(HostNamespace.HOST_NAMESPACE);
assertWires(systemFrag1HostWires, hostWires);
// install a fragment that satisfies the failed requirement
Map<String, String> systemFragManifest4 = new HashMap<String, String>();
systemFragManifest4.put(Constants.BUNDLE_MANIFESTVERSION, "2");
systemFragManifest4.put(Constants.BUNDLE_SYMBOLICNAME, "systemFrag4");
systemFragManifest4.put(Constants.FRAGMENT_HOST, Constants.SYSTEM_BUNDLE_SYMBOLICNAME);
systemFragManifest4.put(Constants.PROVIDE_CAPABILITY, "fragment.capability; fragment.capability=test4");
Module systemFrag4 = installDummyModule(systemFragManifest4, "systemFrag4", container);
report = container.resolve(Arrays.asList(systemFrag3), true);
Assert.assertNull("Failed to resolve.", report.getResolutionException());
hostWires = systemBundle.getCurrentRevision().getWiring().getProvidedModuleWires(HostNamespace.HOST_NAMESPACE);
assertEquals("Wrong number of fragments.", 4, hostWires.size());
systemFrag1HostWires = systemFrag1.getCurrentRevision().getWiring().getRequiredModuleWires(HostNamespace.HOST_NAMESPACE);
List<ModuleWire> systemFrag2HostWires = systemFrag2.getCurrentRevision().getWiring().getRequiredModuleWires(HostNamespace.HOST_NAMESPACE);
List<ModuleWire> systemFrag3HostWires = systemFrag3.getCurrentRevision().getWiring().getRequiredModuleWires(HostNamespace.HOST_NAMESPACE);
List<ModuleWire> systemFrag4HostWires = systemFrag4.getCurrentRevision().getWiring().getRequiredModuleWires(HostNamespace.HOST_NAMESPACE);
assertWires(systemFrag1HostWires, hostWires);
assertWires(systemFrag2HostWires, hostWires);
assertWires(systemFrag3HostWires, hostWires);
assertWires(systemFrag4HostWires, hostWires);
List<ModuleCapability> fragmentCapabilities = systemBundle.getCurrentRevision().getWiring().getModuleCapabilities("fragment.capability");
assertEquals("Wrong number of fragment capabilities.", 4, fragmentCapabilities.size());
// Use set since the order of required and provided wires will be different
Set<ModuleWire> hostRequiredFragmentCapWires = new HashSet<ModuleWire>(systemBundle.getCurrentRevision().getWiring().getRequiredModuleWires("fragment.capability"));
Set<ModuleWire> hostProvidedFragmentCapWires = new HashSet<ModuleWire>(systemBundle.getCurrentRevision().getWiring().getProvidedModuleWires("fragment.capability"));
assertEquals("Wrong number of wires.", 2, hostProvidedFragmentCapWires.size());
assertEquals("Wrong wires found from host.", hostRequiredFragmentCapWires, hostProvidedFragmentCapWires);
}
use of org.eclipse.osgi.report.resolution.ResolutionReport in project rt.equinox.framework by eclipse.
the class TestModuleContainer method testSystemBundleFragmentsWithPayloadRequirements.
@Test
public void testSystemBundleFragmentsWithPayloadRequirements() throws BundleException, IOException {
// install the system.bundle
Module systemBundle = createContainerWithSystemBundle(true);
ModuleContainer container = systemBundle.getContainer();
// install an system.bundle fragment that requires a payload requirement from system.bundle
Map<String, String> systemFragManifest = new HashMap<String, String>();
systemFragManifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
systemFragManifest.put(Constants.BUNDLE_SYMBOLICNAME, "systemFrag");
systemFragManifest.put(Constants.FRAGMENT_HOST, Constants.SYSTEM_BUNDLE_SYMBOLICNAME);
systemFragManifest.put(Constants.REQUIRE_CAPABILITY, "equinox.test; filter:=\"(equinox.test=system)\"");
Module systemFrag = installDummyModule(systemFragManifest, "systemFrag", container);
ResolutionReport report = container.resolve(Arrays.asList(systemFrag), true);
Assert.assertNull("Failed to resolve system.bundle.", report.getResolutionException());
List<ModuleWire> hostWires = systemBundle.getCurrentRevision().getWiring().getProvidedModuleWires(HostNamespace.HOST_NAMESPACE);
assertEquals("Wrong number of fragments.", 1, hostWires.size());
Assert.assertEquals("Unexpected fragment revision: " + hostWires, systemFrag.getCurrentRevision(), hostWires.get(0).getRequirer());
List<ModuleWire> systemBundleRequiredWires = systemBundle.getCurrentRevision().getWiring().getRequiredModuleWires(null);
assertEquals("Wrong number of wires.", 1, systemBundleRequiredWires.size());
assertEquals("Wrong requirer.", systemBundle.getCurrentRevision(), systemBundleRequiredWires.get(0).getRequirer());
assertEquals("Wrong requirement.", systemFrag.getCurrentRevision(), systemBundleRequiredWires.get(0).getRequirement().getRevision());
List<ModuleWire> fragRequiredWires = systemFrag.getCurrentRevision().getWiring().getRequiredModuleWires(null);
assertEquals("Wrong number of required wires.", 1, fragRequiredWires.size());
assertWires(fragRequiredWires, hostWires);
}
Aggregations