Search in sources :

Example 66 with State

use of org.eclipse.osgi.service.resolver.State in project rt.equinox.framework by eclipse.

the class StateResolverTest method testResolveFragmentEE02.

public void testResolveFragmentEE02() throws BundleException, IOException {
    State state = buildEmptyState();
    Dictionary[] props = new Dictionary[] { new Hashtable() };
    // $NON-NLS-1$ //$NON-NLS-2$
    props[0].put("org.osgi.framework.executionenvironment", "test");
    state.setPlatformProperties(props);
    int bundleID = 0;
    Hashtable manifest = new Hashtable();
    manifest.clear();
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "org.eclipse.osgi");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
    manifest.put(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT, "test");
    BundleDescription a = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + manifest.get(Constants.BUNDLE_VERSION), bundleID++);
    manifest.clear();
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "b");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
    manifest.put(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT, "test");
    BundleDescription b = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + manifest.get(Constants.BUNDLE_VERSION), bundleID++);
    manifest.clear();
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "c");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
    manifest.put(Constants.IMPORT_PACKAGE, "d");
    manifest.put(Constants.FRAGMENT_HOST, "b");
    manifest.put(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT, "test");
    BundleDescription c = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + manifest.get(Constants.BUNDLE_VERSION), bundleID++);
    state.addBundle(b);
    state.addBundle(a);
    state.addBundle(c);
    state.resolve();
    // $NON-NLS-1$
    assertTrue("A is not resolved", a.isResolved());
    // $NON-NLS-1$
    assertTrue("B is not resolved", b.isResolved());
    // $NON-NLS-1$
    assertFalse("C is resolved", c.isResolved());
    manifest.clear();
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "d");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
    manifest.put(Constants.EXPORT_PACKAGE, "d");
    manifest.put(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT, "test");
    BundleDescription d = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + manifest.get(Constants.BUNDLE_VERSION), bundleID++);
    state.addBundle(d);
    state.resolve();
    // $NON-NLS-1$
    assertTrue("A is not resolved", a.isResolved());
    // $NON-NLS-1$
    assertTrue("B is not resolved", b.isResolved());
    // $NON-NLS-1$
    assertFalse("C is resolved", c.isResolved());
    // $NON-NLS-1$
    assertTrue("D is not resolved", d.isResolved());
    state.resolve(new BundleDescription[] { b });
    // $NON-NLS-1$
    assertTrue("A is not resolved", a.isResolved());
    // $NON-NLS-1$
    assertTrue("B is not resolved", b.isResolved());
    // $NON-NLS-1$
    assertTrue("C is not resolved", c.isResolved());
    // $NON-NLS-1$
    assertTrue("D is not resolved", d.isResolved());
    BundleWiring aWiring = a.getWiring();
    List aRequirements = a.getRequirements("osgi.ee");
    List aRequiredWires = aWiring.getRequiredWires("osgi.ee");
    assertEquals("Wrong number of osgi.ee requirements from system bundle", 1, aRequirements.size());
    assertEquals("Wrong number of wires from system bundle", 1, aRequiredWires.size());
    BundleWiring bWiring = b.getWiring();
    List bRequirements = b.getRequirements("osgi.ee");
    List bRequiredWires = bWiring.getRequiredWires("osgi.ee");
    assertEquals("Wrong number of osgi.ee requirements from fragment", 1, bRequirements.size());
    assertEquals("Wrong number of wires from fragment", 1, bRequiredWires.size());
    BundleWiring cWiring = c.getWiring();
    List cRequirements = c.getRequirements("osgi.ee");
    List cRequiredWires = cWiring.getRequiredWires("osgi.ee");
    assertEquals("Wrong number of osgi.ee requirements from c", 1, cRequirements.size());
    assertEquals("Wrong number of wires from c", 1, cRequiredWires.size());
    // $NON-NLS-1$
    File stateCache = OSGiTestsActivator.getContext().getDataFile("statecache");
    stateCache.mkdirs();
    StateObjectFactory.defaultFactory.writeState(state, stateCache);
    state = StateObjectFactory.defaultFactory.readState(stateCache);
    a = state.getBundle("org.eclipse.osgi", null);
    b = state.getBundle("b", null);
    c = state.getBundle("c", null);
    d = state.getBundle("d", null);
    aWiring = a.getWiring();
    aRequirements = a.getRequirements("osgi.ee");
    aRequiredWires = aWiring.getRequiredWires("osgi.ee");
    assertEquals("Wrong number of osgi.ee requirements from system bundle", 1, aRequirements.size());
    assertEquals("Wrong number of wires from system bundle", 1, aRequiredWires.size());
    bWiring = b.getWiring();
    bRequirements = b.getRequirements("osgi.ee");
    bRequiredWires = bWiring.getRequiredWires("osgi.ee");
    assertEquals("Wrong number of osgi.ee requirements from fragment", 1, bRequirements.size());
    assertEquals("Wrong number of wires from fragment", 1, bRequiredWires.size());
    cWiring = c.getWiring();
    cRequirements = c.getRequirements("osgi.ee");
    cRequiredWires = cWiring.getRequiredWires("osgi.ee");
    assertEquals("Wrong number of osgi.ee requirements from c", 1, cRequirements.size());
    assertEquals("Wrong number of wires from c", 1, cRequiredWires.size());
}
Also used : Dictionary(java.util.Dictionary) State(org.eclipse.osgi.service.resolver.State) Hashtable(java.util.Hashtable) BundleDescription(org.eclipse.osgi.service.resolver.BundleDescription) BundleWiring(org.osgi.framework.wiring.BundleWiring) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File)

