Search in sources :

Example 1 with VersionRangeConstraint

use of org.eclipse.n4js.semver.Semver.VersionRangeConstraint in project n4js by eclipse.

the class SemverSemanticSequencer method sequence.

@Override
public void sequence(ISerializationContext context, EObject semanticObject) {
    EPackage epackage = semanticObject.eClass().getEPackage();
    ParserRule rule = context.getParserRule();
    Action action = context.getAssignedAction();
    Set<Parameter> parameters = context.getEnabledBooleanParameters();
    if (epackage == SemverPackage.eINSTANCE)
        switch(semanticObject.eClass().getClassifierID()) {
            case SemverPackage.GIT_HUB_VERSION_REQUIREMENT:
                sequence_GitHubVersionRequirement(context, (GitHubVersionRequirement) semanticObject);
                return;
            case SemverPackage.HYPHEN_VERSION_RANGE:
                sequence_HyphenVersionRange(context, (HyphenVersionRange) semanticObject);
                return;
            case SemverPackage.LOCAL_PATH_VERSION_REQUIREMENT:
                sequence_LocalPathVersionRequirement(context, (LocalPathVersionRequirement) semanticObject);
                return;
            case SemverPackage.QUALIFIER:
                sequence_Qualifier(context, (Qualifier) semanticObject);
                return;
            case SemverPackage.QUALIFIER_TAG:
                sequence_QualifierTag(context, (QualifierTag) semanticObject);
                return;
            case SemverPackage.SIMPLE_VERSION:
                sequence_SimpleVersion(context, (SimpleVersion) semanticObject);
                return;
            case SemverPackage.TAG_VERSION_REQUIREMENT:
                sequence_TagVersionRequirement(context, (TagVersionRequirement) semanticObject);
                return;
            case SemverPackage.URL_COMMIT_ISH:
                sequence_URLVersionSpecifier(context, (URLCommitISH) semanticObject);
                return;
            case SemverPackage.URL_SEMVER:
                sequence_URLSemver(context, (URLSemver) semanticObject);
                return;
            case SemverPackage.URL_VERSION_REQUIREMENT:
                sequence_URLVersionRequirement(context, (URLVersionRequirement) semanticObject);
                return;
            case SemverPackage.VERSION_NUMBER:
                sequence_VersionNumber(context, (VersionNumber) semanticObject);
                return;
            case SemverPackage.VERSION_PART:
                sequence_VersionPart(context, (VersionPart) semanticObject);
                return;
            case SemverPackage.VERSION_RANGE_CONSTRAINT:
                sequence_VersionRangeContraint(context, (VersionRangeConstraint) semanticObject);
                return;
            case SemverPackage.VERSION_RANGE_SET_REQUIREMENT:
                sequence_VersionRangeSetRequirement(context, (VersionRangeSetRequirement) semanticObject);
                return;
        }
    if (errorAcceptor != null)
        errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
Also used : URLSemver(org.eclipse.n4js.semver.Semver.URLSemver) ParserRule(org.eclipse.xtext.ParserRule) GitHubVersionRequirement(org.eclipse.n4js.semver.Semver.GitHubVersionRequirement) Action(org.eclipse.xtext.Action) URLCommitISH(org.eclipse.n4js.semver.Semver.URLCommitISH) QualifierTag(org.eclipse.n4js.semver.Semver.QualifierTag) VersionRangeSetRequirement(org.eclipse.n4js.semver.Semver.VersionRangeSetRequirement) URLVersionRequirement(org.eclipse.n4js.semver.Semver.URLVersionRequirement) TagVersionRequirement(org.eclipse.n4js.semver.Semver.TagVersionRequirement) VersionNumber(org.eclipse.n4js.semver.Semver.VersionNumber) EPackage(org.eclipse.emf.ecore.EPackage) VersionPart(org.eclipse.n4js.semver.Semver.VersionPart) VersionRangeConstraint(org.eclipse.n4js.semver.Semver.VersionRangeConstraint) HyphenVersionRange(org.eclipse.n4js.semver.Semver.HyphenVersionRange) Parameter(org.eclipse.xtext.Parameter) Qualifier(org.eclipse.n4js.semver.Semver.Qualifier) SimpleVersion(org.eclipse.n4js.semver.Semver.SimpleVersion) LocalPathVersionRequirement(org.eclipse.n4js.semver.Semver.LocalPathVersionRequirement)

Example 2 with VersionRangeConstraint

use of org.eclipse.n4js.semver.Semver.VersionRangeConstraint in project n4js by eclipse.

the class SemverConverter method simplify.

static List<SimpleVersion> simplify(VersionRange vr) {
    List<SimpleVersion> constraints = new LinkedList<>();
    if (vr instanceof HyphenVersionRange) {
        HyphenVersionRange hvr = (HyphenVersionRange) vr;
        constraints.addAll(simplify(hvr));
    }
    if (vr instanceof VersionRangeConstraint) {
        VersionRangeConstraint vrc = (VersionRangeConstraint) vr;
        for (SimpleVersion sv : vrc.getVersionConstraints()) {
            constraints.addAll(simplify(sv));
        }
    }
    return constraints;
}
Also used : VersionRangeConstraint(org.eclipse.n4js.semver.Semver.VersionRangeConstraint) HyphenVersionRange(org.eclipse.n4js.semver.Semver.HyphenVersionRange) SimpleVersion(org.eclipse.n4js.semver.Semver.SimpleVersion) LinkedList(java.util.LinkedList)

Example 3 with VersionRangeConstraint

use of org.eclipse.n4js.semver.Semver.VersionRangeConstraint in project n4js by eclipse.

the class SemverMatcher method isWildcard.

/**
 * The matching of wildcards is specified different on <a href="https://docs.npmjs.com/misc/semver">npmjs.com<a>
 * than it is behaving using npm with regard to the handling of pre-release tagged versions. Namely, npmjs.com says
 * {@code "" (empty string) := * := >=0.0.0} which is not true for npm. Therefore, this matching method will mimic
 * the npm behavior e.g. when executing 'npm install package@*' and match any version for {@code @*} including
 * pre-release tagged ones.
 *
 * @return true iff the given constraint consists of one wildcard only
 */
private static boolean isWildcard(VersionRangeSetRequirement constraint) {
    if (constraint.getRanges().size() != 1) {
        return false;
    }
    VersionRange versionRange = constraint.getRanges().get(0);
    if (!(versionRange instanceof VersionRangeConstraint)) {
        return false;
    }
    VersionRangeConstraint vrc = (VersionRangeConstraint) versionRange;
    if (vrc.getVersionConstraints().size() != 1) {
        return false;
    }
    SimpleVersion simpleVersion = vrc.getVersionConstraints().get(0);
    return simpleVersion.isWildcard();
}
Also used : VersionRangeConstraint(org.eclipse.n4js.semver.Semver.VersionRangeConstraint) VersionRange(org.eclipse.n4js.semver.Semver.VersionRange) SimpleVersion(org.eclipse.n4js.semver.Semver.SimpleVersion)

Example 4 with VersionRangeConstraint

use of org.eclipse.n4js.semver.Semver.VersionRangeConstraint 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 5 with VersionRangeConstraint

use of org.eclipse.n4js.semver.Semver.VersionRangeConstraint 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)7 VersionRangeConstraint (org.eclipse.n4js.semver.Semver.VersionRangeConstraint)7 VersionRangeSetRequirement (org.eclipse.n4js.semver.Semver.VersionRangeSetRequirement)5 VersionRange (org.eclipse.n4js.semver.Semver.VersionRange)3 HyphenVersionRange (org.eclipse.n4js.semver.Semver.HyphenVersionRange)2 VersionNumber (org.eclipse.n4js.semver.Semver.VersionNumber)2 LinkedList (java.util.LinkedList)1 EPackage (org.eclipse.emf.ecore.EPackage)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 Action (org.eclipse.xtext.Action)1