use of org.eclipse.n4js.semver.Semver.SimpleVersion in project n4js by eclipse.
the class SemverMatcher method matches.
/**
* This method checks {@link VersionRangeSetRequirement}s whether they match or not. Its semantics is aligned to
* <a href="https://semver.npmjs.com/">semver.npmjs.com<a>.
*
* @param proband
* version that is checked to match the constraint
* @param constraint
* version that must be met by the proband
* @return true iff the given {@code proband} version matches the given {@code constraint} version
*/
private static boolean matches(VersionNumber proband, VersionRangeSetRequirement constraint) {
EList<VersionRange> cRanges = constraint.getRanges();
if (cRanges.isEmpty()) {
// Empty versions are interpreted as "latest". Thus return true here.
return true;
}
if (isWildcard(constraint)) {
return true;
}
for (VersionRange cRange : cRanges) {
List<SimpleVersion> simpleConstraints = SemverConverter.simplify(cRange);
boolean rangeMatches = matches(proband, simpleConstraints);
if (rangeMatches) {
return true;
}
}
return false;
}
use of org.eclipse.n4js.semver.Semver.SimpleVersion in project n4js by eclipse.
the class SemverMatcher method matches.
private static boolean matches(VersionNumber proband, List<SimpleVersion> simpleConstraints) {
Collections.sort(simpleConstraints, SemverMatcher::compareToClusterPrereleases);
// check constraints on the given proband
for (int i = 0; i < simpleConstraints.size(); i++) {
SimpleVersion simpleConstraint = simpleConstraints.get(i);
RelationKind relationKind = computeSemverRelationKind(proband, i, simpleConstraint);
boolean constraintMatchesProband = matches(proband, simpleConstraint, relationKind);
if (!constraintMatchesProband) {
return false;
}
}
return true;
}
use of org.eclipse.n4js.semver.Semver.SimpleVersion in project n4js by eclipse.
the class SemverMatcher method matches.
/**
* This method checks {@link VersionRangeSetRequirement}s whether they match or not. Its semantics is aligned to
* <a href="https://semver.npmjs.com/">semver.npmjs.com<a>.
*
* @param proband
* version that is checked to match the constraint
* @param constraint
* version that must be met by the proband
* @return true iff the given {@code proband} version matches the given {@code constraint} version
*/
private static boolean matches(VersionNumber proband, URLVersionRequirement constraint) {
if (constraint.hasSimpleVersion()) {
SimpleVersion simpleVersion = constraint.getSimpleVersion();
List<SimpleVersion> simpleConstraints = SemverConverter.simplify(simpleVersion);
return matches(proband, simpleConstraints);
}
return true;
}
use of org.eclipse.n4js.semver.Semver.SimpleVersion in project n4js by eclipse.
the class SemverUtils method isWildcardVersionRequirement.
/**
* Tells if the given version requirement is a wildcard version requirement, as obtained by parsing the string "*".
*/
public static boolean isWildcardVersionRequirement(NPMVersionRequirement versionRequirement) {
if (versionRequirement instanceof VersionRangeSetRequirement) {
List<VersionRange> ranges = ((VersionRangeSetRequirement) versionRequirement).getRanges();
VersionRange range = ranges.size() == 1 ? ranges.get(0) : null;
List<SimpleVersion> constraints = range instanceof VersionRangeConstraint ? ((VersionRangeConstraint) range).getVersionConstraints() : Collections.emptyList();
SimpleVersion simple = constraints.size() == 1 ? constraints.get(0) : null;
if (simple != null) {
return simple.isWildcard();
}
}
return false;
}
use of org.eclipse.n4js.semver.Semver.SimpleVersion in project n4js by eclipse.
the class PackageJsonValidatorExtension method checkVersion.
/**
* Check the version property.
*/
@CheckProperty(property = VERSION)
public void checkVersion(JSONValue versionValue) {
if (!checkIsType(versionValue, JSONPackage.Literals.JSON_STRING_LITERAL, "as package version")) {
return;
}
JSONStringLiteral versionJsonString = (JSONStringLiteral) versionValue;
String versionString = versionJsonString.getValue();
IParseResult parseResult = validateSemver(versionValue, versionString);
NPMVersionRequirement npmVersion = semverHelper.parse(parseResult);
VersionRangeSetRequirement vrs = semverHelper.parseVersionRangeSet(parseResult);
if (vrs == null) {
String reason = "Cannot parse given string";
if (npmVersion != null) {
reason = "Given string is parsed as " + getVersionRequirementType(npmVersion);
}
String msg = IssueCodes.getMessageForPKGJ_INVALID_VERSION_NUMBER(versionString, reason);
addIssue(msg, versionValue, IssueCodes.PKGJ_INVALID_VERSION_NUMBER);
return;
}
if (!vrs.getRanges().isEmpty() && vrs.getRanges().get(0) instanceof VersionRangeConstraint) {
VersionRangeConstraint vrc = (VersionRangeConstraint) vrs.getRanges().get(0);
SimpleVersion simpleVersion = vrc.getVersionConstraints().get(0);
if (!simpleVersion.getComparators().isEmpty()) {
String comparator = SemverSerializer.serialize(simpleVersion.getComparators().get(0));
String reason = "Version numbers must not have comparators: '" + comparator + "'";
String msg = IssueCodes.getMessageForPKGJ_INVALID_VERSION_NUMBER(versionString, reason);
addIssue(msg, versionValue, IssueCodes.PKGJ_INVALID_VERSION_NUMBER);
return;
}
}
}
Aggregations