Search in sources :

Example 31 with IRequirement

use of org.eclipse.equinox.p2.metadata.IRequirement in project tycho by eclipse.

the class AbstractSlicerResolutionStrategy method createUnitRequiring.

protected static IInstallableUnit createUnitRequiring(String name, Collection<IInstallableUnit> units, Collection<IRequirement> additionalRequirements) {
    InstallableUnitDescription result = new MetadataFactory.InstallableUnitDescription();
    String time = Long.toString(System.currentTimeMillis());
    result.setId(name + "-" + time);
    result.setVersion(Version.createOSGi(0, 0, 0, time));
    ArrayList<IRequirement> requirements = new ArrayList<>();
    if (units != null) {
        for (IInstallableUnit unit : units) {
            requirements.add(createStrictRequirementTo(unit));
        }
    }
    if (additionalRequirements != null) {
        requirements.addAll(additionalRequirements);
    }
    result.addRequirements(requirements);
    return MetadataFactory.createInstallableUnit(result);
}
Also used : IRequirement(org.eclipse.equinox.p2.metadata.IRequirement) InstallableUnitDescription(org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescription) ArrayList(java.util.ArrayList) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) ResolverDebugUtils.toDebugString(org.eclipse.tycho.p2.util.resolution.ResolverDebugUtils.toDebugString)

Example 32 with IRequirement

use of org.eclipse.equinox.p2.metadata.IRequirement 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 33 with IRequirement

use of org.eclipse.equinox.p2.metadata.IRequirement in project tycho by eclipse.

the class ProjectorResolutionStrategy method resolve.

@Override
public Collection<IInstallableUnit> resolve(Map<String, String> properties, IProgressMonitor monitor) throws ResolverException {
    Map<String, String> newSelectionContext = SimplePlanner.createSelectionContext(properties);
    IQueryable<IInstallableUnit> slice = slice(properties, monitor);
    Set<IInstallableUnit> seedUnits = new LinkedHashSet<>(data.getRootIUs());
    List<IRequirement> seedRequires = new ArrayList<>();
    if (data.getAdditionalRequirements() != null) {
        seedRequires.addAll(data.getAdditionalRequirements());
    }
    // force profile UIs to be used during resolution
    seedUnits.addAll(data.getEEResolutionHints().getMandatoryUnits());
    seedRequires.addAll(data.getEEResolutionHints().getMandatoryRequires());
    Projector projector = new Projector(slice, newSelectionContext, new HashSet<IInstallableUnit>(), false);
    projector.encode(createUnitRequiring("tycho", seedUnits, seedRequires), EMPTY_IU_ARRAY, /* alreadyExistingRoots */
    new QueryableArray(EMPTY_IU_ARRAY), /* installedIUs */
    seedUnits, /* newRoots */
    monitor);
    IStatus s = projector.invokeSolver(monitor);
    if (s.getSeverity() == IStatus.ERROR) {
        // log all transitive requirements which cannot be satisfied; this doesn't print the dependency chain from the seed to the units with missing requirements, so this is less useful than the "explanation"
        logger.debug(StatusTool.collectProblems(s));
        // suppress "Cannot complete the request.  Generating details."
        Set<Explanation> explanation = projector.getExplanation(new NullProgressMonitor());
        throw new ResolverException(toString(explanation), newSelectionContext.toString(), StatusTool.findException(s));
    }
    Collection<IInstallableUnit> newState = projector.extractSolution();
    // remove fake IUs from resolved state
    newState.removeAll(data.getEEResolutionHints().getTemporaryAdditions());
    fixSWT(data.getAvailableIUs(), newState, newSelectionContext, monitor);
    if (logger.isExtendedDebugEnabled()) {
        logger.debug("Resolved IUs:\n" + ResolverDebugUtils.toDebugString(newState, false));
    }
    return newState;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) IRequirement(org.eclipse.equinox.p2.metadata.IRequirement) Projector(org.eclipse.equinox.internal.p2.director.Projector) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) Explanation(org.eclipse.equinox.internal.p2.director.Explanation) ArrayList(java.util.ArrayList) QueryableArray(org.eclipse.equinox.internal.p2.director.QueryableArray) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit)

Example 34 with IRequirement

use of org.eclipse.equinox.p2.metadata.IRequirement 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)

Example 35 with IRequirement

use of org.eclipse.equinox.p2.metadata.IRequirement in project tycho by eclipse.

the class MirrorApplicationServiceTest method strictRequirementTo.

private static Set<IRequirement> strictRequirementTo(VersionedId unit) {
    VersionRange strictRange = new VersionRange(unit.getVersion(), true, unit.getVersion(), true);
    IRequirement requirement = new RequiredCapability(IInstallableUnit.NAMESPACE_IU_ID, unit.getId(), strictRange, null, false, false);
    return Collections.singleton(requirement);
}
Also used : IRequirement(org.eclipse.equinox.p2.metadata.IRequirement) RequiredCapability(org.eclipse.equinox.internal.p2.metadata.RequiredCapability) VersionRange(org.eclipse.equinox.p2.metadata.VersionRange)

Aggregations

IRequirement (org.eclipse.equinox.p2.metadata.IRequirement)31 IInstallableUnit (org.eclipse.equinox.p2.metadata.IInstallableUnit)23 ArrayList (java.util.ArrayList)17 Test (org.junit.Test)17 VersionRange (org.eclipse.equinox.p2.metadata.VersionRange)11 IRequiredCapability (org.eclipse.equinox.internal.p2.metadata.IRequiredCapability)8 File (java.io.File)7 DefaultDependencyMetadataGenerator (org.eclipse.tycho.p2.impl.publisher.DefaultDependencyMetadataGenerator)6 ArtifactMock (org.eclipse.tycho.p2.impl.test.ArtifactMock)6 LinkedHashSet (java.util.LinkedHashSet)5 SourcesBundleDependencyMetadataGenerator (org.eclipse.tycho.p2.impl.publisher.SourcesBundleDependencyMetadataGenerator)5 DependencyMetadataGenerator (org.eclipse.tycho.p2.metadata.DependencyMetadataGenerator)5 InstallableUnitDescription (org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescription)4 List (java.util.List)2 Map (java.util.Map)2 IStatus (org.eclipse.core.runtime.IStatus)2 MultiStatus (org.eclipse.core.runtime.MultiStatus)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 Version (org.eclipse.equinox.p2.metadata.Version)2 FeatureEntry (org.eclipse.equinox.p2.publisher.eclipse.FeatureEntry)2