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

Fix for issue 11984: Add CLI option for consistency check and implement functionality #12061

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

FeiLi-lab
Copy link

@FeiLi-lab FeiLi-lab commented Oct 23, 2024

Purpose

Closes #11984

This PR adds a new command line option to perform consistency checks on BibTeX files, with the ability to specify the output format (TXT/CSV). The functionality is implemented in the ArgumentProcessor class, and appropriate unit tests have been added to ensure correct behavior.

Description

The new CLI option --check-consistency allows users to perform consistency checks on BibTeX files directly from the command line. Users can also specify the output format using the --check-consistency-output-format option.

The main changes include:

  1. Adding new CLI options in the CliOptions class
  2. Implementing the checkConsistency() method in the ArgumentProcessor class
  3. Adding unit tests for the new CLI options and functionality
  4. Updating CliOptionsTest and ArgumentProcessorTest classes

Solution

The solution involves the following steps:

  1. Add new options to the CliOptions class for consistency checking and output format specification
  2. Implement the checkConsistency() method in ArgumentProcessor to handle the consistency check logic
  3. Update the processArguments() method to call checkConsistency() when the option is specified
  4. Add unit tests to verify the correct behavior of the new functionality

Outcome

The new CLI option allows users to perform consistency checks on BibTeX files without opening the GUI. The check results are written to a file in either TXT or CSV format, as specified by the user.
[we have a test.bib file]
image
image

[we check this file's consistency and ask to output in CSV format]
image

[we get a CSV file successfully]
image
image

[Of course, we can also get a TXT file ]
a2ca2676a28bfb4adaa69bc8feeb59d
d63cf9d72ae90493d06b0c700a2bb7d

Mandatory checks

  • I own the copyright of the code submitted and I licence it under the MIT license
  • 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: Is the information available and up to date? If not, I outlined it in this pull request.
  • Checked documentation: 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.

FeiLi-lab and others added 3 commits October 22, 2024 14:38
…ionality

- Add new CLI options --check-consistency and --check-consistency-output-format
- Implement checkConsistency() method in ArgumentProcessor
- Add unit tests for new CLI options and functionality
- Update CliOptionsTest and ArgumentProcessorTest classes

This commit adds a new command line option to perform consistency checks
on BibTeX files, with the ability to specify the output format (TXT/CSV).
The functionality is implemented in the ArgumentProcessor class, and
appropriate unit tests have been added to ensure correct behavior.
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Your code currently does not meet JabRef's code guidelines.
We use Checkstyle to identify issues.
The tool reviewdog already placed comments on GitHub to indicate the places. See the tab "Files" in you PR.
Please carefully follow the setup guide for the codestyle.
Afterwards, please run checkstyle locally and fix the issues.

You can check review dog's comments at the tab "Files changed" of your pull request.

@FeiLi-lab
Copy link
Author

Thanks, I will revise it immediately

@koppor
Copy link
Member

koppor commented Oct 23, 2024

@FeiLi-lab pleae also click on the respective "Details" link for other failing tests:

image

@koppor koppor added the status: changes required Pull requests that are not yet complete label Oct 23, 2024
@YZYGitHubYZY
Copy link

@FeiLi-lab There are multiple unit tests in PR that fail, which may be due to the fact that the implementation of the new functionality does not adequately consider all possible use cases or boundary cases. It is recommended to check the reasons for unit test failures, especially the parts related to the ArgumentProcessor. Ensure that the checkConsistency() method works correctly for all possible input scenarios and add or modify the test cases if necessary.

@@ -187,6 +187,7 @@ public String getCheckConsistencyOutputFormat() {
return commandLine.getOptionValue("check-consistency-output-format", "TXT");
}

@SuppressWarnings("checkstyle:EmptyLineSeparator")
Copy link
Member

Choose a reason for hiding this comment

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

Checkstyle rules are there to enfore consistency, not to ingore them!

Copy link
Author

Choose a reason for hiding this comment

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

Thanks, i get it.

Copy link
Member

@koppor koppor left a comment

Choose a reason for hiding this comment

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

I would like to have a non-file output.

Some minor comment on the test

Otherwise: Looks good.

Comment on lines +307 to +310
if (fileName == null) {
System.out.println(Localization.lang("No file specified for consistency check."));
return;
}
Copy link
Member

Choose a reason for hiding this comment

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

Move this up to after filename -> fail fast


private void checkConsistency() {
String fileName = cli.getCheckConsistency();
String outputFormat = cli.getCheckConsistencyOutputFormat().toUpperCase();
Copy link
Member

Choose a reason for hiding this comment

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

cli.getCheckConsistencyOutputFormat() could be null? - Please handle. No need to use toUpperCase(). I give you a hint below.

Suggested change
String outputFormat = cli.getCheckConsistencyOutputFormat().toUpperCase();
Optional<String> outputFormat = Optional.ofNullable(cli.getCheckConsistencyOutputFormat());

Update: I saw that you put TXT as default. Can you check if it is a default value somewhow? Otherwise, just remove the default and use my proposal.

--> Without --check-consistency-output-format: Write to console


String outputFileName = fileName + "_consistency_check." + outputFormat.toLowerCase();
try (Writer writer = new FileWriter(outputFileName, StandardCharsets.UTF_8)) {
if ("CSV".equals(outputFormat)) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if ("CSV".equals(outputFormat)) {
if ("CSV".equalsIgnoreCase(outputFormat.orElse(""))) {

BibliographyConsistencyCheck.Result result = checker.check(databaseContext.getDatabase().getEntries());

String outputFileName = fileName + "_consistency_check." + outputFormat.toLowerCase();
try (Writer writer = new FileWriter(outputFileName, StandardCharsets.UTF_8)) {
Copy link
Member

Choose a reason for hiding this comment

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

Please rewrite. If outputFormat.isEmpty() then just output to System.out (and use TXT as format).

}
}

System.out.println(Localization.lang("Consistency check completed. Results written to %0", outputFileName));
Copy link
Member

Choose a reason for hiding this comment

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

No output if outputFormat.isEmpty().


@Test
void checkConsistency(@TempDir Path tempDir) throws Exception {
Path testBib = Path.of(Objects.requireNonNull(ArgumentProcessorTest.class.getResource("test-entry.bib")).toURI());
Copy link
Member

Choose a reason for hiding this comment

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

Please use an existing .bib file (and remove test-entry.bib)

Reason: The abstracts could be copyrighted. We would need to spend time on cleaining up test-entry.bib. But you are just checking if something is output. Thus, the concrete checks are not tested. This is OK!

Use /testbib/jabref-authors.bib.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for your review!I will revise it.

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

Successfully merging this pull request may close these issues.

Add Cli option for BibliographyConsistencyCheckResultTxtWriter
4 participants