diff --git a/CHANGELOG.md b/CHANGELOG.md index 5432ff309fb..bb3cc514b88 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,12 +13,14 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv - We added the possibility to find (and add) papers that cite or are cited by a given paper. [#6187](https://github.com/JabRef/jabref/issues/6187) - We added an error-specific message for when a download from a URL fails. [#9826](https://github.com/JabRef/jabref/issues/9826) -- We added support for customizating the citation command (e.g., `[@key1,@key2]`) when [pushing to external applications](https://docs.jabref.org/cite/pushtoapplications). [#10133](https://github.com/JabRef/jabref/issues/10133) +- We added support for customizing the citation command (e.g., `[@key1,@key2]`) when [pushing to external applications](https://docs.jabref.org/cite/pushtoapplications). [#10133](https://github.com/JabRef/jabref/issues/10133) - We added an integrity check for more special characters. [#8712](https://github.com/JabRef/jabref/issues/8712) - We added protected terms described as "Computer science". [#10222](https://github.com/JabRef/jabref/pull/10222) ### Changed +- In the exports listrefs, tablerefs, tablerefsabsbib, use ISO date format in the footer. + ### Fixed - It is possible again to use "current table sort order" for the order of entries when saving. [#9869](https://github.com/JabRef/jabref/issues/9869) @@ -28,6 +30,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv - We fixed an issue where the ISBN fetcher returned the entrytype `misc` for certain ISBN numbers [#10348](https://github.com/JabRef/jabref/issues/10348) - We fixed a bug where an exception was raised when saving less than three export save orders in the preference. [#10157](https://github.com/JabRef/jabref/issues/10157) - We fixed an issue where it was possible to create a group with no name or with a group separator inside the name [#9776](https://github.com/JabRef/jabref/issues/9776) +- JabRef does not hang anymore when exporting via CLI. [#10380](https://github.com/JabRef/jabref/issues/10380) ### Removed diff --git a/buildres/abbrv.jabref.org b/buildres/abbrv.jabref.org index d47628aa8ae..cf71cb48dbd 160000 --- a/buildres/abbrv.jabref.org +++ b/buildres/abbrv.jabref.org @@ -1 +1 @@ -Subproject commit d47628aa8ae2d7d47d5b18a82982d2246996347c +Subproject commit cf71cb48dbd78b2d85856e689e2834f14b91fdbc diff --git a/src/main/java/org/jabref/cli/ArgumentProcessor.java b/src/main/java/org/jabref/cli/ArgumentProcessor.java index 5d5c2c025d6..1f436070319 100644 --- a/src/main/java/org/jabref/cli/ArgumentProcessor.java +++ b/src/main/java/org/jabref/cli/ArgumentProcessor.java @@ -67,13 +67,20 @@ public class ArgumentProcessor { private static final Logger LOGGER = LoggerFactory.getLogger(ArgumentProcessor.class); private final JabRefCLI cli; - private final List parserResults; + + // Written once by processArguments() + private List parserResults = List.of(); + private final Mode startupMode; private final PreferencesService preferencesService; private final FileUpdateMonitor fileUpdateMonitor; private final BibEntryTypesManager entryTypesManager; private boolean noGUINeeded; + /** + * First call the constructor, then call {@link #processArguments()}. + * Afterward, you can access the {@link #getParserResults()} and other getters. + */ public ArgumentProcessor(String[] args, Mode startupMode, PreferencesService preferencesService, @@ -84,8 +91,6 @@ public ArgumentProcessor(String[] args, this.preferencesService = preferencesService; this.fileUpdateMonitor = fileUpdateMonitor; this.entryTypesManager = entryTypesManager; - - this.parserResults = processArguments(); } /** @@ -145,8 +150,8 @@ private Optional importFile(String argument) { Optional importResult = importFile(file, importFormat); importResult.ifPresent(result -> { - OutputPrinter printer = new SystemOutputPrinter(); if (result.hasWarnings()) { + OutputPrinter printer = new SystemOutputPrinter(); printer.showMessage(result.getErrorMessage()); } }); @@ -161,22 +166,21 @@ private Optional importFile(Path file, String importFormat) { fileUpdateMonitor); if (!"*".equals(importFormat)) { - System.out.println(Localization.lang("Importing") + ": " + file); + System.out.println(Localization.lang("Importing %0", file)); ParserResult result = importFormatReader.importFromFile(importFormat, file); return Optional.of(result); } else { // * means "guess the format": - System.out.println(Localization.lang("Importing in unknown format") + ": " + file); + System.out.println(Localization.lang("Importing file %0 as unknown format", file)); ImportFormatReader.UnknownFormatImport importResult = importFormatReader.importUnknownFormat(file, new DummyFileUpdateMonitor()); - System.out.println(Localization.lang("Format used") + ": " + importResult.format()); + System.out.println(Localization.lang("Format used: %0", importResult.format())); return Optional.of(importResult.parserResult()); } } catch (ImportException ex) { - System.err - .println(Localization.lang("Error opening file") + " '" + file + "': " + ex.getLocalizedMessage()); + System.err.println(Localization.lang("Error opening file '%0'", file) + "\n" + ex.getLocalizedMessage()); return Optional.empty(); } } @@ -185,11 +189,7 @@ public List getParserResults() { return parserResults; } - public boolean hasParserResults() { - return !parserResults.isEmpty(); - } - - private List processArguments() { + public void processArguments() { if ((startupMode == Mode.INITIAL_START) && cli.isShowVersion()) { cli.displayVersion(); } @@ -197,7 +197,8 @@ private List processArguments() { if ((startupMode == Mode.INITIAL_START) && cli.isHelp()) { JabRefCLI.printUsage(preferencesService); noGUINeeded = true; - return Collections.emptyList(); + this.parserResults = Collections.emptyList(); + return; } // Check if we should reset all preferences to default values: @@ -220,7 +221,8 @@ private List processArguments() { if (cli.isExportMatches()) { if (!loaded.isEmpty()) { if (!exportMatches(loaded)) { - return Collections.emptyList(); + this.parserResults = Collections.emptyList(); + return; } } else { System.err.println(Localization.lang("The output option depends on a valid input option.")); @@ -275,7 +277,7 @@ private List processArguments() { doAuxImport(loaded); } - return loaded; + this.parserResults = loaded; } private void writeMetadataToPdf(List loaded, @@ -475,15 +477,14 @@ private boolean exportMatches(List loaded) { Globals.entryTypesManager); Optional exporter = exporterFactory.getExporterByName(formatName); if (exporter.isEmpty()) { - System.err.println(Localization.lang("Unknown export format") + ": " + formatName); + System.err.println(Localization.lang("Unknown export format %0", formatName)); } else { // We have an TemplateExporter instance: try { - System.out.println(Localization.lang("Exporting") + ": " + data[1]); + System.out.println(Localization.lang("Exporting %0", data[1])); exporter.get().export(databaseContext, Path.of(data[1]), matches, Collections.emptyList(), Globals.journalAbbreviationRepository); } catch (Exception ex) { - System.err.println(Localization.lang("Could not export file") + " '" + data[1] + "': " - + Throwables.getStackTraceAsString(ex)); + System.err.println(Localization.lang("Could not export file '%0' (reason: %1)", data[1], Throwables.getStackTraceAsString(ex))); } } } @@ -503,7 +504,7 @@ private void doAuxImport(List loaded) { } if (usageMsg) { - System.out.println(Localization.lang("no base-BibTeX-file specified") + "!"); + System.out.println(Localization.lang("no base-BibTeX-file specified!")); System.out.println(Localization.lang("usage") + " :"); System.out.println("jabref --aux infile[.aux],outfile[.bib] base-BibTeX-file"); } @@ -634,32 +635,31 @@ private void exportFile(List loaded, String[] data) { } else if (data.length == 2) { // This signals that the latest import should be stored in the given // format to the given file. - ParserResult pr = loaded.get(loaded.size() - 1); + ParserResult parserResult = loaded.get(loaded.size() - 1); - Path path = pr.getPath().get().toAbsolutePath(); - BibDatabaseContext databaseContext = pr.getDatabaseContext(); + Path path = parserResult.getPath().get().toAbsolutePath(); + BibDatabaseContext databaseContext = parserResult.getDatabaseContext(); databaseContext.setDatabasePath(path); List fileDirForDatabase = databaseContext .getFileDirectories(preferencesService.getFilePreferences()); - System.out.println(Localization.lang("Exporting") + ": " + data[0]); + System.out.println(Localization.lang("Exporting %0", data[0])); ExporterFactory exporterFactory = ExporterFactory.create( preferencesService, Globals.entryTypesManager); Optional exporter = exporterFactory.getExporterByName(data[1]); if (exporter.isEmpty()) { - System.err.println(Localization.lang("Unknown export format") + ": " + data[1]); + System.err.println(Localization.lang("Unknown export format %0", data[1])); } else { // We have an exporter: try { exporter.get().export( - pr.getDatabaseContext(), + parserResult.getDatabaseContext(), Path.of(data[0]), - pr.getDatabaseContext().getDatabase().getEntries(), + parserResult.getDatabaseContext().getDatabase().getEntries(), fileDirForDatabase, Globals.journalAbbreviationRepository); } catch (Exception ex) { - System.err.println(Localization.lang("Could not export file") + " '" + data[0] + "': " - + Throwables.getStackTraceAsString(ex)); + System.err.println(Localization.lang("Could not export file '%0' (reason: %1)", data[0], Throwables.getStackTraceAsString(ex))); } } } diff --git a/src/main/java/org/jabref/cli/Launcher.java b/src/main/java/org/jabref/cli/Launcher.java index caaa9d62744..a49ea92e865 100644 --- a/src/main/java/org/jabref/cli/Launcher.java +++ b/src/main/java/org/jabref/cli/Launcher.java @@ -65,17 +65,18 @@ public static void main(String[] args) { BibEntryTypesManager entryTypesManager = new BibEntryTypesManager(); Globals.entryTypesManager = entryTypesManager; - // Init preferences + // Initialize preferences final JabRefPreferences preferences = JabRefPreferences.getInstance(); - Globals.prefs = preferences; - PreferencesMigrations.runMigrations(preferences, entryTypesManager); // Early exit in case another instance is already running - if (!handleMultipleAppInstances(ARGUMENTS, preferences)) { + if (!handleMultipleAppInstances(ARGUMENTS, preferences.getRemotePreferences())) { return; } - // Init rest of preferences + Globals.prefs = preferences; + PreferencesMigrations.runMigrations(preferences, entryTypesManager); + + // Initialize rest of preferences configureProxy(preferences.getProxyPreferences()); configureSSL(preferences.getSSLPreferences()); initGlobals(preferences); @@ -86,13 +87,17 @@ public static void main(String[] args) { // Process arguments ArgumentProcessor argumentProcessor = new ArgumentProcessor( - ARGUMENTS, ArgumentProcessor.Mode.INITIAL_START, + ARGUMENTS, + ArgumentProcessor.Mode.INITIAL_START, preferences, fileUpdateMonitor, entryTypesManager); + argumentProcessor.processArguments(); if (argumentProcessor.shouldShutDown()) { LOGGER.debug("JabRef shut down after processing command line arguments"); - return; + // A clean shutdown takes 60s time + // We don't need the clean shutdown here + System.exit(0); } MainApplication.main(argumentProcessor.getParserResults(), argumentProcessor.isBlank(), preferences, fileUpdateMonitor, ARGUMENTS); @@ -141,8 +146,7 @@ private static void initializeLogger() { LOGGER = LoggerFactory.getLogger(MainApplication.class); } - private static boolean handleMultipleAppInstances(String[] args, PreferencesService preferences) { - RemotePreferences remotePreferences = preferences.getRemotePreferences(); + private static boolean handleMultipleAppInstances(String[] args, RemotePreferences remotePreferences) { if (remotePreferences.useRemoteServer()) { // Try to contact already running JabRef RemoteClient remoteClient = new RemoteClient(remotePreferences.getPort()); diff --git a/src/main/java/org/jabref/gui/Globals.java b/src/main/java/org/jabref/gui/Globals.java index c78330180b7..04ead50bf63 100644 --- a/src/main/java/org/jabref/gui/Globals.java +++ b/src/main/java/org/jabref/gui/Globals.java @@ -15,7 +15,7 @@ import org.jabref.logic.util.BuildInfo; import org.jabref.model.entry.BibEntryTypesManager; import org.jabref.model.util.FileUpdateMonitor; -import org.jabref.preferences.JabRefPreferences; +import org.jabref.preferences.PreferencesService; import kong.unirest.Unirest; @@ -43,7 +43,7 @@ public class Globals { /** * Each test case initializes this field if required */ - public static JabRefPreferences prefs; + public static PreferencesService prefs; /** * This field is initialized upon startup. diff --git a/src/main/java/org/jabref/gui/JabRefGUI.java b/src/main/java/org/jabref/gui/JabRefGUI.java index 0345881c5b7..9a402703619 100644 --- a/src/main/java/org/jabref/gui/JabRefGUI.java +++ b/src/main/java/org/jabref/gui/JabRefGUI.java @@ -251,7 +251,7 @@ private void openDatabases() { } for (ParserResult pr : failed) { - String message = Localization.lang("Error opening file '%0'.", + String message = Localization.lang("Error opening file '%0'", pr.getPath().map(Path::toString).orElse("(File name unknown)")) + "\n" + pr.getErrorMessage(); diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java index 26ba6b0ac53..4ab31eb094f 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java @@ -217,7 +217,7 @@ public void open() { dialogService.showErrorDialogAndWait(Localization.lang("File not found"), Localization.lang("Could not find file '%0'.", linkedFile.getLink())); } } catch (IOException e) { - dialogService.showErrorDialogAndWait(Localization.lang("Error opening file '%0'.", linkedFile.getLink()), e); + dialogService.showErrorDialogAndWait(Localization.lang("Error opening file '%0'", linkedFile.getLink()), e); } } diff --git a/src/main/java/org/jabref/gui/importer/ImportCommand.java b/src/main/java/org/jabref/gui/importer/ImportCommand.java index 60012994b97..fd74e7a5199 100644 --- a/src/main/java/org/jabref/gui/importer/ImportCommand.java +++ b/src/main/java/org/jabref/gui/importer/ImportCommand.java @@ -146,7 +146,7 @@ private ParserResult doImport(List files, Importer importFormat) throws IO if (FileUtil.isPDFFile(filename) && GrobidOptInDialogHelper.showAndWaitIfUserIsUndecided(dialogService, preferencesService.getGrobidPreferences())) { importFormatReader.reset(); } - dialogService.notify(Localization.lang("Importing in unknown format") + "..."); + dialogService.notify(Localization.lang("Importing file %0 as unknown format", filename.getFileName().toString())); }); // This import method never throws an IOException imports.add(importFormatReader.importUnknownFormat(filename, fileUpdateMonitor)); diff --git a/src/main/java/org/jabref/gui/remote/CLIMessageHandler.java b/src/main/java/org/jabref/gui/remote/CLIMessageHandler.java index c24d4298442..272d84fd600 100644 --- a/src/main/java/org/jabref/gui/remote/CLIMessageHandler.java +++ b/src/main/java/org/jabref/gui/remote/CLIMessageHandler.java @@ -38,7 +38,7 @@ public void handleCommandLineArguments(String[] message) { preferencesService, fileUpdateMonitor, entryTypesManager); - + argumentProcessor.processArguments(); List loaded = argumentProcessor.getParserResults(); for (int i = 0; i < loaded.size(); i++) { ParserResult pr = loaded.get(i); diff --git a/src/main/java/org/jabref/logic/bst/BstPreviewLayout.java b/src/main/java/org/jabref/logic/bst/BstPreviewLayout.java index a002d388e60..06a253968b9 100644 --- a/src/main/java/org/jabref/logic/bst/BstPreviewLayout.java +++ b/src/main/java/org/jabref/logic/bst/BstPreviewLayout.java @@ -30,14 +30,14 @@ public BstPreviewLayout(Path path) { name = path.getFileName().toString(); if (!Files.exists(path)) { LOGGER.error("File {} not found", path.toAbsolutePath()); - error = Localization.lang("Error opening file '%0'.", path.toString()); + error = Localization.lang("Error opening file '%0'", path.toString()); return; } try { bstVM = new BstVM(path); } catch (Exception e) { LOGGER.error("Could not read {}.", path.toAbsolutePath(), e); - error = Localization.lang("Error opening file '%0'.", path.toString()); + error = Localization.lang("Error opening file '%0'", path.toString()); } } diff --git a/src/main/java/org/jabref/logic/exporter/TemplateExporter.java b/src/main/java/org/jabref/logic/exporter/TemplateExporter.java index c2e0e7e6e1c..d9d0c33766d 100644 --- a/src/main/java/org/jabref/logic/exporter/TemplateExporter.java +++ b/src/main/java/org/jabref/logic/exporter/TemplateExporter.java @@ -311,7 +311,6 @@ public void export(final BibDatabaseContext databaseContext, missingFormatters.addAll(endLayout.getMissingFormatters()); } - // Clear custom name formatters: layoutPreferences.clearCustomExportNameFormatters(); if (!missingFormatters.isEmpty() && LOGGER.isWarnEnabled()) { diff --git a/src/main/java/org/jabref/logic/layout/Layout.java b/src/main/java/org/jabref/logic/layout/Layout.java index a465d578fd0..65587b1f81b 100644 --- a/src/main/java/org/jabref/logic/layout/Layout.java +++ b/src/main/java/org/jabref/logic/layout/Layout.java @@ -117,7 +117,7 @@ public String doLayout(BibEntry bibtex, BibDatabase database) { /** * Returns the processed text. If the database argument is - * null, no string references will be resolved. Otherwise all valid + * null, no string references will be resolved. Otherwise, all valid * string references will be replaced by the strings' contents. Even * recursive string references are resolved. */ diff --git a/src/main/java/org/jabref/preferences/ExportPreferences.java b/src/main/java/org/jabref/preferences/ExportPreferences.java index 85e1129410e..1e653f45c8a 100644 --- a/src/main/java/org/jabref/preferences/ExportPreferences.java +++ b/src/main/java/org/jabref/preferences/ExportPreferences.java @@ -24,7 +24,6 @@ public ExportPreferences(String lastExportExtension, Path exportWorkingDirectory, SaveOrder exportSaveOrder, List customExporters) { - this.lastExportExtension = new SimpleStringProperty(lastExportExtension); this.exportWorkingDirectory = new SimpleObjectProperty<>(exportWorkingDirectory); this.exportSaveOrder = new SimpleObjectProperty<>(exportSaveOrder); diff --git a/src/main/java/org/jabref/preferences/JabRefPreferences.java b/src/main/java/org/jabref/preferences/JabRefPreferences.java index ba88549b5b0..64eb1845322 100644 --- a/src/main/java/org/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java @@ -2287,7 +2287,7 @@ private void storeExportSaveOrder(SaveOrder saveOrder) { * For the export configuration, generates the SelfContainedSaveOrder having the reference to TABLE resolved. */ public SelfContainedSaveOrder getSelfContainedTableSaveOrder() { - List sortOrder = mainTableColumnPreferences.getColumnSortOrder(); + List sortOrder = getMainTableColumnPreferences().getColumnSortOrder(); return new SelfContainedSaveOrder( SaveOrder.OrderType.SPECIFIED, sortOrder.stream().flatMap(model -> model.getSortCriteria().stream()).toList()); diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index 2e8c314d89b..7abf562ad2c 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -179,8 +179,6 @@ Copy\ to\ clipboard=Copy to clipboard Could\ not\ call\ executable=Could not call executable -Could\ not\ export\ file=Could not export file - Could\ not\ export\ preferences=Could not export preferences Could\ not\ find\ a\ suitable\ import\ format.=Could not find a suitable import format. @@ -315,7 +313,6 @@ Entry\ table\ columns=Entry table columns Entry\ Title\ (Required\ to\ deliver\ recommendations.)=Entry Title (Required to deliver recommendations.) Error=Error Error\ occurred\ when\ parsing\ entry=Error occurred when parsing entry -Error\ opening\ file=Error opening file Error\ during\ persistence\ of\ crawling\ results.=Error during persistence of crawling results. Error\ during\ reading\ of\ study\ definition\ file.=Error during reading of study definition file. '%0'\ exists.\ Overwrite\ file?='%0' exists. Overwrite file? @@ -324,7 +321,15 @@ Export\ preferences=Export preferences Export\ preferences\ to\ file=Export preferences to file Export\ to\ clipboard=Export to clipboard Export\ to\ text\ file.=Export to text file. -Exporting=Exporting + +Exporting\ %0=Exporting %0 +Could\ not\ export\ file\ '%0'\ (reason\:\ %1)=Could not export file '%0' (reason: %1) +Unknown\ export\ format\ %0=Unknown export format %0 + +Importing\ %0=Importing %0 +Importing\ file\ %0\ as\ unknown\ format=Importing file %0 as unknown format +Format\ used\:\ %0=Format used: %0 + Extension=Extension External\ Changes\ Resolver=External Changes Resolver @@ -376,7 +381,6 @@ Format\:\ Tab\:field;field;...\ (e.g.\ General\:url;pdf;note...)=Format\: Tab\:f Format\ of\ author\ and\ editor\ names=Format of author and editor names Format\ string=Format string -Format\ used=Format used Formatter\ name=Formatter name found\ in\ AUX\ file=found in AUX file @@ -444,10 +448,6 @@ Imported\ entries=Imported entries Importer\ class=Importer class -Importing=Importing - -Importing\ in\ unknown\ format=Importing in unknown format - Include\ subgroups\:\ When\ selected,\ view\ entries\ contained\ in\ this\ group\ or\ its\ subgroups=Include subgroups: When selected, view entries contained in this group or its subgroups Independent\ group\:\ When\ selected,\ view\ only\ this\ group's\ entries=Independent group: When selected, view only this group's entries @@ -573,7 +573,7 @@ New\ group=New group New\ string=New string Next\ entry=Next entry -no\ base-BibTeX-file\ specified=no base-BibTeX-file specified +no\ base-BibTeX-file\ specified!=no base-BibTeX-file specified! no\ library\ generated=no library generated @@ -932,8 +932,6 @@ Unknown\ BibTeX\ entries\:=Unknown BibTeX entries\: unknown\ edit=unknown edit -Unknown\ export\ format=Unknown export format - untitled=untitled Upgrade\ external\ PDF/PS\ links\ to\ use\ the\ '%0'\ field.=Upgrade external PDF/PS links to use the '%0' field. @@ -1021,7 +1019,8 @@ Cannot\ use\ port\ %0\ for\ remote\ operation;\ another\ application\ may\ be\ u Looking\ for\ full\ text\ document...=Looking for full text document... A\ local\ copy\ will\ be\ opened.=A local copy will be opened. -Error\ opening\ file\ '%0'.=Error opening file '%0'. +Error\ opening\ file=Error opening file +Error\ opening\ file\ '%0'=Error opening file '%0' Formatter\ not\ found\:\ %0=Formatter not found: %0 diff --git a/src/main/resources/resource/layout/listrefs/listrefs.end.layout b/src/main/resources/resource/layout/listrefs/listrefs.end.layout index b3b7bb80672..9b01f32434f 100644 --- a/src/main/resources/resource/layout/listrefs/listrefs.end.layout +++ b/src/main/resources/resource/layout/listrefs/listrefs.end.layout @@ -1,8 +1,8 @@
- Created by JabRef on \format[CurrentDate]{dd/MM/yyyy}. + Created by JabRef on \format[CurrentDate]{yyyy/MM/dd}.
- \ No newline at end of file + diff --git a/src/main/resources/resource/layout/tablerefs/tablerefs.end.layout b/src/main/resources/resource/layout/tablerefs/tablerefs.end.layout index f59a0f8bd6c..3b054a36bcf 100644 --- a/src/main/resources/resource/layout/tablerefs/tablerefs.end.layout +++ b/src/main/resources/resource/layout/tablerefs/tablerefs.end.layout @@ -1,10 +1,10 @@
- Created by JabRef on \format[CurrentDate]{dd/MM/yyyy}. + Created by JabRef on \format[CurrentDate]{yyyy/MM/dd}.
- \ No newline at end of file + diff --git a/src/main/resources/resource/layout/tablerefsabsbib/tablerefsabsbib.end.layout b/src/main/resources/resource/layout/tablerefsabsbib/tablerefsabsbib.end.layout index b3b7bb80672..9b01f32434f 100644 --- a/src/main/resources/resource/layout/tablerefsabsbib/tablerefsabsbib.end.layout +++ b/src/main/resources/resource/layout/tablerefsabsbib/tablerefsabsbib.end.layout @@ -1,8 +1,8 @@
- Created by JabRef on \format[CurrentDate]{dd/MM/yyyy}. + Created by JabRef on \format[CurrentDate]{yyyy/MM/dd}.
- \ No newline at end of file + diff --git a/src/test/java/org/jabref/cli/ArgumentProcessorTest.java b/src/test/java/org/jabref/cli/ArgumentProcessorTest.java index 78dcb77f755..55c9520b30a 100644 --- a/src/test/java/org/jabref/cli/ArgumentProcessorTest.java +++ b/src/test/java/org/jabref/cli/ArgumentProcessorTest.java @@ -10,14 +10,19 @@ import org.jabref.cli.ArgumentProcessor.Mode; import org.jabref.logic.bibtex.BibEntryAssert; +import org.jabref.logic.exporter.BibDatabaseWriter; +import org.jabref.logic.exporter.SelfContainedSaveConfiguration; import org.jabref.logic.importer.ImportFormatPreferences; import org.jabref.logic.importer.ImporterPreferences; import org.jabref.logic.importer.fileformat.BibtexImporter; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.BibEntryTypesManager; +import org.jabref.model.metadata.SaveOrder; +import org.jabref.model.metadata.SelfContainedSaveOrder; import org.jabref.model.search.rules.SearchRules; import org.jabref.model.util.DummyFileUpdateMonitor; import org.jabref.model.util.FileUpdateMonitor; +import org.jabref.preferences.ExportPreferences; import org.jabref.preferences.PreferencesService; import org.jabref.preferences.SearchPreferences; @@ -32,8 +37,6 @@ class ArgumentProcessorTest { - private ArgumentProcessor processor; - private BibtexImporter bibtexImporter; private final PreferencesService preferencesService = mock(PreferencesService.class, Answers.RETURNS_DEEP_STUBS); private final BibEntryTypesManager entryTypesManager = mock(BibEntryTypesManager.class); private final ImporterPreferences importerPreferences = mock(ImporterPreferences.class, Answers.RETURNS_DEEP_STUBS); @@ -42,16 +45,16 @@ class ArgumentProcessorTest { @BeforeEach() void setup() { when(importerPreferences.getCustomImporters()).thenReturn(FXCollections.emptyObservableSet()); + + when(preferencesService.getImporterPreferences()).thenReturn(importerPreferences); + when(preferencesService.getImportFormatPreferences()).thenReturn(importFormatPreferences); when(preferencesService.getSearchPreferences()).thenReturn( new SearchPreferences(null, EnumSet.noneOf(SearchRules.SearchFlags.class), false) ); - - bibtexImporter = new BibtexImporter(importFormatPreferences, new DummyFileUpdateMonitor()); } @Test void testAuxImport(@TempDir Path tempDir) throws Exception { - String auxFile = Path.of(AuxCommandLineTest.class.getResource("paper.aux").toURI()).toAbsolutePath().toString(); String originBib = Path.of(AuxCommandLineTest.class.getResource("origin.bib").toURI()).toAbsolutePath().toString(); @@ -60,12 +63,13 @@ void testAuxImport(@TempDir Path tempDir) throws Exception { List args = List.of("--nogui", "--debug", "--aux", auxFile + "," + outputBibFile, originBib); - processor = new ArgumentProcessor( + ArgumentProcessor processor = new ArgumentProcessor( args.toArray(String[]::new), Mode.INITIAL_START, preferencesService, mock(FileUpdateMonitor.class), entryTypesManager); + processor.processArguments(); assertTrue(Files.exists(outputBib)); } @@ -79,6 +83,8 @@ void testExportMatches(@TempDir Path tempDir) throws Exception { Objects.requireNonNull(ArgumentProcessorTest.class.getResource("ArgumentProcessorTestExportMatches.bib")) .toURI() ); + + BibtexImporter bibtexImporter = new BibtexImporter(importFormatPreferences, new DummyFileUpdateMonitor()); List expectedEntries = bibtexImporter.importDatabase(expectedBib).getDatabase().getEntries(); Path outputBib = tempDir.resolve("output.bib").toAbsolutePath(); @@ -86,14 +92,46 @@ void testExportMatches(@TempDir Path tempDir) throws Exception { List args = List.of("-n", "--debug", "--exportMatches", "Author=Einstein," + outputBibFile, originBibFile); - processor = new ArgumentProcessor( + ArgumentProcessor processor = new ArgumentProcessor( args.toArray(String[]::new), Mode.INITIAL_START, preferencesService, mock(FileUpdateMonitor.class), entryTypesManager); + processor.processArguments(); assertTrue(Files.exists(outputBib)); BibEntryAssert.assertEquals(expectedEntries, outputBib, bibtexImporter); } + + @Test + void convertBibtexToTablerefsabsbib(@TempDir Path tempDir) throws Exception { + Path originBib = Path.of(Objects.requireNonNull(ArgumentProcessorTest.class.getResource("origin.bib")).toURI()); + String originBibFile = originBib.toAbsolutePath().toString(); + + Path outputHtml = tempDir.resolve("output.html").toAbsolutePath(); + String outputHtmlFile = outputHtml.toAbsolutePath().toString(); + + when(importerPreferences.getCustomImporters()) .thenReturn(FXCollections.emptyObservableSet()); + + SaveOrder saveOrder = new SaveOrder(SaveOrder.OrderType.TABLE, List.of()); + ExportPreferences exportPreferences = new ExportPreferences(".html", tempDir, saveOrder, List.of()); + when(preferencesService.getExportPreferences()).thenReturn(exportPreferences); + + SelfContainedSaveOrder selfContainedSaveOrder = new SelfContainedSaveOrder(SaveOrder.OrderType.ORIGINAL, List.of()); + SelfContainedSaveConfiguration selfContainedSaveConfiguration = new SelfContainedSaveConfiguration(selfContainedSaveOrder, false, BibDatabaseWriter.SaveType.WITH_JABREF_META_DATA, false); + when(preferencesService.getSelfContainedExportConfiguration()).thenReturn(selfContainedSaveConfiguration); + + List args = List.of("-n", "-i", originBibFile + ",bibtex", "-o", outputHtmlFile + ",tablerefsabsbib"); + + ArgumentProcessor processor = new ArgumentProcessor( + args.toArray(String[]::new), + Mode.INITIAL_START, + preferencesService, + mock(FileUpdateMonitor.class), + entryTypesManager); + processor.processArguments(); + + assertTrue(Files.exists(outputHtml)); + } }