Search in sources :

Example 1 with HostSpecification

use of org.eclipse.osgi.service.resolver.HostSpecification in project tycho by eclipse.

the class Activator method getRelevantErrors.

private static void getRelevantErrors(State state, Set<ResolverError> errors, BundleDescription bundle) {
    ResolverError[] bundleErrors = state.getResolverErrors(bundle);
    for (int j = 0; j < bundleErrors.length; j++) {
        ResolverError error = bundleErrors[j];
        errors.add(error);
        VersionConstraint constraint = error.getUnsatisfiedConstraint();
        if (constraint instanceof BundleSpecification || constraint instanceof HostSpecification) {
            BundleDescription[] requiredBundles = state.getBundles(constraint.getName());
            for (int i = 0; i < requiredBundles.length; i++) {
                getRelevantErrors(state, errors, requiredBundles[i]);
            }
        }
    }
}
Also used : VersionConstraint(org.eclipse.osgi.service.resolver.VersionConstraint) HostSpecification(org.eclipse.osgi.service.resolver.HostSpecification) BundleDescription(org.eclipse.osgi.service.resolver.BundleDescription) ResolverError(org.eclipse.osgi.service.resolver.ResolverError) BundleSpecification(org.eclipse.osgi.service.resolver.BundleSpecification) VersionConstraint(org.eclipse.osgi.service.resolver.VersionConstraint)

Example 2 with HostSpecification

use of org.eclipse.osgi.service.resolver.HostSpecification in project tycho by eclipse.

the class EquinoxResolver method getRelevantErrors.

private void getRelevantErrors(State state, Set<ResolverError> errors, BundleDescription bundle) {
    ResolverError[] bundleErrors = state.getResolverErrors(bundle);
    for (int j = 0; j < bundleErrors.length; j++) {
        ResolverError error = bundleErrors[j];
        errors.add(error);
        VersionConstraint constraint = error.getUnsatisfiedConstraint();
        if (constraint instanceof BundleSpecification || constraint instanceof HostSpecification) {
            BundleDescription[] requiredBundles = state.getBundles(constraint.getName());
            for (int i = 0; i < requiredBundles.length; i++) {
                // do not handle that bundle (again). See bug 442594.
                if (bundle.equals(requiredBundles[i])) {
                    continue;
                }
                getRelevantErrors(state, errors, requiredBundles[i]);
            }
        }
    }
}
Also used : VersionConstraint(org.eclipse.osgi.service.resolver.VersionConstraint) HostSpecification(org.eclipse.osgi.service.resolver.HostSpecification) BundleDescription(org.eclipse.osgi.service.resolver.BundleDescription) ResolverError(org.eclipse.osgi.service.resolver.ResolverError) BundleSpecification(org.eclipse.osgi.service.resolver.BundleSpecification) VersionConstraint(org.eclipse.osgi.service.resolver.VersionConstraint)

Example 3 with HostSpecification

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

the class ResolverBundle method attachFragment.

