com.heroku.sdk.deploy.lib.resolver.JdkVersionResolver Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of heroku-deploy Show documentation
Show all versions of heroku-deploy Show documentation
Library for deploying Java applications to Heroku
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"));
}
}