Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into allowReordering
Browse files Browse the repository at this point in the history
* upstream/master:
  Validates the file path of a TexGroup and fixes Texgroup's "Library has been modified by another program" (#6586)
  Bump postgresql from 42.2.12 to 42.2.14 (#6610)
  Add markdown-link-check (#6542)
  Catch InaccessibleObjectException (#6519)
  Fix author formatter for unchanged names (#6552)
  Bump com.simonharrer.modernizer from 1.8.0-1 to 2.1.0-1
  Bump org.beryx.jlink from 2.19.0 to 2.20.0
  Bump classgraph from 4.8.83 to 4.8.86
  Update FileUtilTest.java
  Update FileUtilTest.java
  Squashed 'src/main/resources/csl-styles/' changes from c5f14e2..716f635
  Update FileUtilTest.java
  Update MoveFilesCleanupTest.java
  checkstyle
  Fix dowmloaded files moved to citaiton key dir
  • Loading branch information
Siedlerchr committed Jun 19, 2020
2 parents fbc3d4d + ef0a6bb commit 716a78d
Show file tree
Hide file tree
Showing 66 changed files with 3,624 additions and 600 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,17 @@ jobs:
- name: Run markdown-lint
uses: avto-dev/markdown-lint@v1
with:
args: CHANGELOG.md README.md docs/
args: CHANGELOG.md CONTRIBUTING.md README.md docs/
config: '.markdownlint.yml'
- name: Prepare markdown-link-check
run: mkdir docs/ROOT && cp CHANGELOG.md README.md docs/ROOT
- name: Run markdown-link-check
uses: gaurav-nelson/github-action-markdown-link-check@619e549
with:
use-quiet-mode: 'yes'
use-verbose-mode: 'no'
config-file: 'mlc_config.json'
folder-path: 'docs/'
tests:
name: Unit tests
runs-on: ubuntu-latest
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We fixed an issue where "null" appeared in generated BibTeX keys. [#6459](https://github.com/JabRef/jabref/issues/6459)
- We fixed an issue where the authors' names were incorrectly displayed in the authors' column when they were bracketed. [#6465](https://github.com/JabRef/jabref/issues/6465) [#6459](https://github.com/JabRef/jabref/issues/6459)
- We fixed an issue where importing certain unlinked files would result in an exception [#5815](https://github.com/JabRef/jabref/issues/5815)
- We fixed an issue where downloaded files would be moved to a directory named after the citationkey when no file directory pattern is specified [#6589](https://github.com/JabRef/jabref/issues/6589)
- We fixed an issue with the creation of a group of cited entries which incorrectly showed the message that the library had been modified externally whenever saving the library. [#6420](https://github.com/JabRef/jabref/issues/6420)
- We fixed an issue with the creation of a group of cited entries. Now the file path to an aux file gets validated. [#6585](https://github.com/JabRef/jabref/issues/6585)

### Removed

Expand Down
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import org.jabref.build.xjc.XjcTask

plugins {
id 'application'
id "com.simonharrer.modernizer" version '1.8.0-1'
id "com.simonharrer.modernizer" version '2.1.0-1'
id 'me.champeau.gradle.jmh' version '0.5.0'
id 'com.github.ben-manes.versions' version '0.28.0'
id 'org.javamodularity.moduleplugin' version '1.5.0'
id 'org.openjfx.javafxplugin' version '0.0.8'
id 'org.beryx.jlink' version '2.19.0'
id 'org.beryx.jlink' version '2.20.0'

// nicer test outputs during running and completion
id 'com.adarshr.test-logger' version '2.0.0'
Expand Down Expand Up @@ -140,7 +140,7 @@ dependencies {

implementation group: 'org.mariadb.jdbc', name: 'mariadb-java-client', version: '2.6.0'

implementation 'org.postgresql:postgresql:42.2.12'
implementation 'org.postgresql:postgresql:42.2.14'

implementation ('com.oracle.ojdbc:ojdbc10:19.3.0.0') {
// causing module issues
Expand Down Expand Up @@ -196,7 +196,7 @@ dependencies {
implementation 'com.vladsch.flexmark:flexmark-ext-gfm-strikethrough:0.62.2'
implementation 'com.vladsch.flexmark:flexmark-ext-gfm-tasklist:0.62.2'

testImplementation 'io.github.classgraph:classgraph:4.8.83'
testImplementation 'io.github.classgraph:classgraph:4.8.86'
testImplementation 'org.junit.jupiter:junit-jupiter:5.6.2'
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine:5.6.2'
testImplementation 'org.junit.platform:junit-platform-launcher:1.6.2'
Expand Down
2 changes: 1 addition & 1 deletion config/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<!-- BeforeExecutionFileFilters is required for sources that are based on java14 -->
<module name="BeforeExecutionExclusionFileFilter">
<property name="fileNamePattern" value="AuthorAndsReplacer.java|Ordinal.java|EntryTypeView.java" />
<property name="fileNamePattern" value="AuthorAndsReplacer.java|EntryTypeView.java|MainTableFieldValueFormatter.java|Ordinal.java" />
</module>

<module name="SuppressionFilter">
Expand Down
9 changes: 9 additions & 0 deletions mlc_config.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
{
"ignorePatterns": [
{
"pattern": "^CONTRIBUTING\\.md"
},
{
"pattern": "^https://dl\\.acm\\.org"
},
{
"pattern": "^https://github\\.com"
},
{
"pattern": "^https://.*\\.jabref\\.org"
},
{
"pattern": "^http://purl\\.org/net/bibteXMP"
},
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/jabref/gui/actions/ActionFactory.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jabref.gui.actions;

import java.lang.reflect.InaccessibleObjectException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Objects;
Expand Down Expand Up @@ -66,7 +67,7 @@ private static Label getAssociatedNode(MenuItem menuItem) {
Method getLabel = ContextMenuContent.MenuItemContainer.class.getDeclaredMethod("getLabel");
getLabel.setAccessible(true);
return (Label) getLabel.invoke(container);
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
} catch (InaccessibleObjectException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
LOGGER.warn("Could not get label of menu item", e);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/jabref/gui/groups/GroupDialogView.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ public void initialize() {
validationVisualizer.initVisualization(viewModel.keywordRegexValidationStatus(), keywordGroupSearchTerm);
validationVisualizer.initVisualization(viewModel.keywordSearchTermEmptyValidationStatus(), keywordGroupSearchTerm);
validationVisualizer.initVisualization(viewModel.keywordFieldEmptyValidationStatus(), keywordGroupSearchField);
validationVisualizer.initVisualization(viewModel.texGroupFilePathValidatonStatus(), texGroupFilePath);
nameField.requestFocus();
});

Expand Down
34 changes: 32 additions & 2 deletions src/main/java/org/jabref/gui/groups/GroupDialogViewModel.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jabref.gui.groups;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -98,6 +99,7 @@ public class GroupDialogViewModel {
private Validator keywordSearchTermEmptyValidator;
private Validator searchRegexValidator;
private Validator searchSearchTermEmptyValidator;
private Validator texGroupFilePathValidator;
private final CompositeValidator validator = new CompositeValidator();

private final DialogService dialogService;
Expand Down Expand Up @@ -212,8 +214,24 @@ private void setupValidation() {
input -> !StringUtil.isNullOrEmpty(input),
ValidationMessage.error(String.format("%s > %n %s",
Localization.lang("Free search expression"),
Localization.lang("Search term is empty.")
)));
Localization.lang("Search term is empty."))));

texGroupFilePathValidator = new FunctionBasedValidator<>(
texGroupFilePathProperty,
input -> {
if (StringUtil.isBlank(input)) {
return false;
} else {
Path texFilePath = preferencesService.getWorkingDir().resolve(input);
if (!Files.isRegularFile(texFilePath)) {
return false;
}
return FileUtil.getFileExtension(input)
.map(extension -> extension.toLowerCase().equals("aux"))
.orElse(false);
}
},
ValidationMessage.error(Localization.lang("Please provide a valid aux file.")));

validator.addValidators(nameValidator, sameNameValidator);

Expand All @@ -232,6 +250,14 @@ private void setupValidation() {
validator.removeValidators(keywordFieldEmptyValidator, keywordRegexValidator, keywordSearchTermEmptyValidator);
}
});

typeTexProperty.addListener((obs, oldValue, isSelected) -> {
if (isSelected) {
validator.addValidators(texGroupFilePathValidator);
} else {
validator.removeValidators(texGroupFilePathValidator);
}
});
}

public void validationHandler(Event event) {
Expand Down Expand Up @@ -439,6 +465,10 @@ public ValidationStatus keywordSearchTermEmptyValidationStatus() {
return keywordSearchTermEmptyValidator.getValidationStatus();
}

public ValidationStatus texGroupFilePathValidatonStatus() {
return texGroupFilePathValidator.getValidationStatus();
}

public StringProperty nameProperty() {
return nameProperty;
}
Expand Down
37 changes: 9 additions & 28 deletions src/main/java/org/jabref/gui/maintable/BibEntryTableViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@
import javafx.beans.value.ObservableValue;

import org.jabref.gui.specialfields.SpecialFieldValueViewModel;
import org.jabref.model.database.BibDatabase;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.FileFieldParser;
import org.jabref.model.entry.LinkedFile;
import org.jabref.model.entry.field.Field;
import org.jabref.model.entry.field.FieldProperty;
import org.jabref.model.entry.field.OrFields;
import org.jabref.model.entry.field.SpecialField;
import org.jabref.model.entry.field.StandardField;
Expand All @@ -33,22 +31,20 @@

public class BibEntryTableViewModel {
private final BibEntry entry;
private final BibDatabase database;
private final ObservableValue<MainTableNameFormatter> nameFormatter;
private final ObservableValue<MainTableFieldValueFormatter> fieldValueFormatter;
private final Map<OrFields, ObservableValue<String>> fieldValues = new HashMap<>();
private final Map<SpecialField, OptionalBinding<SpecialFieldValueViewModel>> specialFieldValues = new HashMap<>();
private final EasyBinding<List<LinkedFile>> linkedFiles;
private final EasyBinding<Map<Field, String>> linkedIdentifiers;
private final ObservableValue<List<AbstractGroup>> matchedGroups;

public BibEntryTableViewModel(BibEntry entry, BibDatabaseContext database, ObservableValue<MainTableNameFormatter> nameFormatter) {
public BibEntryTableViewModel(BibEntry entry, BibDatabaseContext bibDatabaseContext, ObservableValue<MainTableFieldValueFormatter> fieldValueFormatter) {
this.entry = entry;
this.database = database.getDatabase();
this.nameFormatter = nameFormatter;
this.fieldValueFormatter = fieldValueFormatter;

this.linkedFiles = getField(StandardField.FILE).map(FileFieldParser::parse).orElse(Collections.emptyList());
this.linkedIdentifiers = createLinkedIdentifiersBinding(entry);
this.matchedGroups = createMatchedGroupsBinding(database, entry);
this.matchedGroups = createMatchedGroupsBinding(bibDatabaseContext, entry);
}

private static EasyBinding<Map<Field, String>> createLinkedIdentifiersBinding(BibEntry entry) {
Expand Down Expand Up @@ -120,26 +116,11 @@ public ObservableValue<String> getFields(OrFields fields) {
}

ArrayList<Observable> observables = new ArrayList<>(List.of(entry.getObservables()));
observables.add(nameFormatter);

value = Bindings.createStringBinding(() -> {
for (Field field : fields) {
if (field.getProperties().contains(FieldProperty.PERSON_NAMES)) {
Optional<String> name = entry.getResolvedFieldOrAlias(field, database);

if (name.isPresent()) {
return nameFormatter.getValue().formatNameLatexFree(name.get());
}
} else {
Optional<String> content = entry.getResolvedFieldOrAliasLatexFree(field, database);

if (content.isPresent()) {
return content.get();
}
}
}
return "";
}, observables.toArray(Observable[]::new));
observables.add(fieldValueFormatter);

value = Bindings.createStringBinding(() ->
fieldValueFormatter.getValue().formatFieldsValues(fields, entry),
observables.toArray(Observable[]::new));
fieldValues.put(fields, value);
return value;
}
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/org/jabref/gui/maintable/MainTableDataModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,19 @@ public class MainTableDataModel {
private final FilteredList<BibEntryTableViewModel> entriesFiltered;
private final SortedList<BibEntryTableViewModel> entriesSorted;
private final GroupViewMode groupViewMode;
private final ObjectProperty<MainTableNameFormatter> nameFormatter;
private final ObjectProperty<MainTableFieldValueFormatter> fieldValueFormatter;
private final PreferencesService preferencesService;
private final BibDatabaseContext bibDatabaseContext;

public MainTableDataModel(BibDatabaseContext context, PreferencesService preferencesService, StateManager stateManager) {
this.nameFormatter = new SimpleObjectProperty<>(new MainTableNameFormatter(preferencesService));
this.preferencesService = preferencesService;
this.bibDatabaseContext = context;
this.fieldValueFormatter = new SimpleObjectProperty<>(
new MainTableFieldValueFormatter(preferencesService, bibDatabaseContext));

ObservableList<BibEntry> allEntries = BindingsHelper.forUI(context.getDatabase().getEntries());
ObservableList<BibEntryTableViewModel> entriesViewModel = EasyBind.mapBacked(allEntries, entry -> new BibEntryTableViewModel(entry, context, nameFormatter));
ObservableList<BibEntryTableViewModel> entriesViewModel = EasyBind.mapBacked(allEntries, entry ->
new BibEntryTableViewModel(entry, bibDatabaseContext, fieldValueFormatter));

entriesFiltered = new FilteredList<>(entriesViewModel);
entriesFiltered.predicateProperty().bind(
Expand Down Expand Up @@ -86,6 +90,6 @@ public SortedList<BibEntryTableViewModel> getEntriesFilteredAndSorted() {
}

public void refresh() {
this.nameFormatter.setValue(new MainTableNameFormatter(preferencesService));
this.fieldValueFormatter.setValue(new MainTableFieldValueFormatter(preferencesService, bibDatabaseContext));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package org.jabref.gui.maintable;

import java.util.Optional;

import org.jabref.model.database.BibDatabase;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.AuthorList;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.field.Field;
import org.jabref.model.entry.field.FieldProperty;
import org.jabref.model.entry.field.OrFields;
import org.jabref.preferences.PreferencesService;

import static org.jabref.gui.maintable.MainTableNameFormatPreferences.AbbreviationStyle;
import static org.jabref.gui.maintable.MainTableNameFormatPreferences.DisplayStyle;

public class MainTableFieldValueFormatter {
private final DisplayStyle displayStyle;
private final AbbreviationStyle abbreviationStyle;
private final BibDatabase bibDatabase;

MainTableFieldValueFormatter(PreferencesService preferences, BibDatabaseContext bibDatabaseContext) {
MainTableNameFormatPreferences nameFormatPreferences = preferences.getMainTableNameFormatPreferences();
this.displayStyle = nameFormatPreferences.getDisplayStyle();
this.abbreviationStyle = nameFormatPreferences.getAbbreviationStyle();
this.bibDatabase = bibDatabaseContext.getDatabase();
}

/**
* Format fields for {@link BibEntryTableViewModel}, according to user preferences and with latex translated to
* unicode if possible.
*
* @param fields the fields argument of {@link BibEntryTableViewModel#getFields(OrFields)}.
* @param entry the BibEntry of {@link BibEntryTableViewModel}.
* @return The formatted name field.
*/
public String formatFieldsValues(final OrFields fields, final BibEntry entry) {
for (Field field : fields) {
if (field.getProperties().contains(FieldProperty.PERSON_NAMES) && displayStyle != DisplayStyle.AS_IS) {
Optional<String> name = entry.getResolvedFieldOrAlias(field, bibDatabase);

if (name.isPresent()) {
return formatFieldWithAuthorValue(name.get());
}
} else {
Optional<String> content = entry.getResolvedFieldOrAliasLatexFree(field, bibDatabase);

if (content.isPresent()) {
return content.get();
}
}
}
return "";
}

/**
* Format a name field for the table, according to user preferences and with latex expressions translated if
* possible.
*
* @param nameToFormat The contents of the name field.
* @return The formatted name field.
*/
private String formatFieldWithAuthorValue(final String nameToFormat) {
if (nameToFormat == null) {
return null;
}

AuthorList authors = AuthorList.parse(nameToFormat);

if (((displayStyle == DisplayStyle.FIRSTNAME_LASTNAME)
|| (displayStyle == DisplayStyle.LASTNAME_FIRSTNAME))
&& abbreviationStyle == AbbreviationStyle.LASTNAME_ONLY) {
return authors.getAsLastNamesLatexFree(false);
}

return switch (displayStyle) {
default -> nameToFormat;
case FIRSTNAME_LASTNAME -> authors.getAsFirstLastNamesLatexFree(
abbreviationStyle == AbbreviationStyle.FULL,
false);
case LASTNAME_FIRSTNAME -> authors.getAsLastFirstNamesLatexFree(
abbreviationStyle == AbbreviationStyle.FULL,
false);
case NATBIB -> authors.getAsNatbibLatexFree();
};
}
}
Loading

0 comments on commit 716a78d

Please sign in to comment.