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

Change lucene index path to have sub directories #9887

Merged
merged 11 commits into from
May 15, 2023
12 changes: 6 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We fixed an issue where entering a date in the format "YYYY/MM" in the entry editor date field caused an exception. [#9492](https://github.com/JabRef/jabref/issues/9492)
- For portable versions, the `.deb` file now works on plain debian again. [#9472](https://github.com/JabRef/jabref/issues/9472)
- We fixed an issue where the download of linked online files failed after an import of entries for certain urls. [#9518](https://github.com/JabRef/jabref/issues/9518)
- We fixed an issue where an exception occured when manually downloading a file from an URL in the entry editor. [#9521](https://github.com/JabRef/jabref/issues/9521)
- We fixed an issue where an exception occurred when manually downloading a file from an URL in the entry editor. [#9521](https://github.com/JabRef/jabref/issues/9521)
- We fixed an issue with open office csv file formatting where commas in the abstract field where not escaped. [#9087][https://github.com/JabRef/jabref/issues/9087]
- We fixed an issue with deleting groups where subgroups different from the selected group were deleted. [#9281][https://github.com/JabRef/jabref/issues/9281]

Expand Down Expand Up @@ -412,7 +412,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
### Fixed

- We fixed an issue where an exception occurred when pasting an entry with a publication date-range of the form 1910/1917 [#7864](https://github.com/JabRef/jabref/issues/7864)
- We fixed an issue where an exception occured when a preview style was edited and afterwards another preview style selected. [#8280](https://github.com/JabRef/jabref/issues/8280)
- We fixed an issue where an exception occurred when a preview style was edited and afterwards another preview style selected. [#8280](https://github.com/JabRef/jabref/issues/8280)
- We fixed an issue where the actions to move a file to a directory were incorrectly disabled. [#7908](https://github.com/JabRef/jabref/issues/7908)
- We fixed an issue where an exception occurred when a linked online file was edited in the entry editor [#8008](https://github.com/JabRef/jabref/issues/8008)
- We fixed an issue when checking for a new version when JabRef is used behind a corporate proxy. [#7884](https://github.com/JabRef/jabref/issues/7884)
Expand Down Expand Up @@ -496,11 +496,11 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve

### Fixed

- We fixed an isuse where some texts (e.g. descriptionss) in dialogs could not be translated [#7854](https://github.com/JabRef/jabref/issues/7854)
- We fixed an issue where some texts (e.g. descriptions) in dialogs could not be translated [#7854](https://github.com/JabRef/jabref/issues/7854)
- We fixed an issue where import hangs for ris files with "ER - " [#7737](https://github.com/JabRef/jabref/issues/7737)
- We fixed an issue where getting bibliograhpic data from DOI or another identifer did not respect the library mode (BibTeX/biblatex)[#1018](https://github.com/JabRef/jabref/issues/6267)
- We fixed an issue where importing entries would not respect the library mode (BibTeX/biblatex)[#1018](https://github.com/JabRef/jabref/issues/1018)
- We fixed an issue where an exception occured when importing entries from a web search [#7606](https://github.com/JabRef/jabref/issues/7606)
- We fixed an issue where an exception occurred when importing entries from a web search [#7606](https://github.com/JabRef/jabref/issues/7606)
- We fixed an issue where the table column sort order was not properly stored and resulted in unsorted eports [#7524](https://github.com/JabRef/jabref/issues/7524)
- We fixed an issue where the value of the field `school` or `institution` would be printed twice in the HTML Export [forum#2634](https://discourse.jabref.org/t/problem-with-exporting-techreport-phdthesis-mastersthesis-to-html/2634)
- We fixed an issue preventing to connect to a shared database. [#7570](https://github.com/JabRef/jabref/pull/7570)
Expand Down Expand Up @@ -725,11 +725,11 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We fixed an issue where long directory names created from patterns could create an exception. [#3915](https://github.com/JabRef/jabref/issues/3915)
- We fixed an issue where sort on numeric cases was broken. [#6349](https://github.com/JabRef/jabref/issues/6349)
- We fixed an issue where year and month fields were not cleared when converting to biblatex [#6224](https://github.com/JabRef/jabref/issues/6224)
- We fixed an issue where an "Not on FX thread" exception occured when saving on linux [#6453](https://github.com/JabRef/jabref/issues/6453)
- We fixed an issue where an "Not on FX thread" exception occurred when saving on linux [#6453](https://github.com/JabRef/jabref/issues/6453)
- We fixed an issue where the library sort order was lost. [#6091](https://github.com/JabRef/jabref/issues/6091)
- We fixed an issue where brackets in regular expressions were not working. [6469](https://github.com/JabRef/jabref/pull/6469)
- We fixed an issue where multiple background task popups stacked over each other.. [#6472](https://github.com/JabRef/jabref/issues/6472)
- We fixed an issue where LaTeX citations for specific commands (\autocites) of biblatex-mla were not recognized. [#6476](https://github.com/JabRef/jabref/issues/6476)
- We fixed an issue where LaTeX citations for specific commands (`\autocite`s) of biblatex-mla were not recognized. [#6476](https://github.com/JabRef/jabref/issues/6476)
- We fixed an issue where drag and drop was not working on empty database. [#6487](https://github.com/JabRef/jabref/issues/6487)
- We fixed an issue where the name fields were not updated after the preferences changed. [#6515](https://github.com/JabRef/jabref/issues/6515)
- We fixed an issue where "null" appeared in generated BibTeX keys. [#6459](https://github.com/JabRef/jabref/issues/6459)
Expand Down
12 changes: 2 additions & 10 deletions src/main/java/org/jabref/cli/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,11 @@
import org.jabref.logic.protectedterms.ProtectedTermsLoader;
import org.jabref.logic.remote.RemotePreferences;
import org.jabref.logic.remote.client.RemoteClient;
import org.jabref.logic.util.BuildInfo;
import org.jabref.logic.util.OS;
import org.jabref.migrations.PreferencesMigrations;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.preferences.JabRefPreferences;
import org.jabref.preferences.PreferencesService;

import net.harawata.appdirs.AppDirsFactory;
import org.apache.commons.cli.ParseException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -90,12 +87,7 @@ public static void main(String[] args) {
* the log configuration programmatically anymore.
*/
private static void addLogToDisk() {
Path directory = Path.of(AppDirsFactory.getInstance()
.getUserDataDir(
OS.APP_DIR_APP_NAME,
"logs",
OS.APP_DIR_APP_AUTHOR))
.resolve(new BuildInfo().version.toString());
Path directory = OS.getNativeDesktop().getLogDirectory();
try {
Files.createDirectories(directory);
} catch (IOException e) {
Expand Down Expand Up @@ -168,7 +160,7 @@ private static void configureSSL(SSLPreferences sslPreferences) {
}

private static void clearOldSearchIndices() {
Path currentIndexPath = BibDatabaseContext.getFulltextIndexBasePath();
Path currentIndexPath = OS.getNativeDesktop().getFulltextIndexBaseDirectory();
Path appData = currentIndexPath.getParent();

try {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/OpenConsoleAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public OpenConsoleAction(StateManager stateManager, PreferencesService preferenc
public void execute() {
Optional.ofNullable(databaseContext.get()).or(stateManager::getActiveDatabase).flatMap(BibDatabaseContext::getDatabasePath).ifPresent(path -> {
try {
JabRefDesktop.openConsole(path.toFile(), preferencesService, dialogService);
JabRefDesktop.openConsole(path, preferencesService, dialogService);
} catch (IOException e) {
LOGGER.info("Could not open console", e);
}
Expand Down
144 changes: 62 additions & 82 deletions src/main/java/org/jabref/gui/desktop/JabRefDesktop.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.jabref.gui.desktop;

import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.nio.file.Files;
Expand All @@ -13,11 +12,7 @@

import org.jabref.gui.DialogService;
import org.jabref.gui.Globals;
import org.jabref.gui.desktop.os.DefaultDesktop;
import org.jabref.gui.desktop.os.Linux;
import org.jabref.gui.desktop.os.NativeDesktop;
import org.jabref.gui.desktop.os.OSX;
import org.jabref.gui.desktop.os.Windows;
import org.jabref.gui.externalfiletype.ExternalFileType;
import org.jabref.gui.externalfiletype.ExternalFileTypes;
import org.jabref.logic.importer.util.IdentifierParser;
Expand All @@ -36,14 +31,14 @@
import org.slf4j.LoggerFactory;

/**
* TODO: Replace by http://docs.oracle.com/javase/7/docs/api/java/awt/Desktop.html
* http://stackoverflow.com/questions/18004150/desktop-api-is-not-supported-on-the-current-platform
* See http://stackoverflow.com/questions/18004150/desktop-api-is-not-supported-on-the-current-platform for more implementation hints.
* http://docs.oracle.com/javase/7/docs/api/java/awt/Desktop.html cannot be used as we don't want to rely on AWT
*/
public class JabRefDesktop {

private static final Logger LOGGER = LoggerFactory.getLogger(JabRefDesktop.class);

private static final NativeDesktop NATIVE_DESKTOP = getNativeDesktop();
private static final NativeDesktop NATIVE_DESKTOP = OS.getNativeDesktop();
private static final Pattern REMOTE_LINK_PATTERN = Pattern.compile("[a-z]+://.*");

private JabRefDesktop() {
Expand All @@ -61,7 +56,7 @@ public static void openExternalViewer(BibDatabaseContext databaseContext,
throws IOException {
String link = initialLink;
Field field = initialField;
if (StandardField.PS == field || StandardField.PDF == field) {
if ((StandardField.PS == field) || (StandardField.PDF == field)) {
// Find the default directory for this field type:
List<Path> directories = databaseContext.getFileDirectories(preferencesService.getFilePreferences());

Expand Down Expand Up @@ -202,25 +197,64 @@ public static void openFolderAndSelectFile(Path fileLink, PreferencesService pre
boolean useCustomFileBrowser = preferencesService.getExternalApplicationsPreferences().useCustomFileBrowser();
if (!useCustomFileBrowser) {
NATIVE_DESKTOP.openFolderAndSelectFile(fileLink);
} else {
String absolutePath = fileLink.toAbsolutePath().getParent().toString();
String command = preferencesService.getExternalApplicationsPreferences().getCustomFileBrowserCommand();
if (!command.isEmpty()) {
command = command.replaceAll("\\s+", " "); // normalize white spaces

// replace the placeholder if used
command = command.replace("%DIR", absolutePath);
String[] subcommands = command.split(" ");

LOGGER.info("Executing command \"" + command + "\"...");

try {
new ProcessBuilder(subcommands).start();
} catch (IOException exception) {
LOGGER.error("Open File Browser", exception);
dialogService.notify(Localization.lang("Error occured while executing the command \"%0\".", command));
}
}
return;
}
String absolutePath = fileLink.toAbsolutePath().getParent().toString();
String command = preferencesService.getExternalApplicationsPreferences().getCustomFileBrowserCommand();
if (command.isEmpty()) {
LOGGER.info("No custom file browser command defined");
NATIVE_DESKTOP.openFolderAndSelectFile(fileLink);
return;
}
executeCommand(command, absolutePath, dialogService);
}

/**
* Opens a new console starting on the given file location
* <p>
* If no command is specified in {@link Globals}, the default system console will be executed.
*
* @param file Location the console should be opened at.
*
*/
public static void openConsole(Path file, PreferencesService preferencesService, DialogService dialogService) throws IOException {
if (file == null) {
return;
}

String absolutePath = file.toAbsolutePath().getParent().toString();

boolean useCustomTerminal = preferencesService.getExternalApplicationsPreferences().useCustomTerminal();
if (!useCustomTerminal) {
NATIVE_DESKTOP.openConsole(absolutePath, dialogService);
return;
}
String command = preferencesService.getExternalApplicationsPreferences().getCustomTerminalCommand();
command = command.trim();
if (command.isEmpty()) {
NATIVE_DESKTOP.openConsole(absolutePath, dialogService);
LOGGER.info("Preference for custom terminal is empty. Using default terminal.");
return;
}
executeCommand(command, absolutePath, dialogService);
}

private static void executeCommand(String command, String absolutePath, DialogService dialogService) {
// normalize white spaces
command = command.replaceAll("\\s+", " ");

// replace the placeholder if used
command = command.replace("%DIR", absolutePath);

LOGGER.info("Executing command \"{}\"...", command);
dialogService.notify(Localization.lang("Executing command \"%0\"...", command));

String[] subcommands = command.split(" ");
try {
new ProcessBuilder(subcommands).start();
} catch (IOException exception) {
LOGGER.error("Error during command execution", exception);
dialogService.notify(Localization.lang("Error occurred while executing the command \"%0\".", command));
}
}

Expand Down Expand Up @@ -256,58 +290,4 @@ public static void openBrowserShowPopup(String url, DialogService dialogService)
dialogService.showErrorDialogAndWait(couldNotOpenBrowser, couldNotOpenBrowser + "\n" + openManually + "\n" + copiedToClipboard);
}
}

/**
* Opens a new console starting on the given file location
* <p>
* If no command is specified in {@link Globals}, the default system console will be executed.
*
* @param file Location the console should be opened at.
*
*/
public static void openConsole(File file, PreferencesService preferencesService, DialogService dialogService) throws IOException {
if (file == null) {
return;
}

String absolutePath = file.toPath().toAbsolutePath().getParent().toString();

boolean useCustomTerminal = preferencesService.getExternalApplicationsPreferences().useCustomTerminal();
if (!useCustomTerminal) {
NATIVE_DESKTOP.openConsole(absolutePath, dialogService);
} else {
String command = preferencesService.getExternalApplicationsPreferences().getCustomTerminalCommand();
command = command.trim();

if (!command.isEmpty()) {
command = command.replaceAll("\\s+", " "); // normalize white spaces
command = command.replace("%DIR", absolutePath); // replace the placeholder if used

String[] subcommands = command.split(" ");

LOGGER.info("Executing command \"" + command + "\"...");
dialogService.notify(Localization.lang("Executing command \"%0\"...", command));

try {
new ProcessBuilder(subcommands).start();
} catch (IOException exception) {
LOGGER.error("Open console", exception);

dialogService.notify(Localization.lang("Error occured while executing the command \"%0\".", command));
}
}
}
}

// TODO: Move to OS.java
public static NativeDesktop getNativeDesktop() {
if (OS.WINDOWS) {
return new Windows();
} else if (OS.OS_X) {
return new OSX();
} else if (OS.LINUX) {
return new Linux();
}
return new DefaultDesktop();
}
}
37 changes: 37 additions & 0 deletions src/main/java/org/jabref/gui/desktop/os/NativeDesktop.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package org.jabref.gui.desktop.os;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;

import org.jabref.gui.DialogService;
import org.jabref.logic.util.BuildInfo;
import org.jabref.logic.util.OS;
import org.jabref.model.pdf.search.SearchFieldConstants;

import net.harawata.appdirs.AppDirsFactory;

public interface NativeDesktop {

Expand Down Expand Up @@ -45,4 +51,35 @@ public interface NativeDesktop {
default Path getUserDirectory() {
return Path.of(System.getProperty("user.home"));
}

default Path getLogDirectory() {
return Path.of(AppDirsFactory.getInstance()
.getUserDataDir(
OS.APP_DIR_APP_NAME,
"logs",
OS.APP_DIR_APP_AUTHOR))
.resolve(new BuildInfo().version.toString());
}

default Path getBackupDirectory() {
return Path.of(AppDirsFactory.getInstance()
.getUserDataDir(
OS.APP_DIR_APP_NAME,
"backups",
OS.APP_DIR_APP_AUTHOR));
}

default Path getFulltextIndexBaseDirectory() {
return Path.of(AppDirsFactory.getInstance()
.getUserDataDir(OS.APP_DIR_APP_NAME,
"lucene" + File.separator + SearchFieldConstants.VERSION,
OS.APP_DIR_APP_AUTHOR));
}

default Path getSslDirectory() {
return Path.of(AppDirsFactory.getInstance()
.getUserDataDir(OS.APP_DIR_APP_NAME,
"ssl",
OS.APP_DIR_APP_AUTHOR));
}
}
5 changes: 2 additions & 3 deletions src/main/java/org/jabref/gui/desktop/os/Windows.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@
import com.sun.jna.platform.win32.Shell32Util;
import com.sun.jna.platform.win32.ShlObj;
import com.sun.jna.platform.win32.Win32Exception;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Windows implements NativeDesktop {
private static final Logger LOGGER = LoggerFactory.getLogger(Windows.class);

private static final String DEFAULT_EXECUTABLE_EXTENSION = ".exe";

Expand Down Expand Up @@ -89,7 +87,8 @@ public Path getDefaultFileChooserDirectory() {
return Path.of(Shell32Util.getFolderPath(ShlObj.CSIDL_MYDOCUMENTS));
}
} catch (Win32Exception e) {
LOGGER.error("Error accessing folder", e);
// needs to be non-static because of org.jabref.cli.Launcher.addLogToDisk
LoggerFactory.getLogger(Windows.class).error("Error accessing folder", e);
return Path.of(System.getProperty("user.home"));
}
}
Expand Down
Loading