Search in sources :

Example 6 with BundleDescription

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

the class DevModeTest method testDevModeSingleton02.

public void testDevModeSingleton02() throws BundleException {
    State state = buildDevModeState();
    int bundleID = 0;
    Hashtable manifest = new Hashtable();
    manifest.clear();
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "A; singleton:=true");
    manifest.put(Constants.BUNDLE_VERSION, "1.0");
    manifest.put(Constants.EXPORT_PACKAGE, "a");
    manifest.put(Constants.IMPORT_PACKAGE, "x");
    BundleDescription a1 = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + "_" + (String) manifest.get(Constants.BUNDLE_VERSION), bundleID++);
    manifest.clear();
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "A; singleton:=true");
    manifest.put(Constants.BUNDLE_VERSION, "2.0");
    manifest.put(Constants.EXPORT_PACKAGE, "a");
    BundleDescription a2 = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + "_" + (String) manifest.get(Constants.BUNDLE_VERSION), bundleID++);
    manifest.clear();
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "B");
    manifest.put(Constants.BUNDLE_VERSION, "1.0");
    manifest.put(Constants.REQUIRE_BUNDLE, "A; bundle-version=2.0");
    BundleDescription b = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + "_" + (String) manifest.get(Constants.BUNDLE_VERSION), bundleID++);
    manifest.clear();
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "C");
    manifest.put(Constants.BUNDLE_VERSION, "1.0");
    manifest.put(Constants.REQUIRE_BUNDLE, "A; bundle-version=\"[1.0,2.0)\"");
    BundleDescription c = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + "_" + (String) manifest.get(Constants.BUNDLE_VERSION), bundleID++);
    state.addBundle(a1);
    state.addBundle(a2);
    state.addBundle(b);
    state.addBundle(c);
    state.resolve();
    // only a2 is resolved because a1 has an unsatisfied constraint
    // c should still be resolved to a1 though
    assertFalse("0.1", a1.isResolved());
    assertTrue("0.2", a2.isResolved());
    assertTrue("0.3", b.isResolved());
    assertTrue("0.4", c.isResolved());
    BundleDescription[] bRequired = b.getResolvedRequires();
    assertTrue("1.1", bRequired.length == 1);
    assertTrue("1.2", bRequired[0] == a2);
    BundleDescription[] cRequired = c.getResolvedRequires();
    assertTrue("2.1", cRequired.length == 1);
    assertTrue("2.2", cRequired[0] == a1);
}
Also used : State(org.eclipse.osgi.service.resolver.State) Hashtable(java.util.Hashtable) BundleDescription(org.eclipse.osgi.service.resolver.BundleDescription)

Example 7 with BundleDescription

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

the class DevModeTest method testDevModeSingleton01.

public void testDevModeSingleton01() throws BundleException {
    State state = buildDevModeState();
    int bundleID = 0;
    Hashtable manifest = new Hashtable();
    manifest.clear();
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "A; singleton:=true");
    manifest.put(Constants.BUNDLE_VERSION, "1.0");
    manifest.put(Constants.EXPORT_PACKAGE, "a");
    BundleDescription a1 = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + "_" + (String) manifest.get(Constants.BUNDLE_VERSION), bundleID++);
    manifest.clear();
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "A; singleton:=true");
    manifest.put(Constants.BUNDLE_VERSION, "2.0");
    manifest.put(Constants.EXPORT_PACKAGE, "a");
    BundleDescription a2 = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + "_" + (String) manifest.get(Constants.BUNDLE_VERSION), bundleID++);
    manifest.clear();
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "B");
    manifest.put(Constants.BUNDLE_VERSION, "1.0");
    manifest.put(Constants.REQUIRE_BUNDLE, "A; bundle-version=2.0");
    BundleDescription b = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + "_" + (String) manifest.get(Constants.BUNDLE_VERSION), bundleID++);
    manifest.clear();
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "C");
    manifest.put(Constants.BUNDLE_VERSION, "1.0");
    manifest.put(Constants.REQUIRE_BUNDLE, "A; bundle-version=\"[1.0,2.0)\"");
    BundleDescription c = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + "_" + (String) manifest.get(Constants.BUNDLE_VERSION), bundleID++);
    state.addBundle(a1);
    state.addBundle(a2);
    state.addBundle(b);
    state.addBundle(c);
    state.resolve();
    // both versions of A should be resolved
    assertTrue("0.1", a1.isResolved());
    assertTrue("0.2", a2.isResolved());
    assertTrue("0.3", b.isResolved());
    assertTrue("0.4", c.isResolved());
    BundleDescription[] bRequired = b.getResolvedRequires();
    assertTrue("1.1", bRequired.length == 1);
    assertTrue("1.2", bRequired[0] == a2);
    BundleDescription[] cRequired = c.getResolvedRequires();
    assertTrue("2.1", cRequired.length == 1);
    assertTrue("2.2", cRequired[0] == a1);
}
Also used : State(org.eclipse.osgi.service.resolver.State) Hashtable(java.util.Hashtable) BundleDescription(org.eclipse.osgi.service.resolver.BundleDescription)

