Search in sources :

Example 6 with BundleDelta

use of org.eclipse.osgi.service.resolver.BundleDelta 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 7 with BundleDelta

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

the class StateResolverTest method testRemovalResolve.

public void testRemovalResolve() throws BundleException {
    State state = buildInitialState();
    StateDelta delta = state.resolve();
    BundleDelta[] deltas = delta.getChanges();
    BundleDescription b0 = state.getBundle(0);
    // $NON-NLS-1$
    assertNotNull("0.1", b0);
    // $NON-NLS-1$
    assertFullyResolved("0.2", b0);
    Hashtable manifest = new Hashtable();
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "org.eclipse.b1");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.0");
    // $NON-NLS-1$
    manifest.put(Constants.IMPORT_PACKAGE, "org.osgi.framework");
    // $NON-NLS-1$
    manifest.put(Constants.EXPORT_PACKAGE, "org.eclipse.p1; specification-version=1.0");
    BundleDescription b1 = null;
    try {
        // $NON-NLS-1$
        b1 = state.getFactory().createBundleDescription(manifest, "org.eclipse.b1", 1);
        state.removeBundle(1);
        state.addBundle(b1);
    } catch (BundleException e) {
        // $NON-NLS-1$
        fail("Failed to create BundleDescription: " + e.getMessage());
    }
    manifest = new Hashtable();
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "org.eclipse.b2");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.0");
    // $NON-NLS-1$
    manifest.put(Constants.IMPORT_PACKAGE, "org.osgi.framework,org.eclipse.p1");
    // $NON-NLS-1$
    manifest.put(Constants.EXPORT_PACKAGE, "org.eclipse.p2; specification-version=1.0");
    BundleDescription b2 = null;
    try {
        // $NON-NLS-1$
        b2 = state.getFactory().createBundleDescription(manifest, "org.eclipse.b2", 2);
        state.removeBundle(2);
        state.addBundle(b2);
    } catch (BundleException e) {
        // $NON-NLS-1$
        fail("Failed to create BundleDescription: " + e.getMessage());
    }
    manifest = new Hashtable();
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "org.eclipse.b3");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.0");
    // $NON-NLS-1$
    manifest.put(Constants.IMPORT_PACKAGE, "org.osgi.framework,org.eclipse.p2");
    // $NON-NLS-1$
    manifest.put(Constants.EXPORT_PACKAGE, "org.eclipse.p3; specification-version=1.0");
    BundleDescription b3 = null;
    try {
        // $NON-NLS-1$
        b3 = state.getFactory().createBundleDescription(manifest, "org.eclipse.b3", 3);
        state.removeBundle(3);
        state.addBundle(b3);
    } catch (BundleException e) {
        // $NON-NLS-1$
        fail("Failed to create BundleDescription: " + e.getMessage());
    }
    delta = state.resolve(false);
    deltas = delta.getChanges();
    // $NON-NLS-1$
    assertEquals("1.0", 4, deltas.length);
    Map deltasMap = new HashMap();
    for (int i = 0; i < deltas.length; i++) deltasMap.put(new Long(deltas[i].getBundle().getBundleId()), deltas[i]);
    // $NON-NLS-1$
    assertNotNull("1.1", deltasMap.get(new Long(1)));
    // $NON-NLS-1$
    assertNotNull("1.2", deltasMap.get(new Long(2)));
    // $NON-NLS-1$
    assertNotNull("1.3", deltasMap.get(new Long(3)));
    // $NON-NLS-1$
    assertEquals("2.1", (BundleDelta.RESOLVED | BundleDelta.ADDED), ((BundleDelta) deltasMap.get(new Long(1))).getType());
    // $NON-NLS-1$
    assertEquals("2.2", (BundleDelta.RESOLVED | BundleDelta.ADDED), ((BundleDelta) deltasMap.get(new Long(2))).getType());
    // $NON-NLS-1$
    assertEquals("2.3", (BundleDelta.RESOLVED | BundleDelta.ADDED), ((BundleDelta) deltasMap.get(new Long(3))).getType());
    state.removeBundle(1);
    delta = state.resolve(false);
    deltas = delta.getChanges();
    b2 = state.getBundle(2);
    b3 = state.getBundle(3);
    // $NON-NLS-1$
    assertEquals("3.1", false, b2.isResolved());
    // $NON-NLS-1$
    assertEquals("3.2", false, b3.isResolved());
}
Also used : HashMap(java.util.HashMap) State(org.eclipse.osgi.service.resolver.State) BundleDescription(org.eclipse.osgi.service.resolver.BundleDescription) Hashtable(java.util.Hashtable) StateDelta(org.eclipse.osgi.service.resolver.StateDelta) BundleDelta(org.eclipse.osgi.service.resolver.BundleDelta) BundleException(org.osgi.framework.BundleException) HashMap(java.util.HashMap) Map(java.util.Map) CaseInsensitiveDictionaryMap(org.eclipse.osgi.framework.util.CaseInsensitiveDictionaryMap)

