本文整理汇总了Java中com.github.zafarkhaja.semver.Version.getMajorVersion方法的典型用法代码示例。如果您正苦于以下问题:Java Version.getMajorVersion方法的具体用法?Java Version.getMajorVersion怎么用?Java Version.getMajorVersion使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.github.zafarkhaja.semver.Version
的用法示例。
在下文中一共展示了Version.getMajorVersion方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: inferScope
import com.github.zafarkhaja.semver.Version; //导入方法依赖的package包/类
public static Optional<Scope> inferScope(Version before, Version after) {
int major = after.getMajorVersion() - before.getMajorVersion();
int minor = after.getMinorVersion() - before.getMinorVersion();
int patch = after.getPatchVersion() - before.getPatchVersion();
if (major == 1 && after.getMinorVersion() == 0 && after.getPatchVersion() == 0) {
return Optional.of(Scope.MAJOR);
} else if (major == 0 && minor == 1 && after.getPatchVersion() == 0) {
return Optional.of(Scope.MINOR);
} else if (major == 0 && minor == 0 && patch == 1) {
return Optional.of(Scope.PATCH);
} else {
logger.debug(
"Invalid increment between the following versions. Cannot infer scope between: {} -> {}",
before,
after);
return Optional.empty();
}
}
示例2: determineVersionChange
import com.github.zafarkhaja.semver.Version; //导入方法依赖的package包/类
/**
* Determines change between two versions
* @param versionStr0 first version string
* @param versionStr1 second version string
* @return version change, one of ["major", "minor", "patch"] or null if some error occurs
*/
public static String determineVersionChange(String versionStr0, String versionStr1) {
Version v0 = VersionWrapper.valueOf(versionStr0);
Version v1 = VersionWrapper.valueOf(versionStr1);
if (v0.getMajorVersion() < v1.getMajorVersion()) {
return CHANGE_MAJOR;
}
else if (v0.getMajorVersion() == v1.getMajorVersion()) {
if (v0.getMinorVersion() < v1.getMinorVersion()) {
return CHANGE_MINOR;
} else if (v0.getMinorVersion() == v1.getMinorVersion()) {
if (v0.getPatchVersion() < v1.getPatchVersion()) {
return CHANGE_PATCH;
} else if (v0.getPatchVersion() == v1.getPatchVersion()) {
if (!v1.getBuildMetadata().isEmpty()) // subpatch levels are encoded by build meta data through VersionWrapper
return CHANGE_PATCH;
} else
return null;
}
}
return null;
}
示例3: dbNeedsMigration
import com.github.zafarkhaja.semver.Version; //导入方法依赖的package包/类
/**
*
* @return {@code true} if there is <b>nothing</b> to do.
*/
public boolean dbNeedsMigration()
{
final Version dbVersion = Version.valueOf(dbVersionStr);
logger.info("AD_System.DBVersion is {}", dbVersion);
final Version rolloutVersion = Version.valueOf(rolloutVersionStr);
logger.info("Our own version is {}", rolloutVersion);
final int comp = dbVersion.compareTo(rolloutVersion);
if (comp == 0)
{
logger.info("AD_System.DBVersion is equal to our version. Nothing to do.");
return false;
}
else if (comp < 0)
{
// dbVersion is lower than rolloutVersion
// => we need to do the migration to "elevate" it
logger.info("The DB version is lower than our own version. Going to migrate");
return true;
}
// Check if we have the special case of issue https://github.com/metasfresh/metasfresh/issues/2260
final boolean sameMajorVersion = dbVersion.getMajorVersion() == rolloutVersion.getMajorVersion();
final boolean sameMinorVersion = dbVersion.getMinorVersion() == rolloutVersion.getMinorVersion();
final boolean patchVersionSwitchBetweenOneAndTwo = //
dbVersion.getPatchVersion() == 1 && rolloutVersion.getPatchVersion() == 2 //
|| dbVersion.getPatchVersion() == 2 && rolloutVersion.getPatchVersion() == 1;
if (sameMajorVersion
&& sameMinorVersion
&& patchVersionSwitchBetweenOneAndTwo)
{
logger.info("Detected a version switch between master (=> patchVersion=1) and release, issue etc (=> patchVersion=2). Assuming that the DB needs migration. Also see https://github.com/metasfresh/metasfresh/issues/2260");
return true;
}
// check if we have a switch between two non-master branches
if(!Objects.equals(dbVersion.getBuildMetadata(), rolloutVersion.getBuildMetadata()))
{
logger.info("Detected a version switch between \"branches\" dbVersion={} and rolloutVersion={}. Assuming that the DB needs migration. Also see https://github.com/metasfresh/metasfresh/issues/2260",
dbVersion.getPreReleaseVersion(), rolloutVersion.getPreReleaseVersion());
return true;
}
// Issue https://github.com/metasfresh/metasfresh/issues/2260 does not apply..
// dbVersion higher....uh-ooh
final String msg = "The code has version " + rolloutVersionStr + " but the DB already has version " + dbVersionStr;
if (!failIfRolloutIsGreaterThanDB)
{
// let's ignore the problem
logger.info(msg + ". *Not* throwing exception because of the +" + CommandlineParams.OPTION_DoNotFailIfRolloutIsGreaterThanDB + " parameter; but not going to attempt migration either.");
return false;
}
throw new InconsistentVersionsException(msg);
}