Example 67 with State

use of org.eclipse.osgi.service.resolver.State in project rt.equinox.framework by eclipse.

the class StateResolverTest method testFragmentConstraints06.

public void testFragmentConstraints06() throws BundleException {
    int id = 0;
    State state = buildEmptyState();
    Hashtable manifest = new Hashtable();
    manifest = new Hashtable();
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "a");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
    // $NON-NLS-1$
    manifest.put(Constants.IMPORT_PACKAGE, "a");
    // $NON-NLS-1$
    manifest.put(Constants.REQUIRE_BUNDLE, "b");
    // $NON-NLS-1$
    BundleDescription a = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + "_" + manifest.get(Constants.BUNDLE_VERSION), id++);
    manifest = new Hashtable();
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "aFrag1");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
    // $NON-NLS-1$
    manifest.put(Constants.FRAGMENT_HOST, "a");
    // $NON-NLS-1$
    manifest.put(Constants.IMPORT_PACKAGE, "b, c, d");
    // $NON-NLS-1$
    manifest.put(Constants.REQUIRE_BUNDLE, "c, d, e");
    // $NON-NLS-1$
    BundleDescription aFrag1 = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + "_" + manifest.get(Constants.BUNDLE_VERSION), id++);
    manifest = new Hashtable();
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "aFrag2");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
    // $NON-NLS-1$
    manifest.put(Constants.FRAGMENT_HOST, "a");
    // $NON-NLS-1$
    manifest.put(Constants.IMPORT_PACKAGE, "b, c, e");
    // $NON-NLS-1$
    manifest.put(Constants.REQUIRE_BUNDLE, "c, d, f");
    // $NON-NLS-1$
    BundleDescription aFrag2 = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + "_" + manifest.get(Constants.BUNDLE_VERSION), id++);
    manifest = new Hashtable();
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "aFrag3");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
    // $NON-NLS-1$
    manifest.put(Constants.FRAGMENT_HOST, "a");
    // $NON-NLS-1$
    manifest.put(Constants.IMPORT_PACKAGE, "b, c");
    // $NON-NLS-1$
    manifest.put(Constants.REQUIRE_BUNDLE, "c, d");
    // $NON-NLS-1$
    BundleDescription aFrag3 = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + "_" + manifest.get(Constants.BUNDLE_VERSION), id++);
    manifest = new Hashtable();
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "b");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
    // $NON-NLS-1$
    manifest.put(Constants.EXPORT_PACKAGE, "a, b, c");
    // $NON-NLS-1$
    BundleDescription b = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + "_" + manifest.get(Constants.BUNDLE_VERSION), id++);
    manifest = new Hashtable();
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "c");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
    // $NON-NLS-1$
    manifest.put(Constants.EXPORT_PACKAGE, "c1, c2, c3");
    // $NON-NLS-1$
    BundleDescription c = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + "_" + manifest.get(Constants.BUNDLE_VERSION), id++);
    manifest = new Hashtable();
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "d");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
    // $NON-NLS-1$
    manifest.put(Constants.EXPORT_PACKAGE, "d1, d2, d3");
    // $NON-NLS-1$
    BundleDescription d = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + "_" + manifest.get(Constants.BUNDLE_VERSION), id++);
    state.addBundle(a);
    state.addBundle(aFrag1);
    state.addBundle(aFrag2);
    state.addBundle(aFrag3);
    state.addBundle(b);
    state.addBundle(c);
    state.addBundle(d);
    state.resolve();
    // $NON-NLS-1$
    assertTrue("0.1", a.isResolved());
    // $NON-NLS-1$
    assertFalse("0.2", aFrag1.isResolved());
    // $NON-NLS-1$
    assertFalse("0.3", aFrag2.isResolved());
    // $NON-NLS-1$
    assertTrue("0.4", aFrag3.isResolved());
    // $NON-NLS-1$
    assertTrue("0.5", b.isResolved());
    // $NON-NLS-1$
    assertTrue("0.6", c.isResolved());
    // $NON-NLS-1$
    assertTrue("0.7", d.isResolved());
    ExportPackageDescription[] aResolvedImports = a.getResolvedImports();
    ExportPackageDescription[] bSelectedExports = b.getSelectedExports();
    // $NON-NLS-1$
    assertEquals("1.0", 3, aResolvedImports.length);
    // $NON-NLS-1$
    assertEquals("1.1", 3, bSelectedExports.length);
    for (int i = 0; i < aResolvedImports.length; i++) {
        assertEquals(bSelectedExports[i], aResolvedImports[i]);
    }
    BundleDescription[] aResolvedRequires = a.getResolvedRequires();
    // $NON-NLS-1$
    assertEquals("1.0", 3, aResolvedRequires.length);
    // $NON-NLS-1$
    assertEquals("1.1", b, aResolvedRequires[0]);
    // $NON-NLS-1$
    assertEquals("1.2", c, aResolvedRequires[1]);
    // $NON-NLS-1$
    assertEquals("1.3", d, aResolvedRequires[2]);
}
Also used : State(org.eclipse.osgi.service.resolver.State) Hashtable(java.util.Hashtable) BundleDescription(org.eclipse.osgi.service.resolver.BundleDescription) ExportPackageDescription(org.eclipse.osgi.service.resolver.ExportPackageDescription)