Example 8 with BundleDelta

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

the class StateResolverTest method testUpdate.

public void testUpdate() throws BundleException {
    State state = buildEmptyState();
    // $NON-NLS-1$
    String B1_LOCATION = "org.eclipse.b";
    // $NON-NLS-1$ //$NON-NLS-2$
    final String B1_RESOLVED = "Bundle-SymbolicName: org.eclipse.b1\n" + "Bundle-Version: 1.0\n";
    // $NON-NLS-1$ //$NON-NLS-2$
    final String B1_UNRESOLVED = "Bundle-SymbolicName: org.eclipse.b1\n" + "Bundle-Version: 2.0\nRequire-Bundle: non.existant.bundle\n";
    BundleDescription b1 = state.getFactory().createBundleDescription(parseManifest(B1_RESOLVED), B1_LOCATION, 1);
    // $NON-NLS-1$
    assertTrue("0.9", state.addBundle(b1));
    StateDelta delta = state.resolve();
    b1 = state.getBundleByLocation(b1.getLocation());
    BundleDelta[] changes = delta.getChanges();
    // $NON-NLS-1$
    assertEquals("1.0", 1, changes.length);
    // $NON-NLS-1$
    assertEquals("1.1", b1, changes[0].getBundle());
    // $NON-NLS-1$
    assertEquals("1.2", (BundleDelta.ADDED | BundleDelta.RESOLVED), changes[0].getType());
    // $NON-NLS-1$
    assertFullyResolved("1.3", b1);
    // $NON-NLS-1$
    assertTrue("1.8", contains(state.getResolvedBundles(), b1));
    BundleDescription b11 = state.getFactory().createBundleDescription(parseManifest(B1_UNRESOLVED), B1_LOCATION, 1);
    // $NON-NLS-1$
    assertTrue("1.8b", state.updateBundle(b11));
    b11 = state.getBundle(b11.getBundleId());
    // $NON-NLS-1$
    assertTrue("1.9", !contains(state.getResolvedBundles(), b11));
    delta = state.resolve();
    changes = delta.getChanges();
    // $NON-NLS-1$
    assertEquals("2.0", 2, changes.length);
    HashMap deltasMap = new HashMap();
    for (int i = 0; i < changes.length; i++) deltasMap.put(changes[i].getBundle(), changes[i]);
    // $NON-NLS-1$
    assertNotNull("2.1", deltasMap.get(b1));
    // $NON-NLS-1$
    assertNotNull("2.2", deltasMap.get(b11));
    // $NON-NLS-1$
    assertEquals("2.3", BundleDelta.UNRESOLVED, ((BundleDelta) deltasMap.get(b1)).getType());
    // $NON-NLS-1$
    assertEquals("2.4", BundleDelta.UPDATED, ((BundleDelta) deltasMap.get(b11)).getType());
    BundleDescription b111 = state.getFactory().createBundleDescription(parseManifest(B1_RESOLVED), B1_LOCATION, 1);
    // $NON-NLS-1$
    assertTrue("3.0", state.updateBundle(b111));
    b111 = state.getBundle(b111.getBundleId());
    // $NON-NLS-1$
    assertTrue("3.1", !contains(state.getResolvedBundles(), b111));
    delta = state.resolve();
    changes = delta.getChanges();
    // $NON-NLS-1$
    assertEquals("3.2", 1, changes.length);
    // $NON-NLS-1$
    assertEquals("3.1", b111, changes[0].getBundle());
    // $NON-NLS-1$
    assertEquals("3.2", BundleDelta.UPDATED | BundleDelta.RESOLVED, changes[0].getType());
    // $NON-NLS-1$
    assertFullyResolved("3.3", b111);
}
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)

Example 9 with BundleDelta

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

the class StateResolverTest method testReresolveBundle.

/**
 * Tests adding 3 new bundles to an already resolved state and then
 * resolving only one of the bundles. The result should be all 3 added
 * bundles being resolved. Then re-resolving the same bundle. The result
 * should be only the one bundle being resolved.
 */
