Skip to content

Commit

Permalink
Merge pull request #406 from ascopes/task/noisy-logging
Browse files Browse the repository at this point in the history
Remove noisy logging in SystemPathBinaryResolver.java
  • Loading branch information
ascopes authored Sep 28, 2024
2 parents 34a0b87 + 8577ce2 commit 5d07f98
Showing 1 changed file with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,32 +46,29 @@ public SystemPathBinaryResolver(HostSystem hostSystem) {
}

public Optional<Path> resolve(String name) throws ResolutionException {
log.debug("Looking for executable matching name '{}' on the path", name);

log.debug("Looking for executable matching name '{}' on PATH", name);
var predicate = hostSystem.isProbablyWindows()
? isWindowsMatch(name)
: isPosixMatch(name);

var result = Optional.<Path>empty();

for (var dir : hostSystem.getSystemPath()) {
try (var files = Files.walk(dir, 1)) {
result = files.filter(predicate).findFirst();
var result = files.filter(predicate).findFirst();

if (result.isPresent()) {
break;
log.debug("Result for lookup of '{}' on PATH was {}", name, result.get());
return result;
}
} catch (IOException ex) {
throw new ResolutionException("An exception occurred while scanning the system PATH", ex);
}
}

log.debug("Result for lookup of '{}' was {}", name, result);
return result;
log.debug("No match found for '{}' on PATH", name);
return Optional.empty();
}

private Predicate<Path> isWindowsMatch(String name) {
log.debug("Using Windows path matching strategy");
return path -> {
var matchesName = FileUtils.getFileNameWithoutExtension(path)
.equalsIgnoreCase(name);
Expand All @@ -81,7 +78,7 @@ private Predicate<Path> isWindowsMatch(String name) {
.isPresent();

log.debug(
"Path '{}' (WINDOWS) matches name = {}, matches executable extension = {}",
"Path '{}' matches name = {}, matches executable extension = {}",
path,
matchesName,
matchesExtension
Expand All @@ -92,13 +89,12 @@ private Predicate<Path> isWindowsMatch(String name) {
}

private Predicate<Path> isPosixMatch(String name) {
log.debug("Using POSIX path matching strategy");
return path -> {
var matchesName = path.getFileName().toString().equals(name);
var matchesExecutableFlag = Files.isExecutable(path);

log.debug(
"Path '{}' (POSIX) matches name = {}, matches executable flag = {}",
"Path '{}' matches name = {}, matches executable flag = {}",
path,
matchesName,
matchesExecutableFlag
Expand Down

0 comments on commit 5d07f98

Please sign in to comment.