Skip to content

Commit 7fae197

Browse files
chore: adjust preference visibility, use setter (#245)
1 parent f03f218 commit 7fae197

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

plugin/src/main/java/io/snyk/eclipse/plugin/preferences/Preferences.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@
1313
import io.snyk.languageserver.LsRuntimeEnvironment;
1414

1515
public class Preferences {
16-
public static Preferences CURRENT_PREFERENCES;
17-
public static LsRuntimeEnvironment LS_RUNTIME_ENV = new LsRuntimeEnvironment();
16+
private static Preferences CURRENT_PREFERENCES;
17+
private static LsRuntimeEnvironment LS_RUNTIME_ENV = new LsRuntimeEnvironment();
1818

1919
public static synchronized Preferences getInstance() {
2020
if (CURRENT_PREFERENCES == null) {
21-
CURRENT_PREFERENCES = new Preferences(new SecurePreferenceStore());
21+
setCurrentPreferences(new Preferences(new SecurePreferenceStore()));
2222
}
2323
return CURRENT_PREFERENCES;
2424
}
2525

2626
public static synchronized Preferences getInstance(PreferenceStore store) {
2727
Preferences preferences = new Preferences(store);
28-
CURRENT_PREFERENCES = preferences;
28+
setCurrentPreferences(preferences);
2929
return preferences;
3030
}
3131

@@ -265,4 +265,8 @@ public static boolean isDeltaEnabled() {
265265
return Preferences.getInstance().getBooleanPref(Preferences.FILTER_DELTA_NEW_ISSUES);
266266
}
267267

268+
public static void setCurrentPreferences(Preferences prefs) {
269+
CURRENT_PREFERENCES = prefs;
270+
}
271+
268272
}

plugin/src/main/java/io/snyk/eclipse/plugin/properties/FolderConfigs.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.snyk.eclipse.plugin.properties;
22

33
import java.nio.file.Path;
4+
import java.nio.file.Paths;
45
import java.util.ArrayList;
56
import java.util.Arrays;
67
import java.util.List;
@@ -35,12 +36,8 @@ public static synchronized FolderConfigs getInstance() {
3536
}
3637

3738
public void addFolderConfig(FolderConfig folderConfig) {
38-
instancePreferences.put(folderConfig.getFolderPath(), gson.toJson(folderConfig));
39-
try {
40-
instancePreferences.flush();
41-
} catch (Exception e) {
42-
SnykLogger.logError(e);
43-
}
39+
var folderPath = Paths.get(folderConfig.getFolderPath());
40+
persist(folderPath, folderConfig);
4441
}
4542

4643
public List<String> getLocalBranches(Path projectPath) {
@@ -94,7 +91,11 @@ public FolderConfigsParam updateFolderConfigs() {
9491
return param;
9592
}
9693

97-
// returns null if nothing found
94+
/**
95+
* Gets folder config for given path, if none exists it is created with defaults and returned
96+
* @param folderPath the path of the folder (usually the project)
97+
* @return a folder config (always)
98+
*/
9899
public FolderConfig getFolderConfig(Path folderPath) {
99100
Path path = folderPath.normalize();
100101
String json = instancePreferences.get(path.toString(), null);

tests/src/test/java/io/snyk/eclipse/plugin/properties/preferences/PreferencesUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
public abstract class PreferencesUtils {
66
public static void setPreferences(Preferences p) {
7-
Preferences.CURRENT_PREFERENCES = p;
7+
Preferences.setCurrentPreferences(p);
88
}
99

1010
public static void reset() {
11-
Preferences.CURRENT_PREFERENCES = null;
11+
Preferences.setCurrentPreferences(null);
1212
}
1313
}

0 commit comments

Comments
 (0)