Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into restapi
Browse files Browse the repository at this point in the history
* upstream/main: (26 commits)
  Remove bibtexml.xsd (We don't support BibTeXML any more)
  Rewrite code of MedlineImporter (#9673)
  Rename variable and add more documentation
  Fix checkstyle
  Add hanling of "field = {content\}"
  Add link to PR
  Add link to PR.
  JabRef writes a new backup file only if there is a change.
  Add debug output to log.txt
  Refine logging howto
  Change log level for non-found files during PDF indexing
  Initial ImportHandlerTest
  Streamline AppDirs paths
  add a clear history button in sub-menu
  Removed redundant list
  add for en.properties
  add Localization.lang for string
  correct changelog
  add test for getLastSearchHistory and change HashLinkedSet to ArrayList
  fix the checkstlye
  ...
  • Loading branch information
Siedlerchr committed Mar 18, 2023
2 parents cf14659 + a0cb4be commit ba80857
Show file tree
Hide file tree
Showing 37 changed files with 2,135 additions and 1,794 deletions.
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
### Added

- We added a field showing the BibTeX/biblatex source for added and deleted entries in the "External Changes Resolver" dialog. [#9509](https://github.com/JabRef/jabref/issues/9509)
- We added a search history list in the search field's right click menu [#7906](https://github.com/JabRef/jabref/issues/7906)
- We added a full text fetcher for IACR eprints. [#9651](https://github.com/JabRef/jabref/pull/9651)
- We added "Attach file from URL" to right-click context menu to download and store a file with the reference library. [#9646](https://github.com/JabRef/jabref/issues/9646)
- We enabled updating an existing entry with data from InspireHEP. [#9351](https://github.com/JabRef/jabref/issues/9351)
Expand All @@ -23,8 +24,16 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
### Changed

- 'Get full text' now also checks the file url. [#568](https://github.com/koppor/jabref/issues/568)
- `log.txt` now contains an entry if a BibTeX entry could not be parsed.
- JabRef writes a new backup file only if there is a change. Before, JabRef created a backup upon start. [#9679](https://github.com/JabRef/jabref/pull/9679)
- We modified the `Add Group` dialog to use the most recently selected group hierarchical context. [#9141](https://github.com/JabRef/jabref/issues/9141)
- We refined the 'main directory not found' error message. [#9625](https://github.com/JabRef/jabref/pull/9625)
- We modified the `Add Group` dialog to use the most recently selected group hierarchical context [#9141](https://github.com/JabRef/jabref/issues/9141)
- JabRef writes a new backup file only if there is a change. Before, JabRef created a backup upon start. [#9679](https://github.com/JabRef/jabref/pull/9679)
- Backups of libraries are not stored per JabRef version, but collected together.
- We streamlined the paths for logs and backups: The parent path fragement is always `logs` or `backups`.
- `log.txt` now contains debug messages. Debugging needs to be enabled explicitly. [#9678](https://github.com/JabRef/jabref/pull/9678)
- `log.txt` does not contain entries for non-found files during PDF indexing. [#9678](https://github.com/JabRef/jabref/pull/9678)
- We improved the Medline importer to correctly import ISO dates for `revised`. [#9536](https://github.com/JabRef/jabref/issues/9536)



Expand All @@ -37,6 +46,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We fixed an issue where the command line export using `--exportMatches` flag does not create an output bib file [#9581](https://github.com/JabRef/jabref/issues/9581)
- We fixed an issue where custom field in the custom entry types could not be set to mulitline [#9609](https://github.com/JabRef/jabref/issues/9609)
- We fixed an issue where the Office XML exporter did not resolve BibTeX-Strings when exporting entries [forum#3741](https://discourse.jabref.org/t/exporting-bibtex-constant-strings-to-ms-office-2007-xml/3741)
- JabRef is now more relaxed when parsing field content: In case a field content ended with `\`, the combination `\}` was treated as plain `}`. [#9668](https://github.com/JabRef/jabref/issues/9668)


### Removed
Expand Down
20 changes: 0 additions & 20 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,6 @@ processResources {

task generateSource(dependsOn: ["generateBstGrammarSource",
"generateSearchGrammarSource",
"generateMedlineSource",
"generateBibtexmlSource",
"generateEndnoteSource",
"generateModsSource",
"generateCitaviSource"]) {
Expand Down Expand Up @@ -302,24 +300,6 @@ tasks.register("generateSearchGrammarSource", JavaExec) {
args = ["-o","src-gen/main/java/org/jabref/search" , "-visitor", "-no-listener", "-package", "org.jabref.search", "$projectDir/src/main/antlr4/org/jabref/search/Search.g4"]
}

task generateMedlineSource(type: XjcTask) {
group = 'JabRef'
description = "Generates java files for the medline importer."

schemaFile = "src/main/resources/xjc/medline/medline.xsd"
outputDirectory = "src-gen/main/java"
javaPackage = "org.jabref.logic.importer.fileformat.medline"
}

task generateBibtexmlSource(type: XjcTask) {
group = 'JabRef'
description = "Generates java files for the bibtexml importer."

schemaFile = "src/main/resources/xjc/bibtexml/bibtexml.xsd"
outputDirectory = "src-gen/main/java/"
javaPackage = "org.jabref.logic.importer.fileformat.bibtexml"
}

task generateEndnoteSource(type: XjcTask) {
group = 'JabRef'
description = "Generates java files for the endnote importer."
Expand Down
50 changes: 37 additions & 13 deletions docs/code-howtos/logging.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,44 @@ parent: Code Howtos

JabRef uses the logging facade [SLF4j](https://www.slf4j.org). All log messages are passed internally to [tinylog](https://tinylog.org/v2/) which handles any filtering, formatting and writing of log messages.

* Obtaining a logger for a class:
Obtaining a logger for a class:

```java
private static final Logger LOGGER = LoggerFactory.getLogger(<ClassName>.class);
```
```java
private static final Logger LOGGER = LoggerFactory.getLogger(<ClassName>.class);
```

* If the logging event is caused by an exception, please add the exception to the log message as:
Please always use `LOGGER.debug` for debugging.

```java
catch (SomeException e) {
LOGGER.warn("Warning text.", e);
...
}
```
Example:

```java
String example = "example";
LOGGER.debug("Some state {}", example);
```

Enable logging in `tinylog.properties`:

```properties
level@org.jabref.example.ExampleClass = debug
```

If the logging event is caused by an exception, please add the exception to the log message as:

```java
catch (SomeException e) {
LOGGER.warn("Warning text.", e);
...
}
```

When running tests, `tinylog-test.properties` is used.
It is located under `src/test/resources`. As default, only `info` is logged.
When developing, it makes sense to use `debug` as log level.
One can change the log level per class using the pattern `level@class=debug` is set to `debug`.
In the `.properties` file, this is done for `org.jabref.model.entry.BibEntry`.

## Further reading

SLF4J also support parameterized logging, e.g. if you want to print out multiple arguments in a log statement use a pair of curly braces (`{}`).
Head to <https://www.slf4j.org/faq.html#logging_performance> for examples.

* SLF4J also support parameterized logging, e.g. if you want to print out multiple arguments in a log statement use a pair of curly braces. [Examples](https://www.slf4j.org/faq.html#logging\_performance)
* When running tests, `tinylog-test.properties` is used. It is located under `src/test/resources`. As default, only `info` is logged. When developing, it makes sense to use `debug` as log level. One can change the log level per class using the pattern `level@class=debug` is set to `debug`. In the `.properties` file, this is done for `org.jabref.model.entry.BibEntry`.
13 changes: 8 additions & 5 deletions src/main/java/org/jabref/cli/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.jabref.logic.remote.client.RemoteClient;
import org.jabref.logic.shared.restserver.rest.Root;
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.model.database.BibDatabaseMode;
Expand Down Expand Up @@ -118,10 +119,12 @@ static void startServer() {
* the log configuration programmatically anymore.
*/
private static void addLogToDisk() {
Path directory = Path.of(AppDirsFactory.getInstance().getUserLogDir(
"jabref",
new BuildInfo().version.toString(),
"org.jabref"));
Path directory = Path.of(AppDirsFactory.getInstance()
.getUserDataDir(
OS.APP_DIR_APP_NAME,
"logs",
OS.APP_DIR_APP_AUTHOR))
.resolve(new BuildInfo().version.toString());
try {
Files.createDirectories(directory);
} catch (IOException e) {
Expand All @@ -133,7 +136,7 @@ private static void addLogToDisk() {
// https://tinylog.org/v2/configuration/#shared-file-writer
Map<String, String> configuration = Map.of(
"writerFile", "shared file",
"writerFile.level", "info",
"writerFile.level", "debug",
"writerFile.file", directory.resolve("log.txt").toString(),
"writerFile.charset", "UTF-8");

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/ClipBoardManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static String getContents() {
return result;
}

public Optional<String> getBibTeXEntriesFromClipbaord() {
public Optional<String> getBibTeXEntriesFromClipboard() {
return Optional.ofNullable(clipboard.getContent(DragAndDropDataFormats.ENTRIES)).map(String.class::cast);
}

Expand Down
23 changes: 23 additions & 0 deletions src/main/java/org/jabref/gui/StateManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ public class StateManager {

private final ObjectProperty<LastAutomaticFieldEditorEdit> lastAutomaticFieldEditorEdit = new SimpleObjectProperty<>();

private final ObservableList<String> searchHistory = FXCollections.observableArrayList();

public StateManager() {
activeGroups.bind(Bindings.valueAt(selectedGroups, activeDatabase.orElseOpt(null)));
}
Expand Down Expand Up @@ -212,4 +214,25 @@ public List<String> collectAllDatabasePaths() {
() -> list.add("")));
return list;
}

public void addSearchHistory(String search) {
searchHistory.remove(search);
searchHistory.add(search);
}

public ObservableList<String> getWholeSearchHistory() {
return searchHistory;
}

public List<String> getLastSearchHistory(int size) {
int sizeSearches = searchHistory.size();
if (size < sizeSearches) {
return searchHistory.subList(sizeSearches - size, sizeSearches);
}
return searchHistory;
}

public void clearSearchHistory() {
searchHistory.clear();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public BackupResolverDialog(Path originalPath) {
getDialogPane().setMinHeight(180);
getDialogPane().getButtonTypes().setAll(RESTORE_FROM_BACKUP, REVIEW_BACKUP, IGNORE_BACKUP);

Optional<Path> backupPathOpt = BackupFileUtil.getPathOfLatestExisingBackupFile(originalPath, BackupFileType.BACKUP);
Optional<Path> backupPathOpt = BackupFileUtil.getPathOfLatestExistingBackupFile(originalPath, BackupFileType.BACKUP);
String backupFilename = backupPathOpt.map(Path::getFileName).map(Path::toString).orElse(Localization.lang("File not found"));
String content = new StringBuilder()
.append(Localization.lang("A backup file for '%0' was found at [%1]",
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/dialogs/BackupUIManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private static Optional<ParserResult> showReviewBackupDialog(DialogService dialo
// This will be modified by using the `DatabaseChangesResolverDialog`.
BibDatabaseContext originalDatabase = originalParserResult.getDatabaseContext();

Path backupPath = BackupFileUtil.getPathOfLatestExisingBackupFile(originalPath, BackupFileType.BACKUP).orElseThrow();
Path backupPath = BackupFileUtil.getPathOfLatestExistingBackupFile(originalPath, BackupFileType.BACKUP).orElseThrow();
BibDatabaseContext backupDatabase = OpenDatabase.loadDatabase(backupPath, importFormatPreferences, new DummyFileUpdateMonitor()).getDatabaseContext();

DatabaseChangeResolverFactory changeResolverFactory = new DatabaseChangeResolverFactory(dialogService, originalDatabase, preferencesService.getBibEntryPreferences());
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/org/jabref/gui/edit/EditAction.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jabref.gui.edit;

import javafx.scene.control.TextField;
import javafx.scene.control.TextInputControl;
import javafx.scene.web.WebView;

Expand All @@ -22,6 +23,7 @@ public class EditAction extends SimpleCommand {
private static final Logger LOGGER = LoggerFactory.getLogger(EditAction.class);

private final JabRefFrame frame;
private TextField text;
private final StandardActions action;
private final StateManager stateManager;

Expand Down Expand Up @@ -52,8 +54,12 @@ public void execute() {
// DELETE_ENTRY in text field should do forward delete
switch (action) {
case COPY -> textInput.copy();
case UNDO -> textInput.undo();
case REDO -> textInput.redo();
case CUT -> textInput.cut();
case PASTE -> textInput.paste();
case DELETE -> textInput.clear();
case SELECT_ALL -> textInput.selectAll();
case DELETE_ENTRY -> textInput.deleteNextChar();
default -> throw new IllegalStateException("Only cut/copy/paste supported in TextInputControl but got " + action);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ private void generateKeys(List<BibEntry> entries) {
}

public List<BibEntry> handleBibTeXData(String entries) {
BibtexParser parser = new BibtexParser(preferencesService.getImportFormatPreferences(), Globals.getFileUpdateMonitor());
BibtexParser parser = new BibtexParser(preferencesService.getImportFormatPreferences(), fileUpdateMonitor);
try {
return parser.parseEntries(new ByteArrayInputStream(entries.getBytes(StandardCharsets.UTF_8)));
} catch (ParseException ex) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/jabref/gui/maintable/MainTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,9 @@ private void clearAndSelectLast() {

public void paste() {
List<BibEntry> entriesToAdd;
entriesToAdd = this.clipBoardManager.getBibTeXEntriesFromClipbaord()
entriesToAdd = this.clipBoardManager.getBibTeXEntriesFromClipboard()
.map(importHandler::handleBibTeXData)
.orElseGet(this::handleNonBibteXStringData);
.orElseGet(this::handleNonBibTeXStringData);

for (BibEntry entry : entriesToAdd) {
importHandler.importEntryWithDuplicateCheck(database, entry);
Expand All @@ -334,7 +334,7 @@ public void paste() {
}
}

private List<BibEntry> handleNonBibteXStringData() {
private List<BibEntry> handleNonBibTeXStringData() {
String data = ClipBoardManager.getContents();
List<BibEntry> entries = new ArrayList<>();
try {
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/org/jabref/gui/search/GlobalSearchBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import javafx.beans.binding.BooleanBinding;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
import javafx.css.PseudoClass;
import javafx.event.Event;
import javafx.geometry.Insets;
Expand Down Expand Up @@ -138,6 +140,19 @@ public GlobalSearchBar(JabRefFrame frame, StateManager stateManager, Preferences
}
});

searchField.setContextMenu(SearchFieldRightClickMenu.create(
keyBindingRepository,
stateManager,
searchField));

ObservableList<String> search = stateManager.getWholeSearchHistory();
search.addListener((ListChangeListener.Change<? extends String> change) -> {
searchField.setContextMenu(SearchFieldRightClickMenu.create(
keyBindingRepository,
stateManager,
searchField));
});

ClipBoardManager.addX11Support(searchField);

regularExpressionButton = IconTheme.JabRefIcons.REG_EX.asToggleButton();
Expand Down Expand Up @@ -292,6 +307,7 @@ public void performSearch() {
informUserAboutInvalidSearchQuery();
return;
}
this.stateManager.addSearchHistory(searchField.textProperty().get());
stateManager.setSearchQuery(searchQuery);
}

Expand Down
72 changes: 72 additions & 0 deletions src/main/java/org/jabref/gui/search/SearchFieldRightClickMenu.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package org.jabref.gui.search;

import javafx.scene.control.ContextMenu;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuItem;
import javafx.scene.control.SeparatorMenuItem;

import org.jabref.gui.StateManager;
import org.jabref.gui.actions.ActionFactory;
import org.jabref.gui.actions.SimpleCommand;
import org.jabref.gui.actions.StandardActions;
import org.jabref.gui.edit.EditAction;
import org.jabref.gui.keyboard.KeyBindingRepository;
import org.jabref.logic.l10n.Localization;

import org.controlsfx.control.textfield.CustomTextField;

public class SearchFieldRightClickMenu {
public static ContextMenu create(KeyBindingRepository keyBindingRepository,
StateManager stateManager,
CustomTextField searchField) {
ActionFactory factory = new ActionFactory(keyBindingRepository);
ContextMenu contextMenu = new ContextMenu();

contextMenu.getItems().addAll(
factory.createMenuItem(StandardActions.UNDO, new EditAction(StandardActions.UNDO, null, stateManager)),
factory.createMenuItem(StandardActions.REDO, new EditAction(StandardActions.REDO, null, stateManager)),
factory.createMenuItem(StandardActions.CUT, new EditAction(StandardActions.CUT, null, stateManager)),
factory.createMenuItem(StandardActions.COPY, new EditAction(StandardActions.COPY, null, stateManager)),
factory.createMenuItem(StandardActions.PASTE, new EditAction(StandardActions.PASTE, null, stateManager)),
factory.createMenuItem(StandardActions.DELETE, new EditAction(StandardActions.DELETE, null, stateManager)),

new SeparatorMenuItem(),

factory.createMenuItem(StandardActions.SELECT_ALL, new EditAction(StandardActions.SELECT_ALL, null, stateManager)),
createSearchFromHistorySubMenu(factory, stateManager, searchField)
);

return contextMenu;
}

private static Menu createSearchFromHistorySubMenu(ActionFactory factory,
StateManager stateManager,
CustomTextField searchField) {
Menu searchFromHistorySubMenu = factory.createMenu(() -> Localization.lang("Search from history..."));

int num = stateManager.getLastSearchHistory(10).size();
if (num == 0) {
MenuItem item = new MenuItem(Localization.lang("your search history is empty"));
searchFromHistorySubMenu.getItems().addAll(item);
} else {
for (int i = 0; i < num; i++) {
int finalI = i;
MenuItem item = factory.createMenuItem(() -> stateManager.getLastSearchHistory(10).get(finalI), new SimpleCommand() {
@Override
public void execute() {
searchField.setText(stateManager.getLastSearchHistory(10).get(finalI));
}
});
searchFromHistorySubMenu.getItems().addAll(item);
}
MenuItem clear = factory.createMenuItem(() -> Localization.lang("Clear history"), new SimpleCommand() {
@Override
public void execute() {
stateManager.clearSearchHistory();
}
});
searchFromHistorySubMenu.getItems().addAll(new SeparatorMenuItem(), clear);
}
return searchFromHistorySubMenu;
}
}
Loading

0 comments on commit ba80857

Please sign in to comment.