From b5cb9440eb7c53a2c0bfa1bd2cd22ec8a4624ac0 Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Wed, 10 Jul 2024 11:00:16 +0200 Subject: [PATCH 1/5] Fix dection of soffice.exe --- CHANGELOG.md | 3 +- .../DetectOpenOfficeInstallation.java | 2 +- .../gui/openoffice/OpenOfficePanel.java | 10 +++---- .../openoffice/OpenOfficeFileSearch.java | 30 +++++++++++-------- .../openoffice/OpenOfficePreferences.java | 2 +- 5 files changed, 25 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 31e42d92857..9dd4a109378 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,12 +13,11 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv - We made new groups automatically to focus upon creation. [#11449](https://github.com/JabRef/jabref/issues/11449) -### Changed - ### Fixed - 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. ### 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..edb7f38c7f0 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,18 @@ 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(); + } + }) + // On Windows, the executable is nested in usb directory "program" + .map(dir -> dir.resolve("program")) + .toList(); } private static List findWindowsOpenOfficeDirs() { 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"; From da1248fd5e22d817ad52da3aa9c25c1925514bff Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Wed, 10 Jul 2024 11:02:19 +0200 Subject: [PATCH 2/5] Fix CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9dd4a109378..c4322dbf84c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv - We made new groups automatically to focus upon creation. [#11449](https://github.com/JabRef/jabref/issues/11449) +### Changed + ### Fixed - We fixed an issue where JabRef was no longer built for Intel based macs (x86) [#11468](https://github.com/JabRef/jabref/issues/11468) From 53f291de1e6e02f75b806d11ccc546b330e9f580 Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Wed, 10 Jul 2024 11:05:32 +0200 Subject: [PATCH 3/5] Fix typo --- .../java/org/jabref/logic/openoffice/OpenOfficeFileSearch.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/logic/openoffice/OpenOfficeFileSearch.java b/src/main/java/org/jabref/logic/openoffice/OpenOfficeFileSearch.java index edb7f38c7f0..5aabc13b3d8 100644 --- a/src/main/java/org/jabref/logic/openoffice/OpenOfficeFileSearch.java +++ b/src/main/java/org/jabref/logic/openoffice/OpenOfficeFileSearch.java @@ -55,7 +55,7 @@ private static List findOpenOfficeDirectories(List programDirectorie return Stream.empty(); } }) - // On Windows, the executable is nested in usb directory "program" + // On Windows, the executable is nested in subdirectory "program" .map(dir -> dir.resolve("program")) .toList(); } From 73e8a2e9f6c8dab7bb7401e50ad70e58c91186e3 Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Wed, 10 Jul 2024 11:06:30 +0200 Subject: [PATCH 4/5] Add link to CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c4322dbf84c..9c68cf0de4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,7 +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. +- We fixed detection for `soffice.exe` on Windows. [#11478](https://github.com/JabRef/jabref/pull/11478) ### Removed From 6d13fd90fcfbaf3bc68a23549de27653d06d5e27 Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Wed, 10 Jul 2024 13:35:58 +0200 Subject: [PATCH 5/5] Fix dir detection --- .../org/jabref/logic/openoffice/OpenOfficeFileSearch.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/jabref/logic/openoffice/OpenOfficeFileSearch.java b/src/main/java/org/jabref/logic/openoffice/OpenOfficeFileSearch.java index 5aabc13b3d8..9755e0fa3db 100644 --- a/src/main/java/org/jabref/logic/openoffice/OpenOfficeFileSearch.java +++ b/src/main/java/org/jabref/logic/openoffice/OpenOfficeFileSearch.java @@ -55,8 +55,6 @@ private static List findOpenOfficeDirectories(List programDirectorie return Stream.empty(); } }) - // On Windows, the executable is nested in subdirectory "program" - .map(dir -> dir.resolve("program")) .toList(); } @@ -75,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() {