Search in sources :

Example 1 with BaseDescription

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

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

the class ResolverImpl method newStateWire.

private static StateWire newStateWire(BundleDescription requirementHost, VersionConstraint declaredRequirement, BundleDescription capabilityHost, BaseDescription declaredCapability) {
    BaseDescription fragDeclared = ((BaseDescriptionImpl) declaredCapability).getFragmentDeclaration();
    declaredCapability = fragDeclared != null ? fragDeclared : declaredCapability;
    return new StateWire(requirementHost, declaredRequirement, capabilityHost, declaredCapability);
}
Also used : BaseDescriptionImpl(org.eclipse.osgi.internal.resolver.BaseDescriptionImpl) BaseDescription(org.eclipse.osgi.service.resolver.BaseDescription) StateWire(org.eclipse.osgi.service.resolver.StateWire)

Example 3 with BaseDescription

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

the class ResolverImpl method stateResolveFragConstraints.

private void stateResolveFragConstraints(ResolverBundle rb) {
    ResolverBundle host = (ResolverBundle) rb.getHost().getSelectedSupplier();
    ImportPackageSpecification[] imports = rb.getBundleDescription().getImportPackages();
    for (int i = 0; i < imports.length; i++) {
        ResolverImport hostImport = host == null ? null : host.getImport(imports[i].getName());
        ResolverExport export = (ResolverExport) (hostImport == null ? null : hostImport.getSelectedSupplier());
        BaseDescription supplier = export == null ? null : export.getExportPackageDescription();
        state.resolveConstraint(imports[i], supplier);
    }
    BundleSpecification[] requires = rb.getBundleDescription().getRequiredBundles();
    for (int i = 0; i < requires.length; i++) {
        BundleConstraint hostRequire = host == null ? null : host.getRequire(requires[i].getName());
        ResolverBundle bundle = (ResolverBundle) (hostRequire == null ? null : hostRequire.getSelectedSupplier());
        BaseDescription supplier = bundle == null ? null : bundle.getBundleDescription();
        state.resolveConstraint(requires[i], supplier);
    }
    GenericConstraint[] genericRequires = rb.getGenericRequires();
    for (int i = 0; i < genericRequires.length; i++) {
        VersionSupplier[] matchingCapabilities = genericRequires[i].getMatchingCapabilities();
        if (matchingCapabilities == null)
            state.resolveConstraint(genericRequires[i].getVersionConstraint(), null);
        else
            for (int j = 0; j < matchingCapabilities.length; j++) state.resolveConstraint(genericRequires[i].getVersionConstraint(), matchingCapabilities[j].getBaseDescription());
    }
}
Also used : BaseDescription(org.eclipse.osgi.service.resolver.BaseDescription) BundleSpecification(org.eclipse.osgi.service.resolver.BundleSpecification) VersionConstraint(org.eclipse.osgi.service.resolver.VersionConstraint) ImportPackageSpecification(org.eclipse.osgi.service.resolver.ImportPackageSpecification)

Example 4 with BaseDescription

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

the class ResolverImpl method stateResolveConstraints.

private void stateResolveConstraints(ResolverBundle rb) {
    ResolverImport[] imports = rb.getImportPackages();
    for (int i = 0; i < imports.length; i++) {
        ResolverExport export = (ResolverExport) imports[i].getSelectedSupplier();
        BaseDescription supplier = export == null ? null : export.getExportPackageDescription();
        state.resolveConstraint(imports[i].getVersionConstraint(), supplier);
    }
    BundleConstraint[] requires = rb.getRequires();
    for (int i = 0; i < requires.length; i++) {
        ResolverBundle bundle = (ResolverBundle) requires[i].getSelectedSupplier();
        BaseDescription supplier = bundle == null ? null : bundle.getBundleDescription();
        state.resolveConstraint(requires[i].getVersionConstraint(), supplier);
    }
    GenericConstraint[] genericRequires = rb.getGenericRequires();
    for (int i = 0; i < genericRequires.length; i++) {
        VersionSupplier[] matchingCapabilities = genericRequires[i].getMatchingCapabilities();
        if (matchingCapabilities == null)
            state.resolveConstraint(genericRequires[i].getVersionConstraint(), null);
        else
            for (int j = 0; j < matchingCapabilities.length; j++) state.resolveConstraint(genericRequires[i].getVersionConstraint(), matchingCapabilities[j].getBaseDescription());
    }
}
Also used : BaseDescription(org.eclipse.osgi.service.resolver.BaseDescription) VersionConstraint(org.eclipse.osgi.service.resolver.VersionConstraint)

Aggregations

BaseDescription (org.eclipse.osgi.service.resolver.BaseDescription)4 VersionConstraint (org.eclipse.osgi.service.resolver.VersionConstraint)2 Comparator (java.util.Comparator)1 Hashtable (java.util.Hashtable)1 BaseDescriptionImpl (org.eclipse.osgi.internal.resolver.BaseDescriptionImpl)1 BundleDescription (org.eclipse.osgi.service.resolver.BundleDescription)1 BundleSpecification (org.eclipse.osgi.service.resolver.BundleSpecification)1 ImportPackageSpecification (org.eclipse.osgi.service.resolver.ImportPackageSpecification)1 Resolver (org.eclipse.osgi.service.resolver.Resolver)1 State (org.eclipse.osgi.service.resolver.State)1 StateWire (org.eclipse.osgi.service.resolver.StateWire)1 Version (org.osgi.framework.Version)1