Search in sources :

Example 31 with State

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

the class StateResolverTest method testSingletons.

public void testSingletons() throws BundleException {
    State state = buildEmptyState();
    Hashtable 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.0");
    // $NON-NLS-1$
    BundleDescription testHost100 = state.getFactory().createBundleDescription(state, manifest, "test.host100", 0);
    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", 1);
    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", 2);
    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", 3);
    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.1,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", 4);
    state.addBundle(testHost100);
    state.addBundle(testFrag100);
    state.addBundle(testHost101);
    state.addBundle(testFrag101);
    state.addBundle(testDependent);
    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());
}
Also used : State(org.eclipse.osgi.service.resolver.State) Hashtable(java.util.Hashtable) BundleDescription(org.eclipse.osgi.service.resolver.BundleDescription)

Example 32 with State

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

the class StateResolverTest method testLinkageChange.

// temporarily disabled
public void testLinkageChange() throws BundleException {
    State state = buildEmptyState();
    // don't add b1 for now
    // $NON-NLS-1$
    String B1_LOCATION = "org.eclipse.b1";
    // $NON-NLS-1$ //$NON-NLS-2$
    final String B1_MANIFEST = "Bundle-SymbolicName: org.eclipse.b1\n" + "Bundle-Version: 1.0\n";
    BundleDescription b1 = state.getFactory().createBundleDescription(parseManifest(B1_MANIFEST), B1_LOCATION, (long) (Math.random() * Long.MAX_VALUE));
    // b2 requires b1 optionally, so should resolve
    // $NON-NLS-1$
    String B2_LOCATION = "org.eclipse.b2";
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    final String B2_MANIFEST = "Bundle-SymbolicName: org.eclipse.b2\n" + "Bundle-Version: 2.0\n" + "Require-Bundle: org.eclipse.b1;optional=true";
    BundleDescription b2 = state.getFactory().createBundleDescription(parseManifest(B2_MANIFEST), B2_LOCATION, (long) (Math.random() * Long.MAX_VALUE));
    // b3 requires b1, so should not resolve
    // $NON-NLS-1$
    String B3_LOCATION = "org.eclipse.b3";
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    final String B3_MANIFEST = "Bundle-SymbolicName: org.eclipse.b3\n" + "Bundle-Version: 2.0\n" + "Require-Bundle: org.eclipse.b1";
    BundleDescription b3 = state.getFactory().createBundleDescription(parseManifest(B3_MANIFEST), B3_LOCATION, (long) (Math.random() * Long.MAX_VALUE));
    // add b2 and b3
    state.addBundle(b2);
    state.addBundle(b3);
    StateDelta delta = state.resolve();
    // ensure we didn't add b1 yet
    // $NON-NLS-1$
    assertFullyUnresolved("0.1", b1);
    BundleDelta[] changes = delta.getChanges();
    // $NON-NLS-1$
    assertEquals("1.0", 2, changes.length);
    BundleDelta[] additions = delta.getChanges(BundleDelta.ADDED, false);
    // $NON-NLS-1$
    assertEquals("2.0", 2, additions.length);
    BundleDelta[] resolutions = delta.getChanges(BundleDelta.RESOLVED, false);
    // $NON-NLS-1$
    assertEquals("3.0", 1, resolutions.length);
    // $NON-NLS-1$
    assertEquals("3.1", b2, resolutions[0].getBundle());
    BundleDelta[] addtionsNotResolved = delta.getChanges(BundleDelta.ADDED, true);
    // $NON-NLS-1$
    assertEquals("4.0", 1, addtionsNotResolved.length);
    // $NON-NLS-1$
    assertEquals("4.1", b3, addtionsNotResolved[0].getBundle());
    state.addBundle(b1);
    delta = state.resolve();
    changes = delta.getChanges();
    // $NON-NLS-1$
    assertEquals("5.0", 2, changes.length);
    additions = delta.getChanges(BundleDelta.ADDED, false);
    // $NON-NLS-1$
    assertEquals("6.0", 1, additions.length);
    // $NON-NLS-1$
    assertEquals("6.1", b1, additions[0].getBundle());
    resolutions = delta.getChanges(BundleDelta.RESOLVED, false);
    // $NON-NLS-1$
    assertEquals("7.0", 2, resolutions.length);
    BundleDelta[] existingResolved = delta.getChanges(BundleDelta.RESOLVED, true);
    // $NON-NLS-1$
    assertEquals("8.0", 1, existingResolved.length);
    // $NON-NLS-1$
    assertEquals("8.1", b3, existingResolved[0].getBundle());
    // TODO linkage changed types are no longer valid
    // BundleDelta[] optionalLinkageChanged = delta.getChanges(BundleDelta.OPTIONAL_LINKAGE_CHANGED, true);
    // assertEquals("9.0", 1, optionalLinkageChanged.length);
    // assertEquals("9.1", b2, optionalLinkageChanged[0].getBundle());
    delta = state.resolve(new BundleDescription[] { b2 });
    changes = delta.getChanges();
    // $NON-NLS-1$
    assertEquals("9.0", 1, changes.length);
    resolutions = delta.getChanges(BundleDelta.RESOLVED, true);
    // $NON-NLS-1$
    assertEquals("9.1", 1, resolutions.length);
    // $NON-NLS-1$
    assertEquals("9.2", b2, resolutions[0].getBundle());
    // $NON-NLS-1$
    assertFullyResolved("10.1", b1);
    // $NON-NLS-1$
    assertFullyResolved("10.2", b2);
    // $NON-NLS-1$
    assertFullyResolved("10.3", b3);
}
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)

