use of org.apache.maven.artifact.versioning.ComparableVersion in project azure-tools-for-java by Microsoft.
the class FunctionRunState method validateFunctionRuntime.
@AzureOperation(name = "function.validate_runtime", params = { "this.functionRunConfiguration.getFuncPath()" }, type = AzureOperation.Type.TASK)
private void validateFunctionRuntime(RunProcessHandler processHandler) {
try {
final String funcPath = functionRunConfiguration.getFuncPath();
if (StringUtils.isEmpty(funcPath)) {
throw new AzureToolkitRuntimeException(message("function.run.error.runtimeNotFound"));
}
final ComparableVersion funcVersion = getFuncVersion();
if (funcVersion == null) {
throw new AzureToolkitRuntimeException(message("function.run.error.runtimeNotFound"));
}
final ComparableVersion javaVersion = getJavaVersion();
if (javaVersion == null) {
processHandler.setText(message("function.run.error.getJavaVersionFailed"));
return;
}
if (javaVersion.compareTo(JAVA_9) < 0) {
// No need validate function host version within java 8 or earlier
return;
}
final ComparableVersion minimumVersion = funcVersion.compareTo(FUNC_3) >= 0 ? MINIMUM_JAVA_9_SUPPORTED_VERSION : MINIMUM_JAVA_9_SUPPORTED_VERSION_V2;
if (funcVersion.compareTo(minimumVersion) < 0) {
throw new AzureToolkitRuntimeException(message("function.run.error.funcOutOfDate"));
}
} catch (IOException e) {
throw new AzureToolkitRuntimeException(message("function.run.error.validateRuntimeFailed", e.getMessage()));
}
}
use of org.apache.maven.artifact.versioning.ComparableVersion in project azure-tools-for-java by Microsoft.
the class FunctionRunState method getJavaVersion.
// Get java runtime version following the strategy of function core tools
// Get java version of JAVA_HOME first, fall back to use PATH if JAVA_HOME not exists
@AzureOperation(name = "function.validate_jre", type = AzureOperation.Type.TASK)
private static ComparableVersion getJavaVersion() throws IOException {
final String javaHome = System.getenv("JAVA_HOME");
final File javaFile = StringUtils.isEmpty(javaHome) ? null : Paths.get(javaHome, "bin", "java").toFile();
final String executeFolder = javaFile == null ? null : javaFile.getParentFile().getAbsolutePath();
final String command = javaFile == null ? "java" : javaFile.getAbsolutePath();
final String javaVersion = CommandUtils.exec("java -version", executeFolder, true);
if (StringUtils.isEmpty(javaVersion)) {
return null;
}
final Matcher matcher = JAVA_VERSION_PATTERN.matcher(javaVersion);
return matcher.find() ? new ComparableVersion(matcher.group(1)) : null;
}
use of org.apache.maven.artifact.versioning.ComparableVersion in project cloudstack by apache.
the class HypervisorHostHelper method isVersionEqualOrHigher.
private static boolean isVersionEqualOrHigher(String check, String base) {
if (check == null || base == null) {
return false;
}
ComparableVersion baseVersion = new ComparableVersion(base);
ComparableVersion checkVersion = new ComparableVersion(check);
return checkVersion.compareTo(baseVersion) >= 0;
}
Aggregations