Skip to content

Commit

Permalink
Importing of BibDesk Groups and Linked Files (#10968)
Browse files Browse the repository at this point in the history
* Add test to check parsing of BibDesk Static Groups

* Add test to check parsing of BibDesk Static Groups

* Change isExpanded attribute to false in expected groups

* remove extra blank line

* Add tests to check parsing of BibDesk Smart and mixed groups

* Add parsing of BibDesk Files

* Attempts at plist

* Now parses bdsk-file and shows it as a file in JabRef

* Add test for parsing a bdsk-file field

* Fix formatting

* Add dd-plist library to documentation

---------

Co-authored-by: Tian0602 <[email protected]>

* Add creation of static JabRef group from a BibDesk file

* Creates an empty ExplicitGroup from BibDesk comment

* Adds citations to new groups
modifies group creations to support multiple groups in the same BibDeskFile

* Fix requested changes
Refactor imports since they did not match with main
Add safety check in addBibDeskGroupEntriesToJabRefGroups

---------

Co-authored-by: Filippa Nilsson <[email protected]>

* Refactor newline to match main branch

Co-authored-by: Filippa Nilsson <[email protected]>

* Add changes to CHANGELOG.md

* Reformat indentation to match previous

* Revert external libraries

Adjust groups serializing

* checkstyle and optional magic

* fix

* fix tests

* fix

* fix dangling do

* better group tree metadata setting

* merge group trees, prevent duplicate group assignment in entry
Add new BibDesk group

Fix IOB for change listeing

* fix tests, and extract constant

* return early

* fixtest and checkstyle

---------

Co-authored-by: Anna Maartensson <[email protected]>
Co-authored-by: Tian0602 <[email protected]>
Co-authored-by: LottaJohnsson <[email protected]>
Co-authored-by: Filippa Nilsson <[email protected]>
Co-authored-by: Filippa Nilsson <[email protected]>
Co-authored-by: Oliver Kopp <[email protected]>
Co-authored-by: Siedlerchr <[email protected]>
  • Loading branch information
8 people authored Mar 17, 2024
1 parent f5f92f9 commit d303aff
Show file tree
Hide file tree
Showing 11 changed files with 561 additions and 38 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- When pasting HTML into the abstract or a comment field, the hypertext is automatically converted to Markdown. [#10558](https://github.com/JabRef/jabref/issues/10558)
- We added the possibility to redownload files that had been present but are no longer in the specified location. [#10848](https://github.com/JabRef/jabref/issues/10848)
- We added the citation key pattern `[camelN]`. Equivalent to the first N words of the `[camel]` pattern.
- We added importing of static groups and linked files from BibDesk .bib files. [#10381](https://github.com/JabRef/jabref/issues/10381)
- We added ability to export in CFF (Citation File Format) [#10661](https://github.com/JabRef/jabref/issues/10661).
- We added ability to push entries to TeXworks. [#3197](https://github.com/JabRef/jabref/issues/3197)
- We added the ability to zoom in and out in the document viewer using <kbd>Ctrl</kbd> + <kbd>Scroll</kbd>. [#10964](https://github.com/JabRef/jabref/pull/10964)
Expand Down
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@ dependencies {
// Because of GraalVM quirks, we need to ship that. See https://github.com/jspecify/jspecify/issues/389#issuecomment-1661130973 for details
implementation 'org.jspecify:jspecify:0.3.0'

// parse plist files
implementation 'com.googlecode.plist:dd-plist:1.23'

testImplementation 'io.github.classgraph:classgraph:4.8.168'
testImplementation 'org.junit.jupiter:junit-jupiter:5.10.2'
testImplementation 'org.junit.platform:junit-platform-launcher:1.10.2'
Expand Down
20 changes: 20 additions & 0 deletions licenses/com.googlecode.plist_ddplist.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
dd-plist - An open source library to parse and generate property lists
Copyright (C) 2016 Daniel Dreibrodt

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
1 change: 1 addition & 0 deletions src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,5 @@
requires org.libreoffice.uno;
requires de.saxsys.mvvmfx.validation;
requires com.jthemedetector;
requires dd.plist;
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ private static EntryComparator getEntryComparator() {
private static List<BibEntryDiff> compareEntries(List<BibEntry> originalEntries, List<BibEntry> newEntries, BibDatabaseMode mode) {
List<BibEntryDiff> differences = new ArrayList<>();

// Prevent IndexOutOfBoundException
if (newEntries.isEmpty()) {
return differences;
}

// Create a HashSet where we can put references to entries in the new
// database that we have matched. This is to avoid matching them twice.
Set<Integer> used = new HashSet<>(newEntries.size());
Expand Down Expand Up @@ -88,7 +93,6 @@ private static List<BibEntryDiff> compareEntries(List<BibEntry> originalEntries,
}
}
}

BibEntry bestEntry = newEntries.get(bestMatchIndex);
if (bestMatch > MATCH_THRESHOLD
|| hasEqualCitationKey(originalEntry, bestEntry)
Expand Down
195 changes: 161 additions & 34 deletions src/main/java/org/jabref/logic/importer/fileformat/BibtexParser.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ public class MetadataSerializationConfiguration {
*/
public static final char GROUP_QUOTE_CHAR = '\\';

/**
* Group Type suffix (part of the GroupType)
*/
public static final String GROUP_TYPE_SUFFIX = ":";

/**
* For separating units (e.g. name and hierarchic context) in the string representation
*/
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/org/jabref/model/groups/AllEntriesGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ public boolean equals(Object o) {
return o instanceof AllEntriesGroup aeg && Objects.equals(aeg.getName(), getName());
}

/**
* Always returns true for any BibEntry!
*
* @param entry The @{@link BibEntry} to check
* @return Always returns true
*/
@Override
public boolean contains(BibEntry entry) {
return true;
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/org/jabref/model/groups/GroupTreeNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ public int hashCode() {
return Objects.hash(group);
}

/**
* Get only groups containing all the entries or just groups containing any of the
*
* @param entries List of {@link BibEntry} to search for
* @param requireAll Whether to return only groups that must contain all entries
* @return List of {@link GroupTreeNode} containing the matches. {@link AllEntriesGroup} is always contained}
*/
public List<GroupTreeNode> getContainingGroups(List<BibEntry> entries, boolean requireAll) {
List<GroupTreeNode> groups = new ArrayList<>();

Expand Down Expand Up @@ -197,6 +204,11 @@ public List<BibEntry> getEntriesInGroup(List<BibEntry> entries) {
return result;
}

/**
* Get the name of the underlying group
*
* @return String the name of the group
*/
public String getName() {
return group.getName();
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/jabref/model/metadata/MetaData.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class MetaData {
public static final String FILE_DIRECTORY_LATEX = "fileDirectoryLatex";
public static final String PROTECTED_FLAG_META = "protectedFlag";
public static final String SELECTOR_META_PREFIX = "selector_";
public static final String BIBDESK_STATIC_FLAG = "BibDesk Static Groups";

public static final char ESCAPE_CHARACTER = '\\';
public static final char SEPARATOR_CHARACTER = ';';
Expand Down
Loading

0 comments on commit d303aff

Please sign in to comment.