Example 33 with State

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

the class StateResolverTest method testPlatformProperties02.

public void testPlatformProperties02() throws BundleException {
    // same as 01 except use alias system.bundle to another name "test.system.bundle"
    State state = buildEmptyState();
    int bundleID = 0;
    // test the selection algorithm of the resolver to pick the bundles which
    // resolve the largest set of bundles; with fragments using Import-Package
    Hashtable manifest = new Hashtable();
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "test.system.bundle");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.0");
    // $NON-NLS-1$
    BundleDescription systemBundle = state.getFactory().createBundleDescription(state, manifest, "test.system.bundle", bundleID++);
    // $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$
    manifest.put(Constants.IMPORT_PACKAGE, "pkg.b, pkg.system.b");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT, "J2SE-1.4");
    // $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$
    manifest.put(Constants.EXPORT_PACKAGE, "pkg.b");
    // $NON-NLS-1$
    manifest.put(Constants.IMPORT_PACKAGE, "pkg.system.b");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT, "J2SE-1.2");
    // $NON-NLS-1$
    BundleDescription b = state.getFactory().createBundleDescription(state, manifest, "B", bundleID++);
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "system.b");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.0");
    // $NON-NLS-1$
    manifest.put(Constants.EXPORT_PACKAGE, "pkg.system.b");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT, "J2SE-1.2");
    // $NON-NLS-1$
    BundleDescription systemB = state.getFactory().createBundleDescription(state, manifest, "system.b", bundleID++);
    Dictionary[] props = new Dictionary[] { new Hashtable(), new Hashtable() };
    // $NON-NLS-1$ //$NON-NLS-2$
    props[0].put("org.osgi.framework.system.packages", "pkg.system.a, pkg.system.c");
    // $NON-NLS-1$ //$NON-NLS-2$
    props[0].put("org.osgi.framework.executionenvironment", "J2SE-1.2");
    // set the system.bundle to another system bundle (other than org.eclipse.osgi) //$NON-NLS-1$ //$NON-NLS-2$
    props[0].put("osgi.system.bundle", "test.system.bundle");
    // $NON-NLS-1$ //$NON-NLS-2$
    props[1].put("org.osgi.framework.system.packages", "pkg.system.a, pkg.system.b, pkg.system.c");
    // $NON-NLS-1$ //$NON-NLS-2$
    props[1].put("org.osgi.framework.executionenvironment", "J2SE-1.4");
    state.setPlatformProperties(props);
    state.addBundle(systemBundle);
    state.addBundle(a);
    state.addBundle(b);
    state.addBundle(systemB);
    state.resolve();
    // $NON-NLS-1$
    assertTrue("1.0", systemBundle.isResolved());
    // $NON-NLS-1$
    assertTrue("1.1", a.isResolved());
    // $NON-NLS-1$
    assertTrue("1.2", b.isResolved());
    // $NON-NLS-1$
    assertTrue("1.3", systemB.isResolved());
    // $NON-NLS-1$
    assertTrue("2.0", a.getResolvedImports()[1].getExporter() == systemBundle);
    // $NON-NLS-1$
    assertTrue("2.1", b.getResolvedImports()[0].getExporter() == systemB);
    // now test the uses clause for pkg.b such that bundle 'A' will be forced to used
    // pkg.system from bundle 'system.b'
    // $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$
    manifest.put(Constants.EXPORT_PACKAGE, "pkg.b; uses:=\"pkg.system.b\"");
    // $NON-NLS-1$
    manifest.put(Constants.IMPORT_PACKAGE, "pkg.system.b");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT, "J2SE-1.2");
    // $NON-NLS-1$
    BundleDescription b_updated = state.getFactory().createBundleDescription(state, manifest, "B", b.getBundleId());
    state.updateBundle(b_updated);
    state.resolve(new BundleDescription[] { b_updated });
    // $NON-NLS-1$
    assertTrue("3.0", systemBundle.isResolved());
    // $NON-NLS-1$
    assertTrue("3.1", a.isResolved());
    // $NON-NLS-1$
    assertTrue("3.2", b_updated.isResolved());
    // $NON-NLS-1$
    assertTrue("3.3", systemB.isResolved());
    // $NON-NLS-1$
    assertTrue("2.0", a.getResolvedImports()[1].getExporter() == systemB);
    // $NON-NLS-1$
    assertTrue("2.1", b_updated.getResolvedImports()[0].getExporter() == systemB);
}
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 34 with State

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