Example 8 with BundleDescription

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

the class DevModeTest method testDevModeDomino02.

public void testDevModeDomino02() throws BundleException {
    State state = buildDevModeState();
    int bundleID = 0;
    Hashtable manifest = new Hashtable();
    manifest.clear();
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "A");
    manifest.put(Constants.BUNDLE_VERSION, "1.0");
    manifest.put(Constants.EXPORT_PACKAGE, "a");
    manifest.put(Constants.IMPORT_PACKAGE, "x, d");
    manifest.put(Constants.REQUIRE_BUNDLE, "X, E");
    BundleDescription a = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + "_" + (String) manifest.get(Constants.BUNDLE_VERSION), bundleID++);
    manifest.clear();
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "B");
    manifest.put(Constants.BUNDLE_VERSION, "1.0");
    manifest.put(Constants.REQUIRE_BUNDLE, "A");
    BundleDescription b = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + "_" + (String) manifest.get(Constants.BUNDLE_VERSION), bundleID++);
    manifest.clear();
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "C");
    manifest.put(Constants.BUNDLE_VERSION, "1.0");
    manifest.put(Constants.REQUIRE_BUNDLE, "A");
    BundleDescription c = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + "_" + (String) manifest.get(Constants.BUNDLE_VERSION), bundleID++);
    manifest.clear();
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "D");
    manifest.put(Constants.BUNDLE_VERSION, "1.0");
    manifest.put(Constants.EXPORT_PACKAGE, "d");
    BundleDescription d = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + "_" + (String) manifest.get(Constants.BUNDLE_VERSION), bundleID++);
    manifest.clear();
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "E");
    manifest.put(Constants.BUNDLE_VERSION, "1.0");
    manifest.put(Constants.EXPORT_PACKAGE, "e");
    BundleDescription e = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + "_" + (String) manifest.get(Constants.BUNDLE_VERSION), bundleID++);
    state.addBundle(a);
    state.addBundle(b);
    state.addBundle(c);
    state.addBundle(d);
    state.addBundle(e);
    state.resolve();
    // bundle a has an unsatisfied constraint
    // b, c, d, e should still be resolved though
    assertFalse("0.1", a.isResolved());
    assertTrue("0.3", b.isResolved());
    assertTrue("0.4", c.isResolved());
    assertTrue("0.5", d.isResolved());
    assertTrue("0.5", e.isResolved());
    BundleDescription[] aRequired = a.getResolvedRequires();
    assertTrue("1.1", aRequired.length == 1);
    assertTrue("1.2", aRequired[0] == e);
    ExportPackageDescription[] aImported = a.getResolvedImports();
    assertTrue("1.3", aImported.length == 1);
    assertTrue("1.4", aImported[0].getExporter() == d);
    BundleDescription[] bRequired = b.getResolvedRequires();
    assertTrue("2.1", bRequired.length == 1);
    assertTrue("2.2", bRequired[0] == a);
    BundleDescription[] cRequired = c.getResolvedRequires();
    assertTrue("3.1", cRequired.length == 1);
    assertTrue("3.2", cRequired[0] == a);
}
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 9 with BundleDescription

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

the class StateResolverTest method testReinstall.