public void testReresolveBundle() throws BundleException {
    State state = buildInitialState();
    StateDelta delta = state.resolve();
    BundleDelta[] deltas = delta.getChanges();
    BundleDescription b0 = state.getBundle(0);
    // $NON-NLS-1$
    assertNotNull("0.1", b0);
    // $NON-NLS-1$
    assertFullyResolved("0.2", b0);
    Hashtable manifest = new Hashtable();
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "org.eclipse.b1");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.0");
    // $NON-NLS-1$
    manifest.put(Constants.IMPORT_PACKAGE, "org.osgi.framework");
    // $NON-NLS-1$
    manifest.put(Constants.EXPORT_PACKAGE, "org.eclipse.p1; specification-version=1.0");
    BundleDescription b1 = null;
    try {
        // $NON-NLS-1$
        b1 = state.getFactory().createBundleDescription(manifest, "org.eclipse.b1", 1);
        state.removeBundle(1);
        state.addBundle(b1);
    } catch (BundleException e) {
        // $NON-NLS-1$
        fail("Failed to create BundleDescription: " + e.getMessage());
    }
    manifest = new Hashtable();
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "org.eclipse.b2");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.0");
    // $NON-NLS-1$
    manifest.put(Constants.IMPORT_PACKAGE, "org.osgi.framework,org.eclipse.p1");
    // $NON-NLS-1$
    manifest.put(Constants.EXPORT_PACKAGE, "org.eclipse.p2; specification-version=1.0");
    BundleDescription b2 = null;
    try {
        // $NON-NLS-1$
        b2 = state.getFactory().createBundleDescription(manifest, "org.eclipse.b2", 2);
        state.removeBundle(2);
        state.addBundle(b2);
    } catch (BundleException e) {
        // $NON-NLS-1$
        fail("Failed to create BundleDescription: " + e.getMessage());
    }
    manifest = new Hashtable();
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "org.eclipse.b3");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.0");
    // $NON-NLS-1$
    manifest.put(Constants.IMPORT_PACKAGE, "org.osgi.framework,org.eclipse.p2");
    // $NON-NLS-1$
    manifest.put(Constants.EXPORT_PACKAGE, "org.eclipse.p3; specification-version=1.0");
    BundleDescription b3 = null;
    try {
        // $NON-NLS-1$
        b3 = state.getFactory().createBundleDescription(manifest, "org.eclipse.b3", 3);
        state.removeBundle(3);
        state.addBundle(b3);
    } catch (BundleException e) {
        // $NON-NLS-1$
        fail("Failed to create BundleDescription: " + e.getMessage());
    }
    delta = state.resolve(new BundleDescription[] { state.getBundle(1) });
    deltas = delta.getChanges();
    // $NON-NLS-1$
    assertEquals("1.0", 3, deltas.length);
    Map deltasMap = new HashMap();
    for (int i = 0; i < deltas.length; i++) deltasMap.put(new Long(deltas[i].getBundle().getBundleId()), deltas[i]);
    // $NON-NLS-1$
    assertNotNull("1.1", deltasMap.get(new Long(1)));
    // $NON-NLS-1$
    assertNotNull("1.2", deltasMap.get(new Long(2)));
    // $NON-NLS-1$
    assertNotNull("1.3", deltasMap.get(new Long(3)));
    // $NON-NLS-1$
    assertEquals("2.1", (BundleDelta.RESOLVED | BundleDelta.ADDED), ((BundleDelta) deltasMap.get(new Long(1))).getType());
    // $NON-NLS-1$
    assertEquals("2.2", (BundleDelta.RESOLVED | BundleDelta.ADDED), ((BundleDelta) deltasMap.get(new Long(2))).getType());
    // $NON-NLS-1$
    assertEquals("2.3", (BundleDelta.RESOLVED | BundleDelta.ADDED), ((BundleDelta) deltasMap.get(new Long(3))).getType());
    delta = state.resolve(new BundleDescription[] { state.getBundle(1) });
    deltas = delta.getChanges();
    // $NON-NLS-1$
    assertEquals("3.0", 3, deltas.length);
    deltasMap = new HashMap();
    for (int i = 0; i < deltas.length; i++) deltasMap.put(new Long(deltas[i].getBundle().getBundleId()), deltas[i]);
    // $NON-NLS-1$
    assertNotNull("3.1", deltasMap.get(new Long(1)));
    // $NON-NLS-1$
    assertNotNull("3.2", deltasMap.get(new Long(2)));
    // $NON-NLS-1$
    assertNotNull("3.3", deltasMap.get(new Long(3)));
    // $NON-NLS-1$
    assertEquals("3.4", BundleDelta.RESOLVED, ((BundleDelta) deltasMap.get(new Long(1))).getType());
    // $NON-NLS-1$
    assertEquals("3.5", BundleDelta.RESOLVED, ((BundleDelta) deltasMap.get(new Long(2))).getType());
    // $NON-NLS-1$
    assertEquals("3.6", BundleDelta.RESOLVED, ((BundleDelta) deltasMap.get(new Long(3))).getType());
}
Also used : HashMap(java.util.HashMap) State(org.eclipse.osgi.service.resolver.State) BundleDescription(org.eclipse.osgi.service.resolver.BundleDescription) Hashtable(java.util.Hashtable) StateDelta(org.eclipse.osgi.service.resolver.StateDelta) BundleDelta(org.eclipse.osgi.service.resolver.BundleDelta) BundleException(org.osgi.framework.BundleException) HashMap(java.util.HashMap) Map(java.util.Map) CaseInsensitiveDictionaryMap(org.eclipse.osgi.framework.util.CaseInsensitiveDictionaryMap)

