From 9795e0dd0c81736b9b1b0fe57ec317f7539c101f Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Fri, 26 Aug 2016 19:56:56 +0200 Subject: [PATCH 1/2] Removed last Globals dependency in MetaData --- .../net/sf/jabref/benchmarks/Benchmarks.java | 2 +- src/main/java/net/sf/jabref/MetaData.java | 26 ++++---- .../sf/jabref/gui/groups/AutoGroupDialog.java | 6 +- .../net/sf/jabref/gui/groups/GroupDialog.java | 11 ++-- .../actions/AppendDatabaseAction.java | 2 +- .../sf/jabref/logic/groups/AbstractGroup.java | 7 +- .../sf/jabref/logic/groups/ExplicitGroup.java | 13 ++-- .../sf/jabref/logic/groups/GroupTreeNode.java | 4 +- .../sf/jabref/logic/groups/GroupsParser.java | 4 +- .../sf/jabref/logic/groups/KeywordGroup.java | 26 ++++---- .../importer/fileformat/BibtexParser.java | 2 +- .../sf/jabref/shared/DBMSSynchronizer.java | 4 +- .../ConvertLegacyExplicitGroupsTest.java | 6 +- .../exporter/BibtexDatabaseWriterTest.java | 6 +- .../logic/groups/ExplicitGroupTest.java | 4 +- .../logic/groups/GroupTreeNodeTest.java | 64 +++++++++++-------- .../jabref/logic/groups/KeywordGroupTest.java | 24 +++---- .../importer/fileformat/BibtexParserTest.java | 12 ++-- 18 files changed, 121 insertions(+), 102 deletions(-) diff --git a/src/jmh/java/net/sf/jabref/benchmarks/Benchmarks.java b/src/jmh/java/net/sf/jabref/benchmarks/Benchmarks.java index ddefa68e5c2..26cdf35c12b 100644 --- a/src/jmh/java/net/sf/jabref/benchmarks/Benchmarks.java +++ b/src/jmh/java/net/sf/jabref/benchmarks/Benchmarks.java @@ -123,7 +123,7 @@ public String htmlToLatexConversion() { @Benchmark public boolean keywordGroupContains() throws ParseException { KeywordGroup group = new KeywordGroup("testGroup", "keyword", "testkeyword", false, false, - GroupHierarchyType.INDEPENDENT, Globals.prefs); + GroupHierarchyType.INDEPENDENT, Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); return group.containsAll(database.getEntries()); } diff --git a/src/main/java/net/sf/jabref/MetaData.java b/src/main/java/net/sf/jabref/MetaData.java index e0b0f6002f6..3131e4137c3 100644 --- a/src/main/java/net/sf/jabref/MetaData.java +++ b/src/main/java/net/sf/jabref/MetaData.java @@ -66,12 +66,13 @@ public class MetaData implements Iterable { * must simply make sure the appropriate changes are reflected in the Vector * it has been passed. */ - private MetaData(Map inData) throws ParseException { + private MetaData(Map inData, String keywordSeparator) throws ParseException { Objects.requireNonNull(inData); - setData(inData); + setData(inData, keywordSeparator); } - private MetaData(Map inData, Charset encoding) throws ParseException { - this(inData); + + private MetaData(Map inData, Charset encoding, String keywordSeparator) throws ParseException { + this(inData, keywordSeparator); this.encoding = Objects.requireNonNull(encoding); } @@ -86,15 +87,16 @@ public MetaData(Charset encoding) { this.encoding = encoding; } - public static MetaData parse(Map data) throws ParseException { - return new MetaData(data); + public static MetaData parse(Map data, String keywordSeparator) throws ParseException { + return new MetaData(data, keywordSeparator); } - public static MetaData parse(Map data, Charset encoding) throws ParseException { - return new MetaData(data, encoding); + public static MetaData parse(Map data, Charset encoding, String keywordSeparator) + throws ParseException { + return new MetaData(data, encoding, keywordSeparator); } - public void setData(Map inData) throws ParseException { + public void setData(Map inData, String keywordSeparator) throws ParseException { clearMetaData(); for (Map.Entry entry : inData.entrySet()) { StringReader data = new StringReader(entry.getValue()); @@ -109,7 +111,7 @@ public void setData(Map inData) throws ParseException { LOGGER.error("Weird error while parsing meta data.", ex); } if (GROUPSTREE.equals(entry.getKey())) { - putGroups(orderedData); + putGroups(orderedData, keywordSeparator); // the keys "groupsversion" and "groups" were used in JabRef versions around 1.3, we will not support them anymore eventBus.post(new GroupUpdatedEvent(this)); } else if (SAVE_ACTIONS.equals(entry.getKey())) { @@ -186,9 +188,9 @@ public void putData(String key, List orderedData) { * * @param orderedData The vector of metadata strings */ - private void putGroups(List orderedData) throws ParseException { + private void putGroups(List orderedData, String keywordSeparator) throws ParseException { try { - groupsRoot = GroupTreeNode.parse(orderedData, Globals.prefs); + groupsRoot = GroupTreeNode.parse(orderedData, keywordSeparator); eventBus.post(new GroupUpdatedEvent(this)); } catch (ParseException e) { throw new ParseException(Localization.lang( diff --git a/src/main/java/net/sf/jabref/gui/groups/AutoGroupDialog.java b/src/main/java/net/sf/jabref/gui/groups/AutoGroupDialog.java index 58b3f3788e2..31c52d198d8 100644 --- a/src/main/java/net/sf/jabref/gui/groups/AutoGroupDialog.java +++ b/src/main/java/net/sf/jabref/gui/groups/AutoGroupDialog.java @@ -36,6 +36,7 @@ import net.sf.jabref.logic.l10n.Localization; import net.sf.jabref.logic.layout.format.LatexToUnicodeFormatter; import net.sf.jabref.model.entry.FieldName; +import net.sf.jabref.preferences.JabRefPreferences; import com.jgoodies.forms.builder.ButtonBarBuilder; import com.jgoodies.forms.builder.FormBuilder; @@ -82,7 +83,8 @@ public void actionPerformed(ActionEvent e) { try { GroupTreeNode autoGroupsRoot = GroupTreeNode.fromGroup( new ExplicitGroup(Localization.lang("Automatically created groups"), - GroupHierarchyType.INCLUDING, Globals.prefs)); + GroupHierarchyType.INCLUDING, + Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR))); Set hs; String fieldText = field.getText(); if (keywords.isSelected()) { @@ -110,7 +112,7 @@ public void actionPerformed(ActionEvent e) { for (String keyword : hs) { KeywordGroup group = new KeywordGroup(formatter.format(keyword), fieldText, keyword, false, false, - GroupHierarchyType.INDEPENDENT, Globals.prefs); + GroupHierarchyType.INDEPENDENT, Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); autoGroupsRoot.addChild(GroupTreeNode.fromGroup(group)); } diff --git a/src/main/java/net/sf/jabref/gui/groups/GroupDialog.java b/src/main/java/net/sf/jabref/gui/groups/GroupDialog.java index 3065a936d65..c03389218fc 100644 --- a/src/main/java/net/sf/jabref/gui/groups/GroupDialog.java +++ b/src/main/java/net/sf/jabref/gui/groups/GroupDialog.java @@ -265,14 +265,15 @@ public void actionPerformed(ActionEvent e) { isOkPressed = true; try { if (explicitRadioButton.isSelected()) { - resultingGroup = new ExplicitGroup(nameField.getText().trim(), getContext(), Globals.prefs); + resultingGroup = new ExplicitGroup(nameField.getText().trim(), getContext(), + Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); } else if (keywordsRadioButton.isSelected()) { // regex is correct, otherwise OK would have been disabled // therefore I don't catch anything here - resultingGroup = new KeywordGroup(nameField.getText().trim(), keywordGroupSearchField.getText().trim(), - keywordGroupSearchTerm.getText().trim(), keywordGroupCaseSensitive.isSelected(), keywordGroupRegExp - .isSelected(), - getContext(), Globals.prefs); + resultingGroup = new KeywordGroup(nameField.getText().trim(), + keywordGroupSearchField.getText().trim(), keywordGroupSearchTerm.getText().trim(), + keywordGroupCaseSensitive.isSelected(), keywordGroupRegExp.isSelected(), getContext(), + Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); } else if (searchRadioButton.isSelected()) { try { // regex is correct, otherwise OK would have been diff --git a/src/main/java/net/sf/jabref/gui/importer/actions/AppendDatabaseAction.java b/src/main/java/net/sf/jabref/gui/importer/actions/AppendDatabaseAction.java index 26d50f5cf73..a78205d0635 100644 --- a/src/main/java/net/sf/jabref/gui/importer/actions/AppendDatabaseAction.java +++ b/src/main/java/net/sf/jabref/gui/importer/actions/AppendDatabaseAction.java @@ -141,7 +141,7 @@ private static void mergeFromBibtex(JabRefFrame frame, BasePanel panel, ParserRe // create a dummy group try { ExplicitGroup group = new ExplicitGroup("Imported", GroupHierarchyType.INDEPENDENT, - Globals.prefs); + Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); newGroups.setGroup(group); group.add(appendedEntries); } catch (ParseException e) { diff --git a/src/main/java/net/sf/jabref/logic/groups/AbstractGroup.java b/src/main/java/net/sf/jabref/logic/groups/AbstractGroup.java index 1322c39195b..33c50d681e4 100644 --- a/src/main/java/net/sf/jabref/logic/groups/AbstractGroup.java +++ b/src/main/java/net/sf/jabref/logic/groups/AbstractGroup.java @@ -8,7 +8,6 @@ import net.sf.jabref.logic.search.SearchMatcher; import net.sf.jabref.model.database.BibDatabase; import net.sf.jabref.model.entry.BibEntry; -import net.sf.jabref.preferences.JabRefPreferences; /** * A group of BibtexEntries. @@ -48,9 +47,9 @@ public abstract class AbstractGroup implements SearchMatcher { * @throws ParseException If an error occurred and a group could not be created, * e.g. due to a malformed regular expression. */ - public static AbstractGroup fromString(String s, JabRefPreferences jabRefPreferences) throws ParseException { + public static AbstractGroup fromString(String s, String keywordSeparator) throws ParseException { if (s.startsWith(KeywordGroup.ID)) { - return KeywordGroup.fromString(s, jabRefPreferences); + return KeywordGroup.fromString(s, keywordSeparator); } if (s.startsWith(AllEntriesGroup.ID)) { return AllEntriesGroup.fromString(s); @@ -59,7 +58,7 @@ public static AbstractGroup fromString(String s, JabRefPreferences jabRefPrefere return SearchGroup.fromString(s); } if (s.startsWith(ExplicitGroup.ID)) { - return ExplicitGroup.fromString(s, jabRefPreferences); + return ExplicitGroup.fromString(s, keywordSeparator); } return null; // unknown group } diff --git a/src/main/java/net/sf/jabref/logic/groups/ExplicitGroup.java b/src/main/java/net/sf/jabref/logic/groups/ExplicitGroup.java index 8011f86724f..083ec572771 100644 --- a/src/main/java/net/sf/jabref/logic/groups/ExplicitGroup.java +++ b/src/main/java/net/sf/jabref/logic/groups/ExplicitGroup.java @@ -11,8 +11,6 @@ import net.sf.jabref.logic.util.strings.QuotedStringTokenizer; import net.sf.jabref.logic.util.strings.StringUtil; import net.sf.jabref.model.entry.FieldName; -import net.sf.jabref.preferences.JabRefPreferences; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -29,12 +27,13 @@ public class ExplicitGroup extends KeywordGroup { private static final Log LOGGER = LogFactory.getLog(ExplicitGroup.class); - public ExplicitGroup(String name, GroupHierarchyType context, JabRefPreferences jabRefPreferences) + + public ExplicitGroup(String name, GroupHierarchyType context, String keywordSeparator) throws ParseException { - super(name, FieldName.GROUPS, name, true, false, context, jabRefPreferences); + super(name, FieldName.GROUPS, name, true, false, context, keywordSeparator); } - public static ExplicitGroup fromString(String s, JabRefPreferences jabRefPreferences) throws ParseException { + public static ExplicitGroup fromString(String s, String keywordSeparator) throws ParseException { if (!s.startsWith(ExplicitGroup.ID)) { throw new IllegalArgumentException("ExplicitGroup cannot be created from \"" + s + "\"."); } @@ -43,7 +42,7 @@ public static ExplicitGroup fromString(String s, JabRefPreferences jabRefPrefere String name = tok.nextToken(); int context = Integer.parseInt(tok.nextToken()); - ExplicitGroup newGroup = new ExplicitGroup(name, GroupHierarchyType.getByNumber(context), jabRefPreferences); + ExplicitGroup newGroup = new ExplicitGroup(name, GroupHierarchyType.getByNumber(context), keywordSeparator); newGroup.addLegacyEntryKeys(tok); return newGroup; } @@ -68,7 +67,7 @@ public void addLegacyEntryKey(String key) { @Override public AbstractGroup deepCopy() { try { - ExplicitGroup copy = new ExplicitGroup(getName(), getContext(), jabRefPreferences); + ExplicitGroup copy = new ExplicitGroup(getName(), getContext(), keywordSeparator); copy.legacyEntryKeys.addAll(legacyEntryKeys); return copy; } catch (ParseException exception) { diff --git a/src/main/java/net/sf/jabref/logic/groups/GroupTreeNode.java b/src/main/java/net/sf/jabref/logic/groups/GroupTreeNode.java index 6ad4eef13f4..a10d496f5f0 100644 --- a/src/main/java/net/sf/jabref/logic/groups/GroupTreeNode.java +++ b/src/main/java/net/sf/jabref/logic/groups/GroupTreeNode.java @@ -234,9 +234,9 @@ public GroupTreeNode copyNode() { return GroupTreeNode.fromGroup(group); } - public static GroupTreeNode parse(List orderedData, JabRefPreferences jabRefPreferences) + public static GroupTreeNode parse(List orderedData, String keywordSeparator) throws ParseException { - return GroupsParser.importGroups(orderedData, jabRefPreferences); + return GroupsParser.importGroups(orderedData, keywordSeparator); } /** diff --git a/src/main/java/net/sf/jabref/logic/groups/GroupsParser.java b/src/main/java/net/sf/jabref/logic/groups/GroupsParser.java index 5377a96adc2..fa52dc681a5 100644 --- a/src/main/java/net/sf/jabref/logic/groups/GroupsParser.java +++ b/src/main/java/net/sf/jabref/logic/groups/GroupsParser.java @@ -11,7 +11,7 @@ */ class GroupsParser { - public static GroupTreeNode importGroups(List orderedData, JabRefPreferences jabRefPreferences) + public static GroupTreeNode importGroups(List orderedData, String keywordSeparator) throws ParseException { GroupTreeNode cursor = null; GroupTreeNode root = null; @@ -27,7 +27,7 @@ public static GroupTreeNode importGroups(List orderedData, JabRefPrefere throw new ParseException(Localization.lang("Expected \"%0\" to contain whitespace", string)); } int level = Integer.parseInt(string.substring(0, spaceIndex)); - AbstractGroup group = AbstractGroup.fromString(string.substring(spaceIndex + 1), jabRefPreferences); + AbstractGroup group = AbstractGroup.fromString(string.substring(spaceIndex + 1), keywordSeparator); GroupTreeNode newNode = GroupTreeNode.fromGroup(group); if (cursor == null) { // create new root diff --git a/src/main/java/net/sf/jabref/logic/groups/KeywordGroup.java b/src/main/java/net/sf/jabref/logic/groups/KeywordGroup.java index 93d0038c0e4..e16ac840c0b 100644 --- a/src/main/java/net/sf/jabref/logic/groups/KeywordGroup.java +++ b/src/main/java/net/sf/jabref/logic/groups/KeywordGroup.java @@ -14,8 +14,6 @@ import net.sf.jabref.model.FieldChange; import net.sf.jabref.model.entry.BibEntry; import net.sf.jabref.model.entry.EntryUtil; -import net.sf.jabref.preferences.JabRefPreferences; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -32,7 +30,7 @@ public class KeywordGroup extends AbstractGroup { private final boolean regExp; private Pattern pattern; private final List searchWords; - protected final JabRefPreferences jabRefPreferences; + protected final String keywordSeparator; private static final Log LOGGER = LogFactory.getLog(KeywordGroup.class); @@ -42,7 +40,7 @@ public class KeywordGroup extends AbstractGroup { */ public KeywordGroup(String name, String searchField, String searchExpression, boolean caseSensitive, boolean regExp, - GroupHierarchyType context, JabRefPreferences jabRefPreferences) throws ParseException { + GroupHierarchyType context, String keywordSeparator) throws ParseException { super(name, context); this.searchField = searchField; this.searchExpression = searchExpression; @@ -51,7 +49,7 @@ public KeywordGroup(String name, String searchField, if (this.regExp) { compilePattern(); } - this.jabRefPreferences = jabRefPreferences; + this.keywordSeparator = keywordSeparator; this.searchWords = EntryUtil.getStringAsWords(searchExpression); } @@ -70,7 +68,7 @@ private void compilePattern() throws ParseException { * @param s The String representation obtained from * KeywordGroup.toString() */ - public static AbstractGroup fromString(String s, JabRefPreferences jabRefPreferences) throws ParseException { + public static AbstractGroup fromString(String s, String keywordSeparator) throws ParseException { if (!s.startsWith(KeywordGroup.ID)) { throw new IllegalArgumentException("KeywordGroup cannot be created from \"" + s + "\"."); } @@ -86,7 +84,7 @@ public static AbstractGroup fromString(String s, JabRefPreferences jabRefPrefere return new KeywordGroup(StringUtil.unquote(name, AbstractGroup.QUOTE_CHAR), StringUtil.unquote(field, AbstractGroup.QUOTE_CHAR), StringUtil.unquote(expression, AbstractGroup.QUOTE_CHAR), caseSensitive, regExp, - GroupHierarchyType.getByNumber(context), jabRefPreferences); + GroupHierarchyType.getByNumber(context), keywordSeparator); } /** @@ -125,9 +123,8 @@ public Optional add(List entriesToAdd) { for (BibEntry entry : entriesToAdd) { if (!contains(entry)) { String oldContent = entry.getFieldOptional(searchField).orElse(null); - String pre = jabRefPreferences.get(JabRefPreferences.KEYWORD_SEPARATOR); String newContent = (oldContent == null ? "" : oldContent - + pre) + + keywordSeparator) + searchExpression; entry.setField(searchField, newContent); @@ -263,21 +260,20 @@ private void removeMatches(BibEntry entry) { int i; int j; int k; - final String separator = jabRefPreferences.get(JabRefPreferences.KEYWORD_SEPARATOR); while ((i = haystack.indexOf(needle)) >= 0) { sbOrig.replace(i, i + needle.length(), ""); sbLower.replace(i, i + needle.length(), ""); // reduce spaces at i to 1 j = i; k = i; - while (((j - 1) >= 0) && (separator.indexOf(haystack.charAt(j - 1)) >= 0)) { + while (((j - 1) >= 0) && (keywordSeparator.indexOf(haystack.charAt(j - 1)) >= 0)) { --j; } - while ((k < haystack.length()) && (separator.indexOf(haystack.charAt(k)) >= 0)) { + while ((k < haystack.length()) && (keywordSeparator.indexOf(haystack.charAt(k)) >= 0)) { ++k; } - sbOrig.replace(j, k, (j >= 0) && (k < sbOrig.length()) ? separator : ""); - sbLower.replace(j, k, (j >= 0) && (k < sbOrig.length()) ? separator : ""); + sbOrig.replace(j, k, (j >= 0) && (k < sbOrig.length()) ? keywordSeparator : ""); + sbLower.replace(j, k, (j >= 0) && (k < sbOrig.length()) ? keywordSeparator : ""); } String result = sbOrig.toString().trim(); @@ -293,7 +289,7 @@ private void removeMatches(BibEntry entry) { public AbstractGroup deepCopy() { try { return new KeywordGroup(getName(), searchField, searchExpression, - caseSensitive, regExp, getContext(), jabRefPreferences); + caseSensitive, regExp, getContext(), keywordSeparator); } catch (ParseException exception) { // this should never happen, because the constructor obviously succeeded in creating _this_ instance! LOGGER.error("Internal error in KeywordGroup.deepCopy(). " diff --git a/src/main/java/net/sf/jabref/logic/importer/fileformat/BibtexParser.java b/src/main/java/net/sf/jabref/logic/importer/fileformat/BibtexParser.java index e212d7d7202..0f8d3c05731 100644 --- a/src/main/java/net/sf/jabref/logic/importer/fileformat/BibtexParser.java +++ b/src/main/java/net/sf/jabref/logic/importer/fileformat/BibtexParser.java @@ -187,7 +187,7 @@ private ParserResult parseFileContent() throws IOException { // Instantiate meta data: try { - parserResult.setMetaData(MetaData.parse(meta)); + parserResult.setMetaData(MetaData.parse(meta, importFormatPreferences.getKeywordSeparator())); } catch (ParseException exception) { parserResult.addWarning(exception.getLocalizedMessage()); } diff --git a/src/main/java/net/sf/jabref/shared/DBMSSynchronizer.java b/src/main/java/net/sf/jabref/shared/DBMSSynchronizer.java index 122648e5106..d2aa162f0cd 100644 --- a/src/main/java/net/sf/jabref/shared/DBMSSynchronizer.java +++ b/src/main/java/net/sf/jabref/shared/DBMSSynchronizer.java @@ -8,6 +8,7 @@ import java.util.Set; import net.sf.jabref.BibDatabaseContext; +import net.sf.jabref.Globals; import net.sf.jabref.MetaData; import net.sf.jabref.event.MetaDataChangedEvent; import net.sf.jabref.event.source.EntryEventSource; @@ -19,6 +20,7 @@ import net.sf.jabref.model.event.EntryEvent; import net.sf.jabref.model.event.EntryRemovedEvent; import net.sf.jabref.model.event.FieldChangedEvent; +import net.sf.jabref.preferences.JabRefPreferences; import net.sf.jabref.shared.event.ConnectionLostEvent; import net.sf.jabref.shared.event.SharedEntryNotPresentEvent; import net.sf.jabref.shared.event.UpdateRefusedEvent; @@ -246,7 +248,7 @@ public void synchronizeLocalMetaData() { } try { - metaData.setData(dbmsProcessor.getSharedMetaData()); + metaData.setData(dbmsProcessor.getSharedMetaData(), Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); } catch (ParseException e) { LOGGER.error("Parse error", e); } diff --git a/src/test/java/net/sf/jabref/gui/importer/actions/ConvertLegacyExplicitGroupsTest.java b/src/test/java/net/sf/jabref/gui/importer/actions/ConvertLegacyExplicitGroupsTest.java index 3ed2cfa2896..0caddafa8ae 100644 --- a/src/test/java/net/sf/jabref/gui/importer/actions/ConvertLegacyExplicitGroupsTest.java +++ b/src/test/java/net/sf/jabref/gui/importer/actions/ConvertLegacyExplicitGroupsTest.java @@ -35,7 +35,8 @@ public void setUp() throws Exception { entry = new BibEntry(); entry.setCiteKey("Entry1"); - group = new ExplicitGroup("TestGroup", GroupHierarchyType.INCLUDING, Globals.prefs); + group = new ExplicitGroup("TestGroup", GroupHierarchyType.INCLUDING, + JabRefPreferences.getInstance().get(JabRefPreferences.KEYWORD_SEPARATOR)); group.addLegacyEntryKey("Entry1"); } @@ -60,7 +61,8 @@ public void performActionClearsLegacyKeys() throws Exception { @Test public void performActionWritesGroupMembershipInEntryForComplexGroupTree() throws Exception { GroupTreeNode root = GroupTreeNode.fromGroup(new AllEntriesGroup()); - root.addSubgroup(new ExplicitGroup("TestGroup2", GroupHierarchyType.INCLUDING, Globals.prefs)); + root.addSubgroup(new ExplicitGroup("TestGroup2", GroupHierarchyType.INCLUDING, + JabRefPreferences.getInstance().get(JabRefPreferences.KEYWORD_SEPARATOR))); root.addSubgroup(group); ParserResult parserResult = generateParserResult(entry, root); diff --git a/src/test/java/net/sf/jabref/logic/exporter/BibtexDatabaseWriterTest.java b/src/test/java/net/sf/jabref/logic/exporter/BibtexDatabaseWriterTest.java index 11e3878c1d8..c6fdc5b1e84 100644 --- a/src/test/java/net/sf/jabref/logic/exporter/BibtexDatabaseWriterTest.java +++ b/src/test/java/net/sf/jabref/logic/exporter/BibtexDatabaseWriterTest.java @@ -186,7 +186,8 @@ public void writeMetadataAndEncoding() throws Exception { @Test public void writeGroups() throws Exception { GroupTreeNode groupRoot = GroupTreeNode.fromGroup(new AllEntriesGroup()); - groupRoot.addSubgroup(new ExplicitGroup("test", GroupHierarchyType.INCLUDING, prefs)); + groupRoot.addSubgroup(new ExplicitGroup("test", GroupHierarchyType.INCLUDING, + prefs.get(JabRefPreferences.KEYWORD_SEPARATOR))); metaData.setGroups(groupRoot); StringSaveSession session = databaseWriter.savePartOfDatabase(bibtexContext, Collections.emptyList(), new SavePreferences()); @@ -205,7 +206,8 @@ public void writeGroupsAndEncoding() throws Exception { SavePreferences preferences = new SavePreferences().withEncoding(Charsets.US_ASCII); GroupTreeNode groupRoot = GroupTreeNode.fromGroup(new AllEntriesGroup()); - groupRoot.addChild(GroupTreeNode.fromGroup(new ExplicitGroup("test", GroupHierarchyType.INCLUDING, prefs))); + groupRoot.addChild(GroupTreeNode.fromGroup(new ExplicitGroup("test", GroupHierarchyType.INCLUDING, + prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)))); metaData.setGroups(groupRoot); StringSaveSession session = databaseWriter.savePartOfDatabase(bibtexContext, Collections.emptyList(), preferences); diff --git a/src/test/java/net/sf/jabref/logic/groups/ExplicitGroupTest.java b/src/test/java/net/sf/jabref/logic/groups/ExplicitGroupTest.java index ba72d905c21..123823fc5b2 100644 --- a/src/test/java/net/sf/jabref/logic/groups/ExplicitGroupTest.java +++ b/src/test/java/net/sf/jabref/logic/groups/ExplicitGroupTest.java @@ -16,14 +16,14 @@ public class ExplicitGroupTest { @Test public void testToStringSimple() throws ParseException { ExplicitGroup group = new ExplicitGroup("myExplicitGroup", GroupHierarchyType.INDEPENDENT, - JabRefPreferences.getInstance()); + JabRefPreferences.getInstance().get(JabRefPreferences.KEYWORD_SEPARATOR)); assertEquals("ExplicitGroup:myExplicitGroup;0;", group.toString()); } @Test public void toStringDoesNotWriteAssignedEntries() throws ParseException { ExplicitGroup group = new ExplicitGroup("myExplicitGroup", GroupHierarchyType.INCLUDING, - JabRefPreferences.getInstance()); + JabRefPreferences.getInstance().get(JabRefPreferences.KEYWORD_SEPARATOR)); group.add(makeBibtexEntry()); assertEquals("ExplicitGroup:myExplicitGroup;2;", group.toString()); } diff --git a/src/test/java/net/sf/jabref/logic/groups/GroupTreeNodeTest.java b/src/test/java/net/sf/jabref/logic/groups/GroupTreeNodeTest.java index fdea3bbd258..192f53a910a 100644 --- a/src/test/java/net/sf/jabref/logic/groups/GroupTreeNodeTest.java +++ b/src/test/java/net/sf/jabref/logic/groups/GroupTreeNodeTest.java @@ -41,13 +41,14 @@ public void setUp() throws Exception { * B ExplicitNode, Refining (<-- this) */ private GroupTreeNode getNodeInSimpleTree(GroupTreeNode root) throws ParseException { - root.addSubgroup(new ExplicitGroup("ExplicitA", GroupHierarchyType.INCLUDING, JabRefPreferences.getInstance())); + root.addSubgroup(new ExplicitGroup("ExplicitA", GroupHierarchyType.INCLUDING, + JabRefPreferences.getInstance().get(JabRefPreferences.KEYWORD_SEPARATOR))); GroupTreeNode parent = root .addSubgroup(new ExplicitGroup("ExplicitParent", GroupHierarchyType.INDEPENDENT, - JabRefPreferences.getInstance())); + JabRefPreferences.getInstance().get(JabRefPreferences.KEYWORD_SEPARATOR))); GroupTreeNode node = parent .addSubgroup(new ExplicitGroup("ExplicitNode", GroupHierarchyType.REFINING, - JabRefPreferences.getInstance())); + JabRefPreferences.getInstance().get(JabRefPreferences.KEYWORD_SEPARATOR))); return node; } @@ -74,10 +75,11 @@ private GroupTreeNode getNodeInSimpleTree() throws ParseException { */ private GroupTreeNode getNodeInComplexTree(GroupTreeNode root) throws ParseException { root.addSubgroup(getSearchGroup("SearchA")); - root.addSubgroup(new ExplicitGroup("ExplicitA", GroupHierarchyType.INCLUDING, JabRefPreferences.getInstance())); + root.addSubgroup(new ExplicitGroup("ExplicitA", GroupHierarchyType.INCLUDING, + JabRefPreferences.getInstance().get(JabRefPreferences.KEYWORD_SEPARATOR))); GroupTreeNode grandParent = root .addSubgroup(new ExplicitGroup("ExplicitGrandParent", GroupHierarchyType.INDEPENDENT, - JabRefPreferences.getInstance())); + JabRefPreferences.getInstance().get(JabRefPreferences.KEYWORD_SEPARATOR))); root.addSubgroup(getKeywordGroup("KeywordA")); grandParent.addSubgroup(getExplict("ExplicitB")); @@ -96,7 +98,7 @@ private GroupTreeNode getNodeInComplexTree(GroupTreeNode root) throws ParseExcep private AbstractGroup getKeywordGroup(String name) throws ParseException { return new KeywordGroup(name, "searchField", "searchExpression", true, false, GroupHierarchyType.INDEPENDENT, - JabRefPreferences.getInstance()); + JabRefPreferences.getInstance().get(JabRefPreferences.KEYWORD_SEPARATOR)); } private AbstractGroup getSearchGroup(String name) { @@ -104,7 +106,8 @@ private AbstractGroup getSearchGroup(String name) { } private AbstractGroup getExplict(String name) throws ParseException { - return new ExplicitGroup(name, GroupHierarchyType.REFINING, JabRefPreferences.getInstance()); + return new ExplicitGroup(name, GroupHierarchyType.REFINING, + JabRefPreferences.getInstance().get(JabRefPreferences.KEYWORD_SEPARATOR)); } /* @@ -176,7 +179,8 @@ public void getTreeAsStringInComplexTree() throws Exception { @Test public void getSearchRuleForIndependentGroupReturnsGroupAsMatcher() throws ParseException { GroupTreeNode node = GroupTreeNode - .fromGroup(new ExplicitGroup("node", GroupHierarchyType.INDEPENDENT, JabRefPreferences.getInstance())); + .fromGroup(new ExplicitGroup("node", GroupHierarchyType.INDEPENDENT, + JabRefPreferences.getInstance().get(JabRefPreferences.KEYWORD_SEPARATOR))); assertEquals(node.getGroup(), node.getSearchRule()); } @@ -184,9 +188,11 @@ public void getSearchRuleForIndependentGroupReturnsGroupAsMatcher() throws Parse public void getSearchRuleForRefiningGroupReturnsParentAndGroupAsMatcher() throws ParseException { GroupTreeNode parent = GroupTreeNode .fromGroup( - new ExplicitGroup("parent", GroupHierarchyType.INDEPENDENT, JabRefPreferences.getInstance())); + new ExplicitGroup("parent", GroupHierarchyType.INDEPENDENT, + JabRefPreferences.getInstance().get(JabRefPreferences.KEYWORD_SEPARATOR))); GroupTreeNode node = parent - .addSubgroup(new ExplicitGroup("node", GroupHierarchyType.REFINING, JabRefPreferences.getInstance())); + .addSubgroup(new ExplicitGroup("node", GroupHierarchyType.REFINING, + JabRefPreferences.getInstance().get(JabRefPreferences.KEYWORD_SEPARATOR))); AndMatcher matcher = new AndMatcher(); matcher.addRule(node.getGroup()); @@ -197,10 +203,12 @@ public void getSearchRuleForRefiningGroupReturnsParentAndGroupAsMatcher() throws @Test public void getSearchRuleForIncludingGroupReturnsGroupOrSubgroupAsMatcher() throws ParseException { GroupTreeNode node = GroupTreeNode - .fromGroup(new ExplicitGroup("node", GroupHierarchyType.INCLUDING, JabRefPreferences.getInstance())); + .fromGroup(new ExplicitGroup("node", GroupHierarchyType.INCLUDING, + JabRefPreferences.getInstance().get(JabRefPreferences.KEYWORD_SEPARATOR))); GroupTreeNode child = node .addSubgroup( - new ExplicitGroup("child", GroupHierarchyType.INDEPENDENT, JabRefPreferences.getInstance())); + new ExplicitGroup("child", GroupHierarchyType.INDEPENDENT, + JabRefPreferences.getInstance().get(JabRefPreferences.KEYWORD_SEPARATOR))); OrMatcher matcher = new OrMatcher(); matcher.addRule(node.getGroup()); @@ -218,7 +226,7 @@ public void numberOfHitsMatchesOneEntry() throws Exception { GroupTreeNode parent = getNodeInSimpleTree(); GroupTreeNode node = parent.addSubgroup( new KeywordGroup("node", "author", "author2", true, false, GroupHierarchyType.INDEPENDENT, - JabRefPreferences.getInstance())); + JabRefPreferences.getInstance().get(JabRefPreferences.KEYWORD_SEPARATOR))); assertEquals(1, node.numberOfHits(entries)); } @@ -227,7 +235,7 @@ public void numberOfHitsMatchesMultipleEntries() throws Exception { GroupTreeNode parent = getNodeInSimpleTree(); GroupTreeNode node = parent.addSubgroup( new KeywordGroup("node", "author", "author1", true, false, GroupHierarchyType.INDEPENDENT, - JabRefPreferences.getInstance())); + JabRefPreferences.getInstance().get(JabRefPreferences.KEYWORD_SEPARATOR))); assertEquals(2, node.numberOfHits(entries)); } @@ -236,10 +244,10 @@ public void numberOfHitsWorksForRefiningGroups() throws Exception { GroupTreeNode grandParent = getNodeInSimpleTree(); GroupTreeNode parent = grandParent.addSubgroup( new KeywordGroup("node", "author", "author2", true, false, GroupHierarchyType.INDEPENDENT, - JabRefPreferences.getInstance())); + JabRefPreferences.getInstance().get(JabRefPreferences.KEYWORD_SEPARATOR))); GroupTreeNode node = parent.addSubgroup( new KeywordGroup("node", "author", "author1", true, false, GroupHierarchyType.REFINING, - JabRefPreferences.getInstance())); + JabRefPreferences.getInstance().get(JabRefPreferences.KEYWORD_SEPARATOR))); assertEquals(1, node.numberOfHits(entries)); } @@ -248,10 +256,10 @@ public void numberOfHitsWorksForHierarchyOfIndependentGroups() throws Exception GroupTreeNode grandParent = getNodeInSimpleTree(); GroupTreeNode parent = grandParent.addSubgroup( new KeywordGroup("node", "author", "author2", true, false, GroupHierarchyType.INDEPENDENT, - JabRefPreferences.getInstance())); + JabRefPreferences.getInstance().get(JabRefPreferences.KEYWORD_SEPARATOR))); GroupTreeNode node = parent.addSubgroup( new KeywordGroup("node", "author", "author1", true, false, GroupHierarchyType.INDEPENDENT, - JabRefPreferences.getInstance())); + JabRefPreferences.getInstance().get(JabRefPreferences.KEYWORD_SEPARATOR))); assertEquals(2, node.numberOfHits(entries)); } @@ -259,7 +267,7 @@ public void numberOfHitsWorksForHierarchyOfIndependentGroups() throws Exception public void setGroupChangesUnderlyingGroup() throws Exception { GroupTreeNode node = getNodeInSimpleTree(); AbstractGroup newGroup = new ExplicitGroup("NewGroup", GroupHierarchyType.INDEPENDENT, - JabRefPreferences.getInstance()); + JabRefPreferences.getInstance().get(JabRefPreferences.KEYWORD_SEPARATOR)); node.setGroup(newGroup, true, entries); @@ -269,11 +277,11 @@ public void setGroupChangesUnderlyingGroup() throws Exception { @Test public void setGroupAddsPreviousAssignmentsExplicitToExplicit() throws Exception { AbstractGroup oldGroup = new ExplicitGroup("OldGroup", GroupHierarchyType.INDEPENDENT, - JabRefPreferences.getInstance()); + JabRefPreferences.getInstance().get(JabRefPreferences.KEYWORD_SEPARATOR)); oldGroup.add(entry); GroupTreeNode node = GroupTreeNode.fromGroup(oldGroup); AbstractGroup newGroup = new ExplicitGroup("NewGroup", GroupHierarchyType.INDEPENDENT, - JabRefPreferences.getInstance()); + JabRefPreferences.getInstance().get(JabRefPreferences.KEYWORD_SEPARATOR)); node.setGroup(newGroup, true, entries); @@ -283,11 +291,11 @@ public void setGroupAddsPreviousAssignmentsExplicitToExplicit() throws Exception @Test public void setGroupWithFalseDoesNotAddsPreviousAssignments() throws Exception { AbstractGroup oldGroup = new ExplicitGroup("OldGroup", GroupHierarchyType.INDEPENDENT, - JabRefPreferences.getInstance()); + JabRefPreferences.getInstance().get(JabRefPreferences.KEYWORD_SEPARATOR)); oldGroup.add(entry); GroupTreeNode node = GroupTreeNode.fromGroup(oldGroup); AbstractGroup newGroup = new ExplicitGroup("NewGroup", GroupHierarchyType.INDEPENDENT, - JabRefPreferences.getInstance()); + JabRefPreferences.getInstance().get(JabRefPreferences.KEYWORD_SEPARATOR)); node.setGroup(newGroup, false, entries); @@ -297,11 +305,11 @@ public void setGroupWithFalseDoesNotAddsPreviousAssignments() throws Exception { @Test public void setGroupAddsOnlyPreviousAssignments() throws Exception { AbstractGroup oldGroup = new ExplicitGroup("OldGroup", GroupHierarchyType.INDEPENDENT, - JabRefPreferences.getInstance()); + JabRefPreferences.getInstance().get(JabRefPreferences.KEYWORD_SEPARATOR)); assertFalse(oldGroup.isMatch(entry)); GroupTreeNode node = GroupTreeNode.fromGroup(oldGroup); AbstractGroup newGroup = new ExplicitGroup("NewGroup", GroupHierarchyType.INDEPENDENT, - JabRefPreferences.getInstance()); + JabRefPreferences.getInstance().get(JabRefPreferences.KEYWORD_SEPARATOR)); node.setGroup(newGroup, true, entries); @@ -311,7 +319,7 @@ public void setGroupAddsOnlyPreviousAssignments() throws Exception { @Test public void setGroupExplicitToSearchDoesNotKeepPreviousAssignments() throws Exception { AbstractGroup oldGroup = new ExplicitGroup("OldGroup", GroupHierarchyType.INDEPENDENT, - JabRefPreferences.getInstance()); + JabRefPreferences.getInstance().get(JabRefPreferences.KEYWORD_SEPARATOR)); oldGroup.add(entry); GroupTreeNode node = GroupTreeNode.fromGroup(oldGroup); AbstractGroup newGroup = new SearchGroup("NewGroup", "test", false, false, GroupHierarchyType.INDEPENDENT); @@ -324,11 +332,11 @@ public void setGroupExplicitToSearchDoesNotKeepPreviousAssignments() throws Exce @Test public void setGroupExplicitToExplicitIsRenameAndSoRemovesPreviousAssignment() throws Exception { AbstractGroup oldGroup = new ExplicitGroup("OldGroup", GroupHierarchyType.INDEPENDENT, - JabRefPreferences.getInstance()); + JabRefPreferences.getInstance().get(JabRefPreferences.KEYWORD_SEPARATOR)); oldGroup.add(entry); GroupTreeNode node = GroupTreeNode.fromGroup(oldGroup); AbstractGroup newGroup = new ExplicitGroup("NewGroup", GroupHierarchyType.INDEPENDENT, - JabRefPreferences.getInstance()); + JabRefPreferences.getInstance().get(JabRefPreferences.KEYWORD_SEPARATOR)); node.setGroup(newGroup, true, entries); diff --git a/src/test/java/net/sf/jabref/logic/groups/KeywordGroupTest.java b/src/test/java/net/sf/jabref/logic/groups/KeywordGroupTest.java index c87d71ac4bd..2d95712b9fe 100644 --- a/src/test/java/net/sf/jabref/logic/groups/KeywordGroupTest.java +++ b/src/test/java/net/sf/jabref/logic/groups/KeywordGroupTest.java @@ -13,22 +13,23 @@ public class KeywordGroupTest { @Test public void testToString() throws ParseException { - KeywordGroup group = new KeywordGroup("myExplicitGroup", "author","asdf", true, true, - GroupHierarchyType.INDEPENDENT, JabRefPreferences.getInstance()); + KeywordGroup group = new KeywordGroup("myExplicitGroup", "author", "asdf", true, true, + GroupHierarchyType.INDEPENDENT, + JabRefPreferences.getInstance().get(JabRefPreferences.KEYWORD_SEPARATOR)); assertEquals("KeywordGroup:myExplicitGroup;0;author;asdf;1;1;", group.toString()); } @Test public void testToString2() throws ParseException { - KeywordGroup group = new KeywordGroup("myExplicitGroup", "author","asdf", false, true, - GroupHierarchyType.REFINING, JabRefPreferences.getInstance()); + KeywordGroup group = new KeywordGroup("myExplicitGroup", "author", "asdf", false, true, + GroupHierarchyType.REFINING, JabRefPreferences.getInstance().get(JabRefPreferences.KEYWORD_SEPARATOR)); assertEquals("KeywordGroup:myExplicitGroup;1;author;asdf;0;1;", group.toString()); } @Test public void containsSimpleWord() throws Exception { KeywordGroup group = new KeywordGroup("name", "keywords", "test", false, false, GroupHierarchyType.INDEPENDENT, - JabRefPreferences.getInstance()); + JabRefPreferences.getInstance().get(JabRefPreferences.KEYWORD_SEPARATOR)); BibEntry entry = new BibEntry().withField("keywords", "test"); assertTrue(group.isMatch(entry)); @@ -37,7 +38,7 @@ public void containsSimpleWord() throws Exception { @Test public void containsSimpleWordInSentence() throws Exception { KeywordGroup group = new KeywordGroup("name", "keywords", "test", false, false, GroupHierarchyType.INDEPENDENT, - JabRefPreferences.getInstance()); + JabRefPreferences.getInstance().get(JabRefPreferences.KEYWORD_SEPARATOR)); BibEntry entry = new BibEntry().withField("keywords", "Some sentence containing test word"); assertTrue(group.isMatch(entry)); @@ -46,7 +47,7 @@ public void containsSimpleWordInSentence() throws Exception { @Test public void containsSimpleWordCommaSeparated() throws Exception { KeywordGroup group = new KeywordGroup("name", "keywords", "test", false, false, GroupHierarchyType.INDEPENDENT, - JabRefPreferences.getInstance()); + JabRefPreferences.getInstance().get(JabRefPreferences.KEYWORD_SEPARATOR)); BibEntry entry = new BibEntry().withField("keywords", "Some,list,containing,test,word"); assertTrue(group.isMatch(entry)); @@ -55,7 +56,7 @@ public void containsSimpleWordCommaSeparated() throws Exception { @Test public void containsSimpleWordSemicolonSeparated() throws Exception { KeywordGroup group = new KeywordGroup("name", "keywords", "test", false, false, GroupHierarchyType.INDEPENDENT, - JabRefPreferences.getInstance()); + JabRefPreferences.getInstance().get(JabRefPreferences.KEYWORD_SEPARATOR)); BibEntry entry = new BibEntry().withField("keywords", "Some;list;containing;test;word"); assertTrue(group.isMatch(entry)); @@ -64,7 +65,7 @@ public void containsSimpleWordSemicolonSeparated() throws Exception { @Test public void containsComplexWord() throws Exception { KeywordGroup group = new KeywordGroup("name", "keywords", "\\H2O", false, false, GroupHierarchyType.INDEPENDENT, - JabRefPreferences.getInstance()); + JabRefPreferences.getInstance().get(JabRefPreferences.KEYWORD_SEPARATOR)); BibEntry entry = new BibEntry().withField("keywords", "\\H2O"); assertTrue(group.isMatch(entry)); @@ -73,7 +74,7 @@ public void containsComplexWord() throws Exception { @Test public void containsComplexWordInSentence() throws Exception { KeywordGroup group = new KeywordGroup("name", "keywords", "\\H2O", false, false, GroupHierarchyType.INDEPENDENT, - JabRefPreferences.getInstance()); + JabRefPreferences.getInstance().get(JabRefPreferences.KEYWORD_SEPARATOR)); BibEntry entry = new BibEntry().withField("keywords", "Some sentence containing \\H2O word"); assertTrue(group.isMatch(entry)); @@ -82,7 +83,8 @@ public void containsComplexWordInSentence() throws Exception { @Test public void containsWordWithWhitespaceInSentence() throws Exception { KeywordGroup group = new KeywordGroup("name", "keywords", "test word", false, false, - GroupHierarchyType.INDEPENDENT, JabRefPreferences.getInstance()); + GroupHierarchyType.INDEPENDENT, + JabRefPreferences.getInstance().get(JabRefPreferences.KEYWORD_SEPARATOR)); BibEntry entry = new BibEntry().withField("keywords", "Some sentence containing test word"); assertTrue(group.isMatch(entry)); diff --git a/src/test/java/net/sf/jabref/logic/importer/fileformat/BibtexParserTest.java b/src/test/java/net/sf/jabref/logic/importer/fileformat/BibtexParserTest.java index 543e1c04f50..946f9ab52d3 100644 --- a/src/test/java/net/sf/jabref/logic/importer/fileformat/BibtexParserTest.java +++ b/src/test/java/net/sf/jabref/logic/importer/fileformat/BibtexParserTest.java @@ -1497,10 +1497,14 @@ public void integrationTestGroupTree() throws IOException, ParseException { assertEquals(new AllEntriesGroup(), root.getGroup()); assertEquals(3, root.getNumberOfChildren()); - assertEquals(new KeywordGroup("Fréchet", "keywords", "FrechetSpace", false, true, - GroupHierarchyType.INDEPENDENT, Globals.prefs), root.getChildren().get(0).getGroup()); - assertEquals(new KeywordGroup("Invariant theory", "keywords", "GIT", false, false, - GroupHierarchyType.INDEPENDENT, Globals.prefs), root.getChildren().get(1).getGroup()); + assertEquals( + new KeywordGroup("Fréchet", "keywords", "FrechetSpace", false, true, GroupHierarchyType.INDEPENDENT, + JabRefPreferences.getInstance().get(JabRefPreferences.KEYWORD_SEPARATOR)), + root.getChildren().get(0).getGroup()); + assertEquals( + new KeywordGroup("Invariant theory", "keywords", "GIT", false, false, GroupHierarchyType.INDEPENDENT, + JabRefPreferences.getInstance().get(JabRefPreferences.KEYWORD_SEPARATOR)), + root.getChildren().get(1).getGroup()); assertEquals(Arrays.asList("Key1", "Key2"), ((ExplicitGroup) root.getChildren().get(2).getGroup()).getLegacyEntryKeys()); } From 7776ff6bed2d6363dacef68dfe8fec92e4d389d5 Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Fri, 26 Aug 2016 20:17:24 +0200 Subject: [PATCH 2/2] Removed Globals from logic tests --- .../sf/jabref/gui/actions/ManageKeywordsAction.java | 4 ++-- .../net/sf/jabref/logic/groups/ExplicitGroup.java | 1 + .../net/sf/jabref/logic/groups/GroupTreeNode.java | 1 - .../java/net/sf/jabref/logic/groups/GroupsParser.java | 1 - .../java/net/sf/jabref/logic/groups/KeywordGroup.java | 1 + .../logic/importer/ImportFormatPreferences.java | 11 +++++++++-- .../net/sf/jabref/logic/importer/OpenDatabase.java | 2 +- .../net/sf/jabref/preferences/JabRefPreferences.java | 8 +++++++- .../SpecialFieldDatabaseChangeListener.java | 3 ++- .../sf/jabref/specialfields/SpecialFieldsUtils.java | 8 +------- .../importer/ImportFormatReaderIntegrationTest.java | 6 ++---- .../importer/ImportFormatReaderTestParameterless.java | 6 ++---- .../sf/jabref/logic/importer/OpenDatabaseTest.java | 8 -------- .../logic/importer/fileformat/BibtexParserTest.java | 1 - .../net/sf/jabref/logic/layout/LayoutEntryTest.java | 7 +------ 15 files changed, 29 insertions(+), 39 deletions(-) diff --git a/src/main/java/net/sf/jabref/gui/actions/ManageKeywordsAction.java b/src/main/java/net/sf/jabref/gui/actions/ManageKeywordsAction.java index e8fa5a8adf1..d575945c1a3 100644 --- a/src/main/java/net/sf/jabref/gui/actions/ManageKeywordsAction.java +++ b/src/main/java/net/sf/jabref/gui/actions/ManageKeywordsAction.java @@ -286,7 +286,7 @@ public void actionPerformed(ActionEvent e) { return; } - if (SpecialFieldsUtils.keywordSyncEnabled() && !keywordsToAdd.isEmpty()) { + if (Globals.prefs.isKeywordSyncEnabled() && !keywordsToAdd.isEmpty()) { synchronizeSpecialFields(keywordsToAdd, keywordsToRemove); } @@ -312,7 +312,7 @@ private NamedCompound updateKeywords(List entries, Set keyword ce.addEdit(new UndoableFieldChange(change.get())); } - if (SpecialFieldsUtils.keywordSyncEnabled()) { + if (Globals.prefs.isKeywordSyncEnabled()) { SpecialFieldsUtils.syncSpecialFieldsFromKeywords(entry, ce); } } diff --git a/src/main/java/net/sf/jabref/logic/groups/ExplicitGroup.java b/src/main/java/net/sf/jabref/logic/groups/ExplicitGroup.java index 083ec572771..7f046cd1a5b 100644 --- a/src/main/java/net/sf/jabref/logic/groups/ExplicitGroup.java +++ b/src/main/java/net/sf/jabref/logic/groups/ExplicitGroup.java @@ -11,6 +11,7 @@ import net.sf.jabref.logic.util.strings.QuotedStringTokenizer; import net.sf.jabref.logic.util.strings.StringUtil; import net.sf.jabref.model.entry.FieldName; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; diff --git a/src/main/java/net/sf/jabref/logic/groups/GroupTreeNode.java b/src/main/java/net/sf/jabref/logic/groups/GroupTreeNode.java index a10d496f5f0..833b0d5dc52 100644 --- a/src/main/java/net/sf/jabref/logic/groups/GroupTreeNode.java +++ b/src/main/java/net/sf/jabref/logic/groups/GroupTreeNode.java @@ -12,7 +12,6 @@ import net.sf.jabref.logic.search.matchers.MatcherSets; import net.sf.jabref.model.database.BibDatabase; import net.sf.jabref.model.entry.BibEntry; -import net.sf.jabref.preferences.JabRefPreferences; /** * A node in the groups tree that holds exactly one AbstractGroup. diff --git a/src/main/java/net/sf/jabref/logic/groups/GroupsParser.java b/src/main/java/net/sf/jabref/logic/groups/GroupsParser.java index fa52dc681a5..7dcfebb2a1a 100644 --- a/src/main/java/net/sf/jabref/logic/groups/GroupsParser.java +++ b/src/main/java/net/sf/jabref/logic/groups/GroupsParser.java @@ -4,7 +4,6 @@ import net.sf.jabref.logic.importer.util.ParseException; import net.sf.jabref.logic.l10n.Localization; -import net.sf.jabref.preferences.JabRefPreferences; /** * Converts string representation of groups to a parsed {@link GroupTreeNode}. diff --git a/src/main/java/net/sf/jabref/logic/groups/KeywordGroup.java b/src/main/java/net/sf/jabref/logic/groups/KeywordGroup.java index e16ac840c0b..d51189b6b01 100644 --- a/src/main/java/net/sf/jabref/logic/groups/KeywordGroup.java +++ b/src/main/java/net/sf/jabref/logic/groups/KeywordGroup.java @@ -14,6 +14,7 @@ import net.sf.jabref.model.FieldChange; import net.sf.jabref.model.entry.BibEntry; import net.sf.jabref.model.entry.EntryUtil; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; diff --git a/src/main/java/net/sf/jabref/logic/importer/ImportFormatPreferences.java b/src/main/java/net/sf/jabref/logic/importer/ImportFormatPreferences.java index a3810a0e993..64d8a8db73e 100644 --- a/src/main/java/net/sf/jabref/logic/importer/ImportFormatPreferences.java +++ b/src/main/java/net/sf/jabref/logic/importer/ImportFormatPreferences.java @@ -22,11 +22,13 @@ public class ImportFormatPreferences { private final boolean useCaseKeeperOnSearch; private final boolean convertUnitsOnSearch; + private final boolean keywordSyncEnabled; + public ImportFormatPreferences(Set customImportList, Charset encoding, String keywordSeparator, BibtexKeyPatternPreferences bibtexKeyPatternPreferences, FieldContentParserPreferences fieldContentParserPreferences, boolean convertUnitsOnSearch, - boolean useCaseKeeperOnSearch) { + boolean useCaseKeeperOnSearch, boolean keywordSyncEnabled) { this.customImportList = customImportList; this.encoding = encoding; this.keywordSeparator = keywordSeparator; @@ -34,6 +36,7 @@ public ImportFormatPreferences(Set customImportList, Charset enc this.fieldContentParserPreferences = fieldContentParserPreferences; this.convertUnitsOnSearch = convertUnitsOnSearch; this.useCaseKeeperOnSearch = useCaseKeeperOnSearch; + this.keywordSyncEnabled = keywordSyncEnabled; } public Set getCustomImportList() { @@ -66,6 +69,10 @@ public boolean isUseCaseKeeperOnSearch() { public ImportFormatPreferences withEncoding(Charset newEncoding) { return new ImportFormatPreferences(customImportList, newEncoding, keywordSeparator, bibtexKeyPatternPreferences, - fieldContentParserPreferences, convertUnitsOnSearch, useCaseKeeperOnSearch); + fieldContentParserPreferences, convertUnitsOnSearch, useCaseKeeperOnSearch, keywordSyncEnabled); + } + + public boolean isKeywordSyncEnabled() { + return keywordSyncEnabled; } } diff --git a/src/main/java/net/sf/jabref/logic/importer/OpenDatabase.java b/src/main/java/net/sf/jabref/logic/importer/OpenDatabase.java index fb33165fca0..cc787ef16b8 100644 --- a/src/main/java/net/sf/jabref/logic/importer/OpenDatabase.java +++ b/src/main/java/net/sf/jabref/logic/importer/OpenDatabase.java @@ -87,7 +87,7 @@ public static ParserResult loadDatabase(File fileToOpen, ImportFormatPreferences ParserResult result = new BibtexImporter(importFormatPreferences).importDatabase(fileToOpen.toPath(), importFormatPreferences.getEncoding()); - if (SpecialFieldsUtils.keywordSyncEnabled()) { + if (importFormatPreferences.isKeywordSyncEnabled()) { for (BibEntry entry : result.getDatabase().getEntries()) { SpecialFieldsUtils.syncSpecialFieldsFromKeywords(entry); } diff --git a/src/main/java/net/sf/jabref/preferences/JabRefPreferences.java b/src/main/java/net/sf/jabref/preferences/JabRefPreferences.java index f60ef40dce6..096c6438251 100644 --- a/src/main/java/net/sf/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/net/sf/jabref/preferences/JabRefPreferences.java @@ -1416,10 +1416,16 @@ public FieldContentParserPreferences getFieldContentParserPreferences() { return new FieldContentParserPreferences(getStringList(NON_WRAPPABLE_FIELDS)); } + public boolean isKeywordSyncEnabled() { + return getBoolean(JabRefPreferences.SPECIALFIELDSENABLED) + && getBoolean(JabRefPreferences.AUTOSYNCSPECIALFIELDSTOKEYWORDS); + } + public ImportFormatPreferences getImportFormatPreferences() { return new ImportFormatPreferences(customImports, getDefaultEncoding(), get(KEYWORD_SEPARATOR), getBibtexKeyPatternPreferences(), getFieldContentParserPreferences(), - getBoolean(USE_UNIT_FORMATTER_ON_SEARCH), getBoolean(USE_CASE_KEEPER_ON_SEARCH)); + getBoolean(USE_UNIT_FORMATTER_ON_SEARCH), getBoolean(USE_CASE_KEEPER_ON_SEARCH), + isKeywordSyncEnabled()); } public BibtexKeyPatternPreferences getBibtexKeyPatternPreferences() { diff --git a/src/main/java/net/sf/jabref/specialfields/SpecialFieldDatabaseChangeListener.java b/src/main/java/net/sf/jabref/specialfields/SpecialFieldDatabaseChangeListener.java index ebc47cb0b98..13397336518 100644 --- a/src/main/java/net/sf/jabref/specialfields/SpecialFieldDatabaseChangeListener.java +++ b/src/main/java/net/sf/jabref/specialfields/SpecialFieldDatabaseChangeListener.java @@ -1,5 +1,6 @@ package net.sf.jabref.specialfields; +import net.sf.jabref.Globals; import net.sf.jabref.gui.undo.NamedCompound; import net.sf.jabref.logic.l10n.Localization; import net.sf.jabref.model.entry.BibEntry; @@ -20,7 +21,7 @@ public static SpecialFieldDatabaseChangeListener getInstance() { @Subscribe public void listen(EntryAddedEvent event) { - if (SpecialFieldsUtils.keywordSyncEnabled()) { + if (Globals.prefs.isKeywordSyncEnabled()) { final BibEntry entry = event.getBibEntry(); // NamedCompount code similar to SpecialFieldUpdateListener NamedCompound nc = new NamedCompound(Localization.lang("Synchronized special fields based on keywords")); diff --git a/src/main/java/net/sf/jabref/specialfields/SpecialFieldsUtils.java b/src/main/java/net/sf/jabref/specialfields/SpecialFieldsUtils.java index 2dbcc789067..b5909a8a024 100644 --- a/src/main/java/net/sf/jabref/specialfields/SpecialFieldsUtils.java +++ b/src/main/java/net/sf/jabref/specialfields/SpecialFieldsUtils.java @@ -45,7 +45,7 @@ private static void exportFieldToKeywords(SpecialField e, BibEntry be, NamedComp private static void exportFieldToKeywords(SpecialField e, String newValue, BibEntry entry, NamedCompound ce) { - if (!SpecialFieldsUtils.keywordSyncEnabled()) { + if (!Globals.prefs.isKeywordSyncEnabled()) { return; } List keywordList = new ArrayList<>(entry.getKeywords()); @@ -165,10 +165,4 @@ public static Optional getSpecialFieldInstanceFromFieldName(String public static boolean isSpecialField(String fieldName) { return SpecialFieldsUtils.getSpecialFieldInstanceFromFieldName(fieldName).isPresent(); } - - public static boolean keywordSyncEnabled() { - return Globals.prefs.getBoolean(JabRefPreferences.SPECIALFIELDSENABLED) && - Globals.prefs.getBoolean(JabRefPreferences.AUTOSYNCSPECIALFIELDSTOKEYWORDS); - } - } diff --git a/src/test/java/net/sf/jabref/logic/importer/ImportFormatReaderIntegrationTest.java b/src/test/java/net/sf/jabref/logic/importer/ImportFormatReaderIntegrationTest.java index a64d9755eac..a35d3defd9c 100644 --- a/src/test/java/net/sf/jabref/logic/importer/ImportFormatReaderIntegrationTest.java +++ b/src/test/java/net/sf/jabref/logic/importer/ImportFormatReaderIntegrationTest.java @@ -7,7 +7,6 @@ import java.util.ArrayList; import java.util.Collection; -import net.sf.jabref.Globals; import net.sf.jabref.preferences.JabRefPreferences; import org.junit.Before; @@ -36,10 +35,9 @@ public ImportFormatReaderIntegrationTest(String resource, String format, int cou @Before public void setUp() { - Globals.prefs = JabRefPreferences.getInstance(); // Needed for special fields reader = new ImportFormatReader(); - reader.resetImportFormats(Globals.prefs.getImportFormatPreferences(), - Globals.prefs.getXMPPreferences()); + reader.resetImportFormats(JabRefPreferences.getInstance().getImportFormatPreferences(), + JabRefPreferences.getInstance().getXMPPreferences()); } @Test diff --git a/src/test/java/net/sf/jabref/logic/importer/ImportFormatReaderTestParameterless.java b/src/test/java/net/sf/jabref/logic/importer/ImportFormatReaderTestParameterless.java index 261dd17c66a..1ae3b8028ff 100644 --- a/src/test/java/net/sf/jabref/logic/importer/ImportFormatReaderTestParameterless.java +++ b/src/test/java/net/sf/jabref/logic/importer/ImportFormatReaderTestParameterless.java @@ -5,7 +5,6 @@ import java.nio.file.Path; import java.nio.file.Paths; -import net.sf.jabref.Globals; import net.sf.jabref.preferences.JabRefPreferences; import org.junit.Before; @@ -20,10 +19,9 @@ public class ImportFormatReaderTestParameterless { @Before public void setUp() { - Globals.prefs = JabRefPreferences.getInstance(); // Needed for special fields reader = new ImportFormatReader(); - reader.resetImportFormats(Globals.prefs.getImportFormatPreferences(), - Globals.prefs.getXMPPreferences()); + reader.resetImportFormats(JabRefPreferences.getInstance().getImportFormatPreferences(), + JabRefPreferences.getInstance().getXMPPreferences()); } @Test diff --git a/src/test/java/net/sf/jabref/logic/importer/OpenDatabaseTest.java b/src/test/java/net/sf/jabref/logic/importer/OpenDatabaseTest.java index e2f2d820d45..ae943b3582f 100644 --- a/src/test/java/net/sf/jabref/logic/importer/OpenDatabaseTest.java +++ b/src/test/java/net/sf/jabref/logic/importer/OpenDatabaseTest.java @@ -9,14 +9,12 @@ import java.util.Collection; import java.util.Optional; -import net.sf.jabref.Globals; import net.sf.jabref.model.database.BibDatabase; import net.sf.jabref.model.entry.BibEntry; import net.sf.jabref.preferences.JabRefPreferences; import org.junit.Assert; import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Test; public class OpenDatabaseTest { @@ -40,12 +38,6 @@ public OpenDatabaseTest() throws URISyntaxException { .get(OpenDatabaseTest.class.getResource("encodingWithoutNewline.bib").toURI()).toFile(); } - @BeforeClass - public static void setUpGlobalsPrefs() { - // otherwise FieldContentParser (called by BibtexParser) and SpecialFields crashes - Globals.prefs = JabRefPreferences.getInstance(); - } - @Before public void setUp() { importFormatPreferences = JabRefPreferences.getInstance().getImportFormatPreferences(); diff --git a/src/test/java/net/sf/jabref/logic/importer/fileformat/BibtexParserTest.java b/src/test/java/net/sf/jabref/logic/importer/fileformat/BibtexParserTest.java index 946f9ab52d3..d6e6d1a29f0 100644 --- a/src/test/java/net/sf/jabref/logic/importer/fileformat/BibtexParserTest.java +++ b/src/test/java/net/sf/jabref/logic/importer/fileformat/BibtexParserTest.java @@ -12,7 +12,6 @@ import java.util.Optional; import java.util.Set; -import net.sf.jabref.Globals; import net.sf.jabref.logic.cleanup.FieldFormatterCleanup; import net.sf.jabref.logic.config.SaveOrderConfig; import net.sf.jabref.logic.exporter.FieldFormatterCleanups; diff --git a/src/test/java/net/sf/jabref/logic/layout/LayoutEntryTest.java b/src/test/java/net/sf/jabref/logic/layout/LayoutEntryTest.java index c1553a7b73c..c642f35a072 100644 --- a/src/test/java/net/sf/jabref/logic/layout/LayoutEntryTest.java +++ b/src/test/java/net/sf/jabref/logic/layout/LayoutEntryTest.java @@ -5,7 +5,6 @@ import java.util.Optional; import java.util.regex.Pattern; -import net.sf.jabref.Globals; import net.sf.jabref.logic.journals.JournalAbbreviationLoader; import net.sf.jabref.model.entry.BibEntry; import net.sf.jabref.preferences.JabRefPreferences; @@ -50,10 +49,6 @@ public class LayoutEntryTest { */ @Before public void setUp() { - if (Globals.prefs == null) { - Globals.prefs = JabRefPreferences.getInstance(); - Globals.prefs.putBoolean("highLightWords", Boolean.TRUE); - } // create Bibtext Entry @@ -87,7 +82,7 @@ public void setUp() { public String layout(String layoutFile, BibEntry entry, Optional highlightPattern) throws IOException { StringReader sr = new StringReader(layoutFile.replace("__NEWLINE__", "\n")); Layout layout = new LayoutHelper(sr, - Globals.prefs.getLayoutFormatterPreferences(mock(JournalAbbreviationLoader.class))) + JabRefPreferences.getInstance().getLayoutFormatterPreferences(mock(JournalAbbreviationLoader.class))) .getLayoutFromText(); return layout.doLayout(entry, null, highlightPattern);