Search in sources :

Example 1 with QueryableCollection

use of org.eclipse.tycho.repository.p2base.metadata.QueryableCollection in project tycho by eclipse.

the class DependencyCollector method resolve.

@Override
public Collection<IInstallableUnit> resolve(Map<String, String> properties, IProgressMonitor monitor) {
    Set<IInstallableUnit> result = new LinkedHashSet<>();
    LinkedHashSet<IStatus> errors = new LinkedHashSet<>();
    if (logger.isExtendedDebugEnabled()) {
        logger.debug("Available IUs:\n" + ResolverDebugUtils.toDebugString(data.getAvailableIUs(), false));
        logger.debug("Root IUs:\n" + ResolverDebugUtils.toDebugString(data.getRootIUs(), true));
    }
    result.addAll(data.getRootIUs());
    QueryableCollection availableUIsQueryable = new QueryableCollection(data.getAvailableIUs());
    for (IInstallableUnit iu : data.getRootIUs()) {
        collectIncludedIUs(availableUIsQueryable, result, errors, iu, true, monitor);
    }
    if (logger.isExtendedDebugEnabled()) {
        logger.debug("Collected IUs:\n" + ResolverDebugUtils.toDebugString(result, false));
    }
    if (!errors.isEmpty()) {
        MultiStatus status = new MultiStatus(Activator.PLUGIN_ID, 0, errors.toArray(new IStatus[errors.size()]), "Missing dependencies", null);
        throw new RuntimeException(status.toString(), new ProvisionException(status));
    }
    return result;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) IStatus(org.eclipse.core.runtime.IStatus) ProvisionException(org.eclipse.equinox.p2.core.ProvisionException) QueryableCollection(org.eclipse.tycho.repository.p2base.metadata.QueryableCollection) MultiStatus(org.eclipse.core.runtime.MultiStatus) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit)

Example 2 with QueryableCollection

use of org.eclipse.tycho.repository.p2base.metadata.QueryableCollection in project tycho by eclipse.

the class ProjectorResolutionStrategy method fixSWT.

/*
     * workaround for SWT bug 361901: bundles generally require org.eclipse.swt, but this is an
     * empty shell and only native fragments of org.eclipse.swt provide classes to compile against.
     * There is no dependency from the host to the fragments, so we need to add the matching SWT
     * fragment manually.
     */
void fixSWT(Collection<IInstallableUnit> availableIUs, Collection<IInstallableUnit> resolutionResult, Map<String, String> newSelectionContext, IProgressMonitor monitor) {
    IInstallableUnit swtHost = findSWTHostIU(resolutionResult);
    if (swtHost == null) {
        return;
    } else if (swtHost.getVersion().compareTo(Version.createOSGi(3, 104, 0)) >= 0) {
        // bug 361901 was fixed in Mars
        return;
    }
    // 380934 one of rootIUs can be SWT or an SWT fragment
    for (IInstallableUnit iu : data.getRootIUs()) {
        if ("org.eclipse.swt".equals(iu.getId())) {
            return;
        }
        for (IProvidedCapability provided : iu.getProvidedCapabilities()) {
            if ("osgi.fragment".equals(provided.getNamespace()) && "org.eclipse.swt".equals(provided.getName())) {
                return;
            }
        }
    }
    IInstallableUnit swtFragment = null;
    all_ius: for (Iterator<IInstallableUnit> iter = new QueryableCollection(availableIUs).query(QueryUtil.ALL_UNITS, monitor).iterator(); iter.hasNext(); ) {
        IInstallableUnit iu = iter.next();
        if (iu.getId().startsWith("org.eclipse.swt") && isApplicable(newSelectionContext, iu.getFilter()) && providesJavaPackages(iu)) {
            for (IProvidedCapability provided : iu.getProvidedCapabilities()) {
                if ("osgi.fragment".equals(provided.getNamespace()) && "org.eclipse.swt".equals(provided.getName())) {
                    if (swtFragment == null || swtFragment.getVersion().compareTo(iu.getVersion()) < 0) {
                        swtFragment = iu;
                    }
                    continue all_ius;
                }
            }
        }
    }
    if (swtFragment == null) {
        throw new RuntimeException("Could not determine SWT implementation fragment bundle for environment " + newSelectionContext);
    }
    resolutionResult.add(swtFragment);
}
Also used : IProvidedCapability(org.eclipse.equinox.p2.metadata.IProvidedCapability) Iterator(java.util.Iterator) QueryableCollection(org.eclipse.tycho.repository.p2base.metadata.QueryableCollection) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit)

Example 3 with QueryableCollection

use of org.eclipse.tycho.repository.p2base.metadata.QueryableCollection in project tycho by eclipse.

the class AbstractSlicerResolutionStrategy method slice.

