File tree Expand file tree Collapse file tree 3 files changed +18
-13
lines changed
plugin/src/main/java/io/snyk/eclipse/plugin
tests/src/test/java/io/snyk/eclipse/plugin/properties/preferences Expand file tree Collapse file tree 3 files changed +18
-13
lines changed Original file line number Diff line number Diff line change 1313import io .snyk .languageserver .LsRuntimeEnvironment ;
1414
1515public 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}
Original file line number Diff line number Diff line change 11package io .snyk .eclipse .plugin .properties ;
22
33import java .nio .file .Path ;
4+ import java .nio .file .Paths ;
45import java .util .ArrayList ;
56import java .util .Arrays ;
67import 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 );
Original file line number Diff line number Diff line change 44
55public 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}
You can’t perform that action at this time.
0 commit comments