Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implements #1664: group based on aux file #3444

Merged
merged 9 commits into from
Jan 28, 2018
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ We refer to [GitHub issues](/~https://github.com/JabRef/jabref/issues) by using `#
- We now show a small notification icon in the entry editor when we detect data inconsistency or other problems. [#3145](/~https://github.com/JabRef/jabref/issues/3145)
- We added [oaDOI](https://oadoi.org/) as a fulltext provider, so that JabRef is now able to provide fulltexts for more than 90 million open-access articles.
- We changed one default of [Cleanup entries dialog](http://help.jabref.org/en/CleanupEntries): Per default, the PDF are not moved to the default file directory anymore. [#3619](/~https://github.com/JabRef/jabref/issues/3619)
- We added a new type of group that shows all items referenced in a given LaTeX file (actually the generated AUX file). [#1664](/~https://github.com/JabRef/jabref/issues/1664)
- We added the export of the `translator` field to the according MS-Office XML field. [#1750, comment](/~https://github.com/JabRef/jabref/issues/1750#issuecomment-357350986)
- We changed the import of the MS-Office XML fields `bookauthor` and `translator`. Both are now imported to their corresponding bibtex/biblatex fields.
- We improved the export of the `address` and `location` field to the MS-Office XML fields. If the address field does not contain a comma, it is treated as single value and exported to the field `city`. [#1750, comment](/~https://github.com/JabRef/jabref/issues/1750#issuecomment-357539167)
Expand Down
3 changes: 2 additions & 1 deletion src/jmh/java/org/jabref/benchmarks/Benchmarks.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.jabref.model.groups.KeywordGroup;
import org.jabref.model.groups.WordKeywordGroup;
import org.jabref.model.metadata.MetaData;
import org.jabref.model.util.DummyFileUpdateMonitor;
import org.jabref.preferences.JabRefPreferences;

import org.openjdk.jmh.Main;
Expand Down Expand Up @@ -73,7 +74,7 @@ public void init() throws Exception {

@Benchmark
public ParserResult parse() throws IOException {
BibtexParser parser = new BibtexParser(Globals.prefs.getImportFormatPreferences());
BibtexParser parser = new BibtexParser(Globals.prefs.getImportFormatPreferences(), new DummyFileUpdateMonitor());
return parser.parse(new StringReader(bibtexString));
}

Expand Down
7 changes: 4 additions & 3 deletions src/main/java/org/jabref/Globals.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@
import org.jabref.gui.GlobalFocusListener;
import org.jabref.gui.StateManager;
import org.jabref.gui.keyboard.KeyBindingRepository;
import org.jabref.gui.util.DefaultFileUpdateMonitor;
import org.jabref.gui.util.DefaultTaskExecutor;
import org.jabref.gui.util.FileUpdateMonitor;
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.exporter.ExporterFactory;
import org.jabref.logic.importer.ImportFormatReader;
import org.jabref.logic.journals.JournalAbbreviationLoader;
import org.jabref.logic.protectedterms.ProtectedTermsLoader;
import org.jabref.logic.remote.server.RemoteListenerServerLifecycle;
import org.jabref.logic.util.BuildInfo;
import org.jabref.model.util.FileUpdateMonitor;
import org.jabref.preferences.JabRefPreferences;

import com.google.common.base.StandardSystemProperty;
Expand Down Expand Up @@ -54,7 +55,7 @@ public class Globals {
private static KeyBindingRepository keyBindingRepository;
// Background tasks
private static GlobalFocusListener focusListener;
private static FileUpdateMonitor fileUpdateMonitor;
private static DefaultFileUpdateMonitor fileUpdateMonitor;
private static TelemetryClient telemetryClient;

private Globals() {
Expand All @@ -73,7 +74,7 @@ public static synchronized KeyBindingRepository getKeyPrefs() {
public static void startBackgroundTasks() {
Globals.focusListener = new GlobalFocusListener();

Globals.fileUpdateMonitor = new FileUpdateMonitor();
Globals.fileUpdateMonitor = new DefaultFileUpdateMonitor();
JabRefExecutorService.INSTANCE.executeInterruptableTask(Globals.fileUpdateMonitor, "FileUpdateMonitor");

if (Globals.prefs.shouldCollectTelemetry()) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/JabRefGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ private void openLastEditedDatabases() {
}

ParserResult parsedDatabase = OpenDatabase.loadDatabase(fileName,
Globals.prefs.getImportFormatPreferences());
Globals.prefs.getImportFormatPreferences(), Globals.getFileUpdateMonitor());

if (parsedDatabase.isEmpty()) {
LOGGER.error(Localization.lang("Error opening file") + " '" + dbFile.getPath() + "'");
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/JabRefMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ private static void start(String[] args) {

/* Build list of Import and Export formats */
Globals.IMPORT_FORMAT_READER.resetImportFormats(Globals.prefs.getImportFormatPreferences(),
Globals.prefs.getXMPPreferences());
Globals.prefs.getXMPPreferences(), Globals.getFileUpdateMonitor());
EntryTypes.loadCustomEntryTypes(preferences.loadCustomEntryTypes(BibDatabaseMode.BIBTEX),
preferences.loadCustomEntryTypes(BibDatabaseMode.BIBLATEX));
Globals.exportFactory = ExporterFactory.create(Globals.prefs, Globals.journalAbbreviationLoader);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/cli/ArgumentProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private static Optional<ParserResult> importFile(Path file, String importFormat)
// * means "guess the format":
System.out.println(Localization.lang("Importing in unknown format") + ": " + file);

ImportFormatReader.UnknownFormatImport importResult = Globals.IMPORT_FORMAT_READER.importUnknownFormat(file);
ImportFormatReader.UnknownFormatImport importResult = Globals.IMPORT_FORMAT_READER.importUnknownFormat(file, Globals.getFileUpdateMonitor());

System.out.println(Localization.lang("Format used") + ": " + importResult.format);
return Optional.of(importResult.parserResult);
Expand Down Expand Up @@ -308,7 +308,7 @@ private List<ParserResult> importAndOpenFiles() {
boolean bibExtension = aLeftOver.toLowerCase(Locale.ENGLISH).endsWith("bib");
ParserResult pr = new ParserResult();
if (bibExtension) {
pr = OpenDatabase.loadDatabase(aLeftOver, Globals.prefs.getImportFormatPreferences());
pr = OpenDatabase.loadDatabase(aLeftOver, Globals.prefs.getImportFormatPreferences(), Globals.getFileUpdateMonitor());
}

if (!bibExtension || (pr.isEmpty())) {
Expand Down
14 changes: 9 additions & 5 deletions src/main/java/org/jabref/cli/AuxCommandLine.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package org.jabref.cli;

import org.jabref.logic.auxparser.AuxParser;
import org.jabref.logic.auxparser.AuxParserResult;
import java.nio.file.Paths;

import org.jabref.gui.auximport.AuxParserResultViewModel;
import org.jabref.logic.auxparser.DefaultAuxParser;
import org.jabref.model.auxparser.AuxParser;
import org.jabref.model.auxparser.AuxParserResult;
import org.jabref.model.database.BibDatabase;
import org.jabref.model.strings.StringUtil;

Expand All @@ -18,11 +22,11 @@ public BibDatabase perform() {
BibDatabase subDatabase = null;

if (!auxFile.isEmpty() && (database != null)) {
AuxParser auxParser = new AuxParser(auxFile, database);
AuxParserResult result = auxParser.parse();
AuxParser auxParser = new DefaultAuxParser(database);
AuxParserResult result = auxParser.parse(Paths.get(auxFile));
subDatabase = result.getGeneratedBibDatabase();
// print statistics
System.out.println(result.getInformation(true));
System.out.println(new AuxParserResultViewModel(result).getInformation(true));
}
return subDatabase;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/cli/CrossrefFetcherEvaluator.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ private CrossrefFetcherEvaluator() {
public static void main(String[] args) throws IOException, InterruptedException {
Globals.prefs = JabRefPreferences.getInstance();
try (FileReader reader = new FileReader(args[0])) {
BibtexParser parser = new BibtexParser(Globals.prefs.getImportFormatPreferences());
BibtexParser parser = new BibtexParser(Globals.prefs.getImportFormatPreferences(), Globals.getFileUpdateMonitor());
ParserResult result = parser.parse(reader);
BibDatabase db = result.getDatabase();

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/jabref/cli/XMPUtilMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static void main(String[] args) throws IOException, TransformerException
} else if (args[0].endsWith(".bib")) {
// Read from BIB and write as XMP
try (FileReader fr = new FileReader(args[0])) {
ParserResult result = new BibtexParser(importFormatPreferences).parse(fr);
ParserResult result = new BibtexParser(importFormatPreferences, Globals.getFileUpdateMonitor()).parse(fr);
Collection<BibEntry> entries = result.getDatabase().getEntries();

if (entries.isEmpty()) {
Expand All @@ -114,7 +114,7 @@ public static void main(String[] args) throws IOException, TransformerException
}

if (args[0].endsWith(".bib") && args[1].endsWith(".pdf")) {
ParserResult result = new BibtexParser(importFormatPreferences).parse(new FileReader(args[0]));
ParserResult result = new BibtexParser(importFormatPreferences, Globals.getFileUpdateMonitor()).parse(new FileReader(args[0]));

Collection<BibEntry> entries = result.getDatabase().getEntries();

Expand All @@ -135,7 +135,7 @@ public static void main(String[] args) throws IOException, TransformerException
break;
}

ParserResult result = new BibtexParser(importFormatPreferences).parse(new FileReader(args[1]));
ParserResult result = new BibtexParser(importFormatPreferences, Globals.getFileUpdateMonitor()).parse(new FileReader(args[1]));

Optional<BibEntry> bibEntry = result.getDatabase().getEntryByKey(args[0]);

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/gui/DefaultInjector.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import org.jabref.Globals;
import org.jabref.gui.keyboard.KeyBindingRepository;
import org.jabref.gui.util.FileUpdateMonitor;
import org.jabref.gui.util.DefaultFileUpdateMonitor;
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.journals.JournalAbbreviationLoader;
import org.jabref.preferences.PreferencesService;
Expand Down Expand Up @@ -36,7 +36,7 @@ private static Object createDependency(Class<?> clazz) {
return Globals.journalAbbreviationLoader;
} else if (clazz == StateManager.class) {
return Globals.stateManager;
} else if (clazz == FileUpdateMonitor.class) {
} else if (clazz == DefaultFileUpdateMonitor.class) {
return Globals.getFileUpdateMonitor();
} else {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.jabref.gui.auximport;

import org.jabref.logic.l10n.Localization;
import org.jabref.model.auxparser.AuxParserResult;

public class AuxParserResultViewModel {

private AuxParserResult auxParserResult;

public AuxParserResultViewModel(AuxParserResult auxParserResult) {
this.auxParserResult = auxParserResult;
}

/**
* Prints parsing statistics
*/
public String getInformation(boolean includeMissingEntries) {
StringBuilder result = new StringBuilder();

result.append(Localization.lang("keys in library")).append(' ').append(this.auxParserResult.getMasterDatabase().getEntryCount()).append('\n')
.append(Localization.lang("found in AUX file")).append(' ').append(this.auxParserResult.getFoundKeysInAux()).append('\n')
.append(Localization.lang("resolved")).append(' ').append(this.auxParserResult.getResolvedKeysCount()).append('\n')
.append(Localization.lang("not found")).append(' ').append(this.auxParserResult.getUnresolvedKeysCount()).append('\n')
.append(Localization.lang("crossreferenced entries included")).append(' ')
.append(this.auxParserResult.getCrossRefEntriesCount()).append(Localization.lang("strings included")).append(' ')
.append(this.auxParserResult.getInsertedStrings()).append('\n');

if (includeMissingEntries && (this.auxParserResult.getUnresolvedKeysCount() > 0)) {
for (String entry : this.auxParserResult.getUnresolvedKeys()) {
result.append(entry).append('\n');
}
}
if (this.auxParserResult.getNestedAuxCount() > 0) {
result.append(Localization.lang("nested AUX files")).append(' ').append(this.auxParserResult.getNestedAuxCount());
}
return result.toString();
}
}
20 changes: 11 additions & 9 deletions src/main/java/org/jabref/gui/auximport/FromAuxDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Optional;

import javax.swing.AbstractAction;
Expand All @@ -29,10 +30,11 @@
import org.jabref.gui.keyboard.KeyBinding;
import org.jabref.gui.util.DefaultTaskExecutor;
import org.jabref.gui.util.FileDialogConfiguration;
import org.jabref.logic.auxparser.AuxParser;
import org.jabref.logic.auxparser.AuxParserResult;
import org.jabref.logic.auxparser.DefaultAuxParser;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.FileType;
import org.jabref.model.auxparser.AuxParser;
import org.jabref.model.auxparser.AuxParserResult;
import org.jabref.model.database.BibDatabase;
import org.jabref.preferences.JabRefPreferences;

Expand Down Expand Up @@ -62,7 +64,7 @@ public class FromAuxDialog extends JabRefDialog {

private boolean generatePressed;

private AuxParser auxParser;
private AuxParserResult auxParserResult;

private final JabRefFrame parentFrame;

Expand Down Expand Up @@ -207,15 +209,15 @@ private void parseActionPerformed() {
String auxName = auxFileField.getText();

if ((auxName != null) && (refBase != null) && !auxName.isEmpty()) {
auxParser = new AuxParser(auxName, refBase);
AuxParserResult result = auxParser.parse();
notFoundList.setListData(result.getUnresolvedKeys().toArray(new String[result.getUnresolvedKeys().size()]));
statusInfos.append(result.getInformation(false));
AuxParser auxParser = new DefaultAuxParser(refBase);
auxParserResult = auxParser.parse(Paths.get(auxName));
notFoundList.setListData(auxParserResult.getUnresolvedKeys().toArray(new String[auxParserResult.getUnresolvedKeys().size()]));
statusInfos.append(new AuxParserResultViewModel(auxParserResult).getInformation(false));

generateButton.setEnabled(true);

// the generated database contains no entries -> no active generate-button
if (!result.getGeneratedBibDatabase().hasEntries()) {
if (!auxParserResult.getGeneratedBibDatabase().hasEntries()) {
statusInfos.append("\n" + Localization.lang("empty library"));
generateButton.setEnabled(false);
}
Expand All @@ -231,7 +233,7 @@ public boolean generatePressed() {
}

public BibDatabase getGenerateDB() {
return auxParser.parse().getGeneratedBibDatabase();
return auxParserResult.getGeneratedBibDatabase();
}

}
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/gui/collab/ChangeScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ public void run() {

// Parse the temporary file.
ImportFormatPreferences importFormatPreferences = Globals.prefs.getImportFormatPreferences();
ParserResult result = OpenDatabase.loadDatabase(tempFile.toFile(), importFormatPreferences);
ParserResult result = OpenDatabase.loadDatabase(tempFile.toFile(), importFormatPreferences, Globals.getFileUpdateMonitor());
databaseInTemp = result.getDatabaseContext();

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

// Start looking at changes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
import org.jabref.JabRefExecutorService;
import org.jabref.gui.BasePanel;
import org.jabref.gui.SidePaneManager;
import org.jabref.gui.util.FileUpdateListener;
import org.jabref.gui.util.FileUpdateMonitor;
import org.jabref.logic.util.io.FileBasedLock;
import org.jabref.logic.util.io.FileUtil;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.util.FileUpdateListener;
import org.jabref.model.util.FileUpdateMonitor;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/entryeditor/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ private List<EntryEditorTab> createTabs() {
tabs.add(new RelatedArticlesTab(Globals.prefs));

// Source tab
sourceTab = new SourceTab(bibDatabaseContext, undoManager, Globals.prefs.getLatexFieldFormatterPreferences(), Globals.prefs);
sourceTab = new SourceTab(bibDatabaseContext, undoManager, Globals.prefs.getLatexFieldFormatterPreferences(), Globals.prefs, Globals.getFileUpdateMonitor());
tabs.add(sourceTab);
return tabs;
}
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/org/jabref/gui/entryeditor/SourceTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.jabref.model.database.BibDatabaseMode;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.InternalBibtexFields;
import org.jabref.model.util.FileUpdateMonitor;
import org.jabref.preferences.JabRefPreferences;

import de.saxsys.mvvmfx.utils.validation.ObservableRuleBasedValidator;
Expand All @@ -51,15 +52,17 @@ public class SourceTab extends EntryEditorTab {
private UndoManager undoManager;
private final ObjectProperty<ValidationMessage> sourceIsValid = new SimpleObjectProperty<>();
private final ObservableRuleBasedValidator sourceValidator = new ObservableRuleBasedValidator(sourceIsValid);
private FileUpdateMonitor fileMonitor;

public SourceTab(BibDatabaseContext bibDatabaseContext, CountingUndoManager undoManager, LatexFieldFormatterPreferences fieldFormatterPreferences, JabRefPreferences preferences) {
public SourceTab(BibDatabaseContext bibDatabaseContext, CountingUndoManager undoManager, LatexFieldFormatterPreferences fieldFormatterPreferences, JabRefPreferences preferences, FileUpdateMonitor fileMonitor) {
this.mode = bibDatabaseContext.getMode();
this.setText(Localization.lang("%0 source", mode.getFormattedName()));
this.setTooltip(new Tooltip(Localization.lang("Show/edit %0 source", mode.getFormattedName())));
this.setGraphic(IconTheme.JabRefIcon.SOURCE.getGraphicNode());
this.undoManager = undoManager;
this.fieldFormatterPreferences = fieldFormatterPreferences;
this.preferences = preferences;
this.fileMonitor = fileMonitor;
}

private static String getSourceString(BibEntry entry, BibDatabaseMode type, LatexFieldFormatterPreferences fieldFormatterPreferences) throws IOException {
Expand Down Expand Up @@ -119,7 +122,7 @@ private void storeSource(String text) {
return;
}

BibtexParser bibtexParser = new BibtexParser(preferences.getImportFormatPreferences());
BibtexParser bibtexParser = new BibtexParser(preferences.getImportFormatPreferences(), fileMonitor);
try {
ParserResult parserResult = bibtexParser.parse(new StringReader(text));
BibDatabase database = parserResult.getDatabase();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
import javafx.scene.text.Text;

import org.jabref.gui.AbstractController;
import org.jabref.gui.util.FileUpdateMonitor;
import org.jabref.gui.util.ViewModelListCellFactory;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.pdf.FileAnnotationCache;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.util.FileUpdateMonitor;

import org.fxmisc.easybind.EasyBind;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
import org.jabref.gui.AbstractViewModel;
import org.jabref.gui.ClipBoardManager;
import org.jabref.gui.util.DefaultTaskExecutor;
import org.jabref.gui.util.FileUpdateListener;
import org.jabref.gui.util.FileUpdateMonitor;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.pdf.FileAnnotationCache;
import org.jabref.logic.util.OS;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.pdf.FileAnnotation;
import org.jabref.model.util.FileUpdateListener;
import org.jabref.model.util.FileUpdateMonitor;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/jabref/gui/groups/GroupDescriptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ public static String getShortDescriptionAllEntriesGroup() {
}

public static String getShortDescription(SearchGroup searchGroup, boolean showDynamic) {

StringBuilder sb = new StringBuilder();
sb.append("<b>");
if (showDynamic) {
Expand Down
Loading