Example 68 with State

use of org.eclipse.osgi.service.resolver.State in project rt.equinox.framework by eclipse.

the class StateResolverTest method testNativeCodeResolution04.

public void testNativeCodeResolution04() throws BundleException {
    State state = buildEmptyState();
    Dictionary[] props = new Dictionary[] { new Hashtable() };
    // Use different case for osname //$NON-NLS-1$
    props[0].put(Constants.FRAMEWORK_OS_NAME, "DoesNotExist");
    // Use different case for processor //$NON-NLS-1$
    props[0].put(Constants.FRAMEWORK_PROCESSOR, "InVaLid");
    state.setPlatformProperties(props);
    Hashtable manifest = new Hashtable();
    long bundleID = 0;
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "NativeBundle");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_NATIVECODE, "Bundle-NativeCode: nativefile1.txt;processor=iNvAlid;osname=doeSnoTexist");
    // $NON-NLS-1$
    BundleDescription testNativeBundle = state.getFactory().createBundleDescription(state, manifest, "NativeBundle", bundleID++);
    state.addBundle(testNativeBundle);
    state.resolve();
    // $NON-NLS-1$
    assertTrue("1.0", testNativeBundle.isResolved());
}
Also used : Dictionary(java.util.Dictionary) State(org.eclipse.osgi.service.resolver.State) Hashtable(java.util.Hashtable) BundleDescription(org.eclipse.osgi.service.resolver.BundleDescription)

Example 69 with State

use of org.eclipse.osgi.service.resolver.State in project rt.equinox.framework by eclipse.

the class StateResolverTest method testBasicResolution.

public void testBasicResolution() throws BundleException {
    State state = buildSimpleState();
    StateDelta delta = state.resolve();
    BundleDescription b1 = state.getBundle(1);
    BundleDescription b2 = state.getBundle(2);
    BundleDescription b3 = state.getBundle(3);
    // $NON-NLS-1$
    assertNotNull("0.1", b1);
    // $NON-NLS-1$
    assertNotNull("0.2", b2);
    // $NON-NLS-1$
    assertNotNull("0.3", b3);
    BundleDelta[] changes = delta.getChanges();
    // $NON-NLS-1$
    assertEquals("1.0", 3, changes.length);
    BundleDelta[] additions = delta.getChanges(BundleDelta.ADDED, false);
    // $NON-NLS-1$
    assertEquals("2.0", 3, additions.length);
    BundleDelta[] resolutions = delta.getChanges(BundleDelta.RESOLVED, false);
    // $NON-NLS-1$
    assertEquals("3.0", 2, resolutions.length);
    Map deltasMap = new HashMap();
    for (int i = 0; i < resolutions.length; i++) deltasMap.put(resolutions[i].getBundle().getSymbolicName(), resolutions[i]);
    // $NON-NLS-1$
    assertNotNull("3.1", deltasMap.get(b1.getSymbolicName()));
    // $NON-NLS-1$
    assertNotNull("3.2", deltasMap.get(b2.getSymbolicName()));
    // TODO why do we expect unresolved deltas here when the bundle was not resolved in the first place?
    // BundleDelta[] unresolutions = delta.getChanges(BundleDelta.UNRESOLVED, false);
    // assertEquals("4.0", 1, unresolutions.length);
    // assertEquals("4.1", unresolutions[0].getBundle(), b3);
    // $NON-NLS-1$
    assertFullyResolved("5.1", b1);
    // $NON-NLS-1$
    assertFullyResolved("5.2", b2);
    // $NON-NLS-1$
    assertFullyUnresolved("5.3", b3);
}
Also used : HashMap(java.util.HashMap) State(org.eclipse.osgi.service.resolver.State) BundleDescription(org.eclipse.osgi.service.resolver.BundleDescription) StateDelta(org.eclipse.osgi.service.resolver.StateDelta) BundleDelta(org.eclipse.osgi.service.resolver.BundleDelta) HashMap(java.util.HashMap) Map(java.util.Map) CaseInsensitiveDictionaryMap(org.eclipse.osgi.framework.util.CaseInsensitiveDictionaryMap)