the class StateResolverTest method createBug266935State.

private State createBug266935State() throws BundleException {
    State state = buildEmptyState();
    int bundleID = 0;
    // test the selection algorithm of the resolver to pick the bundles which
    // resolve the largest set of bundles; with fragments
    Hashtable manifest = new Hashtable();
    manifest.clear();
    // $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");
    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.REQUIRE_BUNDLE, "a");
    BundleDescription b = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + manifest.get(Constants.BUNDLE_VERSION), bundleID++);
    state.addBundle(a);
    state.addBundle(b);
    state.resolve();
    // $NON-NLS-1$
    assertTrue("A is not resolved", a.isResolved());
    // $NON-NLS-1$
    assertTrue("B is not resolved", b.isResolved());
    return state;
}
Also used : State(org.eclipse.osgi.service.resolver.State) Hashtable(java.util.Hashtable) BundleDescription(org.eclipse.osgi.service.resolver.BundleDescription)

Example 35 with State

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

the class StateResolverTest method testFragmentsBug188199.

public void testFragmentsBug188199() throws BundleException {
    State state = buildEmptyState();
    int bundleID = 0;
    // test the selection algorithm of the resolver to pick the bundles which
    // resolve the largest set of bundles; with fragments using Import-Package
    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$
    manifest.put(Constants.EXPORT_PACKAGE, "a");
    // $NON-NLS-1$
    manifest.put(Constants.IMPORT_PACKAGE, "c");
    // $NON-NLS-1$
    BundleDescription a = state.getFactory().createBundleDescription(state, manifest, "A", bundleID++);
    manifest.clear();
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "AFrag");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.0");
    // $NON-NLS-1$
    manifest.put(Constants.FRAGMENT_HOST, "A");
    // $NON-NLS-1$
    manifest.put(Constants.EXPORT_PACKAGE, "a.frag");
    // $NON-NLS-1$
    BundleDescription aFrag = state.getFactory().createBundleDescription(state, manifest, "A", 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");
    // $NON-NLS-1$
    manifest.put(Constants.IMPORT_PACKAGE, "a, a.frag");
    // $NON-NLS-1$
    BundleDescription b = state.getFactory().createBundleDescription(state, manifest, "B", 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");
    // $NON-NLS-1$
    manifest.put(Constants.EXPORT_PACKAGE, "c");
    // $NON-NLS-1$
    BundleDescription c = state.getFactory().createBundleDescription(state, manifest, "C", bundleID++);
    state.addBundle(a);
    state.addBundle(aFrag);
    state.addBundle(b);
    state.addBundle(c);
    state.resolve();
    // $NON-NLS-1$
    assertTrue("0.1", a.isResolved());
    // $NON-NLS-1$
    assertTrue("0.2", aFrag.isResolved());
    // $NON-NLS-1$
    assertTrue("0.3", b.isResolved());
    // $NON-NLS-1$
    assertTrue("0.4", c.isResolved());
    state.removeBundle(c);
    state.resolve(false);
    // $NON-NLS-1$
    assertFalse("1.1", a.isResolved());
    // $NON-NLS-1$
    assertFalse("1.2", aFrag.isResolved());
    // $NON-NLS-1$
    assertFalse("1.3", b.isResolved());
    state.addBundle(c);
    state.resolve();
    // $NON-NLS-1$
    assertTrue("2.1", a.isResolved());
    // $NON-NLS-1$
    assertTrue("2.2", aFrag.isResolved());
    // $NON-NLS-1$
    assertTrue("2.3", b.isResolved());
    // $NON-NLS-1$
    assertTrue("2.4", c.isResolved());
    ExportPackageDescription[] aExports = a.getSelectedExports();
    ExportPackageDescription[] bImports = b.getResolvedImports();
    // $NON-NLS-1$
    assertTrue("3.1", aExports.length == 2);
    // $NON-NLS-1$
    assertTrue("3.2", bImports.length == 2);
    // $NON-NLS-1$
    assertTrue("3.3", aExports[0] == bImports[0]);
    // $NON-NLS-1$
    assertTrue("3.4", aExports[1] == bImports[1]);
}
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)

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