Skip to content

Commit e874c67

Browse files
authored
Fix detection of soffice.exe (#11478)
* Fix dection of soffice.exe * Fix CHANGELOG.md * Fix typo * Add link to CHANGELOG.md * Fix dir detection
1 parent 7b4c3df commit e874c67

File tree

5 files changed

+28
-21
lines changed

5 files changed

+28
-21
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
1919

2020
- We fixed an issue where JabRef was no longer built for Intel based macs (x86) [#11468](https://github.com/JabRef/jabref/issues/11468)
2121
- We fixed usage when using running on Snapcraft. [#11465](https://github.com/JabRef/jabref/issues/11465)
22+
- We fixed detection for `soffice.exe` on Windows. [#11478](https://github.com/JabRef/jabref/pull/11478)
2223

2324
### Removed
2425

src/main/java/org/jabref/gui/openoffice/DetectOpenOfficeInstallation.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ private boolean checkAutoDetectedPaths(OpenOfficePreferences openOfficePreferenc
4949
if (OS.LINUX && (System.getenv("FLATPAK_SANDBOX_DIR") != null)) {
5050
executablePath = OpenOfficePreferences.DEFAULT_LINUX_FLATPAK_EXEC_PATH;
5151
}
52-
return !StringUtil.isNullOrEmpty(executablePath) && Files.exists(Path.of(executablePath));
52+
return !StringUtil.isNullOrEmpty(executablePath) && Files.isRegularFile(Path.of(executablePath));
5353
}
5454

5555
public boolean setOpenOfficePreferences(Path installDir) {

src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -318,12 +318,12 @@ protected List<Path> call() {
318318
};
319319

320320
taskConnectIfInstalled.setOnSucceeded(evt -> {
321-
var installations = new ArrayList<>(taskConnectIfInstalled.getValue());
321+
List<Path> installations = new ArrayList<>(taskConnectIfInstalled.getValue());
322322
if (installations.isEmpty()) {
323323
officeInstallation.selectInstallationPath().ifPresent(installations::add);
324324
}
325-
Optional<Path> actualFile = officeInstallation.chooseAmongInstallations(installations);
326-
if (actualFile.isPresent() && officeInstallation.setOpenOfficePreferences(actualFile.get())) {
325+
Optional<Path> chosenInstallationDirectory = officeInstallation.chooseAmongInstallations(installations);
326+
if (chosenInstallationDirectory.isPresent() && officeInstallation.setOpenOfficePreferences(chosenInstallationDirectory.get())) {
327327
connect();
328328
}
329329
});
@@ -389,7 +389,7 @@ private void connect() {
389389
protected OOBibBase call() throws Exception {
390390
updateProgress(ProgressBar.INDETERMINATE_PROGRESS, ProgressBar.INDETERMINATE_PROGRESS);
391391

392-
var path = Path.of(preferencesService.getOpenOfficePreferences().getExecutablePath());
392+
Path path = Path.of(preferencesService.getOpenOfficePreferences().getExecutablePath());
393393
return createBibBase(path);
394394
}
395395
};
@@ -399,7 +399,7 @@ protected OOBibBase call() throws Exception {
399399

400400
ooBase.guiActionSelectDocument(true);
401401

402-
// Enable actions that depend on Connect:
402+
// Enable actions that depend on a connection
403403
updateButtonAvailability();
404404
});
405405

src/main/java/org/jabref/logic/openoffice/OpenOfficeFileSearch.java

+20-14
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import java.util.List;
1111
import java.util.Locale;
1212
import java.util.function.BiPredicate;
13-
import java.util.stream.Collectors;
1413
import java.util.stream.Stream;
1514

1615
import org.jabref.logic.util.OS;
@@ -30,30 +29,33 @@ public class OpenOfficeFileSearch {
3029
public static List<Path> detectInstallations() {
3130
if (OS.WINDOWS) {
3231
List<Path> programDirs = findWindowsOpenOfficeDirs();
33-
return programDirs.stream().filter(dir -> FileUtil.find(OpenOfficePreferences.WINDOWS_EXECUTABLE, dir).isPresent()).collect(Collectors.toList());
32+
return programDirs.stream().filter(dir -> FileUtil.find(OpenOfficePreferences.WINDOWS_EXECUTABLE, dir).isPresent()).toList();
3433
} else if (OS.OS_X) {
3534
List<Path> programDirs = findOSXOpenOfficeDirs();
36-
return programDirs.stream().filter(dir -> FileUtil.find(OpenOfficePreferences.OSX_EXECUTABLE, dir).isPresent()).collect(Collectors.toList());
35+
return programDirs.stream().filter(dir -> FileUtil.find(OpenOfficePreferences.OSX_EXECUTABLE, dir).isPresent()).toList();
3736
} else if (OS.LINUX) {
3837
List<Path> programDirs = findLinuxOpenOfficeDirs();
39-
return programDirs.stream().filter(dir -> FileUtil.find(OpenOfficePreferences.LINUX_EXECUTABLE, dir).isPresent()).collect(Collectors.toList());
38+
return programDirs.stream().filter(dir -> FileUtil.find(OpenOfficePreferences.LINUX_EXECUTABLE, dir).isPresent()).toList();
39+
} else {
40+
return List.of();
4041
}
41-
return new ArrayList<>(0);
4242
}
4343

4444
private static List<Path> findOpenOfficeDirectories(List<Path> programDirectories) {
4545
BiPredicate<Path, BasicFileAttributes> filePredicate = (path, attr) ->
4646
attr.isDirectory() && (path.toString().toLowerCase(Locale.ROOT).contains("openoffice")
4747
|| path.toString().toLowerCase(Locale.ROOT).contains("libreoffice"));
4848

49-
return programDirectories.stream().flatMap(dirs -> {
50-
try {
51-
return Files.find(dirs, 1, filePredicate);
52-
} catch (IOException e) {
53-
LOGGER.error("Problem searching for openoffice/libreoffice install directory", e);
54-
return Stream.empty();
55-
}
56-
}).collect(Collectors.toList());
49+
return programDirectories.stream()
50+
.flatMap(dirs -> {
51+
try {
52+
return Files.find(dirs, 1, filePredicate);
53+
} catch (IOException e) {
54+
LOGGER.error("Problem searching for openoffice/libreoffice install directory", e);
55+
return Stream.empty();
56+
}
57+
})
58+
.toList();
5759
}
5860

5961
private static List<Path> findWindowsOpenOfficeDirs() {
@@ -71,7 +73,11 @@ private static List<Path> findWindowsOpenOfficeDirs() {
7173
sourceList.add(Path.of(progFiles));
7274
}
7375

74-
return findOpenOfficeDirectories(sourceList);
76+
return findOpenOfficeDirectories(sourceList)
77+
.stream()
78+
// On Windows, the executable is nested in subdirectory "program"
79+
.map(dir -> dir.resolve("program"))
80+
.toList();
7581
}
7682

7783
private static List<Path> findOSXOpenOfficeDirs() {

src/main/java/org/jabref/logic/openoffice/OpenOfficePreferences.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
public class OpenOfficePreferences {
1313

14-
public static final String DEFAULT_WIN_EXEC_PATH = "C:\\Program Files\\LibreOffice 5\\program";
14+
public static final String DEFAULT_WIN_EXEC_PATH = "C:\\Program Files\\LibreOffice\\program";
1515
public static final String WINDOWS_EXECUTABLE = "soffice.exe";
1616

1717
public static final String DEFAULT_OSX_EXEC_PATH = "/Applications/LibreOffice.app/Contents/MacOS/soffice";

0 commit comments

Comments
 (0)