Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix detection of soffice.exe #11478

Merged
merged 5 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -318,12 +318,12 @@ protected List<Path> call() {
};

taskConnectIfInstalled.setOnSucceeded(evt -> {
var installations = new ArrayList<>(taskConnectIfInstalled.getValue());
List<Path> installations = new ArrayList<>(taskConnectIfInstalled.getValue());
if (installations.isEmpty()) {
officeInstallation.selectInstallationPath().ifPresent(installations::add);
}
Optional<Path> actualFile = officeInstallation.chooseAmongInstallations(installations);
if (actualFile.isPresent() && officeInstallation.setOpenOfficePreferences(actualFile.get())) {
Optional<Path> chosenInstallationDirectory = officeInstallation.chooseAmongInstallations(installations);
if (chosenInstallationDirectory.isPresent() && officeInstallation.setOpenOfficePreferences(chosenInstallationDirectory.get())) {
connect();
}
});
Expand Down Expand Up @@ -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);
}
};
Expand All @@ -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();
});

Expand Down
34 changes: 20 additions & 14 deletions src/main/java/org/jabref/logic/openoffice/OpenOfficeFileSearch.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,30 +29,33 @@ public class OpenOfficeFileSearch {
public static List<Path> detectInstallations() {
if (OS.WINDOWS) {
List<Path> 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<Path> 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<Path> 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<Path> findOpenOfficeDirectories(List<Path> programDirectories) {
BiPredicate<Path, BasicFileAttributes> filePredicate = (path, attr) ->
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<Path> findWindowsOpenOfficeDirs() {
Expand All @@ -71,7 +73,11 @@ private static List<Path> 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<Path> findOSXOpenOfficeDirs() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

public class OpenOfficePreferences {

public static final String DEFAULT_WIN_EXEC_PATH = "C:\\Program Files\\LibreOffice 5\\program";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah guess they changed this at some point in time

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";
Expand Down