// temporarily disabled
public void testReinstall() throws BundleException {
    State state = buildComplexState();
    StateDelta delta = state.resolve();
    // remove bundle 4 - should cause 6 to be unresolved
    state.removeBundle(4);
    delta = state.resolve();
    // $NON-NLS-1$
    assertEquals("1.0", 1, delta.getChanges(BundleDelta.REMOVED | BundleDelta.UNRESOLVED | BundleDelta.REMOVAL_COMPLETE, true).length);
    // $NON-NLS-1$
    assertEquals("1.1", 4, delta.getChanges(BundleDelta.REMOVED | BundleDelta.UNRESOLVED | BundleDelta.REMOVAL_COMPLETE, true)[0].getBundle().getBundleId());
    // $NON-NLS-1$
    assertEquals("2.0", 1, delta.getChanges(BundleDelta.UNRESOLVED, true).length);
    // $NON-NLS-1$
    assertEquals("2.1", 6, delta.getChanges(BundleDelta.UNRESOLVED, true)[0].getBundle().getBundleId());
    // reinstall bundle 4 - should cause 6 to be resolved again
    BundleDescription b4 = delta.getChanges(BundleDelta.REMOVED | BundleDelta.UNRESOLVED | BundleDelta.REMOVAL_COMPLETE, true)[0].getBundle();
    state.addBundle(b4);
    delta = state.resolve();
    // $NON-NLS-1$
    assertEquals("3.0", 1, delta.getChanges(BundleDelta.ADDED | BundleDelta.RESOLVED, true).length);
    // $NON-NLS-1$
    assertEquals("3.1", 4, delta.getChanges(BundleDelta.ADDED | BundleDelta.RESOLVED, true)[0].getBundle().getBundleId());
    // $NON-NLS-1$
    assertEquals("4.0", 1, delta.getChanges(BundleDelta.RESOLVED, true).length);
    // $NON-NLS-1$
    assertEquals("4.1", 6, delta.getChanges(BundleDelta.RESOLVED, true)[0].getBundle().getBundleId());
}
Also used : State(org.eclipse.osgi.service.resolver.State) BundleDescription(org.eclipse.osgi.service.resolver.BundleDescription) StateDelta(org.eclipse.osgi.service.resolver.StateDelta)

Example 10 with BundleDescription

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

the class StateResolverTest method testRemoveAndAdd.

public void testRemoveAndAdd() throws BundleException {
    // $NON-NLS-1$
    String B_LOCATION = "org.eclipse.b";
    // $NON-NLS-1$ //$NON-NLS-2$
    final String B_MANIFEST = "Bundle-SymbolicName: org.eclipse.b\n" + "Bundle-Version: 1.0\n";
    State state = buildEmptyState();
    BundleDescription b1 = state.getFactory().createBundleDescription(parseManifest(B_MANIFEST), B_LOCATION, 1);
    BundleDescription b2 = state.getFactory().createBundleDescription(parseManifest(B_MANIFEST), B_LOCATION, 2);
    state.addBundle(b1);
    StateDelta delta = state.resolve();
    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);
    state.removeBundle(b1);
    state.addBundle(b2);
    delta = state.resolve();
    // $NON-NLS-1$
    assertEquals("2.0", 2, delta.getChanges().length);
    // $NON-NLS-1$
    assertEquals("2.1", 1, delta.getChanges(BundleDelta.UNRESOLVED | BundleDelta.REMOVED, true).length);
    // $NON-NLS-1$
    assertEquals("2.2", b1, delta.getChanges(BundleDelta.UNRESOLVED | BundleDelta.REMOVED, true)[0].getBundle());
    // $NON-NLS-1$
    assertEquals("2.3", 1, delta.getChanges(BundleDelta.RESOLVED | BundleDelta.ADDED, true).length);
    // $NON-NLS-1$
    assertEquals("2.3", b2, delta.getChanges(BundleDelta.RESOLVED | BundleDelta.ADDED, true)[0].getBundle());
}
Also used : 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)

Aggregations

BundleDescription (org.eclipse.osgi.service.resolver.BundleDescription)202 BundleException (org.osgi.framework.BundleException)106 State (org.eclipse.osgi.service.resolver.State)87 Hashtable (java.util.Hashtable)70 Dictionary (java.util.Dictionary)28 ExportPackageDescription (org.eclipse.osgi.service.resolver.ExportPackageDescription)18 ArrayList (java.util.ArrayList)11 StateDelta (org.eclipse.osgi.service.resolver.StateDelta)11 BundleDelta (org.eclipse.osgi.service.resolver.BundleDelta)10 List (java.util.List)9 HashMap (java.util.HashMap)8 File (java.io.File)6 Map (java.util.Map)6 CaseInsensitiveDictionaryMap (org.eclipse.osgi.framework.util.CaseInsensitiveDictionaryMap)6 VersionConstraint (org.eclipse.osgi.service.resolver.VersionConstraint)6 Version (org.osgi.framework.Version)6 BundleWiring (org.osgi.framework.wiring.BundleWiring)5 BundleContext (org.osgi.framework.BundleContext)2 ResolverHook (org.osgi.framework.hooks.resolver.ResolverHook)2 Collection (java.util.Collection)1