Fixup #716 Calculate java home from java command (#721)

* Add a test
* Simplify the stream processing

Co-authored-by: Guillaume Nodet <gnodet@gmail.com>
This commit is contained in:
Peter Palaga
2022-12-14 00:35:10 +01:00
committed by GitHub
parent 2b8076d1ed
commit 031c263232
3 changed files with 31 additions and 12 deletions

View File

@@ -139,7 +139,8 @@ public class DaemonParameters {
.orLocalProperty(provider, globalPropertiesPath())
.orSystemProperty()
.orEnvironmentVariable()
.or(new ValueSource(description -> description.append("java command"), this::javaHomeFromPath))
.or(new ValueSource(
description -> description.append("java command"), DaemonParameters::javaHomeFromPath))
.orFail()
.asPath();
try {
@@ -149,8 +150,12 @@ public class DaemonParameters {
}
}
private String javaHomeFromPath() {
final String jHome = OsUtils.findJavaHomeFromPath();
private static String javaHomeFromPath() {
LOG.warn(
"Falling back to finding JAVA_HOME by running java executable available in PATH."
+ " You may want to avoid this time consumig task by setting JAVA_HOME environment variable"
+ " or by passing java.home system property through command line or in one of mvnd configuration files.");
final String jHome = OsUtils.findJavaHomeFromJavaExecutable("java");
if (null != jHome) {
System.setProperty(Environment.JAVA_HOME.getProperty(), jHome);
}