Skip to content
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

Closed
wants to merge 9 commits into from

Conversation

leonzolati
Copy link

@leonzolati leonzolati commented Oct 24, 2022

  • Added UI element to create user friendly way of interacting with the feature
  • Added a command that merges any libraries within a given directory in to the current active library according to the rules specifies in the issue so that users with many .lib files that wish to compile them into one .lib file may do so.

Fixes https://github.com/koppor/jabref/issues/295

  • Change in CHANGELOG.md described in a way that is understandable for the average user (if applicable)
  • Tests created for changes (if applicable)
  • Manually tested changed features in running JabRef (always required)
  • Screenshots added in PR description (for UI changes)
  • Checked developer's documentation](https://devdocs.jabref.org/): Is the information available and up to date? If not, I outlined it in this pull request.
  • Checked documentation](https://docs.jabref.org/): Is the information available and up to date? If not, I created an issue at https://github.com/JabRef/user-documentation/issues or, even better, I submitted a pull request to the documentation repository.

Apologies for the image being in a separate post, github was not cooperating on my computer for whatever reason. Thank you.

@crazycatseven
Copy link

image

Copy link
Member

@calixtus calixtus left a 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'


Copy link
Member

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'
Copy link
Member

@calixtus calixtus Oct 31, 2022

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.*;
Copy link
Member

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;
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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 {
Copy link
Member

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}.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid code duplication

Copy link
Member

@HoussemNasri HoussemNasri left a 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 {
Copy link
Member

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
Copy link
Member

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) {
Copy link
Member

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)){
Copy link
Member

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;
Copy link
Member

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);
Copy link
Member

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.

@calixtus calixtus added the status: changes required Pull requests that are not yet complete label Nov 8, 2022
@calixtus
Copy link
Member

Whats the status here? Do you want to continue this PR?

@Siedlerchr
Copy link
Member

Closing this PR due to inactivity 💤
Please reopen the PR if you intend to work on this agaiin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicateFinder status: changes required Pull requests that are not yet complete ui
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants