Skip to content

Commit

Permalink
Merge branch 'master' of github.com:JabRef/jabref
Browse files Browse the repository at this point in the history
* 'master' of github.com:JabRef/jabref:
  Allow spaces in DOIs
  Remove irrelevant log messages during XMP reading
  Adapt log4j configuration for cleaner junit tests #3511
  Eclipse Django style #3655
  Better code style for chained methods
  Update build.gradle
  Update build.gradle
  cleanup and refactoring in DuplicateCheck class
  code review fixes - consider pages of the same book separately in duplications detection process; add more tests
  differentiate inbooks with the same author and title, but different chapter
  Remove deprecated static BibtexParser.parse method
  Use stream in matcher (#3696)
  Add some BibtexNameFomatter comments
  Add exception for Jacoco
  Set jacoco toolVersion earlier
  set jacoco version globally
  • Loading branch information
Siedlerchr committed Feb 6, 2018
2 parents c914834 + f3d86d5 commit 97a84f6
Show file tree
Hide file tree
Showing 15 changed files with 306 additions and 213 deletions.
16 changes: 14 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ dependencies {
checkstyle 'com.puppycrawl.tools:checkstyle:8.8'
}

jacoco {
toolVersion = '0.8.0'
}

dependencyUpdates {
outputFormatter = "json"
}
Expand Down Expand Up @@ -227,7 +231,16 @@ dependencyUpdates.resolutionStrategy = {
selection.reject("http://dev.mysql.com/downloads/connector/j/ lists the version 5.* as last stable version.")
}
}

withModule("org.jacoco.agent") { ComponentSelection selection ->
if (selection.candidate.version.equals("0.8.0")) {
selection.reject("As a native plugin we cannot control the actual version of jacoco. This dependency should be hidden.")
}
}
withModule("org.jacoco.ant") { ComponentSelection selection ->
if (selection.candidate.version.equals("0.8.0")) {
selection.reject("As a native plugin we cannot control the actual version of jacoco. This dependency should be hidden.")
}
}
}
}