protected final IQueryable<IInstallableUnit> slice(Map<String, String> properties, IProgressMonitor monitor) throws ResolverException {
    if (logger.isExtendedDebugEnabled()) {
        logger.debug("Properties: " + properties.toString());
        logger.debug("Available IUs:\n" + toDebugString(data.getAvailableIUs(), false));
        logger.debug("JRE IUs:\n" + toDebugString(data.getEEResolutionHints().getMandatoryUnits(), false));
        logger.debug("Root IUs:\n" + toDebugString(data.getRootIUs(), true));
        if (data.getAdditionalRequirements() != null && !data.getAdditionalRequirements().isEmpty()) {
            StringBuilder sb = new StringBuilder();
            for (IRequirement req : data.getAdditionalRequirements()) {
                sb.append("   ").append(req.toString()).append("\n");
            }
            logger.debug("Extra Requirements:\n" + sb.toString());
        }
    }
    Set<IInstallableUnit> availableIUs = new LinkedHashSet<>(data.getAvailableIUs());
    availableIUs.addAll(data.getEEResolutionHints().getTemporaryAdditions());
    availableIUs.addAll(data.getEEResolutionHints().getMandatoryUnits());
    Set<IInstallableUnit> seedIUs = new LinkedHashSet<>(data.getRootIUs());
    if (data.getAdditionalRequirements() != null && !data.getAdditionalRequirements().isEmpty()) {
        seedIUs.add(createUnitRequiring("tycho-extra", null, data.getAdditionalRequirements()));
    }
    // make sure profile UIs are part of the slice
    seedIUs.addAll(data.getEEResolutionHints().getMandatoryUnits());
    if (!data.getEEResolutionHints().getMandatoryRequires().isEmpty()) {
        seedIUs.add(createUnitRequiring("tycho-ee", null, data.getEEResolutionHints().getMandatoryRequires()));
    }
    Slicer slicer = newSlicer(new QueryableCollection(availableIUs), properties);
    IQueryable<IInstallableUnit> slice = slicer.slice(seedIUs.toArray(EMPTY_IU_ARRAY), monitor);
    MultiStatus slicerStatus = slicer.getStatus();
    if (slice == null || isSlicerError(slicerStatus)) {
        throw new ResolverException(StatusTool.toLogMessage(slicerStatus), properties.toString(), StatusTool.findException(slicerStatus));
    }
    if (logger.isExtendedDebugEnabled()) {
        logger.debug("Slice:\n" + ResolverDebugUtils.toDebugString(slice, false, monitor));
    }
    return slice;
}
Also used : IRequirement(org.eclipse.equinox.p2.metadata.IRequirement) LinkedHashSet(java.util.LinkedHashSet) Slicer(org.eclipse.equinox.internal.p2.director.Slicer) QueryableCollection(org.eclipse.tycho.repository.p2base.metadata.QueryableCollection) MultiStatus(org.eclipse.core.runtime.MultiStatus) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit)

Example 4 with QueryableCollection

use of org.eclipse.tycho.repository.p2base.metadata.QueryableCollection in project tycho by eclipse.

the class P2ResolverImpl method resolveInstallableUnit.

// TODO 412416 this should be a method on the class TargetPlatform
@Override
public P2ResolutionResult resolveInstallableUnit(TargetPlatform targetPlatform, String id, String versionRange) {
    setContext(targetPlatform, null);
    QueryableCollection queriable = new QueryableCollection(context.getInstallableUnits());
    VersionRange range = new VersionRange(versionRange);
    IRequirement requirement = MetadataFactory.createRequirement(IInstallableUnit.NAMESPACE_IU_ID, id, range, null, 1, /* min */
    Integer.MAX_VALUE, /* max */
    false);
    IQueryResult<IInstallableUnit> result = queriable.query(QueryUtil.createLatestQuery(QueryUtil.createMatchQuery(requirement.getMatches())), monitor);
    Set<IInstallableUnit> newState = result.toUnmodifiableSet();
    return toResolutionResult(newState, null);
}
Also used : IRequirement(org.eclipse.equinox.p2.metadata.IRequirement) QueryableCollection(org.eclipse.tycho.repository.p2base.metadata.QueryableCollection) VersionRange(org.eclipse.equinox.p2.metadata.VersionRange) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit)

Aggregations

IInstallableUnit (org.eclipse.equinox.p2.metadata.IInstallableUnit)4 QueryableCollection (org.eclipse.tycho.repository.p2base.metadata.QueryableCollection)4 LinkedHashSet (java.util.LinkedHashSet)2 MultiStatus (org.eclipse.core.runtime.MultiStatus)2 IRequirement (org.eclipse.equinox.p2.metadata.IRequirement)2 Iterator (java.util.Iterator)1 IStatus (org.eclipse.core.runtime.IStatus)1 Slicer (org.eclipse.equinox.internal.p2.director.Slicer)1 ProvisionException (org.eclipse.equinox.p2.core.ProvisionException)1 IProvidedCapability (org.eclipse.equinox.p2.metadata.IProvidedCapability)1 VersionRange (org.eclipse.equinox.p2.metadata.VersionRange)1