Skip to content

Commit 85eaabb

Browse files
feat: add riskScoreThreshold support to settings (#346)
* feat: add riskScoreThreshold support to settings Add riskScoreThreshold field to enable filtering issues by risk score. This fixes the same issue that was identified in the IntelliJ plugin where the riskScoreThreshold value was being lost. Changes: - Add RISK_SCORE_THRESHOLD constant to Preferences.java - Add riskScoreThreshold field to Settings.java - Update LsConfigurationUpdater to read and include riskScoreThreshold - Handle riskScoreThreshold in HTMLSettingsPreferencePage.parseAndSaveConfig() - Add tests for riskScoreThreshold handling * fix: add NOPMD suppression for empty catch block
1 parent b959eef commit 85eaabb

File tree

6 files changed

+42
-2
lines changed

6 files changed

+42
-2
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,14 @@ private void parseAndSaveConfig(String jsonString) {
276276
applyIfPresent(config, "enableDeltaFindings", value ->
277277
prefs.store(Preferences.ENABLE_DELTA, String.valueOf(value)));
278278

279+
applyIfPresent(config, "riskScoreThreshold", value -> {
280+
if (value instanceof Number) {
281+
prefs.store(Preferences.RISK_SCORE_THRESHOLD, String.valueOf(((Number) value).intValue()));
282+
} else {
283+
prefs.store(Preferences.RISK_SCORE_THRESHOLD, String.valueOf(value));
284+
}
285+
});
286+
279287
applyIfPresent(config, "cliPath", value ->
280288
prefs.store(Preferences.CLI_PATH, String.valueOf(value)));
281289
applyIfPresent(config, "manageBinariesAutomatically", value ->

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public class Preferences {
5858
public static final String LSP_VERSION = "LSP_VERSION";
5959
public static final String ANALYTICS_PLUGIN_INSTALLED_SENT = "analyticsPluginInstalledSent";
6060
public static final String ENABLE_DELTA = "ENABLE_DELTA";
61+
public static final String RISK_SCORE_THRESHOLD = "RISK_SCORE_THRESHOLD";
6162

6263
// all filter preferences are positive: SHOW = true, HIDE = false
6364
public static final String FILTER_SHOW_CRITICAL = "FILTER_SHOW_CRITICAL";
@@ -128,6 +129,7 @@ public static synchronized Preferences getTestInstance(IEclipsePreferences insec
128129
insecureStore.setDefault(FILTER_SHOW_MEDIUM, TRUE);
129130
insecureStore.setDefault(FILTER_SHOW_LOW, TRUE);
130131
insecureStore.setDefault(ENABLE_DELTA, FALSE);
132+
insecureStore.setDefault(RISK_SCORE_THRESHOLD, "0");
131133
insecureStore.setDefault(FILTER_IGNORES_SHOW_OPEN_ISSUES, TRUE);
132134
insecureStore.setDefault(FILTER_IGNORES_SHOW_IGNORED_ISSUES, FALSE);
133135
insecureStore.setDefault(FILTER_SHOW_ONLY_FIXABLE, FALSE);

plugin/src/main/java/io/snyk/languageserver/LsConfigurationUpdater.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,16 @@ Settings getCurrentSettings() {
6565

6666
String enableDeltaFindings = preferences.getPref(Preferences.ENABLE_DELTA, Boolean.FALSE.toString());
6767

68+
Integer riskScoreThreshold = null;
69+
String riskScoreThresholdStr = preferences.getPref(Preferences.RISK_SCORE_THRESHOLD, "0");
70+
try {
71+
int value = Integer.parseInt(riskScoreThresholdStr);
72+
if (value > 0) {
73+
riskScoreThreshold = value;
74+
}
75+
} catch (NumberFormatException e) { // NOPMD - invalid values default to null (no threshold)
76+
}
77+
6878
// only add folder configs that are initialized
6979
var folderConfigs = new ArrayList<FolderConfig>();
7080
for (var p : Collections.unmodifiableSet(FolderConfigs.LanguageServerConfigReceived)) {
@@ -81,6 +91,6 @@ Settings getCurrentSettings() {
8191
insecure, endpoint, additionalParams, additionalEnv, path, issueViewOptions, sendErrorReports,
8292
enableTelemetry, organization, manageBinariesAutomatically, cliPath, token, integrationName,
8393
integrationVersion, automaticAuthentication, trustedFolders, enableTrustedFolderFeature, scanningMode,
84-
enableDeltaFindings, authenticationMethod, folderConfigs, filterSeverity);
94+
enableDeltaFindings, riskScoreThreshold, authenticationMethod, folderConfigs, filterSeverity);
8595
}
8696
}

plugin/src/main/java/io/snyk/languageserver/protocolextension/messageObjects/Settings.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public class Settings {
3535
private final String osPlatform = SystemUtils.OS_NAME;
3636
private final String scanningMode;
3737
private final String enableDeltaFindings;
38+
private final Integer riskScoreThreshold;
3839
private final String requiredProtocolVersion = LsBinaries.REQUIRED_LS_PROTOCOL_VERSION;
3940
private final String authenticationMethod;
4041
private final List<FolderConfig> folderConfigs;
@@ -46,7 +47,8 @@ public Settings(String activateSnykOpenSource, String activateSnykCodeSecurity,
4647
String manageBinariesAutomatically, String cliPath, String token, String integrationName,
4748
String integrationVersion, String automaticAuthentication, String[] trustedFolders,
4849
String enableTrustedFoldersFeature, String scanningMode, String enableDeltaFindings,
49-
String authenticationMethod, List<FolderConfig> folderConfigs, FilterSeverity filterSeverity) {
50+
Integer riskScoreThreshold, String authenticationMethod, List<FolderConfig> folderConfigs,
51+
FilterSeverity filterSeverity) {
5052
this.activateSnykOpenSource = activateSnykOpenSource;
5153
this.activateSnykCodeSecurity = activateSnykCodeSecurity;
5254
this.activateSnykIac = activateSnykIac;
@@ -69,6 +71,7 @@ public Settings(String activateSnykOpenSource, String activateSnykCodeSecurity,
6971
this.enableTrustedFoldersFeature = enableTrustedFoldersFeature;
7072
this.scanningMode = scanningMode;
7173
this.enableDeltaFindings = enableDeltaFindings;
74+
this.riskScoreThreshold = riskScoreThreshold;
7275
this.authenticationMethod = authenticationMethod;
7376
this.folderConfigs = folderConfigs;
7477
this.filterSeverity = filterSeverity;
@@ -190,6 +193,10 @@ public String getEnableDeltaFindings() {
190193
return enableDeltaFindings;
191194
}
192195

196+
public Integer getRiskScoreThreshold() {
197+
return riskScoreThreshold;
198+
}
199+
193200
public FilterSeverity getFilterSeverity() {
194201
return filterSeverity;
195202
}

tests/src/test/java/io/snyk/eclipse/plugin/preferences/HTMLSettingsPreferencePageTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,15 @@ void parseAndSaveConfig_savesEnableDeltaFindings() throws Exception {
188188
assertEquals("true", prefs.getPref(Preferences.ENABLE_DELTA));
189189
}
190190

191+
@Test
192+
void parseAndSaveConfig_savesRiskScoreThreshold() throws Exception {
193+
String json = "{\"riskScoreThreshold\": 200}";
194+
195+
invokeParseAndSaveConfig(json);
196+
197+
assertEquals("200", prefs.getPref(Preferences.RISK_SCORE_THRESHOLD));
198+
}
199+
191200
@Test
192201
void parseAndSaveConfig_savesSendErrorReports() throws Exception {
193202
String json = "{\"sendErrorReports\": false}";

tests/src/test/java/io/snyk/languageserver/LsConfigurationUpdaterTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ void testGetSettings() {
7575
assertEquals(AuthConstants.AUTH_OAUTH2, settings.getAuthenticationMethod());
7676
assertEquals(LsBinaries.REQUIRED_LS_PROTOCOL_VERSION, settings.getRequiredProtocolVersion());
7777

78+
// Verify risk score threshold is included
79+
assertEquals(Integer.valueOf(200), settings.getRiskScoreThreshold());
80+
7881
// Verify filter severity is included
7982
assertNotNull(settings.getFilterSeverity());
8083
assertTrue(settings.getFilterSeverity().isCritical());
@@ -115,6 +118,7 @@ private void setupPreferenceMock() {
115118
when(preferenceMock.getPref(Preferences.AUTHENTICATION_METHOD, AuthConstants.AUTH_OAUTH2)).thenReturn("oauth");
116119
when(preferenceMock.getBooleanPref(Preferences.SCANNING_MODE_AUTOMATIC)).thenReturn(true);
117120
when(preferenceMock.getPref(Preferences.ENABLE_DELTA, Boolean.FALSE.toString())).thenReturn("true");
121+
when(preferenceMock.getPref(Preferences.RISK_SCORE_THRESHOLD, "0")).thenReturn("200");
118122

119123
// Severity filter mocks
120124
when(preferenceMock.getBooleanPref(Preferences.FILTER_SHOW_CRITICAL, true)).thenReturn(true);

0 commit comments

Comments
 (0)