Expand Down Expand Up @@ -391,7 +404,6 @@ afterEvaluate {
def junitPlatformTest = tasks.junitPlatformTest

jacoco {
toolVersion = '0.8.0'
applyTo(junitPlatformTest)
}

Expand Down
1 change: 1 addition & 0 deletions config/IntelliJ Code Style.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<option name="KEEP_BLANK_LINES_IN_DECLARATIONS" value="1" />
<option name="KEEP_BLANK_LINES_IN_CODE" value="1" />
<option name="KEEP_BLANK_LINES_BEFORE_RBRACE" value="0" />
<option name="ALIGN_MULTILINE_CHAINED_METHODS" value="true" />
<arrangement>
<rules>
<section>
Expand Down
2 changes: 1 addition & 1 deletion eclipse.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ tasks.eclipse.doFirst {
org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_resources_in_try=88
org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=16
org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=80
org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=0
org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/jabref/gui/EntryTypeDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ protected Optional<BibEntry> doInBackground() throws Exception {
generateButton.setText(Localization.lang("Searching..."));
});
searchID = idTextField.getText().trim();
searchID = searchID.replaceAll(" ", "");
fetcher = WebFetchers.getIdBasedFetchers(Globals.prefs.getImportFormatPreferences()).get(comboBox.getSelectedIndex());
if (!searchID.isEmpty()) {
try {
Expand Down
275 changes: 169 additions & 106 deletions src/main/java/org/jabref/logic/bibtex/DuplicateCheck.java

Large diffs are not rendered by default.

15 changes: 10 additions & 5 deletions src/main/java/org/jabref/logic/bst/BibtexNameFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ public class BibtexNameFormatter {
private BibtexNameFormatter() {
}

/**
* Formats the nth author of the author name list by a given format string
*
* @param authorsNameList The string from an author field
* @param whichName index of the list, starting with 1
* @param formatString TODO
* @param warn collects the warnings, may-be-null
* @return
*/
public static String formatName(String authorsNameList, int whichName, String formatString, Warn warn) {
AuthorList al = AuthorList.parse(authorsNameList);

Expand All @@ -40,11 +49,7 @@ public static String formatName(String authorsNameList, int whichName, String fo
}

/**
*
* @param author
* @param format
* @param warn may-be-null
* @return
* @param warn collects the warnings, may-be-null
*/
public static String formatName(Author author, String format, Warn warn) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,6 @@ public BibtexParser(ImportFormatPreferences importFormatPreferences, FileUpdateM
metaDataParser = new MetaDataParser(fileMonitor);
}

/**
* Shortcut usage to create a Parser and read the input.
*
* @param in the Reader to read from
* @param fileMonitor
* @throws IOException
* @deprecated inline this method
*/
@Deprecated
public static ParserResult parse(Reader in, ImportFormatPreferences importFormatPreferences, FileUpdateMonitor fileMonitor) throws IOException {
return new BibtexParser(importFormatPreferences, fileMonitor).parse(in);
}

/**
* Parses BibtexEntries from the given string and returns one entry found (or null if none found)
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public static boolean sendToActiveJabRefInstance(String[] args, int remoteServer

if (!Protocol.IDENTIFIER.equals(identifier)) {
String port = String.valueOf(remoteServerPort);
String error = Localization.lang("Cannot use port %0 for remote operation; another application may be using it. Try specifying another port.", port);
System.out.println(error);
String errorMessage = Localization.lang("Cannot use port %0 for remote operation; another application may be using it. Try specifying another port.", port);
LOGGER.error(errorMessage);
return false;
}
protocol.sendMessage(String.join("\n", args));
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/logic/xmp/XMPUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,7 @@ public static boolean hasMetadata(Path path, XMPPreferences xmpPreferences) {
try (InputStream inputStream = Files.newInputStream(path, StandardOpenOption.READ)) {
return hasMetadata(inputStream, xmpPreferences);
} catch (IOException e) {
LOGGER.error("XMP reading failed", e);
// happens if no metadata is found, no reason to log the exception
return false;
}
}
Expand All @@ -1056,7 +1056,7 @@ public static boolean hasMetadata(InputStream inputStream, XMPPreferences xmpPre
LOGGER.info("Encryption not supported by XMPUtil");
return false;
} catch (IOException e) {
LOGGER.error("XMP reading failed", e);
// happens if no metadata is found, no reason to log the exception
return false;
}
}
Expand Down
19 changes: 4 additions & 15 deletions src/main/java/org/jabref/model/search/matchers/AndMatcher.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,15 @@
package org.jabref.model.search.matchers;

import org.jabref.model.entry.BibEntry;
import org.jabref.model.search.SearchMatcher;

/**
* Subclass of MatcherSet that ANDs or ORs between its rules, returning 0 or
* 1.
* A set of matchers that returns true if all matcher match the given entry.
*/
public class AndMatcher extends MatcherSet {

@Override
public boolean isMatch(BibEntry bibEntry) {
int score = 0;

// We let each rule add a maximum of 1 to the score.
for (SearchMatcher rule : matchers) {
if (rule.isMatch(bibEntry)) {
score++;
}
}

// Then an AND rule demands that score == number of rules
return score == matchers.size();
public boolean isMatch(BibEntry entry) {
return matchers.stream()
.allMatch(rule -> rule.isMatch(entry));
}
}
19 changes: 4 additions & 15 deletions src/main/java/org/jabref/model/search/matchers/OrMatcher.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,15 @@
package org.jabref.model.search.matchers;

import org.jabref.model.entry.BibEntry;
import org.jabref.model.search.SearchMatcher;

/**
* Subclass of MatcherSet that ANDs or ORs between its rules, returning 0 or
* 1.
* A set of matchers that returns true if any matcher matches the given entry.
*/
public class OrMatcher extends MatcherSet {

@Override
public boolean isMatch(BibEntry bibEntry) {
int score = 0;

// We let each rule add a maximum of 1 to the score.
for (SearchMatcher rule : matchers) {
if (rule.isMatch(bibEntry)) {
score++;
}
}

// OR rule demands score > 0.
return score > 0;
public boolean isMatch(BibEntry entry) {
return matchers.stream()
.anyMatch(rule -> rule.isMatch(entry));
}
}
60 changes: 60 additions & 0 deletions src/test/java/org/jabref/logic/bibtex/DuplicateCheckTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class DuplicateCheckTest {

private BibEntry simpleArticle;
private BibEntry unrelatedArticle;
private BibEntry simpleInbook;
private BibEntry simpleIncollection;

@Before
public void setUp() {
Expand All @@ -27,6 +29,19 @@ public void setUp() {
.withField(FieldName.AUTHOR, "Completely Different")
.withField(FieldName.TITLE, "Holy Moly Uffdada und Trallalla")
.withField(FieldName.YEAR, "1992");
simpleInbook = new BibEntry(BibtexEntryTypes.INBOOK.getName())
.withField(FieldName.TITLE, "Alice in Wonderland")
.withField(FieldName.AUTHOR, "Charles Lutwidge Dodgson")
.withField(FieldName.CHAPTER, "Chapter One – Down the Rabbit Hole")
.withField(FieldName.LANGUAGE, "English")
.withField(FieldName.PUBLISHER, "Macmillan")
.withField(FieldName.YEAR, "1865");
simpleIncollection = new BibEntry(BibtexEntryTypes.INCOLLECTION.getName())
.withField(FieldName.TITLE, "Innovation and Intellectual Property Rights")
.withField(FieldName.AUTHOR, "Ove Grandstrand")
.withField(FieldName.BOOKTITLE, "The Oxford Handbook of Innovation")
.withField(FieldName.PUBLISHER, "Oxford University Press")
.withField(FieldName.YEAR, "2004");
}

@Test
Expand Down Expand Up @@ -142,6 +157,51 @@ public void twoEntriesWithSameDoiButDifferentTypesAreDuplicates() {
assertTrue(DuplicateCheck.isDuplicate(simpleArticle, duplicateWithDifferentType, BibDatabaseMode.BIBTEX));
}

@Test
public void twoInbooksWithDifferentChaptersAreNotDuplicates() {
twoEntriesWithDifferentSpecificFieldsAreNotDuplicates(simpleInbook, FieldName.CHAPTER,
"Chapter One – Down the Rabbit Hole",
"Chapter Two – The Pool of Tears");
}

@Test
public void twoInbooksWithDifferentPagesAreNotDuplicates() {
twoEntriesWithDifferentSpecificFieldsAreNotDuplicates(simpleInbook, FieldName.PAGES, "1-20", "21-40");
}

@Test
public void twoIncollectionsWithDifferentChaptersAreNotDuplicates() {
twoEntriesWithDifferentSpecificFieldsAreNotDuplicates(simpleIncollection, FieldName.CHAPTER, "10", "9");
}

@Test
public void twoIncollectionsWithDifferentPagesAreNotDuplicates() {
twoEntriesWithDifferentSpecificFieldsAreNotDuplicates(simpleIncollection, FieldName.PAGES, "1-20", "21-40");
}

private void twoEntriesWithDifferentSpecificFieldsAreNotDuplicates(final BibEntry cloneable,
final String fieldType,
final String firstValue,
final String secondValue) {
final BibEntry entry1 = (BibEntry) cloneable.clone();
entry1.setField(fieldType, firstValue);

final BibEntry entry2 = (BibEntry) cloneable.clone();
entry2.setField(fieldType, secondValue);

assertFalse(DuplicateCheck.isDuplicate(entry1, entry2, BibDatabaseMode.BIBTEX));
}

@Test
public void inbookWithoutChapterCouldBeDuplicateOfInbookWithChapter() {
final BibEntry inbook1 = (BibEntry) simpleInbook.clone();
final BibEntry inbook2 = (BibEntry) simpleInbook.clone();
inbook2.setField(FieldName.CHAPTER, "");

assertTrue(DuplicateCheck.isDuplicate(inbook1, inbook2, BibDatabaseMode.BIBTEX));
assertTrue(DuplicateCheck.isDuplicate(inbook2, inbook1, BibDatabaseMode.BIBTEX));
}

@Test
public void twoBooksWithDifferentEditionsAreNotDuplicates() {
BibEntry editionOne = new BibEntry(BibtexEntryTypes.BOOK.getName());
Expand Down
Loading

0 comments on commit 97a84f6

Please sign in to comment.