Skip to content

Commit

Permalink
add additional migrations for earliear version
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasgeiger committed Aug 11, 2016
1 parent a4916a1 commit f63c458
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
34 changes: 23 additions & 11 deletions src/main/java/net/sf/jabref/migrations/PreferencesMigrations.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public static void upgradeLabelPatternToBibtexKeyPattern() {
try {
Preferences mainPrefsNode = Preferences.userNodeForPackage(JabRefMain.class);

// Migrate default pattern
if (mainPrefsNode.get(JabRefPreferences.DEFAULT_BIBTEX_KEY_PATTERN, null)==null) {
// Check whether old defaultLabelPattern is set
String oldDefault = mainPrefsNode.get("defaultLabelPattern", null);
Expand All @@ -107,24 +108,35 @@ public static void upgradeLabelPatternToBibtexKeyPattern() {
}

}
if (mainPrefsNode.nodeExists("bibtexkeypatterns")) {
return; //Pref node already exists do not migrate from previous version
//Pref node already exists do not migrate from previous version
if (mainPrefsNode.nodeExists(JabRefPreferences.BIBTEX_KEY_PATTERNS_NODE)) {
return;
}

// Migrate type specific patterns
// Check for prefs node for Version 3.3-3.5
if (mainPrefsNode.nodeExists("logic/labelpattern")) {
LOGGER.info("Found old Bibtex Key patterns which will be migrated to new version.");

GlobalBibtexKeyPattern keyPattern = new GlobalBibtexKeyPattern(AbstractBibtexKeyPattern
.split(prefs.get(JabRefPreferences.DEFAULT_BIBTEX_KEY_PATTERN)));
Preferences oldPatternPrefs = mainPrefsNode.node("logic/labelpattern");
for (String key : oldPatternPrefs.keys()) {
keyPattern.addBibtexKeyPattern(key, oldPatternPrefs.get(key, null));
}
prefs.putKeyPattern(keyPattern);
migrateTypedKeyPrefs(prefs, mainPrefsNode.node("logic/labelpattern"));
} else if (mainPrefsNode.nodeExists("logic/labelPattern")) { // node used for version 3.0-3.2
migrateTypedKeyPrefs(prefs, mainPrefsNode.node("logic/labelPattern"));
} else if (mainPrefsNode.nodeExists("labelPattern")) { // node used for version <3.0
migrateTypedKeyPrefs(prefs, mainPrefsNode.node("labelPattern"));
}
} catch (BackingStoreException e) {
LOGGER.error("Migrating old bibtexKeyPatterns failed.", e);
}
}

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

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ public class JabRefPreferences {
private static final String CUSTOM_TYPE_PRIOPT = "customTypePriOpt_";

// Prefs node for BibtexKeyPatterns
private static final String BIBTEX_KEY_PATTERNS_NODE = "bibtexkeypatterns";
public static final String BIBTEX_KEY_PATTERNS_NODE = "bibtexkeypatterns";

public String WRAPPED_USERNAME;
public final String MARKING_WITH_NUMBER_PATTERN;
Expand Down

0 comments on commit f63c458

Please sign in to comment.