Example 70 with State

use of org.eclipse.osgi.service.resolver.State in project rt.equinox.framework by eclipse.

the class StateResolverTest method testPlatformPropertiesBug188075.

public void testPlatformPropertiesBug188075() throws BundleException, IOException {
    State state = buildEmptyState();
    int bundleID = 0;
    Hashtable manifest = new Hashtable();
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "A");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.0");
    // $NON-NLS-1$ //$NON-NLS-2$
    manifest.put("Eclipse-PlatformFilter", "(!(test=value))");
    // $NON-NLS-1$
    BundleDescription a = state.getFactory().createBundleDescription(state, manifest, "A", bundleID++);
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "B");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.0");
    // $NON-NLS-1$ //$NON-NLS-2$
    manifest.put("Eclipse-PlatformFilter", "(test=value)");
    // $NON-NLS-1$
    BundleDescription b = state.getFactory().createBundleDescription(state, manifest, "B", bundleID++);
    Dictionary props = new Hashtable();
    // $NON-NLS-1$ //$NON-NLS-2$
    props.put("test", "value");
    state.setPlatformProperties(props);
    state.addBundle(a);
    state.addBundle(b);
    state.resolve();
    // $NON-NLS-1$
    assertFalse("1.1", a.isResolved());
    // $NON-NLS-1$
    assertTrue("1.2", b.isResolved());
    BundleContext context = OSGiTestsActivator.getContext();
    // $NON-NLS-1$
    File stateCache = context.getDataFile("statecache");
    stateCache.mkdirs();
    StateObjectFactory.defaultFactory.writeState(state, stateCache);
    state = StateObjectFactory.defaultFactory.readState(stateCache);
    props = state.getPlatformProperties()[0];
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    assertEquals("2.0", "value", props.get("test"));
    // $NON-NLS-1$
    BundleDescription aCache = state.getBundle("A", null);
    // $NON-NLS-1$
    BundleDescription bCache = state.getBundle("B", null);
    // $NON-NLS-1$
    assertFalse("2.1", aCache.isResolved());
    // $NON-NLS-1$
    assertTrue("2.2", bCache.isResolved());
}
Also used : Dictionary(java.util.Dictionary) State(org.eclipse.osgi.service.resolver.State) Hashtable(java.util.Hashtable) BundleDescription(org.eclipse.osgi.service.resolver.BundleDescription) File(java.io.File) BundleContext(org.osgi.framework.BundleContext)

Aggregations

State (org.eclipse.osgi.service.resolver.State)119 BundleDescription (org.eclipse.osgi.service.resolver.BundleDescription)87 Hashtable (java.util.Hashtable)70 Dictionary (java.util.Dictionary)28 StateObjectFactory (org.eclipse.osgi.service.resolver.StateObjectFactory)27 ExportPackageDescription (org.eclipse.osgi.service.resolver.ExportPackageDescription)22 StateDelta (org.eclipse.osgi.service.resolver.StateDelta)11 BundleDelta (org.eclipse.osgi.service.resolver.BundleDelta)10 ArrayList (java.util.ArrayList)7 List (java.util.List)7 File (java.io.File)6 HashMap (java.util.HashMap)6 Map (java.util.Map)5 CaseInsensitiveDictionaryMap (org.eclipse.osgi.framework.util.CaseInsensitiveDictionaryMap)5 Version (org.osgi.framework.Version)5 BundleWiring (org.osgi.framework.wiring.BundleWiring)4 PerformanceTestRunner (org.eclipse.core.tests.harness.PerformanceTestRunner)3 BundleException (org.osgi.framework.BundleException)3 BundleContext (org.osgi.framework.BundleContext)2 Collection (java.util.Collection)1