Skip to content

Commit

Permalink
Fix jstyle was invalid with default section at the start
Browse files Browse the repository at this point in the history
Fixes #6303
Adapted the error message to give a hint what is probably missing.

I also noticed a problem in eclipse when executing the L10n test. It was missing an add-opens
  • Loading branch information
Siedlerchr committed May 1, 2020
1 parent a123eb1 commit ede97db
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 58 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We changed the buttons for import/export/show all/reset of preferences to smaller icon buttons in the preferences dialog. [#6130](https://github.com/JabRef/jabref/pull/6130)
- We moved the functionality "Manage field names & content" from the "Library" menu to the "Edit" menu, because it affects the selected entries and not the whole library
- We merged the functionality "Append contents from a BibTeX library into the currently viewed library" into the "Import into database" functionality. Fixes [#6049](https://github.com/JabRef/jabref/issues/6049).
- We improved the error message for invalid jstyles. [#6303](https://github.com/JabRef/jabref/issues/6303)

### Fixed

Expand All @@ -40,12 +41,12 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We fixed an issue where custom jstyles for Open/LibreOffice where not saved correctly. [#6170](https://github.com/JabRef/jabref/issues/6170)
- We fixed an issue where the INSPIRE fetcher was no longer working [#6229](https://github.com/JabRef/jabref/issues/6229)
- We fixed an issue where custom exports with an uppercase file extension could not be selected for "Copy...-> Export to Clipboard" [#6285](https://github.com/JabRef/jabref/issues/6285)

- We fixed the display of icon both in the main table and linked file editor. [#6169](https://github.com/JabRef/jabref/issues/6169)
- We fixed the paste entry command in the menu and toolbar, that did not do anything. [#6293](https://github.com/JabRef/jabref/issues/6293)
- We fixed an issue where the windows installer did not create an entry in the start menu [bug report in the forum](https://discourse.jabref.org/t/error-while-fetching-from-doi/2018/3)
- We fixed an issue where JabRef switched to discrete graphics under macOS [#5935](https://github.com/JabRef/jabref/issues/5935)
- We fixed an issue where the Preferences entry preview will be unexpected modified leads to Value too long exception [#6198](https://github.com/JabRef/jabref/issues/6198)
- We fixed an issue where custom jstyles for Open/LibreOffice would only be valid if a layout line for the entry type `default` was at the end of the layout section [#6303](https://github.com/JabRef/jabref/issues/6303)

### Removed

Expand Down
5 changes: 5 additions & 0 deletions eclipse.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ eclipse {
def javafxgraphics = entries.find { isJavafxGraphics(it) };
javafxgraphics.entryAttributes['add-opens'] = 'javafx.graphics/javafx.scene=org.controlsfx.controls';

def javafxfxml = entries.find { isJavafxFXML(it) };
javafxfxml.entryAttributes['add-opens'] = 'javafx.fxml/javafx.fxml=org.jabref';

def graaltruffle = entries.find{ isTruffleGraal(it) } ;
graaltruffle.entryAttributes['add-exports'] = 'com.oracle.truffle.regex/com.oracle.truffle.regex=org.graalvm.truffle';

Expand Down Expand Up @@ -61,6 +64,8 @@ boolean isJavafxControls(entry) { return entry.properties.path.contains('javafx-

boolean isJavafxGraphics(entry) { return entry.properties.path.contains('javafx-graphics'); }

boolean isJavafxFXML(entry) { return entry.properties.path.contains('javafx-fxml'); }

boolean isTruffleGraal(entry) {return entry.properties.path.contains('org.graalvm.regex'); }

// add formatter and cleanup settings to Eclipse settings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void addStyleFile() {
styles.setAll(loadStyles());
selectedItem.setValue(getStyleOrDefault(stylePath));
} else {
dialogService.showErrorDialogAndWait(Localization.lang("Invalid style selected"), Localization.lang("You must select a valid style file."));
dialogService.showErrorDialogAndWait(Localization.lang("Invalid style selected"), Localization.lang("You must select a valid style file. Your style is probably missing a line for the type \"default\"."));
}
});
}
Expand Down
112 changes: 57 additions & 55 deletions src/main/java/org/jabref/logic/openoffice/OOBibStyle.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public class OOBibStyle implements Comparable<OOBibStyle> {
private boolean isDefaultLayoutPresent;

public OOBibStyle(File styleFile, LayoutFormatterPreferences prefs,
Charset encoding) throws IOException {
Charset encoding) throws IOException {
this.prefs = Objects.requireNonNull(prefs);
this.styleFile = Objects.requireNonNull(styleFile);
this.encoding = Objects.requireNonNull(encoding);
Expand Down Expand Up @@ -281,46 +281,46 @@ private void readFormatFile(Reader in) throws IOException {
}
// Check if we should change mode:
switch (line) {
case NAME_MARK:
mode = BibStyleMode.NAME;
continue;
case LAYOUT_MRK:
mode = BibStyleMode.LAYOUT;
continue;
case PROPERTIES_MARK:
mode = BibStyleMode.PROPERTIES;
continue;
case CITATION_MARK:
mode = BibStyleMode.CITATION;
continue;
case JOURNALS_MARK:
mode = BibStyleMode.JOURNALS;
continue;
default:
break;
case NAME_MARK:
mode = BibStyleMode.NAME;
continue;
case LAYOUT_MRK:
mode = BibStyleMode.LAYOUT;
continue;
case PROPERTIES_MARK:
mode = BibStyleMode.PROPERTIES;
continue;
case CITATION_MARK:
mode = BibStyleMode.CITATION;
continue;
case JOURNALS_MARK:
mode = BibStyleMode.JOURNALS;
continue;
default:
break;

}

switch (mode) {
case NAME:
if (!line.trim().isEmpty()) {
name = line.trim();
}
break;
case LAYOUT:
handleStructureLine(line);
break;
case PROPERTIES:
handlePropertiesLine(line, properties);
break;
case CITATION:
handlePropertiesLine(line, citProperties);
break;
case JOURNALS:
handleJournalsLine(line);
break;
default:
break;
case NAME:
if (!line.trim().isEmpty()) {
name = line.trim();
}
break;
case LAYOUT:
handleStructureLine(line);
break;
case PROPERTIES:
handlePropertiesLine(line, properties);
break;
case CITATION:
handlePropertiesLine(line, citProperties);
break;
case JOURNALS:
handleJournalsLine(line);
break;
default:
break;
}

}
Expand Down Expand Up @@ -349,12 +349,14 @@ public boolean isValid() {
private void handleStructureLine(String line) {
int index = line.indexOf('=');
if ((index > 0) && (index < (line.length() - 1))) {
String formatString = line.substring(index + 1);
isDefaultLayoutPresent = line.substring(0, index).equals(OOBibStyle.DEFAULT_MARK);
EntryType type = EntryTypeFactory.parse(line.substring(0, index));

try {
String formatString = line.substring(index + 1);
Layout layout = new LayoutHelper(new StringReader(formatString), this.prefs).getLayoutFromText();
if (isDefaultLayoutPresent) {
EntryType type = EntryTypeFactory.parse(line.substring(0, index));

if (!isDefaultLayoutPresent && line.substring(0, index).equals(OOBibStyle.DEFAULT_MARK)) {
isDefaultLayoutPresent = true;
defaultBibLayout = layout;
} else {
bibLayout.put(type, layout);
Expand Down Expand Up @@ -493,7 +495,7 @@ public String getNumCitationMarker(List<Integer> number, int minGroupingCount, b
* @return The formatted citation.
*/
public String getCitationMarker(List<BibEntry> entries, Map<BibEntry, BibDatabase> database, boolean inParenthesis,
String[] uniquefiers, int[] unlimAuthors) {
String[] uniquefiers, int[] unlimAuthors) {
// Look for groups of uniquefied entries that should be combined in the output.
// E.g. (Olsen, 2005a, b) should be output instead of (Olsen, 2005a; Olsen, 2005b).
int piv = -1;
Expand All @@ -515,20 +517,20 @@ public String getCitationMarker(List<BibEntry> entries, Map<BibEntry, BibDatabas
if (piv == -1) {
piv = i;
tmpMarker = getAuthorYearParenthesisMarker(Collections.singletonList(currentEntry), database,
null, unlimAuthors);
null, unlimAuthors);
} else {
// See if this entry can go into a group with the previous one:
String thisMarker = getAuthorYearParenthesisMarker(Collections.singletonList(currentEntry),
database, null, unlimAuthors);
database, null, unlimAuthors);

String authorField = getStringCitProperty(AUTHOR_FIELD);
int maxAuthors = getIntCitProperty(MAX_AUTHORS);
String author = getCitationMarkerField(currentEntry, database.get(currentEntry),
authorField);
authorField);
AuthorList al = AuthorList.parse(author);
int prevALim = unlimAuthors[i - 1]; // i always at least 1 here
if (!thisMarker.equals(tmpMarker)
|| ((al.getNumberOfAuthors() > maxAuthors) && (unlimAuthors[i] != prevALim))) {
|| ((al.getNumberOfAuthors() > maxAuthors) && (unlimAuthors[i] != prevALim))) {
// No match. Update piv to exclude the previous entry. But first check if the
// previous entry was part of a group:
if ((piv > -1) && (i > (piv + 1))) {
Expand Down Expand Up @@ -584,11 +586,11 @@ private void group(List<BibEntry> entries, String[] uniquefiers, int from, int t
* @return The formatted citation.
*/
private String getAuthorYearParenthesisMarker(List<BibEntry> entries, Map<BibEntry, BibDatabase> database,
String[] uniquifiers, int[] unlimAuthors) {
String[] uniquifiers, int[] unlimAuthors) {

String authorField = getStringCitProperty(AUTHOR_FIELD); // The bibtex field providing author names, e.g. "author" or "editor".
int maxA = getIntCitProperty(MAX_AUTHORS); // The maximum number of authors to write out in full without using etal. Set to
// -1 to always write out all authors.
// -1 to always write out all authors.
String yearSep = getStringCitProperty(YEAR_SEPARATOR); // The String to separate authors from year, e.g. "; ".
String startBrace = getStringCitProperty(BRACKET_BEFORE); // The opening parenthesis.
String endBrace = getStringCitProperty(BRACKET_AFTER); // The closing parenthesis.
Expand Down Expand Up @@ -637,11 +639,11 @@ private String getAuthorYearParenthesisMarker(List<BibEntry> entries, Map<BibEnt
* @return The formatted citation.
*/
private String getAuthorYearInTextMarker(List<BibEntry> entries, Map<BibEntry, BibDatabase> database,
String[] uniquefiers,
int[] unlimAuthors) {
String[] uniquefiers,
int[] unlimAuthors) {
String authorField = getStringCitProperty(AUTHOR_FIELD); // The bibtex field providing author names, e.g. "author" or "editor".
int maxA = getIntCitProperty(MAX_AUTHORS); // The maximum number of authors to write out in full without using etal. Set to
// -1 to always write out all authors.
// -1 to always write out all authors.
String yearSep = getStringCitProperty(IN_TEXT_YEAR_SEPARATOR); // The String to separate authors from year, e.g. "; ".
String startBrace = getStringCitProperty(BRACKET_BEFORE); // The opening parenthesis.
String endBrace = getStringCitProperty(BRACKET_AFTER); // The closing parenthesis.
Expand Down Expand Up @@ -865,9 +867,9 @@ public boolean equals(Object o) {
if (o instanceof OOBibStyle) {
OOBibStyle otherStyle = (OOBibStyle) o;
return Objects.equals(path, otherStyle.path)
&& Objects.equals(name, otherStyle.name)
&& Objects.equals(citProperties, otherStyle.citProperties)
&& Objects.equals(properties, otherStyle.properties);
&& Objects.equals(name, otherStyle.name)
&& Objects.equals(citProperties, otherStyle.citProperties)
&& Objects.equals(properties, otherStyle.properties);
}
return false;
}
Expand All @@ -878,7 +880,7 @@ public int hashCode() {
}

private String createAuthorList(String author, int maxAuthors, String andString,
String yearSep) {
String yearSep) {
Objects.requireNonNull(author);
String etAlString = getStringCitProperty(ET_AL_STRING); // The String to represent authors that are not mentioned, e.g. " et al."
String authorSep = getStringCitProperty(AUTHOR_SEPARATOR); // The String to add between author names except the last two, e.g. ", ".
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1402,7 +1402,7 @@ Internal\ style=Internal style
Add\ style\ file=Add style file
Current\ style\ is\ '%0'=Current style is '%0'
Remove\ style=Remove style
You\ must\ select\ a\ valid\ style\ file.=You must select a valid style file.
You\ must\ select\ a\ valid\ style\ file.\ Your\ style\ is\ probably\ missing\ a\ line\ for\ the\ type\ "default".=You must select a valid style file. Your style is probably missing a line for the type "default".
Invalid\ style\ selected=Invalid style selected

Reload=Reload
Expand Down

0 comments on commit ede97db

Please sign in to comment.