/** * Returns the range of versions that satisfy this required capability. Returns * an empty version range ({@link VersionRange#emptyRange} if any version * will satisfy the capability. * @return the range of versions that satisfy this required capability. */ public VersionRange getRange() { return extractRange(matchExpression); }
/** * Create and return a new requirement ({@link IRequirement}) with the specified values. * * @param requirement the match expression * @param filter the filter, or <code>null</code> * @param minCard minimum cardinality * @param maxCard maximum cardinality * @param greedy <code>true</code> if the requirement should be considered greedy and <code>false</code> otherwise * @param description a <code>String</code> description of the requirement, or <code>null</code> * @return the requirement */ public static IRequirement createRequirement(IMatchExpression<IInstallableUnit> requirement, IMatchExpression<IInstallableUnit> filter, int minCard, int maxCard, boolean greedy, String description) { return new RequiredCapability(requirement, filter, minCard, maxCard, greedy, description); }
public static String extractNamespace(IMatchExpression<IInstallableUnit> matchExpression) { assertValid(matchExpression); return (String) matchExpression.getParameters()[1]; }
protected void writeRequirement(IRequirement requirement) { start(REQUIREMENT_ELEMENT); IMatchExpression<IInstallableUnit> match = requirement.getMatches(); if (requirement.getMax() > 0 && RequiredCapability.isSimpleRequirement(match)) { attribute(NAMESPACE_ATTRIBUTE, RequiredCapability.extractNamespace(match)); attribute(NAME_ATTRIBUTE, RequiredCapability.extractName(match)); attribute(VERSION_RANGE_ATTRIBUTE, RequiredCapability.extractRange(match)); attribute(CAPABILITY_OPTIONAL_ATTRIBUTE, requirement.getMin() == 0, false); attribute(CAPABILITY_MULTIPLE_ATTRIBUTE, requirement.getMax() > 1, false); } else { writeMatchExpression(match); if (requirement.getMin() != 1) attribute(MIN_ATTRIBUTE, requirement.getMin()); if (requirement.getMax() != 1) attribute(MAX_ATTRIBUTE, requirement.getMax()); } attribute(CAPABILITY_GREED_ATTRIBUTE, requirement.isGreedy(), true); if (requirement.getFilter() != null) writeTrimmedCdata(CAPABILITY_FILTER_ELEMENT, requirement.getFilter().getParameters()[0].toString()); if (requirement.getDescription() != null) writeTrimmedCdata(REQUIREMENT_DESCRIPTION_ELEMENT, requirement.getDescription()); end(REQUIREMENT_ELEMENT); }
protected void writeUpdateDescriptor(IInstallableUnit iu, IUpdateDescriptor descriptor) { if (descriptor == null) return; if (descriptor.getIUsBeingUpdated().size() > 1) throw new IllegalStateException(); IMatchExpression<IInstallableUnit> singleUD = descriptor.getIUsBeingUpdated().iterator().next(); start(UPDATE_DESCRIPTOR_ELEMENT); if (RequiredCapability.isSimpleRequirement(singleUD)) { attribute(ID_ATTRIBUTE, RequiredCapability.extractName(singleUD)); attribute(VERSION_RANGE_ATTRIBUTE, RequiredCapability.extractRange(singleUD)); } else { writeMatchExpression(singleUD); } attribute(UPDATE_DESCRIPTOR_SEVERITY, descriptor.getSeverity()); attribute(DESCRIPTION_ATTRIBUTE, descriptor.getDescription()); end(UPDATE_DESCRIPTOR_ELEMENT); }
private boolean hasOnlySimpleRequirements(IInstallableUnit iu) { for (IRequirement r : iu.getRequirements()) if (r.getMax() == 0 || !RequiredCapability.isSimpleRequirement(r.getMatches())) return false; if (iu.getUpdateDescriptor() != null) { for (IMatchExpression<IInstallableUnit> m : iu.getUpdateDescriptor().getIUsBeingUpdated()) { if (!RequiredCapability.isSimpleRequirement(m)) return false; } } for (IRequirement r : iu.getMetaRequirements()) if (r.getMax() == 0 || !RequiredCapability.isSimpleRequirement(r.getMatches())) return false; if (iu instanceof IInstallableUnitFragment) { for (IRequirement r : ((IInstallableUnitFragment) iu).getHost()) if (!RequiredCapability.isSimpleRequirement(r.getMatches())) return false; } if (iu instanceof IInstallableUnitPatch) { IInstallableUnitPatch iuPatch = (IInstallableUnitPatch) iu; for (IRequirement[] rArr : iuPatch.getApplicabilityScope()) for (IRequirement r : rArr) if (!RequiredCapability.isSimpleRequirement(r.getMatches())) return false; IRequirement lifeCycle = iuPatch.getLifeCycle(); if (lifeCycle != null && !RequiredCapability.isSimpleRequirement(lifeCycle.getMatches())) return false; } return true; }
return matchExpression.toString(); if (!isSimpleRequirement(matchExpression)) { result.append(matchExpression.toString()).append(' '); for (int i = 0; i < matchExpression.getParameters().length; i++) { if (IInstallableUnit.NAMESPACE_IU_ID.equals(getNamespace())) { } else if ("osgi.bundle".equals(getNamespace())) { //$NON-NLS-1$ result.append("bundle"); //$NON-NLS-1$ } else if ("java.package".equals(getNamespace())) { //$NON-NLS-1$ result.append("package"); //$NON-NLS-1$ } else { result.append(getNamespace()); result.append(getName()); result.append(' '); VersionRange range = getRange();
private boolean isIncluded(IInstallableUnit iu, IRequirement req, IInstallableUnit match) { Set<String> includedIUs = FeatureDependenciesAction.getIncludedUIs(iu); if (includedIUs.contains(match.getId())) { return true; } return RequiredCapability.isStrictVersionRequirement(req.getMatches()); }
protected void writeRequirement(IRequirement requirement) { start(REQUIREMENT_ELEMENT); IMatchExpression<IInstallableUnit> match = requirement.getMatches(); if (requirement.getMax() > 0 && RequiredCapability.isSimpleRequirement(match)) { attribute(NAMESPACE_ATTRIBUTE, RequiredCapability.extractNamespace(match)); attribute(NAME_ATTRIBUTE, RequiredCapability.extractName(match)); attribute(VERSION_RANGE_ATTRIBUTE, RequiredCapability.extractRange(match)); attribute(CAPABILITY_OPTIONAL_ATTRIBUTE, requirement.getMin() == 0, false); attribute(CAPABILITY_MULTIPLE_ATTRIBUTE, requirement.getMax() > 1, false); } else { writeMatchExpression(match); if (requirement.getMin() != 1) attribute(MIN_ATTRIBUTE, requirement.getMin()); if (requirement.getMax() != 1) attribute(MAX_ATTRIBUTE, requirement.getMax()); } attribute(CAPABILITY_GREED_ATTRIBUTE, requirement.isGreedy(), true); if (requirement.getFilter() != null) writeTrimmedCdata(CAPABILITY_FILTER_ELEMENT, requirement.getFilter().getParameters()[0].toString()); if (requirement.getDescription() != null) writeTrimmedCdata(REQUIREMENT_DESCRIPTION_ELEMENT, requirement.getDescription()); end(REQUIREMENT_ELEMENT); }
protected void writeUpdateDescriptor(IInstallableUnit iu, IUpdateDescriptor descriptor) { if (descriptor == null) return; if (descriptor.getIUsBeingUpdated().size() > 1) throw new IllegalStateException(); IMatchExpression<IInstallableUnit> singleUD = descriptor.getIUsBeingUpdated().iterator().next(); start(UPDATE_DESCRIPTOR_ELEMENT); if (RequiredCapability.isSimpleRequirement(singleUD)) { attribute(ID_ATTRIBUTE, RequiredCapability.extractName(singleUD)); attribute(VERSION_RANGE_ATTRIBUTE, RequiredCapability.extractRange(singleUD)); } else { writeMatchExpression(singleUD); } attribute(UPDATE_DESCRIPTOR_SEVERITY, descriptor.getSeverity()); attribute(DESCRIPTION_ATTRIBUTE, descriptor.getDescription()); end(UPDATE_DESCRIPTOR_ELEMENT); }
private boolean hasOnlySimpleRequirements(IInstallableUnit iu) { for (IRequirement r : iu.getRequirements()) if (r.getMax() == 0 || !RequiredCapability.isSimpleRequirement(r.getMatches())) return false; if (iu.getUpdateDescriptor() != null) { for (IMatchExpression<IInstallableUnit> m : iu.getUpdateDescriptor().getIUsBeingUpdated()) { if (!RequiredCapability.isSimpleRequirement(m)) return false; } } for (IRequirement r : iu.getMetaRequirements()) if (r.getMax() == 0 || !RequiredCapability.isSimpleRequirement(r.getMatches())) return false; if (iu instanceof IInstallableUnitFragment) { for (IRequirement r : ((IInstallableUnitFragment) iu).getHost()) if (!RequiredCapability.isSimpleRequirement(r.getMatches())) return false; } if (iu instanceof IInstallableUnitPatch) { IInstallableUnitPatch iuPatch = (IInstallableUnitPatch) iu; for (IRequirement[] rArr : iuPatch.getApplicabilityScope()) for (IRequirement r : rArr) if (!RequiredCapability.isSimpleRequirement(r.getMatches())) return false; IRequirement lifeCycle = iuPatch.getLifeCycle(); if (lifeCycle != null && !RequiredCapability.isSimpleRequirement(lifeCycle.getMatches())) return false; } return true; }
@Override protected boolean isApplicable(IRequirement req) { //Every filter in this method needs to continue except when the filter does not pass if (!includeOptionalDependencies) if (req.getMin() == 0) return false; if (considerOnlyStrictDependency) { if (!RequiredCapability.isStrictVersionRequirement(req.getMatches())) return false; } //deal with filters if (considerFilter) { if (onlyFilteredRequirements && req.getFilter() == null) { return false; } return super.isApplicable(req); } if (req.getFilter() == null) { if (onlyFilteredRequirements) return false; return true; } return evalFilterTo; }
protected void writeRequirement(IRequirement requirement) { start(REQUIREMENT_ELEMENT); IMatchExpression<IInstallableUnit> match = requirement.getMatches(); if (requirement.getMax() > 0 && RequiredCapability.isSimpleRequirement(match)) { attribute(NAMESPACE_ATTRIBUTE, RequiredCapability.extractNamespace(match)); attribute(NAME_ATTRIBUTE, RequiredCapability.extractName(match)); attribute(VERSION_RANGE_ATTRIBUTE, RequiredCapability.extractRange(match)); attribute(CAPABILITY_OPTIONAL_ATTRIBUTE, requirement.getMin() == 0, false); attribute(CAPABILITY_MULTIPLE_ATTRIBUTE, requirement.getMax() > 1, false); } else { writeMatchExpression(match); if (requirement.getMin() != 1) attribute(MIN_ATTRIBUTE, requirement.getMin()); if (requirement.getMax() != 1) attribute(MAX_ATTRIBUTE, requirement.getMax()); } attribute(CAPABILITY_GREED_ATTRIBUTE, requirement.isGreedy(), true); if (requirement.getFilter() != null) writeTrimmedCdata(CAPABILITY_FILTER_ELEMENT, requirement.getFilter().getParameters()[0].toString()); if (requirement.getDescription() != null) writeTrimmedCdata(REQUIREMENT_DESCRIPTION_ELEMENT, requirement.getDescription()); end(REQUIREMENT_ELEMENT); }
protected void writeUpdateDescriptor(IInstallableUnit iu, IUpdateDescriptor descriptor) { if (descriptor == null) return; if (descriptor.getIUsBeingUpdated().size() > 1) throw new IllegalStateException(); IMatchExpression<IInstallableUnit> singleUD = descriptor.getIUsBeingUpdated().iterator().next(); start(UPDATE_DESCRIPTOR_ELEMENT); if (RequiredCapability.isSimpleRequirement(singleUD)) { attribute(ID_ATTRIBUTE, RequiredCapability.extractName(singleUD)); attribute(VERSION_RANGE_ATTRIBUTE, RequiredCapability.extractRange(singleUD)); } else { writeMatchExpression(singleUD); } attribute(UPDATE_DESCRIPTOR_SEVERITY, descriptor.getSeverity()); attribute(DESCRIPTION_ATTRIBUTE, descriptor.getDescription()); end(UPDATE_DESCRIPTOR_ELEMENT); }
private boolean hasOnlySimpleRequirements(IInstallableUnit iu) { for (IRequirement r : iu.getRequirements()) if (r.getMax() == 0 || !RequiredCapability.isSimpleRequirement(r.getMatches())) return false; if (iu.getUpdateDescriptor() != null) { for (IMatchExpression<IInstallableUnit> m : iu.getUpdateDescriptor().getIUsBeingUpdated()) { if (!RequiredCapability.isSimpleRequirement(m)) return false; } } for (IRequirement r : iu.getMetaRequirements()) if (r.getMax() == 0 || !RequiredCapability.isSimpleRequirement(r.getMatches())) return false; if (iu instanceof IInstallableUnitFragment) { for (IRequirement r : ((IInstallableUnitFragment) iu).getHost()) if (!RequiredCapability.isSimpleRequirement(r.getMatches())) return false; } if (iu instanceof IInstallableUnitPatch) { IInstallableUnitPatch iuPatch = (IInstallableUnitPatch) iu; for (IRequirement[] rArr : iuPatch.getApplicabilityScope()) for (IRequirement r : rArr) if (!RequiredCapability.isSimpleRequirement(r.getMatches())) return false; IRequirement lifeCycle = iuPatch.getLifeCycle(); if (lifeCycle != null && !RequiredCapability.isSimpleRequirement(lifeCycle.getMatches())) return false; } return true; }
/** * Create and return a new requirement ({@link IRequirement}) with the specified values. * * @param requirement the match expression * @param filter The filter used to evaluate whether this capability is applicable in the * current environment, or <code>null</code> to indicate this capability is always applicable * @param minCard minimum cardinality * @param maxCard maximum cardinality * @param greedy <code>true</code> if the requirement should be considered greedy and <code>false</code> otherwise * @return the requirement */ public static IRequirement createRequirement(IMatchExpression<IInstallableUnit> requirement, IMatchExpression<IInstallableUnit> filter, int minCard, int maxCard, boolean greedy) { return new RequiredCapability(requirement, filter, minCard, maxCard, greedy, null); }
public static String extractName(IMatchExpression<IInstallableUnit> matchExpression) { assertValid(matchExpression); return (String) matchExpression.getParameters()[0]; }
@Override protected Object getQueriedIDs(IEvaluationContext ctx, IExpression variable, String memberName, IExpression booleanExpr, Object queriedKeys) { if (booleanExpr.getExpressionType() != IExpression.TYPE_MATCHES) return super.getQueriedIDs(ctx, variable, memberName, booleanExpr, queriedKeys); Matches matches = (Matches) booleanExpr; if (matches.lhs != variable) return null; Object rhsObj = matches.rhs.evaluate(ctx); if (!(rhsObj instanceof IRequirement)) return null; // Let the requirement expression participate in the // index usage query // IMatchExpression<IInstallableUnit> rm = ((IRequirement) rhsObj).getMatches(); return RequiredCapability.isSimpleRequirement(rm) ? concatenateUnique(queriedKeys, rm.getParameters()[0]) : getRequirementIDs(rm.createContext(), ((Unary) rm).operand, queriedKeys); }
/** * Create and return a new requirement ({@link IRequirement}) with the specified values. * * @param namespace the namespace for the requirement. Must not be <code>null</code>. * @param name the name for the requirement. Must not be <code>null</code>. * @param range the version range. A value of <code>null</code> is equivalent to {@link VersionRange#emptyRange} and matches all versions. * @param filter The filter used to evaluate whether this capability is applicable in the * current environment, or <code>null</code> to indicate this capability is always applicable * @param optional <code>true</code> if this requirement is optional, and <code>false</code> otherwise. * @param multiple <code>true</code> if this requirement can be satisfied by multiple provided capabilities, or <code>false</code> * if it requires exactly one match * @param greedy <code>true</code> if the requirement should be considered greedy and <code>false</code> otherwise * @return the requirement */ public static IRequirement createRequirement(String namespace, String name, VersionRange range, String filter, boolean optional, boolean multiple, boolean greedy) { return new RequiredCapability(namespace, name, range, filter, optional, multiple, greedy); }
public static VersionRange extractRange(IMatchExpression<IInstallableUnit> matchExpression) { IExpression expr = assertValid(matchExpression); Object[] params = matchExpression.getParameters(); if (params.length < 3) return VersionRange.emptyRange; Version v = (Version) params[2]; if (params.length < 4) { if (expr.equals(strictVersionExpression)) return new VersionRange(v, true, v, true); return new VersionRange(v, expr.equals(openEndedExpression), Version.MAX_VERSION, true); } Version h = (Version) params[3]; return new VersionRange(v, expr.equals(range_II_Expression) || expr.equals(range_IN_Expression), h, expr.equals(range_II_Expression) || expr.equals(range_NI_Expression)); }