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

Migrate Review field in entry preview to comment #4100

Merged
merged 10 commits into from
Jun 13, 2018
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- We fixed an issue where the month was not shown in the preview https://github.com/JabRef/jabref/issues/3239.
- Rewritten logic to detect a second jabref instance. [#4023](https://github.com/JabRef/jabref/issues/4023)
- We fixed an issue where the preview pane in entry preview in preferences wasn't showing the citation style selected [#3849](https://github.com/JabRef/jabref/issues/3849)
- We fixed an issue where the default entry preview style still contained the field `review`. The field `review` in the style is now replaced with comment to be consistent with the entry editor [#4098](https://github.com/JabRef/jabref/issues/4098)



### Removed
- The feature to "mark entries" was removed and merged with the groups functionality. For migration, a group is created for every value of the `__markedentry` field and the entry is added to this group.
Expand Down
117 changes: 58 additions & 59 deletions src/main/java/org/jabref/migrations/PreferencesMigrations.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.slf4j.LoggerFactory;

public class PreferencesMigrations {

private static final Logger LOGGER = LoggerFactory.getLogger(PreferencesMigrations.class);

private PreferencesMigrations() {
Expand All @@ -31,23 +32,25 @@ private PreferencesMigrations() {
* Perform checks and changes for users with a preference set from an older JabRef version.
*/
public static void runMigrations() {
upgradePrefsToOrgJabRef();
upgradeSortOrder();
upgradeFaultyEncodingStrings();
upgradeLabelPatternToBibtexKeyPattern();
upgradeImportFileAndDirePatterns();
upgradeStoredCustomEntryTypes();
upgradeKeyBindingsToJavaFX();
addCrossRefRelatedFieldsForAutoComplete();
upgradeObsoleteLookAndFeels();

Preferences mainPrefsNode = Preferences.userNodeForPackage(JabRefMain.class);

upgradePrefsToOrgJabRef(mainPrefsNode);
upgradeSortOrder(Globals.prefs);
upgradeFaultyEncodingStrings(Globals.prefs);
upgradeLabelPatternToBibtexKeyPattern(Globals.prefs);
upgradeImportFileAndDirePatterns(Globals.prefs, mainPrefsNode);
upgradeStoredCustomEntryTypes(Globals.prefs, mainPrefsNode);
upgradeKeyBindingsToJavaFX(Globals.prefs);
addCrossRefRelatedFieldsForAutoComplete(Globals.prefs);
upgradeObsoleteLookAndFeels(Globals.prefs);
upgradePreviewStyleFromReviewToComment(Globals.prefs);
}

/**
* Migrate all preferences from net/sf/jabref to org/jabref
*/
private static void upgradePrefsToOrgJabRef() {
JabRefPreferences prefs = Globals.prefs;
Preferences mainPrefsNode = Preferences.userNodeForPackage(JabRefMain.class);
private static void upgradePrefsToOrgJabRef(Preferences mainPrefsNode) {
try {
if (mainPrefsNode.childrenNames().length != 0) {
// skip further processing as prefs already have been migrated
Expand Down Expand Up @@ -82,8 +85,7 @@ private static void copyPrefsRecursively(Preferences from, Preferences to) throw
/**
* Added from Jabref 2.11 beta 4 onwards to fix wrong encoding names
*/
private static void upgradeFaultyEncodingStrings() {
JabRefPreferences prefs = Globals.prefs;
private static void upgradeFaultyEncodingStrings(JabRefPreferences prefs) {
String defaultEncoding = prefs.get(JabRefPreferences.DEFAULT_ENCODING);
if (defaultEncoding == null) {
return;
Expand Down Expand Up @@ -123,8 +125,7 @@ private static void upgradeFaultyEncodingStrings() {
* these preferences, but it is only used when the new preference does not
* exist
*/
private static void upgradeSortOrder() {
JabRefPreferences prefs = Globals.prefs;
private static void upgradeSortOrder(JabRefPreferences prefs) {

if (prefs.get(JabRefPreferences.EXPORT_IN_SPECIFIED_ORDER, null) == null) {
if (prefs.getBoolean("exportInStandardOrder", false)) {
Expand All @@ -151,13 +152,11 @@ private static void upgradeSortOrder() {
/**
* Migrate all customized entry types from versions <=3.7
*/
private static void upgradeStoredCustomEntryTypes() {
JabRefPreferences prefs = Globals.prefs;
Preferences mainPrefsNode = Preferences.userNodeForPackage(JabRefMain.class);
private static void upgradeStoredCustomEntryTypes(JabRefPreferences prefs, Preferences mainPrefsNode) {

try {
if (mainPrefsNode.nodeExists(JabRefPreferences.CUSTOMIZED_BIBTEX_TYPES) ||
mainPrefsNode.nodeExists(JabRefPreferences.CUSTOMIZED_BIBLATEX_TYPES)) {
mainPrefsNode.nodeExists(JabRefPreferences.CUSTOMIZED_BIBLATEX_TYPES)) {
// skip further processing as prefs already have been migrated
} else {
LOGGER.info("Migrating old custom entry types.");
Expand All @@ -171,8 +170,7 @@ private static void upgradeStoredCustomEntryTypes() {
/**
* Migrate LabelPattern configuration from versions <=3.5 to new BibtexKeyPatterns
*/
private static void upgradeLabelPatternToBibtexKeyPattern() {
JabRefPreferences prefs = Globals.prefs;
private static void upgradeLabelPatternToBibtexKeyPattern(JabRefPreferences prefs) {

try {
Preferences mainPrefsNode = Preferences.userNodeForPackage(JabRefMain.class);
Expand Down Expand Up @@ -213,39 +211,36 @@ private static void migrateFileImportPattern(String oldStylePattern, String newS
String preferenceFileNamePattern = mainPrefsNode.get(JabRefPreferences.IMPORT_FILENAMEPATTERN, null);

if ((preferenceFileNamePattern != null) &&
oldStylePattern.equals(preferenceFileNamePattern)) {
oldStylePattern.equals(preferenceFileNamePattern)) {
// Upgrade the old-style File Name pattern to new one:
mainPrefsNode.put(JabRefPreferences.IMPORT_FILENAMEPATTERN, newStylePattern);
LOGGER.info("migrated old style " + JabRefPreferences.IMPORT_FILENAMEPATTERN +
" value \"" + oldStylePattern + "\" to new value \"" +
newStylePattern + "\" in the preference file");
" value \"" + oldStylePattern + "\" to new value \"" +
newStylePattern + "\" in the preference file");

if (prefs.hasKey(JabRefPreferences.IMPORT_FILENAMEPATTERN)) {
// Update also the key in the current application settings, if necessary:
String fileNamePattern = prefs.get(JabRefPreferences.IMPORT_FILENAMEPATTERN);
if (oldStylePattern.equals(fileNamePattern)) {
prefs.put(JabRefPreferences.IMPORT_FILENAMEPATTERN, newStylePattern);
LOGGER.info("migrated old style " + JabRefPreferences.IMPORT_FILENAMEPATTERN +
" value \"" + oldStylePattern + "\" to new value \"" +
newStylePattern + "\" in the running application");
" value \"" + oldStylePattern + "\" to new value \"" +
newStylePattern + "\" in the running application");
}
}
}
}

static void upgradeImportFileAndDirePatterns() {
JabRefPreferences prefs = Globals.prefs;

Preferences mainPrefsNode = Preferences.userNodeForPackage(JabRefMain.class);
static void upgradeImportFileAndDirePatterns(JabRefPreferences prefs, Preferences mainPrefsNode) {

// Migrate Import patterns
// Check for prefs node for Version <= 4.0
if (mainPrefsNode.get(JabRefPreferences.IMPORT_FILENAMEPATTERN, null) != null) {

String[] oldStylePatterns = new String[]{"\\bibtexkey",
"\\bibtexkey\\begin{title} - \\format[RemoveBrackets]{\\title}\\end{title}"};
String[] newStylePatterns = new String[]{"[bibtexkey]",
"[bibtexkey] - [fulltitle]"};
String[] oldStylePatterns = new String[] {"\\bibtexkey",
"\\bibtexkey\\begin{title} - \\format[RemoveBrackets]{\\title}\\end{title}"};
String[] newStylePatterns = new String[] {"[bibtexkey]",
"[bibtexkey] - [fulltitle]"};
for (int i = 0; i < oldStylePatterns.length; i++) {
migrateFileImportPattern(oldStylePatterns[i], newStylePatterns[i], prefs, mainPrefsNode);
}
Expand All @@ -254,7 +249,7 @@ static void upgradeImportFileAndDirePatterns() {
// the user defined old-style patterns, and the default pattern is "".
}

private static void upgradeKeyBindingsToJavaFX() {
private static void upgradeKeyBindingsToJavaFX(JabRefPreferences prefs) {
UnaryOperator<String> replaceKeys = (str) -> {
String result = str.replace("ctrl ", "ctrl+");
result = result.replace("shift ", "shift+");
Expand All @@ -264,14 +259,12 @@ private static void upgradeKeyBindingsToJavaFX() {
return result;
};

JabRefPreferences prefs = Globals.prefs;
List<String> keys = prefs.getStringList(JabRefPreferences.BINDINGS);
keys.replaceAll(replaceKeys);
prefs.putStringList(JabRefPreferences.BINDINGS, keys);
}

private static void addCrossRefRelatedFieldsForAutoComplete() {
JabRefPreferences prefs = Globals.prefs;
private static void addCrossRefRelatedFieldsForAutoComplete(JabRefPreferences prefs) {
//LinkedHashSet because we want to retain the order and add new fields to the end
Set<String> keys = new LinkedHashSet<>(prefs.getStringList(JabRefPreferences.AUTOCOMPLETER_COMPLETE_FIELDS));
keys.add("crossref");
Expand All @@ -281,36 +274,42 @@ private static void addCrossRefRelatedFieldsForAutoComplete() {
}

private static void migrateTypedKeyPrefs(JabRefPreferences prefs, Preferences oldPatternPrefs)
throws BackingStoreException {
throws BackingStoreException {
LOGGER.info("Found old Bibtex Key patterns which will be migrated to new version.");

GlobalBibtexKeyPattern keyPattern = GlobalBibtexKeyPattern.fromPattern(
prefs.get(JabRefPreferences.DEFAULT_BIBTEX_KEY_PATTERN));
prefs.get(JabRefPreferences.DEFAULT_BIBTEX_KEY_PATTERN));
for (String key : oldPatternPrefs.keys()) {
keyPattern.addBibtexKeyPattern(key, oldPatternPrefs.get(key, null));
}
prefs.putKeyPattern(keyPattern);
}

private static void upgradeObsoleteLookAndFeels() {
JabRefPreferences prefs = Globals.prefs;
String currentLandF = prefs.get(JabRefPreferences.WIN_LOOK_AND_FEEL);
private static void upgradeObsoleteLookAndFeels(JabRefPreferences prefs) {

String currentLandF = prefs.getLookAndFeel();

Stream.of("com.jgoodies.looks.windows.WindowsLookAndFeel", "com.jgoodies.looks.plastic.PlasticLookAndFeel",
"com.jgoodies.looks.plastic.Plastic3DLookAndFeel", "com.jgoodies.looks.plastic.PlasticXPLookAndFeel",
"com.sun.java.swing.plaf.gtk.GTKLookAndFeel")
.filter(style -> style.equals(currentLandF))
.findAny()
.ifPresent(loolAndFeel -> {
if (OS.WINDOWS) {
String windowsLandF = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
prefs.put(JabRefPreferences.WIN_LOOK_AND_FEEL, windowsLandF);
LOGGER.info("Switched from obsolete look and feel " + currentLandF + " to " + windowsLandF);
} else {
String nimbusLandF = "javax.swing.plaf.nimbus.NimbusLookAndFeel";
prefs.put(JabRefPreferences.WIN_LOOK_AND_FEEL, nimbusLandF);
LOGGER.info("Switched from obsolete look and feel " + currentLandF + " to " + nimbusLandF);
}
});
"com.jgoodies.looks.plastic.Plastic3DLookAndFeel", "com.jgoodies.looks.plastic.PlasticXPLookAndFeel",
"com.sun.java.swing.plaf.gtk.GTKLookAndFeel")
.filter(style -> style.equals(currentLandF))
.findAny()
.ifPresent(loolAndFeel -> {
if (OS.WINDOWS) {
String windowsLandF = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
prefs.setLookAndFeel(windowsLandF);
LOGGER.info("Switched from obsolete look and feel " + currentLandF + " to " + windowsLandF);
} else {
String nimbusLandF = "javax.swing.plaf.nimbus.NimbusLookAndFeel";
prefs.setLookAndFeel(nimbusLandF);
LOGGER.info("Switched from obsolete look and feel " + currentLandF + " to " + nimbusLandF);
}
});
}

static void upgradePreviewStyleFromReviewToComment(JabRefPreferences prefs) {
String currentPreviewStyle = prefs.getPreviewStyle();
String migratedStyle = currentPreviewStyle.replace("\\begin{review}<BR><BR><b>Review: </b> \\format[HTMLChars]{\\review} \\end{review}", "\\begin{comment}<BR><BR><b>Comment: </b> \\format[HTMLChars]{\\comment} \\end{comment}");
prefs.setPreviewStyle(migratedStyle);
}
}
Loading