All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sap.cds.impl.parser.VersionParser Maven / Gradle / Ivy

There is a newer version: 3.8.0
Show newest version
package com.sap.cds.impl.parser;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.sap.cds.reflect.impl.CdsVersion;

/**
 * Parses and returns the comparable version object. Supported version patterns
 * are:
* 1.22.333 - simple version,
* 01.022.0333 - leading zeroes are ignored,
* 1.22.033-ms.4 - milestone build number * */ public class VersionParser { private static final String VERSION_PATTERN = "(\\d+)\\.(\\d+)\\.(\\d+)(?:\\-[ms]{2}\\.(\\d+))?"; public static CdsVersion parse(String versionString) { Pattern pattern = Pattern.compile(VERSION_PATTERN); Matcher matcher = pattern.matcher(versionString); if (!matcher.matches()) { throw new IllegalArgumentException(String.format("Unable to parse version string '%s'", versionString)); } int major = Integer.valueOf(matcher.group(1)); int minor = Integer.valueOf(matcher.group(2)); int micro = Integer.valueOf(matcher.group(3)); int buildNumber = matcher.group(4) == null ? 0 : Integer.valueOf(matcher.group(4)); return new CdsVersion(major, minor, micro, buildNumber); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy