Skip to content

Instantly share code, notes, and snippets.

@gastaldi
Created September 20, 2012 14:17
Show Gist options
  • Select an option

  • Save gastaldi/3756211 to your computer and use it in GitHub Desktop.

Select an option

Save gastaldi/3756211 to your computer and use it in GitHub Desktop.
/**
* This method only returns true if:
*
* The major version of pluginApiVersion is equal to the major version of runtimeVersion AND
*
* The minor version of pluginApiVersion is less or equal to the minor version of runtimeVersion
*
* @param runtimeVersion a version in the format x.x.x
* @param pluginApiVersion a version in the format x.x.x
* @return
*/
public static boolean isApiCompatible(CharSequence runtimeVersion, String pluginApiVersion)
{
Matcher runtimeMatcher = VERSION_PATTERN.matcher(runtimeVersion);
if (runtimeMatcher.matches())
{
int runtimeMajorVersion = Integer.parseInt(runtimeMatcher.group(1));
int runtimeMinorVersion = Integer.parseInt(runtimeMatcher.group(2));
Matcher pluginApiMatcher = VERSION_PATTERN.matcher(pluginApiVersion);
if (pluginApiMatcher.matches())
{
int pluginApiMajorVersion = Integer.parseInt(pluginApiMatcher.group(1));
int pluginApiMinorVersion = Integer.parseInt(pluginApiMatcher.group(2));
if (pluginApiMajorVersion == runtimeMajorVersion && pluginApiMinorVersion <= runtimeMinorVersion)
{
return true;
}
}
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment