Search in sources :

Example 6 with SimpleVersion

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;
}
Also used : VersionRange(org.eclipse.n4js.semver.Semver.VersionRange) SimpleVersion(org.eclipse.n4js.semver.Semver.SimpleVersion)

Example 7 with SimpleVersion

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;
}
Also used : SimpleVersion(org.eclipse.n4js.semver.Semver.SimpleVersion) VersionRangeConstraint(org.eclipse.n4js.semver.Semver.VersionRangeConstraint)

Example 8 with SimpleVersion

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;
}
Also used : SimpleVersion(org.eclipse.n4js.semver.Semver.SimpleVersion)

Example 9 with SimpleVersion

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;
}
Also used : VersionRangeConstraint(org.eclipse.n4js.semver.Semver.VersionRangeConstraint) VersionRangeSetRequirement(org.eclipse.n4js.semver.Semver.VersionRangeSetRequirement) VersionRange(org.eclipse.n4js.semver.Semver.VersionRange) SimpleVersion(org.eclipse.n4js.semver.Semver.SimpleVersion)

Example 10 with SimpleVersion

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;
        }
    }
}
Also used : VersionRangeConstraint(org.eclipse.n4js.semver.Semver.VersionRangeConstraint) VersionRangeSetRequirement(org.eclipse.n4js.semver.Semver.VersionRangeSetRequirement) SimpleVersion(org.eclipse.n4js.semver.Semver.SimpleVersion) IParseResult(org.eclipse.xtext.parser.IParseResult) JSONStringLiteral(org.eclipse.n4js.json.JSON.JSONStringLiteral) NPMVersionRequirement(org.eclipse.n4js.semver.Semver.NPMVersionRequirement)

Aggregations

SimpleVersion (org.eclipse.n4js.semver.Semver.SimpleVersion)13 VersionRangeConstraint (org.eclipse.n4js.semver.Semver.VersionRangeConstraint)8 VersionRangeSetRequirement (org.eclipse.n4js.semver.Semver.VersionRangeSetRequirement)5 VersionNumber (org.eclipse.n4js.semver.Semver.VersionNumber)4 VersionRange (org.eclipse.n4js.semver.Semver.VersionRange)4 HyphenVersionRange (org.eclipse.n4js.semver.Semver.HyphenVersionRange)2 LinkedList (java.util.LinkedList)1 EPackage (org.eclipse.emf.ecore.EPackage)1 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)1 JSONStringLiteral (org.eclipse.n4js.json.JSON.JSONStringLiteral)1 GitHubVersionRequirement (org.eclipse.n4js.semver.Semver.GitHubVersionRequirement)1 LocalPathVersionRequirement (org.eclipse.n4js.semver.Semver.LocalPathVersionRequirement)1 NPMVersionRequirement (org.eclipse.n4js.semver.Semver.NPMVersionRequirement)1 Qualifier (org.eclipse.n4js.semver.Semver.Qualifier)1 QualifierTag (org.eclipse.n4js.semver.Semver.QualifierTag)1 TagVersionRequirement (org.eclipse.n4js.semver.Semver.TagVersionRequirement)1 URLCommitISH (org.eclipse.n4js.semver.Semver.URLCommitISH)1 URLSemver (org.eclipse.n4js.semver.Semver.URLSemver)1 URLVersionRequirement (org.eclipse.n4js.semver.Semver.URLVersionRequirement)1 VersionPart (org.eclipse.n4js.semver.Semver.VersionPart)1