diff --git a/src/main/java/org/jabref/gui/desktop/os/DefaultDesktop.java b/src/main/java/org/jabref/gui/desktop/os/DefaultDesktop.java index 86d97fb45ae..30f651bbbbd 100644 --- a/src/main/java/org/jabref/gui/desktop/os/DefaultDesktop.java +++ b/src/main/java/org/jabref/gui/desktop/os/DefaultDesktop.java @@ -6,14 +6,19 @@ import java.nio.file.Path; import org.jabref.architecture.AllowedToUseAwt; +import org.jabref.cli.Launcher; import org.jabref.gui.DialogService; -import org.slf4j.Logger; import org.slf4j.LoggerFactory; +/** + * This class contains some default implementations (if OS is neither linux, windows or osx) file directories and file/application open handling methods
+ * We cannot use a static logger instance here in this class as the Logger first needs to be configured in the {@link Launcher#addLogToDisk} + * The configuration of tinylog will become immutable as soon as the first log entry is issued. + * https://tinylog.org/v2/configuration/ + **/ @AllowedToUseAwt("Requires AWT to open a file") public class DefaultDesktop implements NativeDesktop { - private static final Logger LOGGER = LoggerFactory.getLogger(NativeDesktop.class); @Override public void openFile(String filePath, String fileType) throws IOException { @@ -33,7 +38,7 @@ public void openFolderAndSelectFile(Path filePath) throws IOException { @Override public void openConsole(String absolutePath, DialogService dialogService) throws IOException { - LOGGER.error("This feature is not supported by your Operating System."); + LoggerFactory.getLogger(DefaultDesktop.class).error("This feature is not supported by your Operating System."); } @Override diff --git a/src/main/java/org/jabref/gui/desktop/os/Linux.java b/src/main/java/org/jabref/gui/desktop/os/Linux.java index f3c3c3e3b4f..a81a81bca55 100644 --- a/src/main/java/org/jabref/gui/desktop/os/Linux.java +++ b/src/main/java/org/jabref/gui/desktop/os/Linux.java @@ -12,6 +12,7 @@ import java.util.Optional; import org.jabref.architecture.AllowedToUseAwt; +import org.jabref.cli.Launcher; import org.jabref.gui.DialogService; import org.jabref.gui.Globals; import org.jabref.gui.JabRefExecutorService; @@ -20,30 +21,33 @@ import org.jabref.gui.util.StreamGobbler; import org.jabref.logic.l10n.Localization; -import org.slf4j.Logger; import org.slf4j.LoggerFactory; +/** + * This class contains Linux specific implementations for file directories and file/application open handling methods
+ * We cannot use a static logger instance here in this class as the Logger first needs to be configured in the {@link Launcher#addLogToDisk} + * The configuration of tinylog will become immutable as soon as the first log entry is issued. + * https://tinylog.org/v2/configuration/ + **/ @AllowedToUseAwt("Requires AWT to open a file with the native method") public class Linux implements NativeDesktop { - private static final Logger LOGGER = LoggerFactory.getLogger(Linux.class); - private void nativeOpenFile(String filePath) { JabRefExecutorService.INSTANCE.execute(() -> { try { File file = new File(filePath); Desktop.getDesktop().open(file); - LOGGER.debug("Open file in default application with Desktop integration"); + LoggerFactory.getLogger(Linux.class).debug("Open file in default application with Desktop integration"); } catch (IllegalArgumentException e) { - LOGGER.debug("Fail back to xdg-open"); + LoggerFactory.getLogger(Linux.class).debug("Fail back to xdg-open"); try { String[] cmd = {"xdg-open", filePath}; Runtime.getRuntime().exec(cmd); } catch (Exception e2) { - LOGGER.warn("Open operation not successful: " + e2); + LoggerFactory.getLogger(Linux.class).warn("Open operation not successful: ", e2); } } catch (IOException e) { - LOGGER.warn("Native open operation not successful: " + e); + LoggerFactory.getLogger(Linux.class).warn("Native open operation not successful: ", e); } }); } @@ -57,8 +61,8 @@ public void openFile(String filePath, String fileType) throws IOException { viewer = type.get().getOpenWithApplication(); ProcessBuilder processBuilder = new ProcessBuilder(viewer, filePath); Process process = processBuilder.start(); - StreamGobbler streamGobblerInput = new StreamGobbler(process.getInputStream(), LOGGER::debug); - StreamGobbler streamGobblerError = new StreamGobbler(process.getErrorStream(), LOGGER::debug); + StreamGobbler streamGobblerInput = new StreamGobbler(process.getInputStream(), LoggerFactory.getLogger(Linux.class)::debug); + StreamGobbler streamGobblerError = new StreamGobbler(process.getErrorStream(), LoggerFactory.getLogger(Linux.class)::debug); JabRefExecutorService.INSTANCE.execute(streamGobblerInput); JabRefExecutorService.INSTANCE.execute(streamGobblerError); @@ -80,8 +84,8 @@ public void openFileWithApplication(String filePath, String application) throws ProcessBuilder processBuilder = new ProcessBuilder(cmdArray); Process process = processBuilder.start(); - StreamGobbler streamGobblerInput = new StreamGobbler(process.getInputStream(), LOGGER::debug); - StreamGobbler streamGobblerError = new StreamGobbler(process.getErrorStream(), LOGGER::debug); + StreamGobbler streamGobblerInput = new StreamGobbler(process.getInputStream(), LoggerFactory.getLogger(Linux.class)::debug); + StreamGobbler streamGobblerError = new StreamGobbler(process.getErrorStream(), LoggerFactory.getLogger(Linux.class)::debug); JabRefExecutorService.INSTANCE.execute(streamGobblerInput); JabRefExecutorService.INSTANCE.execute(streamGobblerError); @@ -112,8 +116,8 @@ public void openFolderAndSelectFile(Path filePath) throws IOException { ProcessBuilder processBuilder = new ProcessBuilder(cmd); Process process = processBuilder.start(); - StreamGobbler streamGobblerInput = new StreamGobbler(process.getInputStream(), LOGGER::debug); - StreamGobbler streamGobblerError = new StreamGobbler(process.getErrorStream(), LOGGER::debug); + StreamGobbler streamGobblerInput = new StreamGobbler(process.getInputStream(), LoggerFactory.getLogger(Linux.class)::debug); + StreamGobbler streamGobblerError = new StreamGobbler(process.getErrorStream(), LoggerFactory.getLogger(Linux.class)::debug); JabRefExecutorService.INSTANCE.execute(streamGobblerInput); JabRefExecutorService.INSTANCE.execute(streamGobblerError); @@ -150,8 +154,8 @@ public void openConsole(String absolutePath, DialogService dialogService) throws builder.directory(new File(absolutePath)); Process processTerminal = builder.start(); - StreamGobbler streamGobblerInput = new StreamGobbler(processTerminal.getInputStream(), LOGGER::debug); - StreamGobbler streamGobblerError = new StreamGobbler(processTerminal.getErrorStream(), LOGGER::debug); + StreamGobbler streamGobblerInput = new StreamGobbler(processTerminal.getInputStream(), LoggerFactory.getLogger(Linux.class)::debug); + StreamGobbler streamGobblerError = new StreamGobbler(processTerminal.getErrorStream(), LoggerFactory.getLogger(Linux.class)::debug); JabRefExecutorService.INSTANCE.execute(streamGobblerInput); JabRefExecutorService.INSTANCE.execute(streamGobblerError); diff --git a/src/main/java/org/jabref/gui/desktop/os/OSX.java b/src/main/java/org/jabref/gui/desktop/os/OSX.java index ece1d553d56..ccd0ca56f92 100644 --- a/src/main/java/org/jabref/gui/desktop/os/OSX.java +++ b/src/main/java/org/jabref/gui/desktop/os/OSX.java @@ -5,11 +5,18 @@ import java.util.Optional; import org.jabref.architecture.AllowedToUseAwt; +import org.jabref.cli.Launcher; import org.jabref.gui.DialogService; import org.jabref.gui.Globals; import org.jabref.gui.externalfiletype.ExternalFileType; import org.jabref.gui.externalfiletype.ExternalFileTypes; +/** + * This class contains macOS (OSX) specific implementations for file directories and file/application open handling methods
+ * We cannot use a static logger instance here in this class as the Logger first needs to be configured in the {@link Launcher#addLogToDisk} + * The configuration of tinylog will become immutable as soon as the first log entry is issued. + * https://tinylog.org/v2/configuration/ + **/ @AllowedToUseAwt("Requires AWT to open a file") public class OSX implements NativeDesktop { diff --git a/src/main/java/org/jabref/gui/desktop/os/Windows.java b/src/main/java/org/jabref/gui/desktop/os/Windows.java index 7e5c2069703..e559f7dd033 100644 --- a/src/main/java/org/jabref/gui/desktop/os/Windows.java +++ b/src/main/java/org/jabref/gui/desktop/os/Windows.java @@ -6,6 +6,7 @@ import java.nio.file.Path; import java.util.Optional; +import org.jabref.cli.Launcher; import org.jabref.gui.DialogService; import org.jabref.gui.Globals; import org.jabref.gui.externalfiletype.ExternalFileType; @@ -17,6 +18,12 @@ import com.sun.jna.platform.win32.Win32Exception; import org.slf4j.LoggerFactory; +/** + * This class contains Windows specific implementations for file directories and file/application open handling methods
+ * We cannot use a static logger instance here in this class as the Logger first needs to be configured in the {@link Launcher#addLogToDisk} + * The configuration of tinylog will become immutable as soon as the first log entry is issued. + * https://tinylog.org/v2/configuration/ + **/ public class Windows implements NativeDesktop { private static final String DEFAULT_EXECUTABLE_EXTENSION = ".exe";