Search in sources :

Example 16 with State

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

the class StateResolverTest method testResolveFragmentEE01.

public void testResolveFragmentEE01() throws BundleException {
    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");
    // $NON-NLS-1$
    manifest.put(Constants.FRAGMENT_HOST, "org.eclipse.osgi; bundle-version=\"[1.0, 1.1)\"");
    manifest.put(Constants.REQUIRE_CAPABILITY, "osgi.ee; filter:=\"(osgi.ee=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");
    // $NON-NLS-1$
    manifest.put(Constants.REQUIRE_CAPABILITY, "osgi.identity; filter:=\"(osgi.identity=b)\"");
    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$
    assertTrue("C is not resolved", c.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.identity");
    List cRequiredWires = cWiring.getRequiredWires("osgi.identity");
    assertEquals("Wrong number of osgi.identity requirements from c", 1, cRequirements.size());
    assertEquals("Wrong number of wires from c", 1, cRequiredWires.size());
    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");
    // $NON-NLS-1$
    manifest.put(Constants.FRAGMENT_HOST, "org.eclipse.osgi; bundle-version=\"[1.0, 1.1)\"");
    manifest.put(Constants.REQUIRE_CAPABILITY, "osgi.ee; filter:=\"(osgi.ee=fail)\"");
    b = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + manifest.get(Constants.BUNDLE_VERSION), b.getBundleId());
    state.updateBundle(b);
    state.resolve(false);
    // $NON-NLS-1$
    assertTrue("A is not resolved", a.isResolved());
    // $NON-NLS-1$
    assertFalse("B is not resolved", b.isResolved());
    // $NON-NLS-1$
    assertFalse("C is not resolved", c.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) BundleWiring(org.osgi.framework.wiring.BundleWiring) ArrayList(java.util.ArrayList) List(java.util.List)

Example 17 with State

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

the class StateResolverTest method testImportJavaPackages.

public void testImportJavaPackages() throws Exception {
    State state = buildEmptyState();
    int bundleID = 0;
    Hashtable manifest = new Hashtable();
    Dictionary[] props = new Dictionary[] { new Hashtable() };
    props[0].put("org.osgi.framework.executionenvironment", "J2SE-1.5, JavaSE-1.6");
    props[0].put(Constants.FRAMEWORK_SYSTEMPACKAGES, "java.lang,java.util");
    state.setPlatformProperties(props);
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "org.eclipse.osgi");
    BundleDescription systemBundle = state.getFactory().createBundleDescription(state, manifest, "org.eclipse.osgi", bundleID++);
    state.addBundle(systemBundle);
    List bundles = new ArrayList();
    manifest.clear();
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "A");
    manifest.put(Constants.IMPORT_PACKAGE, "java.lang");
    manifest.put(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT, "JavaSE-1.6");
    BundleDescription a = state.getFactory().createBundleDescription(state, manifest, "A", bundleID++);
    bundles.add(a);
    state.addBundle(a);
    manifest.clear();
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "A.FRAG");
    manifest.put(Constants.FRAGMENT_HOST, "A");
    manifest.put(Constants.IMPORT_PACKAGE, "java.lang,java.util");
    manifest.put(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT, "J2SE-1.5");
    BundleDescription aFrag = state.getFactory().createBundleDescription(state, manifest, "A.FRAG", bundleID++);
    bundles.add(aFrag);
    state.addBundle(aFrag);
    manifest.clear();
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "B");
    manifest.put(Constants.IMPORT_PACKAGE, "java.xyz");
    manifest.put(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT, "JavaSE-1.6");
    BundleDescription b = state.getFactory().createBundleDescription(state, manifest, "B", bundleID++);
    bundles.add(b);
    state.addBundle(b);
    state.resolve();
    assertTrue("host A not resolved", a.isResolved());
    assertTrue("fragment A.FRAG not resolved", aFrag.isResolved());
    assertFalse("host B is wrongly resolved", b.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) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 18 with State

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

the class StateResolverTest method testComplexResolution.

