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

Directory pattern bracketed expressions #3238

Merged

Conversation

sauliusg
Copy link
Contributor

  • [ x] Change in CHANGELOG.md described
  • [ x] Tests created for changes
  • Screenshots added (for bigger UI changes)
  • [ x] Manually tested changed features in running JabRef
  • Check documentation status (Issue created for outdated help page at help.jabref.org?)
  • If you changed the localization: Did you run gradle localizationUpdate?

The offered PR implements functionality discussed in my "File linking functionality update?" proposal (http://discourse.jabref.org/t/file-linking-functionality-update/723). It is now possible to use bracketed expressions (like "[bibtexkey]" or "[year]_[auth]_[firstpage]") consistently in:

  • BibTex key generator patterns;
  • File search regular expressions (for automatic file linking);
  • Import file name patterns;
  • Import directory patterns.

To maintain consistent formatting, I have created a new BracketedExpressionExpander class which provides its main methods, 'expandBrackets()'. They essentially contain all bracket expansion functionality moved from BibtexKeyPatternUtil, and the BibtexKeyPatternUtil class now extends BracketedExpressionExpander, and uses its static methods. The BracketedExpressionExpander is also used in FileUtil and RegExpBasedFileFinder, avoiding the previous duplication of functionality in BibtexKeyPatternUtil.makeLabel(...) and RegExpBasedFileFinder.getFieldAndFormat(...) methods (both now use BracketedExpressionExpander.expandBrackets() for dealing with all aspects of bracket expansion in one place).

The bracketed expressions now can be used for Import File name patterns and Import File Directory patterns, providing consistent behavior of all "pattern" tabs in the JabRef "Preferences" dialogue; it is also possible to use underscores in the Import File and Directory patterns (e.g. "[year]_[auth]_[pages]") and to place Import destination directories deeper in the tree (e.g. "by-author/[authIni1]/[auth]" Directory Pattern now works as expected, creating "by-author/P/Pezzotti/2013_Pezzotti_211301.pdf" for the reference: Pezzotti, G. Raman spectroscopy of piezoelectrics Journal of Applied Physics, 2013, 113, 211301).

To retain functionality that was previously implemented by the '\entrytype' Layout pattern, a new bracketed expression "[entrytype]" was created and tested. It is suggested that Layout manager is used exclusively for describing layouts in citation lists, and bracketed expressions are used for describing file system and database entry patterns.

The functionality was tested under LinuxMint 18.1 and Ubuntu 16.04. Unfortunately, I could not test it on Windows hosts since I do not have any of them available for Java testing. I have put in provisions to deal with both '/' and '' directory separators in Directory Patterns, but I would be grateful if someone checks them on a Windows system.

Sincerely,
Saulius

sauliusg and others added 30 commits August 1, 2017 22:38
Also, adding tools/BracketedExpressionExpanderRunner main class to call
the methods of the first class from a command line. Makefile to build
and run classes from the tools/ directory is also added, so that I can
test the new methods without resirting to IDEs such as Eclipse (too
slow on my computers).
Adding command line argument processing to the
BracketedExpressionExpanderRunner.
Probably because of misconfigured apache logger...
gradel loggers, but still the BibEntry instance is not properly created
(raises exception).
now works.

Apparently, it used to find and link old Apache logging library in the
gradle tree.
BracketedExpressionExpanderRunner.
The bracket expansion works as desired, but for some reason it uses the
last page, not the first page.
cases throw (log?) unexpected exception.

This is still an ugly (and dangerous!) solution, therefore adding FIXME
to mark places where this happens; we should understand what goes on
here and add the appropriate logger initialisation (maybe in the JUnit
framework itself?).
The test passes, but it overwrites the
~/.java/.userPrefs/org/jabref/prefs.xml file elements with test values
-- not good!.
as intended.

The problem is that JabRefPreferences is a sigleton, and Mockito
apparently can not mock singletons or static methods.
dependening on JabRefPreferences is permitted.
@sauliusg
Copy link
Contributor Author

sauliusg commented Sep 30, 2017 via email

@sauliusg
Copy link
Contributor Author

sauliusg commented Sep 30, 2017 via email

Copy link
Member

@lenhard lenhard left a comment

Choose a reason for hiding this comment

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

@sauliusg Thanks for the elaboration. Everything you write regarding the bracketed expressions and the ASCII codes seems reasonable and is fine from my point of view. For me, the lack of conditional expressions in the bracketed expressions is also no show stopper and I am not even 100% sure that a follow-up PR is actually needed. We could also wait until someone actually complains about this missing functionality. Nevertheless, you are of course welcome to provide such a PR.

Thanks for offering a make file, but we're happy with gradle, so no need.

I have looked at the new migrations code and tested the functionality locally. As before, it seems to work for the bibtex key patterns. So this PR has its ok for merging from me.

Please note, though, that there might still be hidden problems. Users do very interesting things with bibtex key patterns. Especially when you touch something in the preferences, there might be problems that are almost impossible to foresee. It would be great if you could jump in for a fix if users report problems related to this PR in the future.

@LinusDietz
Copy link
Member

okay, this looks good to be tested with real users. since we release 4.0 today, I would kindly ask you to fix the conflict in the changelog, then I would merge this.

…ory-pattern-bracketed-expressions

Resolving the conflict in CHANGELOG.md, leaving just my changes in the
@LinusDietz LinusDietz merged commit effe334 into JabRef:master Oct 4, 2017
Siedlerchr added a commit that referenced this pull request Oct 7, 2017
* upstream/master: (113 commits)
  Open statistics dialog from correct thread (#3272)
  Fix for issue 2811: bibtexkey generator does not use crossref information (#3248)
  Fix for issue 3143: Import entry from clipboard in different formats (#3243)
  French translation correction (#3262)
  Wait to ask to collect anonymous statistics in JabRefExecutorService to allow jvm to terminate (#3266)
  Directory pattern bracketed expressions (#3238)
  Show development information
  Release v4.0
  add another author to mailmap
  moved changelog entry to the right category
  update new AUTHORS info
  Update log4j from 2.9.0 -> 2.9.1
  fix dblp fetcher
  Add missing Turkish translation
  Add "-console" parameter for Windows launcher (#3242)
  Path check converted to if statement
  Changelog updated
  Fixed renaming files which are not in main directory.
  Only use last name for auto completion in search bar. Fixes JabRef#253
  Implemented issue #3229 (#3233)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants