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);
}
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;
}
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;
}
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);
}
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);
}
Aggregations