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

Simplify LO connection and fix threading errors #7271

Merged
merged 8 commits into from
Jan 4, 2021
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
20 changes: 5 additions & 15 deletions src/main/java/org/jabref/gui/openoffice/Bootstrap.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@
package org.jabref.gui.openoffice;

import java.io.BufferedReader;
import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.net.URLClassLoader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
Expand Down Expand Up @@ -254,10 +253,9 @@ public static final XComponentContext defaultBootstrap_InitialComponentContext(S
* @throws BootstrapException if things go awry.
* @since UDK 3.1.0
*/
public static final XComponentContext bootstrap(URLClassLoader loader) throws BootstrapException {

public static final XComponentContext bootstrap(Path ooPath) throws BootstrapException {
String[] defaultArgArray = getDefaultOptions();
return bootstrap(defaultArgArray, loader);
return bootstrap(defaultArgArray, ooPath);
}

/**
Expand All @@ -269,7 +267,7 @@ public static final XComponentContext bootstrap(URLClassLoader loader) throws Bo
* @see #getDefaultOptions()
* @since LibreOffice 5.1
*/
public static final XComponentContext bootstrap(String[] argArray, URLClassLoader loader) throws BootstrapException {
public static final XComponentContext bootstrap(String[] argArray, Path path) throws BootstrapException {

XComponentContext xContext = null;

Expand All @@ -280,18 +278,10 @@ public static final XComponentContext bootstrap(String[] argArray, URLClassLoade
throw new BootstrapException("no local component context!");
}

// find office executable relative to this class's class loader
String sOffice = System.getProperty("os.name").startsWith("Windows") ? "soffice.exe" : "soffice";

File fOffice = NativeLibraryLoader.getResource(loader, sOffice);
if (fOffice == null) {
throw new BootstrapException("no office executable found!");
}

// create call with arguments
// We need a socket, pipe does not work. https://api.libreoffice.org/examples/examples.html
String[] cmdArray = new String[argArray.length + 2];
cmdArray[0] = fOffice.getPath();
cmdArray[0] = path.toAbsolutePath().toString();
cmdArray[1] = ("--accept=socket,host=localhost,port=2083" + ";urp;");

System.arraycopy(argArray, 0, cmdArray, 2, argArray.length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.jabref.gui.desktop.os.NativeDesktop;
import org.jabref.gui.util.DirectoryDialogConfiguration;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.openoffice.OpenOfficeFileSearch;
import org.jabref.logic.openoffice.OpenOfficePreferences;
import org.jabref.logic.util.OS;
import org.jabref.logic.util.io.FileUtil;
Expand All @@ -32,15 +31,11 @@ public DetectOpenOfficeInstallation(PreferencesService preferencesService, Dialo
this.ooPrefs = preferencesService.getOpenOfficePreferences();
}

public boolean isInstalled() {
return autoDetectPaths();
}

public boolean isExecutablePathDefined() {
return checkAutoDetectedPaths(ooPrefs);
}

private Optional<Path> selectInstallationPath() {
public Optional<Path> selectInstallationPath() {

final NativeDesktop nativeDesktop = JabRefDesktop.getNativeDesktop();

Expand All @@ -52,32 +47,19 @@ private Optional<Path> selectInstallationPath() {
return dialogService.showDirectorySelectionDialog(dirDialogConfiguration);
}

private boolean autoDetectPaths() {
List<Path> installations = OpenOfficeFileSearch.detectInstallations();

// manually add installation path
if (installations.isEmpty()) {
selectInstallationPath().ifPresent(installations::add);
}

// select among multiple installations
Optional<Path> actualFile = chooseAmongInstallations(installations);
if (actualFile.isPresent()) {
return setOpenOfficePreferences(actualFile.get());
}

return false;
}

/**
* Checks whether the executablePath exists
*/
private boolean checkAutoDetectedPaths(OpenOfficePreferences openOfficePreferences) {
String executablePath = openOfficePreferences.getExecutablePath();

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));
}

private boolean setOpenOfficePreferences(Path installDir) {
public boolean setOpenOfficePreferences(Path installDir) {
Optional<Path> execPath = Optional.empty();

if (OS.WINDOWS) {
Expand All @@ -88,20 +70,16 @@ private boolean setOpenOfficePreferences(Path installDir) {
execPath = FileUtil.find(OpenOfficePreferences.LINUX_EXECUTABLE, installDir);
}

Optional<Path> jarFilePath = FileUtil.find(OpenOfficePreferences.OO_JARS.get(0), installDir);

if (execPath.isPresent() && jarFilePath.isPresent()) {
ooPrefs.setInstallationPath(installDir.toString());
if (execPath.isPresent()) {
ooPrefs.setExecutablePath(execPath.get().toString());
ooPrefs.setJarsPath(jarFilePath.get().getParent().toString());
preferencesService.setOpenOfficePreferences(ooPrefs);
return true;
}

return false;
}

private Optional<Path> chooseAmongInstallations(List<Path> installDirs) {
public Optional<Path> chooseAmongInstallations(List<Path> installDirs) {
if (installDirs.isEmpty()) {
return Optional.empty();
}
Expand Down
49 changes: 0 additions & 49 deletions src/main/java/org/jabref/gui/openoffice/ManualConnectDialog.fxml

This file was deleted.

This file was deleted.

This file was deleted.

Loading