Search in sources :

Example 41 with State

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

the class StateResolverTest method testSelectionPolicy.

public void testSelectionPolicy() throws BundleException {
    State state = buildEmptyState();
    Resolver resolver = state.getResolver();
    resolver.setSelectionPolicy(new Comparator() {

        public int compare(Object o1, Object o2) {
            if (!(o1 instanceof BaseDescription) || !(o2 instanceof BaseDescription))
                throw new IllegalArgumentException();
            Version v1 = null;
            Version v2 = null;
            v1 = ((BaseDescription) o1).getVersion();
            v2 = ((BaseDescription) o2).getVersion();
            // only take version in to account and use lower versions over higher ones
            return v1.compareTo(v2);
        }
    });
    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);
    state.resolve();
    // $NON-NLS-1$
    assertTrue("1.0", testHost100.isResolved());
    // $NON-NLS-1$
    assertFalse("1.1", testHost101.isResolved());
    // $NON-NLS-1$
    assertTrue("1.2", testFrag100.isResolved());
    // $NON-NLS-1$
    assertFalse("1.3", testFrag101.isResolved());
    // $NON-NLS-1$
    assertTrue("1.4", testDependent.isResolved());
}
Also used : Resolver(org.eclipse.osgi.service.resolver.Resolver) Version(org.osgi.framework.Version) State(org.eclipse.osgi.service.resolver.State) Hashtable(java.util.Hashtable) BundleDescription(org.eclipse.osgi.service.resolver.BundleDescription) BaseDescription(org.eclipse.osgi.service.resolver.BaseDescription) Comparator(java.util.Comparator)

Example 42 with State

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

the class StateResolverTest method testFragmentConstraints05.

public void testFragmentConstraints05() throws BundleException {
    // same as testFragmentConstraints04 but with a cycle
    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.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.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.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.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, "b1, b2, b3");
    // $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.REQUIRE_BUNDLE, "a");
    // $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());
    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]);
    BundleDescription[] dResolvedRequires = d.getResolvedRequires();
    // $NON-NLS-1$
    assertEquals("2.0", 1, dResolvedRequires.length);
    // $NON-NLS-1$
    assertEquals("2.1", a, dResolvedRequires[0]);
}
Also used : State(org.eclipse.osgi.service.resolver.State) Hashtable(java.util.Hashtable) BundleDescription(org.eclipse.osgi.service.resolver.BundleDescription)

Example 43 with State

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

the class StateResolverTest method testFragmentsMultipleVersion.

public void testFragmentsMultipleVersion() 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");
    BundleDescription a1 = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + '_' + (String) 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, "AFrag");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.0");
    // $NON-NLS-1$
    manifest.put(Constants.FRAGMENT_HOST, "A");
    BundleDescription aFrag1 = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + '_' + (String) 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, "A");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "2.0");
    BundleDescription a2 = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + '_' + (String) 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, "AFrag");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "2.0");
    // $NON-NLS-1$
    manifest.put(Constants.FRAGMENT_HOST, "A");
    BundleDescription aFrag2 = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + '_' + (String) manifest.get(Constants.BUNDLE_VERSION), bundleID++);
    state.addBundle(a1);
    state.addBundle(aFrag1);
    state.addBundle(a2);
    state.addBundle(aFrag2);
    state.resolve();
    // $NON-NLS-1$
    assertTrue("0.1", a1.isResolved());
    // $NON-NLS-1$
    assertTrue("0.2", aFrag1.isResolved());
    // $NON-NLS-1$
    assertTrue("0.3", a2.isResolved());
    // $NON-NLS-1$
    assertTrue("0.4", aFrag2.isResolved());
    state.removeBundle(a2);
    state.resolve(false);
    // $NON-NLS-1$
    assertTrue("1.1", a1.isResolved());
    // $NON-NLS-1$
    assertTrue("1.2", aFrag2.isResolved());
    // $NON-NLS-1$
    assertFalse("1.3", aFrag1.isResolved());
    // $NON-NLS-1$
    assertEquals("1.4", a1, aFrag2.getHost().getSupplier());
}
Also used : State(org.eclipse.osgi.service.resolver.State) Hashtable(java.util.Hashtable) BundleDescription(org.eclipse.osgi.service.resolver.BundleDescription)

Example 44 with State

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

the class StatePerformanceTest method testResolution.

private void testResolution(int stateSize, int repetitions, String localName, String degradation) {
    final State originalState = buildRandomState(stateSize);
    PerformanceTestRunner runner = new PerformanceTestRunner() {

        protected void test() {
            originalState.resolve(false);
        }
    };
    runner.setRegressionReason(degradation);
    runner.run(this, localName, 10, repetitions);
}
Also used : PerformanceTestRunner(org.eclipse.core.tests.harness.PerformanceTestRunner) State(org.eclipse.osgi.service.resolver.State)

Example 45 with State

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

the class StatePerformanceTest method testStoreAndRetrieve.

public void testStoreAndRetrieve() {
    int stateSize = 5000;
    final State originalState = buildRandomState(stateSize);
    PerformanceTestRunner runner = new PerformanceTestRunner() {

        protected void test() {
            try {
                storeAndRetrieve(originalState);
            } catch (IOException e) {
                CoreTest.fail("", e);
            }
        }
    };
    runner.setRegressionReason(DEGREDATION_STORE_RETRIEVE);
    runner.run(this, 10, 10);
}
Also used : PerformanceTestRunner(org.eclipse.core.tests.harness.PerformanceTestRunner) State(org.eclipse.osgi.service.resolver.State)

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