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 9f0996a3480..02608d60f7b 100644 --- a/src/main/java/org/jabref/gui/desktop/os/DefaultDesktop.java +++ b/src/main/java/org/jabref/gui/desktop/os/DefaultDesktop.java @@ -18,7 +18,7 @@ * https://tinylog.org/v2/configuration/ **/ @AllowedToUseAwt("Requires AWT to open a file") -public class DefaultDesktop implements NativeDesktop { +public class DefaultDesktop extends NativeDesktop { @Override public void openFile(String filePath, String fileType) throws IOException { 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 a115f04837e..7ff673136bd 100644 --- a/src/main/java/org/jabref/gui/desktop/os/Linux.java +++ b/src/main/java/org/jabref/gui/desktop/os/Linux.java @@ -31,7 +31,7 @@ * https://tinylog.org/v2/configuration/ **/ @AllowedToUseAwt("Requires AWT to open a file with the native method") -public class Linux implements NativeDesktop { +public class Linux extends NativeDesktop { private static final String ETC_ALTERNATIVES_X_TERMINAL_EMULATOR = "/etc/alternatives/x-terminal-emulator"; diff --git a/src/main/java/org/jabref/gui/desktop/os/NativeDesktop.java b/src/main/java/org/jabref/gui/desktop/os/NativeDesktop.java index 7c3441a24c4..2a7b50ea688 100644 --- a/src/main/java/org/jabref/gui/desktop/os/NativeDesktop.java +++ b/src/main/java/org/jabref/gui/desktop/os/NativeDesktop.java @@ -2,19 +2,34 @@ import java.io.File; import java.io.IOException; +import java.net.InetAddress; +import java.net.UnknownHostException; import java.nio.file.Files; import java.nio.file.Path; +import org.jabref.cli.Launcher; import org.jabref.gui.DialogService; import org.jabref.logic.util.BuildInfo; import org.jabref.logic.util.OS; import org.jabref.model.pdf.search.SearchFieldConstants; +import org.jabref.model.strings.StringUtil; import net.harawata.appdirs.AppDirsFactory; - -public interface NativeDesktop { - - void openFile(String filePath, String fileType) throws IOException; +import org.slf4j.LoggerFactory; + +/** + * This class contains bundles OS specific implementations for file directories and file/application open handling methods. + * In case the default does not work, subclasses provide the correct behavior. + * + *
+ * 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 abstract class NativeDesktop { + + public abstract void openFile(String filePath, String fileType) throws IOException; /** * Opens a file on an Operating System, using the given application. @@ -22,27 +37,27 @@ public interface NativeDesktop { * @param filePath The filename. * @param application Link to the app that opens the file. */ - void openFileWithApplication(String filePath, String application) throws IOException; + public abstract void openFileWithApplication(String filePath, String application) throws IOException; - void openFolderAndSelectFile(Path file) throws IOException; + public abstract void openFolderAndSelectFile(Path file) throws IOException; - void openConsole(String absolutePath, DialogService dialogService) throws IOException; + public abstract void openConsole(String absolutePath, DialogService dialogService) throws IOException; - String detectProgramPath(String programName, String directoryName); + public abstract String detectProgramPath(String programName, String directoryName); /** * Returns the path to the system's applications folder. * * @return the path to the applications folder. */ - Path getApplicationDirectory(); + public abstract Path getApplicationDirectory(); /** * Get the user's default file chooser directory * * @return The path to the directory */ - default Path getDefaultFileChooserDirectory() { + public Path getDefaultFileChooserDirectory() { Path userDirectory = getUserDirectory(); Path documents = userDirectory.resolve("Documents"); if (!Files.exists(documents)) { @@ -56,11 +71,11 @@ default Path getDefaultFileChooserDirectory() { * * @return the path to the user directory. */ - default Path getUserDirectory() { + public Path getUserDirectory() { return Path.of(System.getProperty("user.home")); } - default Path getLogDirectory() { + public Path getLogDirectory() { return Path.of(AppDirsFactory.getInstance() .getUserDataDir( OS.APP_DIR_APP_NAME, @@ -69,7 +84,7 @@ default Path getLogDirectory() { .resolve(new BuildInfo().version.toString()); } - default Path getBackupDirectory() { + public Path getBackupDirectory() { return Path.of(AppDirsFactory.getInstance() .getUserDataDir( OS.APP_DIR_APP_NAME, @@ -77,14 +92,14 @@ default Path getBackupDirectory() { OS.APP_DIR_APP_AUTHOR)); } - default Path getFulltextIndexBaseDirectory() { + public Path getFulltextIndexBaseDirectory() { return Path.of(AppDirsFactory.getInstance() .getUserDataDir(OS.APP_DIR_APP_NAME, "lucene" + File.separator + SearchFieldConstants.VERSION, OS.APP_DIR_APP_AUTHOR)); } - default Path getSslDirectory() { + public Path getSslDirectory() { return Path.of(AppDirsFactory.getInstance() .getUserDataDir(OS.APP_DIR_APP_NAME, "ssl", 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 de85b103eb6..84bad205b84 100644 --- a/src/main/java/org/jabref/gui/desktop/os/OSX.java +++ b/src/main/java/org/jabref/gui/desktop/os/OSX.java @@ -18,7 +18,7 @@ * https://tinylog.org/v2/configuration/ **/ @AllowedToUseAwt("Requires AWT to open a file") -public class OSX implements NativeDesktop { +public class OSX extends NativeDesktop { @Override public void openFile(String filePath, String fileType) throws IOException { 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 e559f7dd033..994bc785c90 100644 --- a/src/main/java/org/jabref/gui/desktop/os/Windows.java +++ b/src/main/java/org/jabref/gui/desktop/os/Windows.java @@ -24,7 +24,7 @@ * 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 { +public class Windows extends NativeDesktop { private static final String DEFAULT_EXECUTABLE_EXTENSION = ".exe";