Skip to content

Commit efabb85

Browse files
committed
Merge remote-tracking branch 'upstream/master' into removeObsoleteSwing
* upstream/master: Revert "Revert "Fix: bibkey generated does not handle diacritics" (#4741)" (#4742) Revert "Fix: bibkey generated does not handle diacritics" (#4741) Rename method to removeUnwantedCharacters Remove the dashes from test case Remove -s from key Update test cases Filter unwanted characters before removing whitespaces Fix NotOnJavaFXThread exception for remote import Remove old swing-based tests Extract authN method Shift cleaning of authString to authN only Clean key in BracketedPattern after author value is retrieved
2 parents 29e04a5 + fac6e62 commit efabb85

20 files changed

+77
-931
lines changed

build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ dependencies {
169169
testRuntime 'org.apache.logging.log4j:log4j-jul:2.11.2'
170170
testCompile 'org.mockito:mockito-core:2.25.0'
171171
testCompile 'com.github.tomakehurst:wiremock:2.21.0'
172-
testCompile 'org.assertj:assertj-swing-junit:3.9.2'
173172
testCompile 'org.reflections:reflections:0.9.11'
174173
testCompile 'org.xmlunit:xmlunit-core:2.6.2'
175174
testCompile 'org.xmlunit:xmlunit-matchers:2.6.2'

src/main/java/org/jabref/gui/remote/JabRefMessageHandler.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import java.util.Arrays;
44
import java.util.List;
55

6+
import javafx.application.Platform;
7+
68
import org.jabref.JabRefGUI;
79
import org.jabref.cli.ArgumentProcessor;
810
import org.jabref.logic.importer.ParserResult;
@@ -20,7 +22,11 @@ public void handleCommandLineArguments(String[] message) {
2022
List<ParserResult> loaded = argumentProcessor.getParserResults();
2123
for (int i = 0; i < loaded.size(); i++) {
2224
ParserResult pr = loaded.get(i);
23-
JabRefGUI.getMainFrame().addParserResult(pr, i == 0);
25+
boolean focusPanel = i == 0;
26+
Platform.runLater(() ->
27+
// Need to run this on the JavaFX thread
28+
JabRefGUI.getMainFrame().addParserResult(pr, focusPanel)
29+
);
2430
}
2531
}
2632
}

src/main/java/org/jabref/logic/bibtexkeypattern/BibtexKeyGenerator.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ public class BibtexKeyGenerator extends BracketedPattern {
2626
*/
2727
public static final String APPENDIX_CHARACTERS = "abcdefghijklmnopqrstuvwxyz";
2828
private static final Logger LOGGER = LoggerFactory.getLogger(BibtexKeyGenerator.class);
29-
private static final String KEY_ILLEGAL_CHARACTERS = "{}(),\\\"#~^':`";
30-
private static final String KEY_UNWANTED_CHARACTERS = "{}(),\\\"";
29+
private static final String KEY_ILLEGAL_CHARACTERS = "{}(),\\\"-#~^':`";
30+
private static final String KEY_UNWANTED_CHARACTERS = "{}(),\\\"-";
3131
private final AbstractBibtexKeyPattern citeKeyPattern;
3232
private final BibDatabase database;
3333
private final BibtexKeyPatternPreferences bibtexKeyPatternPreferences;
@@ -72,15 +72,15 @@ private static String getAppendix(int number) {
7272
}
7373
}
7474

75-
public static String cleanKey(String key, boolean enforceLegalKey) {
75+
public static String removeUnwantedCharacters(String key, boolean enforceLegalKey) {
7676
if (!enforceLegalKey) {
7777
// User doesn't want us to enforce legal characters. We must still look
7878
// for whitespace and some characters such as commas, since these would
7979
// interfere with parsing:
8080
StringBuilder newKey = new StringBuilder();
8181
for (int i = 0; i < key.length(); i++) {
8282
char c = key.charAt(i);
83-
if (!Character.isWhitespace(c) && (KEY_UNWANTED_CHARACTERS.indexOf(c) == -1)) {
83+
if (KEY_UNWANTED_CHARACTERS.indexOf(c) == -1) {
8484
newKey.append(c);
8585
}
8686
}
@@ -90,7 +90,7 @@ public static String cleanKey(String key, boolean enforceLegalKey) {
9090
StringBuilder newKey = new StringBuilder();
9191
for (int i = 0; i < key.length(); i++) {
9292
char c = key.charAt(i);
93-
if (!Character.isWhitespace(c) && (KEY_ILLEGAL_CHARACTERS.indexOf(c) == -1)) {
93+
if (KEY_ILLEGAL_CHARACTERS.indexOf(c) == -1) {
9494
newKey.append(c);
9595
}
9696
}
@@ -100,6 +100,10 @@ public static String cleanKey(String key, boolean enforceLegalKey) {
100100
return StringUtil.replaceSpecialCharacters(newKey.toString());
101101
}
102102

103+
public static String cleanKey(String key, boolean enforceLegalKey) {
104+
return removeUnwantedCharacters(key, enforceLegalKey).replaceAll("\\s","");
105+
}
106+
103107
public String generateKey(BibEntry entry) {
104108
String key;
105109
StringBuilder stringBuilder = new StringBuilder();
@@ -123,7 +127,7 @@ public String generateKey(BibEntry entry) {
123127
List<String> parts = parseFieldMarker(typeListEntry);
124128
Character delimiter = bibtexKeyPatternPreferences.getKeywordDelimiter();
125129
String pattern = "[" + parts.get(0) + "]";
126-
String label = expandBrackets(pattern, delimiter, entry, database);
130+
String label = expandBrackets(pattern, delimiter, entry, database, bibtexKeyPatternPreferences.isEnforceLegalKey());
127131
// apply modifier if present
128132
if (parts.size() > 1) {
129133
label = applyModifiers(label, parts, 1);

src/main/java/org/jabref/logic/bibtexkeypattern/BracketedPattern.java

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ public String expand(BibEntry bibentry, Character keywordDelimiter, BibDatabase
9292
return expandBrackets(this.pattern, keywordDelimiter, bibentry, database);
9393
}
9494

95+
public static String expandBrackets(String pattern, Character keywordDelimiter, BibEntry entry, BibDatabase database) {
96+
return expandBrackets(pattern, keywordDelimiter, entry, database, false);
97+
}
98+
9599
/**
96100
* Expands a pattern
97101
*
@@ -101,7 +105,7 @@ public String expand(BibEntry bibentry, Character keywordDelimiter, BibDatabase
101105
* @param database The database for field resolving. May be null.
102106
* @return The expanded pattern. Not null.
103107
*/
104-
public static String expandBrackets(String pattern, Character keywordDelimiter, BibEntry entry, BibDatabase database) {
108+
public static String expandBrackets(String pattern, Character keywordDelimiter, BibEntry entry, BibDatabase database, boolean isEnforceLegalKey) {
105109
Objects.requireNonNull(pattern);
106110
Objects.requireNonNull(entry);
107111
StringBuilder sb = new StringBuilder();
@@ -122,10 +126,10 @@ public static String expandBrackets(String pattern, Character keywordDelimiter,
122126
// check whether there is a modifier on the end such as
123127
// ":lower":
124128
if (fieldParts.size() <= 1) {
125-
sb.append(getFieldValue(entry, token, keywordDelimiter, database));
129+
sb.append(getFieldValue(entry, token, keywordDelimiter, database, isEnforceLegalKey));
126130
} else {
127131
// apply modifiers:
128-
String fieldValue = getFieldValue(entry, fieldParts.get(0), keywordDelimiter, database);
132+
String fieldValue = getFieldValue(entry, fieldParts.get(0), keywordDelimiter, database, isEnforceLegalKey);
129133
sb.append(applyModifiers(fieldValue, fieldParts, 1));
130134
}
131135
// Fetch and discard the closing ']'
@@ -156,7 +160,7 @@ public static String expandBrackets(String pattern, Character keywordDelimiter,
156160
*
157161
* @return String containing the evaluation result. Empty string if the pattern cannot be resolved.
158162
*/
159-
public static String getFieldValue(BibEntry entry, String value, Character keywordDelimiter, BibDatabase database) {
163+
public static String getFieldValue(BibEntry entry, String value, Character keywordDelimiter, BibDatabase database, boolean isEnforceLegalKey) {
160164

161165
String val = value;
162166
try {
@@ -224,15 +228,8 @@ else if ("authorLast".equals(val)) {
224228
return authNofMth(authString, Integer.parseInt(nums[0]),
225229
Integer.parseInt(nums[1]));
226230
} else if (val.matches("auth\\d+")) {
227-
// authN. First N chars of the first author's last
228-
// name.
229-
230-
String fa = firstAuthor(authString);
231231
int num = Integer.parseInt(val.substring(4));
232-
if (num > fa.length()) {
233-
num = fa.length();
234-
}
235-
return fa.substring(0, num);
232+
return authN(authString, num, isEnforceLegalKey);
236233
} else if (val.matches("authors\\d+")) {
237234
return nAuthors(authString, Integer.parseInt(val.substring(7)));
238235
} else {
@@ -840,6 +837,18 @@ public static String authNofMth(String authorField, int n, int m) {
840837
}
841838
}
842839

840+
/**
841+
* First N chars of the first author's last name.
842+
*/
843+
public static String authN(String authString, int num, boolean isEnforceLegalKey) {
844+
authString = BibtexKeyGenerator.removeUnwantedCharacters(authString, isEnforceLegalKey);
845+
String fa = firstAuthor(authString);
846+
if (num > fa.length()) {
847+
num = fa.length();
848+
}
849+
return fa.substring(0, num);
850+
}
851+
843852
/**
844853
* authshort format:
845854
* added by Kolja Brix, [email protected]

src/test/java/org/jabref/gui/AWTExceptionHandler.java

Lines changed: 0 additions & 24 deletions
This file was deleted.

src/test/java/org/jabref/gui/AbstractUITest.java

Lines changed: 0 additions & 105 deletions
This file was deleted.

src/test/java/org/jabref/gui/DialogTest.java

Lines changed: 0 additions & 51 deletions
This file was deleted.

src/test/java/org/jabref/gui/DialogTest2.java

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)