Example 10 with BundleDelta

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

the class StateResolverTest method testBug187616.

public void testBug187616() throws BundleException {
    State state = buildEmptyState();
    Hashtable manifest = new Hashtable();
    long bundleID = 0;
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "test.host; singleton:=true");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
    // $NON-NLS-1$
    BundleDescription testHost100 = state.getFactory().createBundleDescription(state, manifest, "test.host100", bundleID++);
    manifest = new Hashtable();
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "test.host; singleton:=true");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.0.1");
    // $NON-NLS-1$
    BundleDescription testHost101 = state.getFactory().createBundleDescription(state, manifest, "test.host101", bundleID++);
    manifest = new Hashtable();
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "test.frag; singleton:=true");
    // $NON-NLS-1$
    manifest.put(Constants.FRAGMENT_HOST, "test.host; bundle-version=\"[1.0.0,2.0.0)\"");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
    // $NON-NLS-1$
    BundleDescription testFrag100 = state.getFactory().createBundleDescription(state, manifest, "test.frag100", bundleID++);
    manifest = new Hashtable();
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "test.frag; singleton:=true");
    // $NON-NLS-1$
    manifest.put(Constants.FRAGMENT_HOST, "test.host; bundle-version=\"[1.0.0,2.0.0)\"");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.0.1");
    // $NON-NLS-1$
    BundleDescription testFrag101 = state.getFactory().createBundleDescription(state, manifest, "test.frag101", bundleID++);
    manifest = new Hashtable();
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "test.dependent; singleton:=true");
    // $NON-NLS-1$
    manifest.put(Constants.REQUIRE_BUNDLE, "test.host; bundle-version=\"[1.0.0,2.0.0)\"");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
    // $NON-NLS-1$
    BundleDescription testDependent = state.getFactory().createBundleDescription(state, manifest, "test.frag101", bundleID++);
    state.addBundle(testHost100);
    state.addBundle(testFrag100);
    state.addBundle(testHost101);
    state.addBundle(testFrag101);
    state.addBundle(testDependent);
    StateDelta stateDelta = state.resolve();
    // $NON-NLS-1$
    assertFalse("1.0", testHost100.isResolved());
    // $NON-NLS-1$
    assertTrue("1.1", testHost101.isResolved());
    // $NON-NLS-1$
    assertFalse("1.2", testFrag100.isResolved());
    // $NON-NLS-1$
    assertTrue("1.3", testFrag101.isResolved());
    // $NON-NLS-1$
    assertTrue("1.4", testDependent.isResolved());
    BundleDelta[] bDelta = stateDelta.getChanges(BundleDelta.ADDED | BundleDelta.RESOLVED, false);
    // $NON-NLS-1$
    assertTrue("2.0", bDelta.length == 5);
}
Also used : State(org.eclipse.osgi.service.resolver.State) Hashtable(java.util.Hashtable) BundleDescription(org.eclipse.osgi.service.resolver.BundleDescription) StateDelta(org.eclipse.osgi.service.resolver.StateDelta) BundleDelta(org.eclipse.osgi.service.resolver.BundleDelta)

Aggregations

BundleDelta (org.eclipse.osgi.service.resolver.BundleDelta)10 BundleDescription (org.eclipse.osgi.service.resolver.BundleDescription)10 State (org.eclipse.osgi.service.resolver.State)10 StateDelta (org.eclipse.osgi.service.resolver.StateDelta)10 HashMap (java.util.HashMap)6 Map (java.util.Map)5 CaseInsensitiveDictionaryMap (org.eclipse.osgi.framework.util.CaseInsensitiveDictionaryMap)5 Hashtable (java.util.Hashtable)4 BundleException (org.osgi.framework.BundleException)3