From e874c67f8ca3cebc74dd877ced9005c7f065018c Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Wed, 10 Jul 2024 15:55:34 +0200 Subject: [PATCH] Fix detection of soffice.exe (#11478) * Fix dection of soffice.exe * Fix CHANGELOG.md * Fix typo * Add link to CHANGELOG.md * Fix dir detection --- CHANGELOG.md | 1 + .../DetectOpenOfficeInstallation.java | 2 +- .../gui/openoffice/OpenOfficePanel.java | 10 +++--- .../openoffice/OpenOfficeFileSearch.java | 34 +++++++++++-------- .../openoffice/OpenOfficePreferences.java | 2 +- 5 files changed, 28 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 31e42d92857..9c68cf0de4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv - We fixed an issue where JabRef was no longer built for Intel based macs (x86) [#11468](https://github.com/JabRef/jabref/issues/11468) - We fixed usage when using running on Snapcraft. [#11465](https://github.com/JabRef/jabref/issues/11465) +- We fixed detection for `soffice.exe` on Windows. [#11478](https://github.com/JabRef/jabref/pull/11478) ### Removed diff --git a/src/main/java/org/jabref/gui/openoffice/DetectOpenOfficeInstallation.java b/src/main/java/org/jabref/gui/openoffice/DetectOpenOfficeInstallation.java index 9ab8e25b623..1c987f4abc4 100644 --- a/src/main/java/org/jabref/gui/openoffice/DetectOpenOfficeInstallation.java +++ b/src/main/java/org/jabref/gui/openoffice/DetectOpenOfficeInstallation.java @@ -49,7 +49,7 @@ private boolean checkAutoDetectedPaths(OpenOfficePreferences openOfficePreferenc if (OS.LINUX && (System.getenv("FLATPAK_SANDBOX_DIR") != null)) { executablePath = OpenOfficePreferences.DEFAULT_LINUX_FLATPAK_EXEC_PATH; } - return !StringUtil.isNullOrEmpty(executablePath) && Files.exists(Path.of(executablePath)); + return !StringUtil.isNullOrEmpty(executablePath) && Files.isRegularFile(Path.of(executablePath)); } public boolean setOpenOfficePreferences(Path installDir) { diff --git a/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java b/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java index cc3226cf8dc..2f3096b95f1 100644 --- a/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java +++ b/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java @@ -318,12 +318,12 @@ protected List call() { }; taskConnectIfInstalled.setOnSucceeded(evt -> { - var installations = new ArrayList<>(taskConnectIfInstalled.getValue()); + List installations = new ArrayList<>(taskConnectIfInstalled.getValue()); if (installations.isEmpty()) { officeInstallation.selectInstallationPath().ifPresent(installations::add); } - Optional actualFile = officeInstallation.chooseAmongInstallations(installations); - if (actualFile.isPresent() && officeInstallation.setOpenOfficePreferences(actualFile.get())) { + Optional chosenInstallationDirectory = officeInstallation.chooseAmongInstallations(installations); + if (chosenInstallationDirectory.isPresent() && officeInstallation.setOpenOfficePreferences(chosenInstallationDirectory.get())) { connect(); } }); @@ -389,7 +389,7 @@ private void connect() { protected OOBibBase call() throws Exception { updateProgress(ProgressBar.INDETERMINATE_PROGRESS, ProgressBar.INDETERMINATE_PROGRESS); - var path = Path.of(preferencesService.getOpenOfficePreferences().getExecutablePath()); + Path path = Path.of(preferencesService.getOpenOfficePreferences().getExecutablePath()); return createBibBase(path); } }; @@ -399,7 +399,7 @@ protected OOBibBase call() throws Exception { ooBase.guiActionSelectDocument(true); - // Enable actions that depend on Connect: + // Enable actions that depend on a connection updateButtonAvailability(); }); diff --git a/src/main/java/org/jabref/logic/openoffice/OpenOfficeFileSearch.java b/src/main/java/org/jabref/logic/openoffice/OpenOfficeFileSearch.java index c20124f943d..9755e0fa3db 100644 --- a/src/main/java/org/jabref/logic/openoffice/OpenOfficeFileSearch.java +++ b/src/main/java/org/jabref/logic/openoffice/OpenOfficeFileSearch.java @@ -10,7 +10,6 @@ import java.util.List; import java.util.Locale; import java.util.function.BiPredicate; -import java.util.stream.Collectors; import java.util.stream.Stream; import org.jabref.logic.util.OS; @@ -30,15 +29,16 @@ public class OpenOfficeFileSearch { public static List detectInstallations() { if (OS.WINDOWS) { List programDirs = findWindowsOpenOfficeDirs(); - return programDirs.stream().filter(dir -> FileUtil.find(OpenOfficePreferences.WINDOWS_EXECUTABLE, dir).isPresent()).collect(Collectors.toList()); + return programDirs.stream().filter(dir -> FileUtil.find(OpenOfficePreferences.WINDOWS_EXECUTABLE, dir).isPresent()).toList(); } else if (OS.OS_X) { List programDirs = findOSXOpenOfficeDirs(); - return programDirs.stream().filter(dir -> FileUtil.find(OpenOfficePreferences.OSX_EXECUTABLE, dir).isPresent()).collect(Collectors.toList()); + return programDirs.stream().filter(dir -> FileUtil.find(OpenOfficePreferences.OSX_EXECUTABLE, dir).isPresent()).toList(); } else if (OS.LINUX) { List programDirs = findLinuxOpenOfficeDirs(); - return programDirs.stream().filter(dir -> FileUtil.find(OpenOfficePreferences.LINUX_EXECUTABLE, dir).isPresent()).collect(Collectors.toList()); + return programDirs.stream().filter(dir -> FileUtil.find(OpenOfficePreferences.LINUX_EXECUTABLE, dir).isPresent()).toList(); + } else { + return List.of(); } - return new ArrayList<>(0); } private static List findOpenOfficeDirectories(List programDirectories) { @@ -46,14 +46,16 @@ private static List findOpenOfficeDirectories(List programDirectorie attr.isDirectory() && (path.toString().toLowerCase(Locale.ROOT).contains("openoffice") || path.toString().toLowerCase(Locale.ROOT).contains("libreoffice")); - return programDirectories.stream().flatMap(dirs -> { - try { - return Files.find(dirs, 1, filePredicate); - } catch (IOException e) { - LOGGER.error("Problem searching for openoffice/libreoffice install directory", e); - return Stream.empty(); - } - }).collect(Collectors.toList()); + return programDirectories.stream() + .flatMap(dirs -> { + try { + return Files.find(dirs, 1, filePredicate); + } catch (IOException e) { + LOGGER.error("Problem searching for openoffice/libreoffice install directory", e); + return Stream.empty(); + } + }) + .toList(); } private static List findWindowsOpenOfficeDirs() { @@ -71,7 +73,11 @@ private static List findWindowsOpenOfficeDirs() { sourceList.add(Path.of(progFiles)); } - return findOpenOfficeDirectories(sourceList); + return findOpenOfficeDirectories(sourceList) + .stream() + // On Windows, the executable is nested in subdirectory "program" + .map(dir -> dir.resolve("program")) + .toList(); } private static List findOSXOpenOfficeDirs() { diff --git a/src/main/java/org/jabref/logic/openoffice/OpenOfficePreferences.java b/src/main/java/org/jabref/logic/openoffice/OpenOfficePreferences.java index 22fbcbf885a..be6b0e6ff97 100644 --- a/src/main/java/org/jabref/logic/openoffice/OpenOfficePreferences.java +++ b/src/main/java/org/jabref/logic/openoffice/OpenOfficePreferences.java @@ -11,7 +11,7 @@ public class OpenOfficePreferences { - public static final String DEFAULT_WIN_EXEC_PATH = "C:\\Program Files\\LibreOffice 5\\program"; + public static final String DEFAULT_WIN_EXEC_PATH = "C:\\Program Files\\LibreOffice\\program"; public static final String WINDOWS_EXECUTABLE = "soffice.exe"; public static final String DEFAULT_OSX_EXEC_PATH = "/Applications/LibreOffice.app/Contents/MacOS/soffice";