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 could not connect to LO on Mac OSX #6970

Merged
merged 7 commits into from
Oct 3, 2020
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
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We fixed the failure to Copy citation key and link. [#5835](https://github.com/JabRef/jabref/issues/5835)
- We fixed an issue where the sort order of the entry table was reset after a restart of JabRef. [#6898](https://github.com/JabRef/jabref/pull/6898)
- We fixed an issue where no longer a warning was displayed when inserting references into LibreOffice with an invalid "ReferenceParagraphFormat". [#6907](https://github.com/JabRef/jabref/pull/60907).
- We fixed an issue where a selected field was not removed after the first click in the custom entry types dialog [#6934](https://github.com/JabRef/jabref/issues/6934)
- We fixed an issue where a remove icon was shown for standard entry types in the custom entry types dialog [6906](https://github.com/JabRef/jabref/issues/6906)
- We fixed an issue with the python script used by browser plugins that failed to locate JabRef if not installed in its default location.
- We fixed an issue where a selected field was not removed after the first click in the custom entry types dialog. [#6934](https://github.com/JabRef/jabref/issues/6934)
- We fixed an issue where a remove icon was shown for standard entry types in the custom entry types dialog. [6906](https://github.com/JabRef/jabref/issues/6906)
- We fixed an issue where it was impossible to connect to OpenOffice/LibreOffice on Mac OSX. [#6970](https://github.com/JabRef/jabref/pull/6970)
- We fixed an issue with the python script used by browser plugins that failed to locate JabRef if not installed in its default location. [#6963](https://github.com/JabRef/jabref/pull/6963/files)

### Removed

Expand Down
7 changes: 6 additions & 1 deletion src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.jabref.logic.openoffice.OpenOfficePreferences;
import org.jabref.logic.openoffice.StyleLoader;
import org.jabref.logic.openoffice.UndefinedParagraphFormatException;
import org.jabref.logic.util.OS;
import org.jabref.logic.util.io.FileUtil;
import org.jabref.model.database.BibDatabase;
import org.jabref.model.database.BibDatabaseContext;
Expand Down Expand Up @@ -430,9 +431,13 @@ private List<URL> findOpenOfficeJars(Path configurationPath) throws IOException
throw new IOException("(Not all) required Open Office Jars were found inside installation path. Searched for " + OpenOfficePreferences.OO_JARS + " in " + configurationPath);
}

List<URL> jarURLs = new ArrayList<>(OpenOfficePreferences.OO_JARS.size());
List<URL> jarURLs = new ArrayList<>(OpenOfficePreferences.OO_JARS.size() + 1);
for (Optional<Path> jarPath : filePaths) {
jarURLs.add((jarPath.get().toUri().toURL()));
// For Mac OSX we need to add the "Contents/MacOS", because otherwise we cannot connect to LO
if (OS.OS_X) {
jarURLs.add(configurationPath.resolve("Contents/MacOS/").toUri().toURL());
}
}
return jarURLs;
}
Expand Down
34 changes: 21 additions & 13 deletions src/main/java/org/jabref/logic/openoffice/OpenOfficeFileSearch.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
package org.jabref.logic.openoffice;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
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;
import org.jabref.logic.util.io.FileUtil;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class OpenOfficeFileSearch {
private static final Logger LOGGER = LoggerFactory.getLogger(OpenOfficeFileSearch.class);

/**
* Detects existing installation of OpenOffice and LibreOffice.
*
Expand All @@ -33,19 +42,18 @@ public static List<Path> detectInstallations() {
}

private static List<Path> findOpenOfficeDirectories(List<Path> programDirectories) {
List<Path> result = new ArrayList<>();

for (Path programDir : programDirectories) {
File[] subDirs = programDir.toFile().listFiles(File::isDirectory);
if (subDirs != null) {
for (File dir : subDirs) {
if (dir.getPath().toLowerCase(Locale.ROOT).contains("openoffice") || dir.getPath().toLowerCase(Locale.ROOT).contains("libreoffice")) {
result.add(dir.toPath());
}
}

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();
Siedlerchr marked this conversation as resolved.
Show resolved Hide resolved
}
}
return result;
}).collect(Collectors.toList());
}

private static List<Path> findWindowsOpenOfficeDirs() {
Expand Down