public void testComplexResolution() throws BundleException {
    State state = buildComplexState();
    StateDelta delta = state.resolve();
    // $NON-NLS-1$ //$NON-NLS-2$
    BundleDescription b1 = state.getBundle("org.eclipse.b1", Version.parseVersion("1.0"));
    // $NON-NLS-1$ //$NON-NLS-2$
    BundleDescription b2 = state.getBundle("org.eclipse.b2", Version.parseVersion("2.0"));
    // $NON-NLS-1$ //$NON-NLS-2$
    BundleDescription b3 = state.getBundle("org.eclipse.b3", Version.parseVersion("2.0"));
    // $NON-NLS-1$ //$NON-NLS-2$
    BundleDescription b4 = state.getBundle("org.eclipse.b4", Version.parseVersion("2.0"));
    // $NON-NLS-1$ //$NON-NLS-2$
    BundleDescription b5 = state.getBundle("org.eclipse.b5", Version.parseVersion("1.0"));
    // $NON-NLS-1$ //$NON-NLS-2$
    BundleDescription b6 = state.getBundle("org.eclipse.b6", Version.parseVersion("1.0"));
    // $NON-NLS-1$
    assertNotNull("0.1", b1);
    // $NON-NLS-1$
    assertNotNull("0.2", b2);
    // $NON-NLS-1$
    assertNotNull("0.3", b3);
    // $NON-NLS-1$
    assertNotNull("0.4", b4);
    // $NON-NLS-1$
    assertNotNull("0.5", b5);
    // $NON-NLS-1$
    assertNotNull("0.6", b6);
    BundleDelta[] changes = delta.getChanges();
    // $NON-NLS-1$
    assertEquals("1.0", 6, changes.length);
    BundleDelta[] additions = delta.getChanges(BundleDelta.ADDED, false);
    // $NON-NLS-1$
    assertEquals("2.0", 6, additions.length);
    BundleDelta[] resolutions = delta.getChanges(BundleDelta.RESOLVED, false);
    // $NON-NLS-1$
    assertEquals("3.0", 6, 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()));
    // $NON-NLS-1$
    assertNotNull("3.3", deltasMap.get(b3.getSymbolicName()));
    // $NON-NLS-1$
    assertNotNull("3.4", deltasMap.get(b4.getSymbolicName()));
    // $NON-NLS-1$
    assertNotNull("3.5", deltasMap.get(b5.getSymbolicName()));
    // $NON-NLS-1$
    assertNotNull("3.6", deltasMap.get(b6.getSymbolicName()));
    BundleDelta[] unresolutions = delta.getChanges(BundleDelta.UNRESOLVED, false);
    // $NON-NLS-1$
    assertEquals("4.0", 0, unresolutions.length);
    // $NON-NLS-1$
    assertFullyResolved("5.1", b1);
    // $NON-NLS-1$
    assertFullyResolved("5.2", b2);
    // $NON-NLS-1$
    assertFullyResolved("5.3", b3);
    // $NON-NLS-1$
    assertFullyResolved("5.4", b4);
    // $NON-NLS-1$
    assertFullyResolved("5.5", b5);
    // $NON-NLS-1$
    assertFullyResolved("5.6", b6);
}
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 19 with State

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

the class StateResolverTest method testPrerequisiteBundle.

public void testPrerequisiteBundle() throws BundleException {
    State state = buildComplexState();
    state.resolve();
    BundleDescription[] prereqs;
    prereqs = state.getStateHelper().getPrerequisites(state.getResolvedBundles());
    // $NON-NLS-1$
    assertEquals("1.0", 6, prereqs.length);
    prereqs = state.getStateHelper().getPrerequisites(new BundleDescription[] { state.getBundle(1) });
    // $NON-NLS-1$
    assertEquals("2.0", 2, prereqs.length);
    // $NON-NLS-1$
    assertContains("2.1", prereqs, state.getBundle(1));
    // $NON-NLS-1$
    assertContains("2.2", prereqs, state.getBundle(3));
    prereqs = state.getStateHelper().getPrerequisites(new BundleDescription[] { state.getBundle(2) });
    // $NON-NLS-1$
    assertEquals("3.0", 3, prereqs.length);
    // $NON-NLS-1$
    assertContains("3.1", prereqs, state.getBundle(1));
    // $NON-NLS-1$
    assertContains("3.2", prereqs, state.getBundle(2));
    // $NON-NLS-1$
    assertContains("3.3", prereqs, state.getBundle(3));
    prereqs = state.getStateHelper().getPrerequisites(new BundleDescription[] { state.getBundle(3) });
    // $NON-NLS-1$
    assertEquals("4.0", 1, prereqs.length);
    // $NON-NLS-1$
    assertContains("4.1", prereqs, state.getBundle(3));
    prereqs = state.getStateHelper().getPrerequisites(new BundleDescription[] { state.getBundle(4) });
    // $NON-NLS-1$
    assertEquals("5.0", 3, prereqs.length);
    // $NON-NLS-1$
    assertContains("5.1", prereqs, state.getBundle(1));
    // $NON-NLS-1$
    assertContains("5.2", prereqs, state.getBundle(3));
    // $NON-NLS-1$
    assertContains("5.3", prereqs, state.getBundle(4));
    prereqs = state.getStateHelper().getPrerequisites(new BundleDescription[] { state.getBundle(5) });
    // $NON-NLS-1$
    assertEquals("6.0", 2, prereqs.length);
    // $NON-NLS-1$
    assertContains("6.1", prereqs, state.getBundle(3));
    // $NON-NLS-1$
    assertContains("6.2", prereqs, state.getBundle(5));
    prereqs = state.getStateHelper().getPrerequisites(new BundleDescription[] { state.getBundle(6) });
    // $NON-NLS-1$
    assertEquals("6.0", 4, prereqs.length);
    // $NON-NLS-1$
    assertContains("6.1", prereqs, state.getBundle(1));
    // $NON-NLS-1$
    assertContains("6.2", prereqs, state.getBundle(3));
    // $NON-NLS-1$
    assertContains("6.3", prereqs, state.getBundle(4));
    // $NON-NLS-1$
    assertContains("6.4", prereqs, state.getBundle(6));
}
Also used : State(org.eclipse.osgi.service.resolver.State) BundleDescription(org.eclipse.osgi.service.resolver.BundleDescription)

Example 20 with State

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

the class StateResolverTest method testBug266935_03.

public void testBug266935_03() throws BundleException {
    State state = createBug266935State();
    // $NON-NLS-1$ //$NON-NLS-2$
    BundleDescription a = state.getBundle("a", new Version("1.0"));
    BundleDescription newA = updateStateBug266935(state, a);
    state.removeBundle(newA);
    state.resolve(new BundleDescription[] { newA });
}
Also used : Version(org.osgi.framework.Version) State(org.eclipse.osgi.service.resolver.State) BundleDescription(org.eclipse.osgi.service.resolver.BundleDescription)

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