From 8880de04d00697c9faa0f9cd7be36342c3f5dff3 Mon Sep 17 00:00:00 2001 From: Naofal Date: Thu, 13 Nov 2025 20:53:19 +0300 Subject: [PATCH] fix standard output and console detection --- nobuild/NoBuild.java | 10 +++++----- src/main/java/xyz/naofal/jtags/Jtags.java | 1 + src/main/java/xyz/naofal/jtags/JtagsLogger.java | 3 ++- src/test/java/notest/Test.java | 3 +-- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/nobuild/NoBuild.java b/nobuild/NoBuild.java index 4d469c2..62a206e 100644 --- a/nobuild/NoBuild.java +++ b/nobuild/NoBuild.java @@ -46,6 +46,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.Optional; import java.util.logging.Handler; import java.util.logging.Level; import java.util.logging.LogRecord; @@ -154,7 +155,7 @@ public class NoBuild { @Override public void publish(LogRecord record) { if (record.getMessage() != null && !record.getMessage().isEmpty()) { - if (System.console().isTerminal()) { + if (Optional.ofNullable(System.console()).map(it -> it.isTerminal()).orElse(false)) { int color = colors.get(record.getLevel()); System.err.printf( "\u001b[38;5;%dm[%s]\u001b[0m %s%n", @@ -386,10 +387,9 @@ public class NoBuild { PathMatcher pathMatcher = FileSystems.getDefault() .getPathMatcher(String.join("", "glob:", cwd.toString(), File.separator, globPattern)); - try (@SuppressWarnings("unused") - Stream paths = - Files.find( - cwd, Integer.MAX_VALUE, (path, basicFileAttributes) -> pathMatcher.matches(path))) { + try (Stream paths = + Files.find( + cwd, Integer.MAX_VALUE, (path, basicFileAttributes) -> pathMatcher.matches(path))) { return paths.map(Path::toString).toArray(String[]::new); } catch (IOException e) { return new String[0]; diff --git a/src/main/java/xyz/naofal/jtags/Jtags.java b/src/main/java/xyz/naofal/jtags/Jtags.java index 80f3dbe..aaf1702 100644 --- a/src/main/java/xyz/naofal/jtags/Jtags.java +++ b/src/main/java/xyz/naofal/jtags/Jtags.java @@ -106,6 +106,7 @@ public class Jtags { System.exit(1); yield null; } + case "-" -> Path.of("-"); case String output -> Path.of(output).toAbsolutePath(); }; logger.config("Writing tags to " + options.output.toString()); diff --git a/src/main/java/xyz/naofal/jtags/JtagsLogger.java b/src/main/java/xyz/naofal/jtags/JtagsLogger.java index 187c050..f5fd121 100644 --- a/src/main/java/xyz/naofal/jtags/JtagsLogger.java +++ b/src/main/java/xyz/naofal/jtags/JtagsLogger.java @@ -2,6 +2,7 @@ package xyz.naofal.jtags; import java.util.HashMap; import java.util.Map; +import java.util.Optional; import java.util.logging.Handler; import java.util.logging.Level; import java.util.logging.LogRecord; @@ -47,7 +48,7 @@ public class JtagsLogger { @Override public void publish(LogRecord record) { if (record.getMessage() != null && !record.getMessage().isEmpty()) { - if (System.console().isTerminal()) { + if (Optional.ofNullable(System.console()).map(it->it.isTerminal()).orElse(false)) { int color = colors.get(record.getLevel()); System.err.printf( "\u001b[38;5;%dm[%s]\u001b[0m %s%n", diff --git a/src/test/java/notest/Test.java b/src/test/java/notest/Test.java index 71adcc0..6b8b6d6 100644 --- a/src/test/java/notest/Test.java +++ b/src/test/java/notest/Test.java @@ -76,8 +76,7 @@ public @interface Test { case "-u", "-update-snapshots": options.updateSnapshots = true; break; - case null: - default: + case null, default: break; }