void attachFragment(ResolverBundle fragment, boolean dynamicAttach) {
    if (isFragment())
        // cannot attach to fragments;
        return;
    if (!getBundleDescription().attachFragments() || (isResolved() && !getBundleDescription().dynamicFragments()))
        // host is restricting attachment
        return;
    if (fragment.getHost().getNumPossibleSuppliers() > 0 && !((HostSpecification) fragment.getHost().getVersionConstraint()).isMultiHost())
        // fragment is restricting attachment
        return;
    ImportPackageSpecification[] newImports = fragment.getBundleDescription().getImportPackages();
    BundleSpecification[] newRequires = fragment.getBundleDescription().getRequiredBundles();
    ExportPackageDescription[] newExports = fragment.getBundleDescription().getExportPackages();
    GenericDescription[] newGenericCapabilities = fragment.getBundleDescription().getGenericCapabilities();
    GenericSpecification[] newGenericRequires = fragment.getBundleDescription().getGenericRequires();
    // if this is not during initialization then check if constraints conflict
    if (dynamicAttach && constraintsConflict(fragment.getBundleDescription(), newImports, newRequires, newGenericRequires))
        // do not allow fragments with conflicting constraints
        return;
    if (isResolved() && newExports.length > 0)
        fragment.setNewFragmentExports(true);
    initFragments();
    // already attached to this host
    for (Iterator<ResolverBundle> iFragments = fragments.iterator(); iFragments.hasNext(); ) {
        ResolverBundle existingFragment = iFragments.next();
        String bsn = existingFragment.getName();
        if (bsn != null && bsn.equals(fragment.getName()))
            return;
    }
    if (fragments.contains(fragment))
        return;
    fragments.add(fragment);
    fragment.getHost().addPossibleSupplier(this);
    if (newImports.length > 0) {
        ArrayList<ResolverImport> hostImports = new ArrayList<>(newImports.length);
        for (int i = 0; i < newImports.length; i++) if (!isImported(newImports[i].getName()))
            hostImports.add(new ResolverImport(this, newImports[i]));
        fragmentImports.put(fragment.bundleID, hostImports);
    }
    if (newRequires.length > 0) {
        ArrayList<BundleConstraint> hostRequires = new ArrayList<>(newRequires.length);
        for (int i = 0; i < newRequires.length; i++) if (!isRequired(newRequires[i].getName()))
            hostRequires.add(new BundleConstraint(this, newRequires[i]));
        fragmentRequires.put(fragment.bundleID, hostRequires);
    }
    if (newGenericRequires.length > 0) {
        ArrayList<GenericConstraint> hostGenericRequires = new ArrayList<>(newGenericRequires.length);
        for (int i = 0; i < newGenericRequires.length; i++) {
            // only add namespaces that are not osgi.ee
            if (!StateImpl.OSGI_EE_NAMESPACE.equals(newGenericRequires[i].getType())) {
                hostGenericRequires.add(new GenericConstraint(this, newGenericRequires[i], resolver.isDevelopmentMode()));
            }
        }
        if (!hostGenericRequires.isEmpty())
            fragmentGenericRequires.put(fragment.bundleID, hostGenericRequires);
    }
    ArrayList<ResolverExport> hostExports = new ArrayList<>(newExports.length);
    if (newExports.length > 0 && dynamicAttach) {
        for (int i = 0; i < newExports.length; i++) {
            ResolverExport[] currentExports = getExports(newExports[i].getName());
            boolean foundEquivalent = false;
            for (int j = 0; j < currentExports.length && !foundEquivalent; j++) {
                if (equivalentExports(currentExports[j], newExports[i]))
                    foundEquivalent = true;
            }
            if (!foundEquivalent) {
                ExportPackageDescription hostExport = new ExportPackageDescriptionImpl(getBundleDescription(), newExports[i]);
                hostExports.add(new ResolverExport(this, hostExport));
            }
        }
        fragmentExports.put(fragment.bundleID, hostExports);
    }
    List<GenericCapability> hostCapabilities = new ArrayList<>(newGenericCapabilities.length);
    if (newGenericCapabilities.length > 0 && dynamicAttach) {
        for (GenericDescription capability : newGenericCapabilities) {
            if (!IdentityNamespace.IDENTITY_NAMESPACE.equals(capability.getType())) {
                GenericDescription hostCapabililty = new GenericDescriptionImpl(getBundleDescription(), capability);
                hostCapabilities.add(new GenericCapability(this, hostCapabililty, resolver.isDevelopmentMode()));
            }
        }
        if (hostCapabilities.size() > 0) {
            fragmentGenericCapabilities.put(fragment.bundleID, hostCapabilities);
            if (isResolved())
                fragment.setNewFragmentCapabilities(true);
        }
    }
    if (dynamicAttach) {
        resolver.getResolverExports().put(hostExports.toArray(new ResolverExport[hostExports.size()]));
        resolver.addGenerics(hostCapabilities.toArray(new GenericCapability[hostCapabilities.size()]));
    }
}
Also used : HostSpecification(org.eclipse.osgi.service.resolver.HostSpecification) ExportPackageDescription(org.eclipse.osgi.service.resolver.ExportPackageDescription) ArrayList(java.util.ArrayList) GenericDescription(org.eclipse.osgi.service.resolver.GenericDescription) GenericDescriptionImpl(org.eclipse.osgi.internal.resolver.GenericDescriptionImpl) ExportPackageDescriptionImpl(org.eclipse.osgi.internal.resolver.ExportPackageDescriptionImpl) GenericSpecification(org.eclipse.osgi.service.resolver.GenericSpecification) BundleSpecification(org.eclipse.osgi.service.resolver.BundleSpecification) VersionConstraint(org.eclipse.osgi.service.resolver.VersionConstraint) ImportPackageSpecification(org.eclipse.osgi.service.resolver.ImportPackageSpecification)

Example 4 with HostSpecification

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

the class ResolverImpl method initialize.

