From 8a7e65384d67df046c4f7ab9183d10f4a4653110 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Mon, 28 Dec 2020 11:41:59 +0100 Subject: [PATCH 1/7] add hint Signed-off-by: Siedlerchr --- src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java b/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java index dd2c0418b1f..bbaf0f7ae83 100644 --- a/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java +++ b/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java @@ -341,6 +341,7 @@ private void connectAutomatically() { protected Void call() { updateProgress(ProgressBar.INDETERMINATE_PROGRESS, ProgressBar.INDETERMINATE_PROGRESS); + //TODO put manually afterwards return boolean? boolean installed = officeInstallation.isInstalled(); if (!installed) { throw new IllegalStateException("OpenOffice Installation could not be detected."); From fc324e656b21fbb451d1ef224f6079cfb58f5a91 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Tue, 29 Dec 2020 17:52:25 +0100 Subject: [PATCH 2/7] simplify LibreOffice connection Executable is enough --- .../org/jabref/gui/openoffice/Bootstrap.java | 19 ++++-------- .../openoffice/ManualConnectDialogView.java | 12 -------- .../org/jabref/gui/openoffice/OOBibBase.java | 14 ++++----- .../gui/openoffice/OpenOfficePanel.java | 29 +++---------------- 4 files changed, 14 insertions(+), 60 deletions(-) diff --git a/src/main/java/org/jabref/gui/openoffice/Bootstrap.java b/src/main/java/org/jabref/gui/openoffice/Bootstrap.java index d89fffc3ec2..29228207541 100644 --- a/src/main/java/org/jabref/gui/openoffice/Bootstrap.java +++ b/src/main/java/org/jabref/gui/openoffice/Bootstrap.java @@ -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; @@ -254,10 +253,10 @@ 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); } /** @@ -269,7 +268,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; @@ -280,18 +279,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); diff --git a/src/main/java/org/jabref/gui/openoffice/ManualConnectDialogView.java b/src/main/java/org/jabref/gui/openoffice/ManualConnectDialogView.java index 5e7a2e7649a..79c517961f7 100644 --- a/src/main/java/org/jabref/gui/openoffice/ManualConnectDialogView.java +++ b/src/main/java/org/jabref/gui/openoffice/ManualConnectDialogView.java @@ -12,7 +12,6 @@ import org.jabref.gui.DialogService; import org.jabref.gui.util.BaseDialog; import org.jabref.logic.l10n.Localization; -import org.jabref.logic.util.OS; import org.jabref.preferences.PreferencesService; import com.airhacks.afterburner.views.ViewLoader; @@ -54,20 +53,9 @@ public ManualConnectDialogView(DialogService dialogService) { private void initialize() { viewModel = new ManualConnectDialogViewModel(preferencesService, dialogService); - - ooPath.textProperty().bindBidirectional(viewModel.ooPathProperty()); ooExec.textProperty().bindBidirectional(viewModel.ooExecProperty()); ooJars.textProperty().bind(viewModel.ooJarsProperty()); - if (OS.WINDOWS || OS.OS_X) { - ooPath.setVisible(true); - ooExec.setVisible(false); - ooJars.setVisible(false); - } else { - ooPath.setVisible(false); - ooExec.setVisible(false); - ooJars.setVisible(true); - } } @FXML diff --git a/src/main/java/org/jabref/gui/openoffice/OOBibBase.java b/src/main/java/org/jabref/gui/openoffice/OOBibBase.java index 145b8fe0d84..475b86a7809 100644 --- a/src/main/java/org/jabref/gui/openoffice/OOBibBase.java +++ b/src/main/java/org/jabref/gui/openoffice/OOBibBase.java @@ -2,8 +2,7 @@ import java.io.IOException; import java.lang.reflect.InvocationTargetException; -import java.net.URL; -import java.net.URLClassLoader; +import java.nio.file.Path; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -129,7 +128,7 @@ class OOBibBase { private final DialogService dialogService; - public OOBibBase(List jarUrls, boolean atEnd, DialogService dialogService) throws IllegalAccessException, InvocationTargetException, BootstrapException, CreationException, IOException, ClassNotFoundException { + public OOBibBase(Path loPath, boolean atEnd, DialogService dialogService) throws IllegalAccessException, InvocationTargetException, BootstrapException, CreationException, IOException, ClassNotFoundException { this.dialogService = dialogService; @@ -146,7 +145,7 @@ public OOBibBase(List jarUrls, boolean atEnd, DialogService dialogService) this.atEnd = atEnd; - xDesktop = simpleBootstrap(jarUrls); + xDesktop = simpleBootstrap(loPath); } public boolean isConnectedToDocument() { @@ -232,14 +231,11 @@ private List getTextDocuments() throws NoSuchElementException, Wr return result; } - private XDesktop simpleBootstrap(List jarUrls) + private XDesktop simpleBootstrap(Path loPath) throws CreationException, BootstrapException { - URL[] urls = jarUrls.toArray(new URL[1]); - URLClassLoader loader = new URLClassLoader(urls, null); - // Get the office component context: - XComponentContext xContext = org.jabref.gui.openoffice.Bootstrap.bootstrap(loader); + XComponentContext xContext = org.jabref.gui.openoffice.Bootstrap.bootstrap(loPath); // Get the office service manager: XMultiComponentFactory xServiceManager = xContext.getServiceManager(); // Create the desktop, which is the root frame of the diff --git a/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java b/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java index bbaf0f7ae83..497324be474 100644 --- a/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java +++ b/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java @@ -3,13 +3,10 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.lang.reflect.InvocationTargetException; -import java.net.URL; import java.nio.file.Path; import java.util.ArrayList; import java.util.List; import java.util.Optional; -import java.util.stream.Collectors; - import javafx.concurrent.Task; import javafx.geometry.Insets; import javafx.geometry.Side; @@ -48,8 +45,6 @@ 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; import org.jabref.model.entry.BibEntry; @@ -370,9 +365,9 @@ private void connect() { @Override protected OOBibBase call() throws Exception { updateProgress(ProgressBar.INDETERMINATE_PROGRESS, ProgressBar.INDETERMINATE_PROGRESS); - List jarUrls = findOpenOfficeJars(Path.of(ooPrefs.getInstallationPath())); - return createBibBase(jarUrls); + var path = Path.of(ooPrefs.getExecutablePath()); + return createBibBase(path); } }; @@ -425,27 +420,11 @@ protected OOBibBase call() throws Exception { taskExecutor.execute(connectTask); } - private List findOpenOfficeJars(Path configurationPath) throws IOException { - List> filePaths = OpenOfficePreferences.OO_JARS.stream().map(jar -> FileUtil.find(jar, configurationPath)).collect(Collectors.toList()); - - if (!filePaths.stream().allMatch(Optional::isPresent)) { - throw new IOException("(Not all) required Open Office Jars were found inside installation path. Searched for " + OpenOfficePreferences.OO_JARS + " in " + configurationPath); - } - List jarURLs = new ArrayList<>(OpenOfficePreferences.OO_JARS.size() + 1); - for (Optional 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; - } - private OOBibBase createBibBase(List jarUrls) throws IOException, InvocationTargetException, IllegalAccessException, + private OOBibBase createBibBase(Path loPath) throws IOException, InvocationTargetException, IllegalAccessException, BootstrapException, CreationException, ClassNotFoundException { - return new OOBibBase(jarUrls, true, dialogService); + return new OOBibBase(loPath, true, dialogService); } private Optional showManualConnectionDialog() { From 99f3651c4bf1f12a4e3aa7b83e195863a23b01b4 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Tue, 29 Dec 2020 20:57:01 +0100 Subject: [PATCH 3/7] continue refactoring --- .../org/jabref/gui/openoffice/Bootstrap.java | 1 - .../DetectOpenOfficeInstallation.java | 34 +--- .../gui/openoffice/ManualConnectDialog.fxml | 49 ------ .../openoffice/ManualConnectDialogView.java | 75 --------- .../ManualConnectDialogViewModel.java | 77 --------- .../gui/openoffice/OpenOfficePanel.java | 152 ++++++++++-------- .../openoffice/OpenOfficePreferences.java | 20 --- .../jabref/preferences/JabRefPreferences.java | 6 - 8 files changed, 93 insertions(+), 321 deletions(-) delete mode 100644 src/main/java/org/jabref/gui/openoffice/ManualConnectDialog.fxml delete mode 100644 src/main/java/org/jabref/gui/openoffice/ManualConnectDialogView.java delete mode 100644 src/main/java/org/jabref/gui/openoffice/ManualConnectDialogViewModel.java diff --git a/src/main/java/org/jabref/gui/openoffice/Bootstrap.java b/src/main/java/org/jabref/gui/openoffice/Bootstrap.java index 29228207541..87e242be781 100644 --- a/src/main/java/org/jabref/gui/openoffice/Bootstrap.java +++ b/src/main/java/org/jabref/gui/openoffice/Bootstrap.java @@ -254,7 +254,6 @@ public static final XComponentContext defaultBootstrap_InitialComponentContext(S * @since UDK 3.1.0 */ public static final XComponentContext bootstrap(Path ooPath) throws BootstrapException { - String[] defaultArgArray = getDefaultOptions(); return bootstrap(defaultArgArray, ooPath); } diff --git a/src/main/java/org/jabref/gui/openoffice/DetectOpenOfficeInstallation.java b/src/main/java/org/jabref/gui/openoffice/DetectOpenOfficeInstallation.java index 4a1439cf69e..d8f9e1c8b14 100644 --- a/src/main/java/org/jabref/gui/openoffice/DetectOpenOfficeInstallation.java +++ b/src/main/java/org/jabref/gui/openoffice/DetectOpenOfficeInstallation.java @@ -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; @@ -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 selectInstallationPath() { + public Optional selectInstallationPath() { final NativeDesktop nativeDesktop = JabRefDesktop.getNativeDesktop(); @@ -52,23 +47,6 @@ private Optional selectInstallationPath() { return dialogService.showDirectorySelectionDialog(dirDialogConfiguration); } - private boolean autoDetectPaths() { - List installations = OpenOfficeFileSearch.detectInstallations(); - - // manually add installation path - if (installations.isEmpty()) { - selectInstallationPath().ifPresent(installations::add); - } - - // select among multiple installations - Optional actualFile = chooseAmongInstallations(installations); - if (actualFile.isPresent()) { - return setOpenOfficePreferences(actualFile.get()); - } - - return false; - } - /** * Checks whether the executablePath exists */ @@ -77,7 +55,7 @@ private boolean checkAutoDetectedPaths(OpenOfficePreferences openOfficePreferenc return !StringUtil.isNullOrEmpty(executablePath) && Files.exists(Path.of(executablePath)); } - private boolean setOpenOfficePreferences(Path installDir) { + public boolean setOpenOfficePreferences(Path installDir) { Optional execPath = Optional.empty(); if (OS.WINDOWS) { @@ -88,12 +66,8 @@ private boolean setOpenOfficePreferences(Path installDir) { execPath = FileUtil.find(OpenOfficePreferences.LINUX_EXECUTABLE, installDir); } - Optional 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; } @@ -101,7 +75,7 @@ private boolean setOpenOfficePreferences(Path installDir) { return false; } - private Optional chooseAmongInstallations(List installDirs) { + public Optional chooseAmongInstallations(List installDirs) { if (installDirs.isEmpty()) { return Optional.empty(); } diff --git a/src/main/java/org/jabref/gui/openoffice/ManualConnectDialog.fxml b/src/main/java/org/jabref/gui/openoffice/ManualConnectDialog.fxml deleted file mode 100644 index 34c8b060fdb..00000000000 --- a/src/main/java/org/jabref/gui/openoffice/ManualConnectDialog.fxml +++ /dev/null @@ -1,49 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - -