Skip to content

Commit 46406f7

Browse files
committed
#2: Handle cases where there are multiple java executables available.
1 parent abe4a73 commit 46406f7

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/lib.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,9 @@ At your option, under:
8585
* Apache License, Version 2.0, (http://www.apache.org/licenses/LICENSE-2.0)
8686
* MIT license (http://opensource.org/licenses/MIT)
8787
88-
*/
88+
*/
8989

9090
use std::env;
91-
use std::error::Error;
9291
use std::path::PathBuf;
9392
use std::process::Command;
9493

@@ -190,10 +189,21 @@ fn do_locate_java_home() -> errors::Result<String> {
190189
}
191190

192191
let output = command.output().map_err(|error| {
193-
let message = format!("Command '{}' is not found in the system PATH ({})", command_str, error.description());
192+
let message = format!("Command '{}' is not found in the system PATH ({})", command_str, error);
194193
errors::JavaLocatorError::new(&message)
195194
})?;
196-
let java_exec_path = String::from_utf8(output.stdout)?;
195+
let java_exec_path = String::from_utf8(output.stdout)
196+
.map(|jp| {
197+
let mut lines: Vec<&str> = jp.lines().collect();
198+
if lines.len() > 1 {
199+
println!("WARNING: java_locator found {} possible java locations: {}. Using the last one.",
200+
lines.len(),
201+
lines.join(", "));
202+
lines.remove(lines.len() - 1).to_string()
203+
} else {
204+
jp
205+
}
206+
})?;
197207

198208
// Return early in case that the java executable is not found
199209
if java_exec_path.is_empty() {

0 commit comments

Comments
 (0)