From 27e3f1c0235726629b7d2d29a0c72fe1a1a0742d Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Thu, 23 Aug 2018 15:30:38 +0200 Subject: [PATCH 1/8] fix npe in Merge entries dialog fix fx thread error convert file to path --- .../org/jabref/gui/collab/ChangeScanner.java | 7 +++--- .../gui/collab/DatabaseChangeMonitor.java | 3 +-- .../gui/exporter/SaveDatabaseAction.java | 4 ++-- .../jabref/gui/mergeentries/MergeEntries.java | 3 ++- .../gui/mergeentries/MergeEntriesDialog.java | 22 +++++++++++-------- 5 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/jabref/gui/collab/ChangeScanner.java b/src/main/java/org/jabref/gui/collab/ChangeScanner.java index 553d17cb3a2..4d395c167a8 100644 --- a/src/main/java/org/jabref/gui/collab/ChangeScanner.java +++ b/src/main/java/org/jabref/gui/collab/ChangeScanner.java @@ -1,6 +1,5 @@ package org.jabref.gui.collab; -import java.io.File; import java.io.IOException; import java.nio.file.Path; import java.util.Comparator; @@ -39,7 +38,7 @@ public class ChangeScanner implements Runnable { private static final Logger LOGGER = LoggerFactory.getLogger(ChangeScanner.class); - private final File file; + private final Path file; private final Path tempFile; private final BibDatabaseContext databaseInMemory; @@ -56,7 +55,7 @@ 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(); @@ -126,7 +125,7 @@ public void run() { databaseInTemp = result.getDatabaseContext(); // Parse the modified file. - result = OpenDatabase.loadDatabase(file, importFormatPreferences, Globals.getFileUpdateMonitor()); + result = OpenDatabase.loadDatabase(file.toAbsolutePath().toString(), importFormatPreferences, Globals.getFileUpdateMonitor()); BibDatabaseContext databaseOnDisk = result.getDatabaseContext(); // Start looking at changes. diff --git a/src/main/java/org/jabref/gui/collab/DatabaseChangeMonitor.java b/src/main/java/org/jabref/gui/collab/DatabaseChangeMonitor.java index 8b4424e870b..7c300bcc5d8 100644 --- a/src/main/java/org/jabref/gui/collab/DatabaseChangeMonitor.java +++ b/src/main/java/org/jabref/gui/collab/DatabaseChangeMonitor.java @@ -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())) { @@ -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 diff --git a/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java b/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java index a5a99090927..9187ecee7b8 100644 --- a/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java +++ b/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java @@ -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 -> { diff --git a/src/main/java/org/jabref/gui/mergeentries/MergeEntries.java b/src/main/java/org/jabref/gui/mergeentries/MergeEntries.java index 1a49ed7f9c1..1e4db5bcc0f 100644 --- a/src/main/java/org/jabref/gui/mergeentries/MergeEntries.java +++ b/src/main/java/org/jabref/gui/mergeentries/MergeEntries.java @@ -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; @@ -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)); diff --git a/src/main/java/org/jabref/gui/mergeentries/MergeEntriesDialog.java b/src/main/java/org/jabref/gui/mergeentries/MergeEntriesDialog.java index 39a9e6f789b..ed5fc5a7863 100644 --- a/src/main/java/org/jabref/gui/mergeentries/MergeEntriesDialog.java +++ b/src/main/java/org/jabref/gui/mergeentries/MergeEntriesDialog.java @@ -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; @@ -88,15 +89,18 @@ private void init(List 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(); }); From a09ab966784ac78df9b1d36479714f7514d15d9a Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Thu, 23 Aug 2018 15:52:29 +0200 Subject: [PATCH 2/8] execute changes only if disk db present --- .../org/jabref/gui/collab/ChangeScanner.java | 32 ++++++++----------- 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/jabref/gui/collab/ChangeScanner.java b/src/main/java/org/jabref/gui/collab/ChangeScanner.java index 4d395c167a8..ba99990d46d 100644 --- a/src/main/java/org/jabref/gui/collab/ChangeScanner.java +++ b/src/main/java/org/jabref/gui/collab/ChangeScanner.java @@ -1,6 +1,5 @@ package org.jabref.gui.collab; -import java.io.IOException; import java.nio.file.Path; import java.util.Comparator; import java.util.List; @@ -38,7 +37,7 @@ public class ChangeScanner implements Runnable { private static final Logger LOGGER = LoggerFactory.getLogger(ChangeScanner.class); - private final Path file; + private final Optional file; private final Path tempFile; private final BibDatabaseContext databaseInMemory; @@ -59,7 +58,7 @@ 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; } @@ -73,8 +72,8 @@ public boolean changesFound() { */ private static BibEntry bestFit(BibEntry targetEntry, List 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) { @@ -90,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); } @@ -100,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 databaseWriter = new BibtexDatabaseWriter<>(FileSaveSession::new); SaveSession ss = databaseWriter.saveDatabase(databaseInTemp, prefs); @@ -117,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.toAbsolutePath().toString(), importFormatPreferences, Globals.getFileUpdateMonitor()); + result = OpenDatabase.loadDatabase(diskdb.toAbsolutePath().toString(), importFormatPreferences, Globals.getFileUpdateMonitor()); BibDatabaseContext databaseOnDisk = result.getDatabaseContext(); // Start looking at changes. @@ -137,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) { From d6fe3568a7900b1c27544acf0169922e0dc43042 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Thu, 23 Aug 2018 15:58:47 +0200 Subject: [PATCH 3/8] checkstyle --- .../org/jabref/gui/mergeentries/MergeEntriesDialog.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/jabref/gui/mergeentries/MergeEntriesDialog.java b/src/main/java/org/jabref/gui/mergeentries/MergeEntriesDialog.java index ed5fc5a7863..f081759bb67 100644 --- a/src/main/java/org/jabref/gui/mergeentries/MergeEntriesDialog.java +++ b/src/main/java/org/jabref/gui/mergeentries/MergeEntriesDialog.java @@ -52,7 +52,7 @@ private void init(List 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; @@ -89,7 +89,7 @@ private void init(List 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(); - DefaultTaskExecutor.runInJavaFXThread(()->{ + DefaultTaskExecutor.runInJavaFXThread(() -> { panel.insertEntry(mergedEntry); ce.addEdit(new UndoableInsertEntry(panel.getDatabase(), mergedEntry)); ce.addEdit(new UndoableRemoveEntry(panel.getDatabase(), one, panel)); @@ -114,8 +114,8 @@ private void init(List 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 From 75b54c07b9ee05a72b6e6c196ee884606f59e81a Mon Sep 17 00:00:00 2001 From: Linus Dietz Date: Fri, 24 Aug 2018 14:38:39 +0200 Subject: [PATCH 4/8] update gradle build-scan from 1.15.2 -> 1.16 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 8eb24702287..8e12b13b869 100644 --- a/build.gradle +++ b/build.gradle @@ -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" From f43b9c7e8bc6cba00e0d148ce657795ed0d5aa5a Mon Sep 17 00:00:00 2001 From: Linus Dietz Date: Fri, 24 Aug 2018 14:39:36 +0200 Subject: [PATCH 5/8] update xmlunit-matchers from 2.6.0 -> 2.6.1 --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 8e12b13b869..03da92d1548 100644 --- a/build.gradle +++ b/build.gradle @@ -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.1' + testCompile 'org.xmlunit:xmlunit-matchers:2.6.1' testCompile 'com.tngtech.archunit:archunit-junit:0.8.3' testCompile "org.testfx:testfx-core:4.0.+" testCompile "org.testfx:testfx-junit5:4.0.+" From 64e6c9ed5bdf0a48c115720c7da80922f45170fe Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Tue, 28 Aug 2018 16:54:13 +0200 Subject: [PATCH 6/8] Upgrade gradle to 4.10 update xmlunit and postgres --- build.gradle | 12 +++--------- gradle/wrapper/gradle-wrapper.jar | Bin 54417 -> 54413 bytes gradle/wrapper/gradle-wrapper.properties | 2 +- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/build.gradle b/build.gradle index 03da92d1548..8f5141a30a2 100644 --- a/build.gradle +++ b/build.gradle @@ -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' @@ -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.1' - testCompile 'org.xmlunit:xmlunit-matchers:2.6.1' + 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.+" @@ -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.") - } - } - } } diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 758de960ec7947253b058ff79c88ce51f3abe08a..0d4a9516871afd710a9d84d89e31ba77745607bd 100644 GIT binary patch delta 732 zcmYk4Ur19?9LINl)~4m3n;~1*r8tRj;+ldsTG*&j;mD0LiLwYROK2iKWQ|?~A0o3h zzap4_7J?6pUPQ=BD%&6DHm6Q~$R4bh2%#5!>&Z@s+uDW0{d~^%+{^czdwqed{y>)Z zc+T&yL!MJAm8!{SYf|rYZFe!1SDt!vF<7`q<#K4UACyiSVEQmpTWJ* zCH4Yyp=$OKJ0T0(LXSg>)8PuzGk9Y~a55RAVIwuGg?b~|_z|w56PmQvMb6Mjj-nRY z(x#K25gTpjgx1eD(Bo2p{&_ncGbpGYh+64zl`vOT0mdT|v?eK+msKu}NrWG2H3&p& z=t-@jdDx8_DRo|`ZJ~~CIRy4EIH}`;f_VcmGv8lz>^k${dF(1Rx9~&{Z%aNJQWB2D zW!4H?+{J?M#ZR(rEX8loqq`_*JA`wIMk;e7)u+cbw-)h)k!CuCwj@e%v@^4%wo?S{ zi*>97FBdP?lmGw# delta 674 zcmYk)T}V@590u^ce`_BwX^}IxS%%_;lVr!`V#{7~K>D!@P~?^<`NH4(Ing@BclV!#Ts#S?=kqkqXuP zh4b|_GMTK^ZEaC})BWsS?`2rD8(zFT^*$$2zD;)0rchoVsqNJAp+Rb5f&VDlMi zQYES(UnQk?Z>@gyS?N=rh)4VlG+4lCz=!dlOI4&Q6MV!u zbVzV*se)1`1TBHXk#o* z@F>~s=(iW+T*%107!Fxz!;Wl6Iev$X)Yr|aLv6T;iY{T%osXGt4SR+4a4YGYqG)!i z`5iSFi0EnGRbCZgAz~)AORzt>9ZfDROi?2}zLBXcG2Lu~p&2;mQ;Ja8o z&D|9&iPzEWJ Date: Tue, 28 Aug 2018 19:50:07 +0200 Subject: [PATCH 7/8] Fix freeze on import into current library (#4299) Execute import inspetion dialog in swing thread --- .../org/jabref/gui/importer/ImportAction.java | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/jabref/gui/importer/ImportAction.java b/src/main/java/org/jabref/gui/importer/ImportAction.java index 445a85b06a9..f81bb517c9e 100644 --- a/src/main/java/org/jabref/gui/importer/ImportAction.java +++ b/src/main/java/org/jabref/gui/importer/ImportAction.java @@ -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; @@ -33,7 +35,7 @@ public class ImportAction { private final Optional 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); @@ -78,9 +80,8 @@ private void reportResult(List 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); } @@ -88,16 +89,17 @@ private void reportResult(List imports) } 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(); + }); } } } @@ -147,7 +149,6 @@ private ParserResult mergeImportResults(List Date: Wed, 29 Aug 2018 01:43:08 +0200 Subject: [PATCH 8/8] Fix error prone warnings (#4290) --- .../importer/fileformat/BibtexParserTest.java | 4 +- .../l10n/LocalizationConsistencyTest.java | 30 +++++++++ .../jabref/logic/l10n/LocalizationParser.java | 13 ++-- .../PropertiesLocaleCompletenessTest.java | 67 ------------------- .../jabref/model/strings/StringUtilTest.java | 2 +- 5 files changed, 40 insertions(+), 76 deletions(-) delete mode 100644 src/test/java/org/jabref/logic/l10n/PropertiesLocaleCompletenessTest.java diff --git a/src/test/java/org/jabref/logic/importer/fileformat/BibtexParserTest.java b/src/test/java/org/jabref/logic/importer/fileformat/BibtexParserTest.java index 3ff1092b631..10cb4a4d7bb 100644 --- a/src/test/java/org/jabref/logic/importer/fileformat/BibtexParserTest.java +++ b/src/test/java/org/jabref/logic/importer/fileformat/BibtexParserTest.java @@ -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; @@ -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()); diff --git a/src/test/java/org/jabref/logic/l10n/LocalizationConsistencyTest.java b/src/test/java/org/jabref/logic/l10n/LocalizationConsistencyTest.java index a5c0d30751e..63848639692 100644 --- a/src/test/java/org/jabref/logic/l10n/LocalizationConsistencyTest.java +++ b/src/test/java/org/jabref/logic/l10n/LocalizationConsistencyTest.java @@ -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 { @@ -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; diff --git a/src/test/java/org/jabref/logic/l10n/LocalizationParser.java b/src/test/java/org/jabref/logic/l10n/LocalizationParser.java index 3038fb7fb36..8ffdd5a7a96 100644 --- a/src/test/java/org/jabref/logic/l10n/LocalizationParser.java +++ b/src/test/java/org/jabref/logic/l10n/LocalizationParser.java @@ -155,8 +155,8 @@ private static List getLanguageKeysInJavaFile(Path path, Loca for (String key : keys) { result.add(new LocalizationEntry(path, key, type)); } - } catch (IOException ignore) { - ignore.printStackTrace(); + } catch (IOException exception) { + throw new RuntimeException(exception); } return result; @@ -174,8 +174,8 @@ private static List getLocalizationParametersInJavaFile(Path for (String key : keys) { result.add(new LocalizationEntry(path, key, type)); } - } catch (IOException ignore) { - ignore.printStackTrace(); + } catch (IOException exception) { + throw new RuntimeException(exception); } return result; @@ -209,6 +209,7 @@ public boolean containsKey(String key) { PlatformImpl.startup(() -> { }); + try { FXMLLoader loader = new FXMLLoader(path.toUri().toURL(), registerUsageResourceBundle); // We don't want to initialize controller @@ -216,8 +217,8 @@ public boolean containsKey(String key) { // Don't check if root is null (needed for custom controls, where the root value is normally set in the FXMLLoader) loader.impl_setStaticLoad(true); loader.load(); - } catch (IOException ignore) { - ignore.printStackTrace(); + } catch (IOException exception) { + throw new RuntimeException(exception); } return result.stream() diff --git a/src/test/java/org/jabref/logic/l10n/PropertiesLocaleCompletenessTest.java b/src/test/java/org/jabref/logic/l10n/PropertiesLocaleCompletenessTest.java deleted file mode 100644 index 96ef48148e5..00000000000 --- a/src/test/java/org/jabref/logic/l10n/PropertiesLocaleCompletenessTest.java +++ /dev/null @@ -1,67 +0,0 @@ -package org.jabref.logic.l10n; - -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.List; -import java.util.Locale; -import java.util.ResourceBundle; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import com.google.common.base.Splitter; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertTrue; - -/** - * Checks that all property files are correctly encoded and can be loaded without errors. - */ -class PropertiesLocaleCompletenessTest { - - @Test - void testi10nFiles() throws IOException { - try (Stream pathStream = Files.list(Paths.get("src/main/resources/l10n"))) { - for (Path p : pathStream.collect(Collectors.toList())) { - - String[] parts = getParts(p); - String prefix = "l10n/" + parts[0]; - Locale locale; - if (parts.length == 3) { - locale = new Locale(parts[1], parts[2]); - } else { - locale = new Locale(parts[1]); - } - - checkPropertiesFile(locale, prefix); - } - } - } - - private String[] getParts(Path p) { - List elements = Splitter.on("_").splitToList(p.getFileName().toString().split("\\.")[0]); - String[] parts = new String[elements.size()]; - elements.toArray(parts); - return parts; - } - - @Test - void testCompletenessOfBundles() { - for (Language language : Language.values()) { - Path messagesPropertyFile = Paths.get("src/main/resources").resolve(Localization.RESOURCE_PREFIX + "_" + language.getId() + ".properties"); - assertTrue(Files.exists(messagesPropertyFile)); - } - } - - private void checkPropertiesFile(Locale locale, String prefix) { - Locale oldLocale = Locale.getDefault(); - try { - Locale.setDefault(locale); - ResourceBundle.getBundle(prefix, locale, new EncodingControl(StandardCharsets.UTF_8)); - } finally { - Locale.setDefault(oldLocale); - } - } -} diff --git a/src/test/java/org/jabref/model/strings/StringUtilTest.java b/src/test/java/org/jabref/model/strings/StringUtilTest.java index 0e59d8b375c..19872c9d294 100644 --- a/src/test/java/org/jabref/model/strings/StringUtilTest.java +++ b/src/test/java/org/jabref/model/strings/StringUtilTest.java @@ -120,7 +120,7 @@ void testShaveString() { @Test void testJoin() { - String[] s = "ab/cd/ed".split("/"); + String[] s = {"ab", "cd", "ed"}; assertEquals("ab\\cd\\ed", StringUtil.join(s, "\\", 0, s.length)); assertEquals("cd\\ed", StringUtil.join(s, "\\", 1, s.length));