Search in sources :

Example 16 with VersionNumber

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

the class SemverMatcher method matches.

/**
 * Checks whether a given proband matches the given constraint.
 */
private static boolean matches(VersionNumber proband, SimpleVersion constraint, RelationKind relationKind) {
    VersionNumber constraintVN = constraint.getNumber();
    VersionNumberRelation relation = relation(proband, constraintVN, relationKind);
    if (relation == VersionNumberRelation.Unrelated) {
        return false;
    }
    VersionComparator versionComparator = constraint.getComparators().get(0);
    switch(versionComparator) {
        case GREATER:
            return relation == VersionNumberRelation.Greater;
        case GREATER_EQUALS:
            return relation != VersionNumberRelation.Smaller;
        case SMALLER:
            return relation == VersionNumberRelation.Smaller;
        case SMALLER_EQUALS:
            return relation != VersionNumberRelation.Greater;
        case CARET:
        case TILDE:
        case EQUALS:
            throw new IllegalStateException("This comparator should have been replaced in SemverConverter#simplify.");
    }
    throw new IllegalStateException("The Impossible State.");
}
Also used : VersionComparator(org.eclipse.n4js.semver.Semver.VersionComparator) VersionNumber(org.eclipse.n4js.semver.Semver.VersionNumber)

Example 17 with VersionNumber

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

the class SemverUtils method findClosestMatching.

/**
 * Finds the version in the collection 'versions' that is closest to the given 'toFind'
 */
public static VersionNumber findClosestMatching(Collection<VersionNumber> versions, VersionNumber toFind) {
    if (versions == null || versions.isEmpty()) {
        return null;
    }
    if (null == toFind) {
        return null;
    }
    List<VersionNumber> sortedVersions = new ArrayList<>(versions);
    Collections.sort(sortedVersions, SemverMatcher::compareLoose);
    int index = Collections.binarySearch(sortedVersions, toFind, SemverMatcher::compareLoose);
    if (index > 0) {
        return sortedVersions.get(index);
    }
    VersionNumber current = null;
    for (VersionNumber v : sortedVersions) {
        VersionNumberRelation relation = SemverMatcher.relation(toFind, v);
        if (relation.isGreaterOrEqual()) {
            current = v;
        }
    }
    return current;
}
Also used : VersionNumberRelation(org.eclipse.n4js.semver.SemverMatcher.VersionNumberRelation) ArrayList(java.util.ArrayList) VersionNumber(org.eclipse.n4js.semver.Semver.VersionNumber) VersionRangeConstraint(org.eclipse.n4js.semver.Semver.VersionRangeConstraint)

Example 18 with VersionNumber

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

the class SemverUtils method createVersionRangeSet.

/**
 * Creates a new instance of {@link VersionRangeSetRequirement} with the given properties.
 */
public static VersionRangeSetRequirement createVersionRangeSet(VersionComparator comparator, VersionNumber version) {
    VersionNumber versionNumber = copyVersionNumber(version);
    SimpleVersion simpleVersion = SemverFactory.eINSTANCE.createSimpleVersion();
    simpleVersion.setNumber(versionNumber);
    simpleVersion.getComparators().add(comparator);
    VersionRangeConstraint versionRangeConstraint = SemverFactory.eINSTANCE.createVersionRangeConstraint();
    versionRangeConstraint.getVersionConstraints().add(simpleVersion);
    VersionRangeSetRequirement versionRangeSet = SemverFactory.eINSTANCE.createVersionRangeSetRequirement();
    versionRangeSet.getRanges().add(versionRangeConstraint);
    return versionRangeSet;
}
Also used : VersionRangeConstraint(org.eclipse.n4js.semver.Semver.VersionRangeConstraint) VersionRangeSetRequirement(org.eclipse.n4js.semver.Semver.VersionRangeSetRequirement) SimpleVersion(org.eclipse.n4js.semver.Semver.SimpleVersion) VersionNumber(org.eclipse.n4js.semver.Semver.VersionNumber)

Example 19 with VersionNumber

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

the class SemverUtils method createVersionNumber.

static VersionNumber createVersionNumber(VersionNumberDescriptor descriptor) {
    VersionNumber versNumber = SemverFactory.eINSTANCE.createVersionNumber();
    VersionPart fromMajor = SemverFactory.eINSTANCE.createVersionPart();
    fromMajor.setNumberRaw(descriptor.major);
    versNumber.setMajor(fromMajor);
    if (descriptor.minor != null) {
        VersionPart fromMinor = SemverFactory.eINSTANCE.createVersionPart();
        fromMinor.setNumberRaw(descriptor.minor);
        versNumber.setMinor(fromMinor);
    }
    if (descriptor.patch != null) {
        VersionPart fromPatch = SemverFactory.eINSTANCE.createVersionPart();
        fromPatch.setNumberRaw(descriptor.patch);
        versNumber.setPatch(fromPatch);
    }
    if (descriptor.preReleaseParts != null || descriptor.buildMetadataParts != null) {
        Qualifier qualifier = SemverFactory.eINSTANCE.createQualifier();
        versNumber.setQualifier(qualifier);
        if (descriptor.preReleaseParts != null) {
            QualifierTag prQualifierTag = SemverFactory.eINSTANCE.createQualifierTag();
            prQualifierTag.getParts().addAll(Arrays.asList(descriptor.preReleaseParts));
            qualifier.setPreRelease(prQualifierTag);
        }
        if (descriptor.buildMetadataParts != null) {
            QualifierTag bmQualifierTag = SemverFactory.eINSTANCE.createQualifierTag();
            bmQualifierTag.getParts().addAll(Arrays.asList(descriptor.buildMetadataParts));
            qualifier.setBuildMetadata(bmQualifierTag);
        }
    }
    return versNumber;
}
Also used : VersionPart(org.eclipse.n4js.semver.Semver.VersionPart) QualifierTag(org.eclipse.n4js.semver.Semver.QualifierTag) Qualifier(org.eclipse.n4js.semver.Semver.Qualifier) VersionNumber(org.eclipse.n4js.semver.Semver.VersionNumber)

Aggregations

VersionNumber (org.eclipse.n4js.semver.Semver.VersionNumber)19 SimpleVersion (org.eclipse.n4js.semver.Semver.SimpleVersion)4 VersionRangeConstraint (org.eclipse.n4js.semver.Semver.VersionRangeConstraint)4 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)3 VersionNumberDescriptor (org.eclipse.n4js.semver.SemverUtils.VersionNumberDescriptor)3 Qualifier (org.eclipse.n4js.semver.Semver.Qualifier)2 QualifierTag (org.eclipse.n4js.semver.Semver.QualifierTag)2 VersionPart (org.eclipse.n4js.semver.Semver.VersionPart)2 VersionRangeSetRequirement (org.eclipse.n4js.semver.Semver.VersionRangeSetRequirement)2 ArrayList (java.util.ArrayList)1 EPackage (org.eclipse.emf.ecore.EPackage)1 NameValuePair (org.eclipse.n4js.json.JSON.NameValuePair)1 ProjectDescription (org.eclipse.n4js.packagejson.projectDescription.ProjectDescription)1 SourceContainerDescription (org.eclipse.n4js.packagejson.projectDescription.SourceContainerDescription)1 GitHubVersionRequirement (org.eclipse.n4js.semver.Semver.GitHubVersionRequirement)1 HyphenVersionRange (org.eclipse.n4js.semver.Semver.HyphenVersionRange)1 LocalPathVersionRequirement (org.eclipse.n4js.semver.Semver.LocalPathVersionRequirement)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