Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into sharedblogin
Browse files Browse the repository at this point in the history
* upstream/master:
  Fix error prone warnings (#4290)
  Fix freeze on import into current library (#4299)
  Upgrade gradle to 4.10 update xmlunit and postgres
  update xmlunit-matchers from 2.6.0 -> 2.6.1
  update gradle build-scan from 1.15.2 -> 1.16
  checkstyle
  execute changes only if disk db present
  fix npe in Merge entries dialog
  • Loading branch information
Siedlerchr committed Aug 29, 2018
2 parents 0da63fa + ce713ca commit 4ebf7c2
Show file tree
Hide file tree
Showing 14 changed files with 94 additions and 136 deletions.
14 changes: 4 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ buildscript {
}

plugins {
id 'com.gradle.build-scan' version '1.15.2'
id 'com.gradle.build-scan' version '1.16'
id 'com.install4j.gradle' version '7.0.6'
id 'com.github.johnrengelman.shadow' version '2.0.4'
id "de.sebastianboegl.shadow.transformer.log4j" version "2.1.1"
Expand Down Expand Up @@ -121,7 +121,7 @@ dependencies {

compile 'mysql:mysql-connector-java:8.0.12'

compile 'org.postgresql:postgresql:42.2.4'
compile 'org.postgresql:postgresql:42.2.5'

compile 'net.java.dev.glazedlists:glazedlists_java15:1.9.1'

Expand Down Expand Up @@ -174,8 +174,8 @@ dependencies {
testCompile 'com.github.tomakehurst:wiremock:2.18.0'
testCompile 'org.assertj:assertj-swing-junit:3.8.0'
testCompile 'org.reflections:reflections:0.9.11'
testCompile 'org.xmlunit:xmlunit-core:2.6.0'
testCompile 'org.xmlunit:xmlunit-matchers:2.6.0'
testCompile 'org.xmlunit:xmlunit-core:2.6.2'
testCompile 'org.xmlunit:xmlunit-matchers:2.6.2'
testCompile 'com.tngtech.archunit:archunit-junit:0.8.3'
testCompile "org.testfx:testfx-core:4.0.+"
testCompile "org.testfx:testfx-junit5:4.0.+"
Expand Down Expand Up @@ -217,12 +217,6 @@ dependencyUpdates.resolutionStrategy = {
selection.reject("Cannot be upgraded to version 2")
}
}
rules.withModule("mysql:mysql-connector-java") { ComponentSelection selection ->
if (selection.candidate.version ==~ /[6-9].*/) {
selection.reject("http://dev.mysql.com/downloads/connector/j/ lists the version 5.* as last stable version.")
}
}

}
}

Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
35 changes: 15 additions & 20 deletions src/main/java/org/jabref/gui/collab/ChangeScanner.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.jabref.gui.collab;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Comparator;
import java.util.List;
Expand Down Expand Up @@ -39,7 +37,7 @@ public class ChangeScanner implements Runnable {

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

private final File file;
private final Optional<Path> file;
private final Path tempFile;
private final BibDatabaseContext databaseInMemory;

Expand All @@ -56,11 +54,11 @@ public class ChangeScanner implements Runnable {

// NamedCompound edit = new NamedCompound("Merged external changes")

public ChangeScanner(JabRefFrame frame, BasePanel bp, File file, Path tempFile) {
public ChangeScanner(JabRefFrame frame, BasePanel bp, Path file, Path tempFile) {
this.panel = bp;
this.frame = frame;
this.databaseInMemory = bp.getBibDatabaseContext();
this.file = file;
this.file = Optional.ofNullable(file);
this.tempFile = tempFile;
}

Expand All @@ -74,8 +72,8 @@ public boolean changesFound() {
*/
private static BibEntry bestFit(BibEntry targetEntry, List<BibEntry> entries) {
return entries.stream()
.max(Comparator.comparingDouble(candidate -> DuplicateCheck.compareEntriesStrictly(targetEntry, candidate)))
.orElse(null);
.max(Comparator.comparingDouble(candidate -> DuplicateCheck.compareEntriesStrictly(targetEntry, candidate)))
.orElse(null);
}

public void displayResult(final DisplayResultCallback fup) {
Expand All @@ -91,7 +89,7 @@ public void displayResult(final DisplayResultCallback fup) {
});
} else {
frame.getDialogService().showInformationDialogAndWait(Localization.lang("External changes"),
Localization.lang("No actual changes found."));
Localization.lang("No actual changes found."));

fup.scanResultsResolved(true);
}
Expand All @@ -101,11 +99,11 @@ private void storeTempDatabase() {
JabRefExecutorService.INSTANCE.execute(() -> {
try {
SavePreferences prefs = Globals.prefs.loadForSaveFromPreferences()
.withMakeBackup(false)
.withEncoding(panel.getBibDatabaseContext()
.getMetaData()
.getEncoding()
.orElse(Globals.prefs.getDefaultEncoding()));
.withMakeBackup(false)
.withEncoding(panel.getBibDatabaseContext()
.getMetaData()
.getEncoding()
.orElse(Globals.prefs.getDefaultEncoding()));

BibDatabaseWriter<SaveSession> databaseWriter = new BibtexDatabaseWriter<>(FileSaveSession::new);
SaveSession ss = databaseWriter.saveDatabase(databaseInTemp, prefs);
Expand All @@ -118,15 +116,14 @@ private void storeTempDatabase() {

@Override
public void run() {
try {

file.ifPresent(diskdb -> {
// Parse the temporary file.
ImportFormatPreferences importFormatPreferences = Globals.prefs.getImportFormatPreferences();
ParserResult result = OpenDatabase.loadDatabase(tempFile.toFile(), importFormatPreferences, Globals.getFileUpdateMonitor());
ParserResult result = OpenDatabase.loadDatabase(tempFile.toAbsolutePath().toString(), importFormatPreferences, Globals.getFileUpdateMonitor());
databaseInTemp = result.getDatabaseContext();

// Parse the modified file.
result = OpenDatabase.loadDatabase(file, importFormatPreferences, Globals.getFileUpdateMonitor());
result = OpenDatabase.loadDatabase(diskdb.toAbsolutePath().toString(), importFormatPreferences, Globals.getFileUpdateMonitor());
BibDatabaseContext databaseOnDisk = result.getDatabaseContext();

// Start looking at changes.
Expand All @@ -138,9 +135,7 @@ public void run() {
differences.getPreambleDifferences().ifPresent(diff -> changes.add(new PreambleChangeViewModel(databaseInMemory.getDatabase().getPreamble().orElse(""), diff)));
differences.getBibStringDifferences().forEach(diff -> changes.add(createBibStringDiff(diff)));
differences.getEntryDifferences().forEach(diff -> changes.add(createBibEntryDiff(diff)));
} catch (IOException ex) {
LOGGER.warn("Problem running", ex);
}
});
}

private ChangeViewModel createBibStringDiff(BibStringDiff diff) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void fileUpdated() {

updatedExternally = true;

final ChangeScanner scanner = new ChangeScanner(panel.frame(), panel, database.getDatabaseFile().orElse(null), tmpFile);
final ChangeScanner scanner = new ChangeScanner(panel.frame(), panel, database.getDatabasePath().orElse(null), tmpFile);

// Test: running scan automatically in background
if (database.getDatabasePath().isPresent() && !FileBasedLock.waitForFileLock(database.getDatabasePath().get())) {
Expand All @@ -76,7 +76,6 @@ public void fileUpdated() {
fileUpdated();
return;
}

JabRefExecutorService.INSTANCE.executeInterruptableTaskAndWait(scanner);

// Adding the sidepane component is Swing work, so we must do this in the Swing
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -409,13 +409,13 @@ private boolean checkExternalModification() {
JabRefExecutorService.INSTANCE.execute(() -> {

if (!FileBasedLock
.waitForFileLock(panel.getBibDatabaseContext().getDatabaseFile().get().toPath())) {
.waitForFileLock(panel.getBibDatabaseContext().getDatabasePath().get())) {
// TODO: GUI handling of the situation when the externally modified file keeps being locked.
LOGGER.error("File locked, this will be trouble.");
}

ChangeScanner scanner = new ChangeScanner(panel.frame(), panel,
panel.getBibDatabaseContext().getDatabaseFile().get(), panel.getTempFile());
panel.getBibDatabaseContext().getDatabasePath().orElse(null), panel.getTempFile());
JabRefExecutorService.INSTANCE.executeInterruptableTaskAndWait(scanner);
if (scanner.changesFound()) {
scanner.displayResult(resolved -> {
Expand Down
25 changes: 13 additions & 12 deletions src/main/java/org/jabref/gui/importer/ImportAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import java.util.Optional;
import java.util.stream.Collectors;

import javax.swing.SwingUtilities;

import org.jabref.Globals;
import org.jabref.gui.BasePanel;
import org.jabref.gui.DialogService;
Expand All @@ -33,7 +35,7 @@ public class ImportAction {
private final Optional<Importer> importer;
private final DialogService dialogService;
private Exception importError;
private TaskExecutor taskExecutor = Globals.TASK_EXECUTOR;
private final TaskExecutor taskExecutor = Globals.TASK_EXECUTOR;

public ImportAction(JabRefFrame frame, boolean openInNew) {
this(frame, openInNew, null);
Expand Down Expand Up @@ -78,26 +80,26 @@ private void reportResult(List<ImportFormatReader.UnknownFormatImport> imports)
} else {
// Import in a specific format was specified. Check if we have stored error information:
if (importError == null) {
dialogService.showErrorDialogAndWait(
Localization.lang("Import failed"),
Localization.lang("No entries found. Please make sure you are using the correct import filter."));
dialogService.showErrorDialogAndWait(Localization.lang("Import failed"),
Localization.lang("No entries found. Please make sure you are using the correct import filter."));
} else {
dialogService.showErrorDialogAndWait(Localization.lang("Import failed"), importError);
}
}
} else {
if (openInNew) {
frame.addTab(bibtexResult.getDatabaseContext(), true);
frame.output(
Localization.lang("Imported entries") + ": " + bibtexResult.getDatabase().getEntryCount());
frame.output(Localization.lang("Imported entries") + ": " + bibtexResult.getDatabase().getEntryCount());
} else {
final BasePanel panel = frame.getCurrentBasePanel();

ImportInspectionDialog diag = new ImportInspectionDialog(frame, panel, Localization.lang("Import"), false);
diag.addEntries(bibtexResult.getDatabase().getEntries());
diag.entryListComplete();
diag.setVisible(true);
diag.toFront();
SwingUtilities.invokeLater(() -> {
ImportInspectionDialog diag = new ImportInspectionDialog(frame, panel, Localization.lang("Import"), false);
diag.addEntries(bibtexResult.getDatabase().getEntries());
diag.entryListComplete();
diag.setVisible(true);
diag.toFront();
});
}
}
}
Expand Down Expand Up @@ -147,7 +149,6 @@ private ParserResult mergeImportResults(List<ImportFormatReader.UnknownFormatImp
if (directParserResult == null) {
directParserResult = pr;
}

// Merge entries:
for (BibEntry entry : pr.getDatabase().getEntries()) {
database.insertEntry(entry);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/jabref/gui/mergeentries/MergeEntries.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.jabref.logic.formatter.casechanger.SentenceCaseFormatter;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.strings.DiffHighlighting;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.database.BibDatabaseMode;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.InternalBibtexFields;
Expand Down Expand Up @@ -179,7 +180,7 @@ private void initialize() {
// Setup a PreviewPanel and a Bibtex source box for the merged entry
mainPanel.add(boldFontLabel(Localization.lang("Merged entry")), CELL_CONSTRAINTS.xyw(1, 6, 6));

entryPreview = new PreviewPanel(null, null, Globals.getKeyPrefs(), Globals.prefs.getPreviewPreferences(), new FXDialogService(), ExternalFileTypes.getInstance());
entryPreview = new PreviewPanel(null, new BibDatabaseContext(), Globals.getKeyPrefs(), Globals.prefs.getPreviewPreferences(), new FXDialogService(), ExternalFileTypes.getInstance());
entryPreview.setEntry(mergedEntry);
JFXPanel container = CustomJFXPanel.wrap(new Scene(entryPreview));
mainPanel.add(container, CELL_CONSTRAINTS.xyw(1, 8, 6));
Expand Down
28 changes: 16 additions & 12 deletions src/main/java/org/jabref/gui/mergeentries/MergeEntriesDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.jabref.gui.undo.NamedCompound;
import org.jabref.gui.undo.UndoableInsertEntry;
import org.jabref.gui.undo.UndoableRemoveEntry;
import org.jabref.gui.util.DefaultTaskExecutor;
import org.jabref.gui.util.WindowLocation;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.entry.BibEntry;
Expand Down Expand Up @@ -51,7 +52,7 @@ private void init(List<BibEntry> selected) {
if (selected.size() != 2) { // None selected. Inform the user to select entries first.

dialogService.showInformationDialogAndWait(Localization.lang("Merge entries"),
Localization.lang("You have to choose exactly two entries to merge."));
Localization.lang("You have to choose exactly two entries to merge."));

this.dispose();
return;
Expand Down Expand Up @@ -88,15 +89,18 @@ private void init(List<BibEntry> selected) {
// Create a new entry and add it to the undo stack
// Remove the other two entries and add them to the undo stack (which is not working...)
BibEntry mergedEntry = mergeEntries.getMergeEntry();
panel.insertEntry(mergedEntry);
ce.addEdit(new UndoableInsertEntry(panel.getDatabase(), mergedEntry));
ce.addEdit(new UndoableRemoveEntry(panel.getDatabase(), one, panel));
panel.getDatabase().removeEntry(one);
ce.addEdit(new UndoableRemoveEntry(panel.getDatabase(), two, panel));
panel.getDatabase().removeEntry(two);
ce.end();
panel.getUndoManager().addEdit(ce);
panel.output(Localization.lang("Merged entries"));
DefaultTaskExecutor.runInJavaFXThread(() -> {
panel.insertEntry(mergedEntry);
ce.addEdit(new UndoableInsertEntry(panel.getDatabase(), mergedEntry));
ce.addEdit(new UndoableRemoveEntry(panel.getDatabase(), one, panel));
panel.getDatabase().removeEntry(one);
ce.addEdit(new UndoableRemoveEntry(panel.getDatabase(), two, panel));
panel.getDatabase().removeEntry(two);
ce.end();
panel.getUndoManager().addEdit(ce);
panel.output(Localization.lang("Merged entries"));
});

dispose();
});

Expand All @@ -110,8 +114,8 @@ private void init(List<BibEntry> selected) {
layout.insertColumn(1, ColumnSpec.decode(MARGIN));

WindowLocation pw = new WindowLocation(this, JabRefPreferences.MERGEENTRIES_POS_X,
JabRefPreferences.MERGEENTRIES_POS_Y, JabRefPreferences.MERGEENTRIES_SIZE_X,
JabRefPreferences.MERGEENTRIES_SIZE_Y);
JabRefPreferences.MERGEENTRIES_POS_Y, JabRefPreferences.MERGEENTRIES_SIZE_X,
JabRefPreferences.MERGEENTRIES_SIZE_Y);
pw.displayWindowAtStoredLocation();

// Show what we've got
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -1172,7 +1172,7 @@ void parsePreambleAndEntryWithoutNewLine() throws IOException {
@Test
void parseFileHeaderAndPreambleWithoutNewLine() throws IOException {
ParserResult result = parser
.parse(new StringReader("% Encoding: US-ASCII@preamble{some text and \\latex}"));
.parse(new StringReader("\\% Encoding: US-ASCII@preamble{some text and \\latex}"));

assertFalse(result.hasWarnings());
assertEquals(Optional.of("some text and \\latex"), result.getDatabase().getPreamble());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,21 @@
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.ResourceBundle;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

class LocalizationConsistencyTest {
Expand Down Expand Up @@ -140,6 +145,31 @@ void localizationParameterMustIncludeAString() throws IOException {
}
}

private static Language[] installedLanguages() {
return Language.values();
}

@ParameterizedTest
@MethodSource("installedLanguages")
void resourceBundleExists(Language language) {
Path messagesPropertyFile = Paths.get("src/main/resources").resolve(Localization.RESOURCE_PREFIX + "_" + language.getId() + ".properties");
assertTrue(Files.exists(messagesPropertyFile));
}

@ParameterizedTest
@MethodSource("installedLanguages")
void languageCanBeLoaded(Language language) {
Locale oldLocale = Locale.getDefault();
try {
Locale locale = Language.convertToSupportedLocale(language).get();
Locale.setDefault(locale);
ResourceBundle messages = ResourceBundle.getBundle(Localization.RESOURCE_PREFIX, locale, new EncodingControl(StandardCharsets.UTF_8));
assertNotNull(messages);
} finally {
Locale.setDefault(oldLocale);
}
}

private static class DuplicationDetectionProperties extends Properties {

private static final long serialVersionUID = 1L;
Expand Down
Loading

0 comments on commit 4ebf7c2

Please sign in to comment.