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.");
}
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;
}
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;
}
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;
}
Aggregations