// Initializes the resolver
private void initialize() {
    resolverExports = new VersionHashMap<>(this);
    resolverBundles = new VersionHashMap<>(this);
    resolverGenerics = new HashMap<>();
    unresolvedBundles = new HashSet<>();
    bundleMapping = new HashMap<>();
    BundleDescription[] bundles = state.getBundles();
    groupingChecker = new GroupingChecker();
    ArrayList<ResolverBundle> fragmentBundles = new ArrayList<>();
    // Add each bundle to the resolver's internal state
    for (int i = 0; i < bundles.length; i++) initResolverBundle(bundles[i], fragmentBundles, false);
    // Add each removal pending bundle to the resolver's internal state
    List<BundleDescription> removedBundles = removalPending.getAllValues();
    for (BundleDescription removed : removedBundles) initResolverBundle(removed, fragmentBundles, true);
    // Iterate over the resolved fragments and attach them to their hosts
    for (Iterator<ResolverBundle> iter = fragmentBundles.iterator(); iter.hasNext(); ) {
        ResolverBundle fragment = iter.next();
        BundleDescription[] hosts = ((HostSpecification) fragment.getHost().getVersionConstraint()).getHosts();
        for (int i = 0; i < hosts.length; i++) {
            ResolverBundle host = bundleMapping.get(hosts[i]);
            if (host != null)
                // Do not add fragment exports here because they would have been added by the host above.
                host.attachFragment(fragment, false);
        }
    }
    // Reconstruct wirings
    rewireBundles();
    setDebugOptions();
    initialized = true;
}
Also used : HostSpecification(org.eclipse.osgi.service.resolver.HostSpecification) BundleDescription(org.eclipse.osgi.service.resolver.BundleDescription) ArrayList(java.util.ArrayList) VersionConstraint(org.eclipse.osgi.service.resolver.VersionConstraint)

Example 5 with HostSpecification

use of org.eclipse.osgi.service.resolver.HostSpecification in project tycho by eclipse.

the class DependencyComputer method computeDependencies.

public List<DependencyEntry> computeDependencies(StateHelper helper, BundleDescription desc) {
    ArrayList<DependencyEntry> entries = new ArrayList<>();
    if (desc == null)
        return entries;
    Map<BundleDescription, ArrayList<AccessRule>> map = retrieveVisiblePackagesFromState(helper, desc);
    HashSet<BundleDescription> added = new HashSet<>();
    // to avoid cycles, e.g. when a bundle imports a package it exports
    added.add(desc);
    HostSpecification host = desc.getHost();
    if (host != null) {
        addHostPlugin(host, added, map, entries);
    }
    // add dependencies
    BundleSpecification[] required = desc.getRequiredBundles();
    for (int i = 0; i < required.length; i++) {
        addDependency((BundleDescription) required[i].getSupplier(), added, map, entries);
    }
    // addSecondaryDependencies(desc, added, entries);
    // add Import-Package
    // sort by symbolicName_version to get a consistent order
    Map<String, BundleDescription> sortedMap = new TreeMap<>();
    for (BundleDescription bundle : map.keySet()) {
        sortedMap.put(bundle.toString(), bundle);
    }
    for (BundleDescription bundle : sortedMap.values()) {
        addDependencyViaImportPackage(bundle, added, map, entries);
    }
    return entries;
}
Also used : HostSpecification(org.eclipse.osgi.service.resolver.HostSpecification) BundleDescription(org.eclipse.osgi.service.resolver.BundleDescription) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) BundleSpecification(org.eclipse.osgi.service.resolver.BundleSpecification) HashSet(java.util.HashSet)

Aggregations

HostSpecification (org.eclipse.osgi.service.resolver.HostSpecification)5 BundleDescription (org.eclipse.osgi.service.resolver.BundleDescription)4 BundleSpecification (org.eclipse.osgi.service.resolver.BundleSpecification)4 VersionConstraint (org.eclipse.osgi.service.resolver.VersionConstraint)4 ArrayList (java.util.ArrayList)3 ResolverError (org.eclipse.osgi.service.resolver.ResolverError)2 HashSet (java.util.HashSet)1 TreeMap (java.util.TreeMap)1 ExportPackageDescriptionImpl (org.eclipse.osgi.internal.resolver.ExportPackageDescriptionImpl)1 GenericDescriptionImpl (org.eclipse.osgi.internal.resolver.GenericDescriptionImpl)1 ExportPackageDescription (org.eclipse.osgi.service.resolver.ExportPackageDescription)1 GenericDescription (org.eclipse.osgi.service.resolver.GenericDescription)1 GenericSpecification (org.eclipse.osgi.service.resolver.GenericSpecification)1 ImportPackageSpecification (org.eclipse.osgi.service.resolver.ImportPackageSpecification)1