Search in sources :

Example 46 with BundleDescription

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

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

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

the class TestDynamic_001 method create_bundle_2.

// end of method
public BundleDescription create_bundle_2(StateObjectFactory sof) {
    java.util.Dictionary dictionary_2 = new java.util.Properties();
    BundleDescription bundle = null;
    dictionary_2.put("Bundle-ManifestVersion", "2");
    dictionary_2.put("Bundle-SymbolicName", "B");
    dictionary_2.put("Export-Package", "p");
    try {
        bundle = sof.createBundleDescription(dictionary_2, "bundle_2", 2);
    } catch (BundleException be) {
        fail(be.getMessage());
    }
    return bundle;
}
Also used : BundleDescription(org.eclipse.osgi.service.resolver.BundleDescription) BundleException(org.osgi.framework.BundleException)

Example 49 with BundleDescription

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

the class TestDynamic_001 method create_bundle_1.

// end method
public BundleDescription create_bundle_1(StateObjectFactory sof) {
    java.util.Dictionary dictionary_1 = new java.util.Properties();
    BundleDescription bundle = null;
    dictionary_1.put("Bundle-ManifestVersion", "2");
    dictionary_1.put("Bundle-SymbolicName", "A");
    dictionary_1.put("DynamicImport-Package", "p");
    try {
        bundle = sof.createBundleDescription(dictionary_1, "bundle_1", 1);
    } catch (BundleException be) {
        fail(be.getMessage());
    }
    return bundle;
}
Also used : BundleDescription(org.eclipse.osgi.service.resolver.BundleDescription) BundleException(org.osgi.framework.BundleException)

Example 50 with BundleDescription

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

the class TestDynamic_003 method create_bundle_2.

// end of method
public BundleDescription create_bundle_2(StateObjectFactory sof) {
    java.util.Dictionary dictionary_2 = new java.util.Properties();
    BundleDescription bundle = null;
    dictionary_2.put("Bundle-ManifestVersion", "2");
    dictionary_2.put("Bundle-SymbolicName", "B");
    dictionary_2.put("Export-Package", "r");
    try {
        bundle = sof.createBundleDescription(dictionary_2, "bundle_2", 2);
    } catch (BundleException be) {
        fail(be.getMessage());
    }
    return bundle;
}
Also used : BundleDescription(org.eclipse.osgi.service.resolver.BundleDescription) BundleException(org.osgi.framework.BundleException)

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