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

com.heroku.sdk.deploy.lib.resolver.JdkVersionResolver Maven / Gradle / Ivy

There is a newer version: 3.0.7
Show newest version
package com.heroku.sdk.deploy.lib.resolver;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Optional;
import java.util.Properties;
import java.util.function.Supplier;

public class JdkVersionResolver {

    public static Optional resolve(Path projectDirectory, Supplier> customResolver) throws IOException {
        Optional customResolverJdkVersion = customResolver.get();
        if (customResolverJdkVersion.isPresent()) {
            return customResolverJdkVersion;
        }

        Optional systemPropertiesAppName = resolveViaSystemProperty();
        if (systemPropertiesAppName.isPresent()) {
            return systemPropertiesAppName;
        }

        return resolveViaSystemPropertiesFile(projectDirectory);
    }

    private static Optional resolveViaSystemProperty() {
        return Optional.ofNullable(System.getProperty("heroku.jdkVersion"));
    }

    private static Optional resolveViaSystemPropertiesFile(Path projectDirectory) throws IOException {
        Properties properties = new Properties();

        try {
            properties.load(new FileInputStream(projectDirectory.resolve("system.properties").toFile()));
        } catch (FileNotFoundException e) {
            return Optional.empty();
        }

        return Optional.ofNullable(properties.getProperty("java.runtime.version"));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy