-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add MergeLibraries functionality #9292
Conversation
Added test case for MergeCommand
… match in the test case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, thanks for your interest in JabRef and your great contribution. After a very quick first look I noticed some issues I would like you to address. We will also take a deeper look into your code as soon we have some time in the next days.
@@ -221,6 +225,8 @@ dependencies { | |||
// xjc needs the runtime as well for the ant task, otherwise it fails | |||
xjc group: 'org.glassfish.jaxb', name: 'jaxb-xjc', version: '3.0.2' | |||
xjc group: 'org.glassfish.jaxb', name: 'jaxb-runtime', version: '3.0.2' | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove the empty lines
implementation 'com.google.jimfs:jimfs:1.2' | ||
implementation 'com.google.jimfs:jimfs-parent:1.2' | ||
implementation 'org.junit.jupiter:junit-jupiter:5.8.1' | ||
implementation 'org.junit.jupiter:junit-jupiter:5.8.1' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be testImplementation
, otherwise I think blink will break?
import java.io.File; | ||
import java.io.IOException; | ||
import java.lang.module.Configuration; | ||
import java.nio.file.*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No wildcard imports please
public MergeCommand(JabRefFrame frame,PreferencesService preferences, StateManager stateManager) { | ||
|
||
this.preferences = preferences; | ||
this.frame = frame; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try to avoid reverse dependencies
|
||
@Override | ||
public void execute() { | ||
//TODO: write the execute method |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Artifact comments?
//construct a configuration with the current directory | ||
//(this really could have just been a constructor so think of it like that) | ||
DirectoryDialogConfiguration.Builder config = new DirectoryDialogConfiguration.Builder().withInitialDirectory(preferences.getFilePreferences().getWorkingDirectory()); | ||
//open dialog box using the dialog service which will return a path to a directory |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty much self explaining the line above. Really need a comment for this?
* to merge | ||
* @return all the .bib files in a given directory and subdirectories | ||
*/ | ||
private List<Path> getAllFiles(Path path) throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getAllBibFiles
} | ||
|
||
/** | ||
* This method is taken from the loadDatabase method in {@link OpenDatabaseAction}. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please avoid code duplication
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The feature seems to function correctly, however, I have a few comments about the implementation.
In general, this is a great feature and I'm sure users would appreciate it, but I don't believe it's complete. I suggest that we wait until 5.8 is released before merging it.
I can think of a few things missing:
- When there are duplicates, the three-way merge dialog does not appear. For instance, if you copy all of the entries from one library and paste them into another, a merge dialog will appear to resolve duplicates. So, for consistency, I believe JabRef should include that when merging libraries as well.
- It's not possible to undo merging a library into the current library.
import java.util.*; | ||
|
||
|
||
public class MergeCommand extends SimpleCommand { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please use a more descriptive name; maybe MergeLibrariesInFolderIntoCurrent
?
} | ||
|
||
public BibDatabase doMerge(Path path, BibDatabase database) throws IOException { | ||
//find all the .lib files by crawling in doMerge and merge them |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just like what Carl said earlier; this comment is describing HOW the code works, but comments are better used to describe the WHY. In this case, there is no 'why' to answer, so it's better to remove the comment.
List<Path> paths = new ArrayList<>(); | ||
|
||
try (DirectoryStream<Path> stream = Files.newDirectoryStream(path)) { | ||
for (Path entry : stream) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code can be replaced using Files#find.
break; | ||
} | ||
|
||
if (new DuplicateCheck(entryTypesManager).isDuplicate(entry, dbEntry, BibDatabaseMode.BIBTEX)){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could make one instance of DuplicateCheck and reuse it. It won't make much of a difference in terms of performance, but it will result in the garbage collector doing less work and thus shorter GC pauses.
database.insertEntries(toAdd.stream().toList()); | ||
// | ||
//then add the database to the StateManager's activeDatabase | ||
return database; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need to return the database here?
|
||
for (BibEntry dbEntry : db.getEntries()) { | ||
boolean equalFlag = false; | ||
System.out.println("dbEntry: " + dbEntry); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove the System.out.println
calls. If you think they are necessary use a logger.
Whats the status here? Do you want to continue this PR? |
Closing this PR due to inactivity 💤 |
Fixes https://github.com/koppor/jabref/issues/295
CHANGELOG.md
described in a way that is understandable for the average user (if applicable)Apologies for the image being in a separate post, github was not cooperating on my computer for whatever reason. Thank you.