Search in sources :

Example 11 with ComparableVersion

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()));
    }
}
Also used : AzureToolkitRuntimeException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException) IOException(java.io.IOException) ComparableVersion(org.apache.maven.artifact.versioning.ComparableVersion) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)

Example 12 with ComparableVersion

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;
}
Also used : Matcher(java.util.regex.Matcher) ComparableVersion(org.apache.maven.artifact.versioning.ComparableVersion) File(java.io.File) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)

Example 13 with ComparableVersion

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;
}
Also used : ComparableVersion(org.apache.maven.artifact.versioning.ComparableVersion)

Aggregations

ComparableVersion (org.apache.maven.artifact.versioning.ComparableVersion)13 IOException (java.io.IOException)4 InputStream (java.io.InputStream)4 ArrayList (java.util.ArrayList)4 Matcher (java.util.regex.Matcher)4 File (java.io.File)3 List (java.util.List)3 AzureOperation (com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)2 URL (java.net.URL)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Set (java.util.Set)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Collectors (java.util.stream.Collectors)2 ProjectDependency (meghanada.project.ProjectDependency)2 LogManager (org.apache.logging.log4j.LogManager)2 Logger (org.apache.logging.log4j.Logger)2 DomainObjectSet (org.gradle.tooling.model.DomainObjectSet)2