Skip to content

feat: add handlers and refactor handler logic [IDE-782] #247

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

Merged
merged 6 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 8 additions & 28 deletions plugin/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
</extension>
<extension point="org.eclipse.ui.commands">
<command
defaultHandler="io.snyk.eclipse.plugin.views.MenuHandler"
defaultHandler="io.snyk.eclipse.plugin.views.ScanWorkspaceFolderHandler"
id="io.snyk.eclipse.plugin.commands.execute"
name="%command.name">
</command>
Expand Down Expand Up @@ -102,7 +102,7 @@
</command>
<command
id="io.snyk.eclipse.plugin.commands.enableIAC"
name="Infrastructure as Code"
name="Configuration"
defaultHandler="io.snyk.eclipse.plugin.views.snyktoolview.handlers.EnableIacProductHandler">
</command>
<command
Expand Down Expand Up @@ -133,28 +133,18 @@
<command
defaultHandler="io.snyk.eclipse.plugin.views.snyktoolview.handlers.FilterFixableIssuesHandler"
id="io.snyk.eclipse.plugin.commands.snykFilterFixableIssues"
name="AI Fixable">
</command>
<command
defaultHandler="io.snyk.eclipse.plugin.views.snyktoolview.handlers.FilterOssFixableIssuesHandler"
id="io.snyk.eclipse.plugin.commands.snykFilterOssFixableIssues"
name="Fixable">
</command>
<command
defaultHandler="io.snyk.eclipse.plugin.views.snyktoolview.handlers.EnableAllAiFixHandler"
id="io.snyk.eclipse.plugin.snykShowAllSeverities"
defaultHandler="io.snyk.eclipse.plugin.views.snyktoolview.handlers.EnableAllSeveritiesHandler"
id="io.snyk.eclipse.plugin.commands.snykShowAllSeverities"
name="Show All Severities">
</command>
<command
defaultHandler="io.snyk.eclipse.plugin.views.snyktoolview.handlers.EnableAllProductHandler"
id="io.snyk.eclipse.plugin.command.snykShowAllProducts"
name="Show All Products">
</command>
<command
defaultHandler="io.snyk.eclipse.plugin.views.snyktoolview.handlers.EnableAllIssuesHandler"
id="io.snyk.eclipse.plugin.command.snykShowAllIssuesStatus"
name="Show All Issues">
</command>
</extension>
<extension point="org.eclipse.ui.menus">
<menuContribution
Expand Down Expand Up @@ -284,7 +274,7 @@
visible="true">
</separator>
<command
commandId="io.snyk.eclipse.plugin.snykShowAllSeverities"
commandId="io.snyk.eclipse.plugin.commands.snykShowAllSeverities"
icon="icons/enabled.png"
style="push"
tooltip="Show Issues of all Severities">
Expand Down Expand Up @@ -351,23 +341,13 @@
</command>
</menu>
<menu
id="io.snyk.eclipse.plugin.views.snyktoolview.filtersAiFixMenu"
label="Open Source Fixability">
<command
commandId="io.snyk.eclipse.plugin.commands.snykFilterOssFixableIssues"
icon="icons/enabled.png"
style="push"
tooltip="Show only issues with Open Source Upgrade suggestions">
</command>
</menu>
<menu
id="io.snyk.eclipse.plugin.views.snyktoolview.filtersOssMenu"
label="Code AI Fixability">
id="io.snyk.eclipse.plugin.views.snyktoolview.filtersFixability"
label="Fixability">
<command
commandId="io.snyk.eclipse.plugin.commands.snykFilterFixableIssues"
icon="icons/enabled.png"
style="push"
tooltip="Show only issues with AIFix or Fix suggestions">
tooltip="Show only issues that can be automatically fixed">
</command>
</menu>
</menuContribution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,14 @@ public static synchronized Preferences getInstance(PreferenceStore store) {
public static final String LSP_VERSION = "LSP_VERSION";
public static final String USE_TOKEN_AUTH = "useTokenAuth";
public static final String ANALYTICS_PLUGIN_INSTALLED_SENT = "analyticsPluginInstalledSent";
public static final String FILTER_CRITICAL = "FILTER_SNYK_CRITICAL";
public static final String FILTER_HIGH = "FILTER_SNYK_HIGH";
public static final String FILTER_MEDIUM = "FILTER_SNYK_MEDIUM";
public static final String FILTER_LOW = "FILTER_SNYK_LOW";
public static final String FILTER_DELTA_NEW_ISSUES = "FILTER_SNYK_NEW_ISSUES";
public static final String FILTER_SHOW_CRITICAL = "FILTER_SNYK_CRITICAL";
public static final String FILTER_SHOW_HIGH = "FILTER_SNYK_HIGH";
public static final String FILTER_SHOW_MEDIUM = "FILTER_SNYK_MEDIUM";
public static final String FILTER_SHOW_LOW = "FILTER_SNYK_LOW";
public static final String ENABLE_DELTA = "FILTER_SNYK_NEW_ISSUES";
public static final String FILTER_IGNORES_SHOW_OPEN_ISSUES = "FILTER_IGNORES_OPEN_ISSUES";
public static final String FILTER_IGNORES_SHOW_IGNORED_ISSUES = "FILTER_IGNORES_IGNORED_ISSUES";
public static final String FILTER_FIXABLE_ISSUES = "FILTER_FIXABLE_ISSUES";
public static final String FILTER_OSS_FIXABLE_ISSUES = "FILTER_OSS_FIXABLE_ISSUES";

// Feature flags
public static final String IS_GLOBAL_IGNORES_FEATURE_ENABLED = "IS_GLOBAL_IGNORES_FEATURE_ENABLED";
Expand Down Expand Up @@ -87,33 +86,30 @@ public static synchronized Preferences getInstance(PreferenceStore store) {
if (getPref(ACTIVATE_SNYK_IAC) == null) {
store(ACTIVATE_SNYK_IAC, "true");
}
if (getPref(FILTER_CRITICAL) == null) {
store(FILTER_CRITICAL, "false");
if (getPref(FILTER_SHOW_CRITICAL) == null) {
store(FILTER_SHOW_CRITICAL, "true");
}
if (getPref(FILTER_HIGH) == null) {
store(FILTER_HIGH, "false");
if (getPref(FILTER_SHOW_HIGH) == null) {
store(FILTER_SHOW_HIGH, "true");
}
if (getPref(FILTER_MEDIUM) == null) {
store(FILTER_MEDIUM, "false");
if (getPref(FILTER_SHOW_MEDIUM) == null) {
store(FILTER_SHOW_MEDIUM, "true");
}
if (getPref(FILTER_LOW) == null) {
store(FILTER_LOW, "false");
if (getPref(FILTER_SHOW_LOW) == null) {
store(FILTER_SHOW_LOW, "true");
}
if (getPref(FILTER_DELTA_NEW_ISSUES) == null) {
store(FILTER_DELTA_NEW_ISSUES, "false");
if (getPref(ENABLE_DELTA) == null) {
store(ENABLE_DELTA, "false");
}
if (getPref(FILTER_IGNORES_SHOW_OPEN_ISSUES) == null) {
store(FILTER_IGNORES_SHOW_OPEN_ISSUES, "true");
}
if (getPref(FILTER_IGNORES_SHOW_IGNORED_ISSUES) == null) {
store(FILTER_IGNORES_SHOW_IGNORED_ISSUES, "true");
store(FILTER_IGNORES_SHOW_IGNORED_ISSUES, "false");
}
if (getPref(FILTER_FIXABLE_ISSUES) == null) {
store(FILTER_FIXABLE_ISSUES, "false");
}
if (getPref(FILTER_OSS_FIXABLE_ISSUES) == null) {
store(FILTER_OSS_FIXABLE_ISSUES, "false");
}

if (getPref(SEND_ERROR_REPORTS) == null) {
store(SEND_ERROR_REPORTS, "true");
Expand Down Expand Up @@ -262,7 +258,7 @@ public boolean isTest() {
}

public static boolean isDeltaEnabled() {
return Preferences.getInstance().getBooleanPref(Preferences.FILTER_DELTA_NEW_ISSUES);
return Preferences.getInstance().getBooleanPref(Preferences.ENABLE_DELTA);
}

public static void setCurrentPreferences(Preferences prefs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import io.snyk.eclipse.plugin.utils.ResourceUtils;
import io.snyk.languageserver.protocolextension.SnykExtendedLanguageClient;

public class MenuHandler extends AbstractHandler {
public class ScanWorkspaceFolderHandler extends AbstractHandler {

@SuppressWarnings("restriction")
public Object execute(ExecutionEvent event) throws ExecutionException {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
package io.snyk.eclipse.plugin.views.snyktoolview;

import static io.snyk.eclipse.plugin.preferences.Preferences.FILTER_FIXABLE_ISSUES;
import static io.snyk.eclipse.plugin.preferences.Preferences.FILTER_IGNORES_SHOW_IGNORED_ISSUES;
import static io.snyk.eclipse.plugin.preferences.Preferences.FILTER_IGNORES_SHOW_OPEN_ISSUES;
import static io.snyk.eclipse.plugin.preferences.Preferences.FILTER_SHOW_CRITICAL;
import static io.snyk.eclipse.plugin.preferences.Preferences.FILTER_SHOW_HIGH;
import static io.snyk.eclipse.plugin.preferences.Preferences.FILTER_SHOW_LOW;
import static io.snyk.eclipse.plugin.preferences.Preferences.FILTER_SHOW_MEDIUM;

import java.util.function.Predicate;

import org.eclipse.jface.viewers.TreeViewer;

import io.snyk.eclipse.plugin.SnykStartup;
import io.snyk.eclipse.plugin.preferences.Preferences;
import io.snyk.eclipse.plugin.views.snyktoolview.filters.FixableFilter;
import io.snyk.eclipse.plugin.views.snyktoolview.filters.IgnoresFilter;
import io.snyk.eclipse.plugin.views.snyktoolview.filters.IgnoresOpenIssuesFilter;
import io.snyk.eclipse.plugin.views.snyktoolview.filters.OssFixableFilter;
import io.snyk.eclipse.plugin.views.snyktoolview.filters.SeverityCriticalFilter;
import io.snyk.eclipse.plugin.views.snyktoolview.filters.SeverityHighFilter;
import io.snyk.eclipse.plugin.views.snyktoolview.filters.SeverityLowFilter;
import io.snyk.eclipse.plugin.views.snyktoolview.filters.SeverityMediumFilter;
import io.snyk.eclipse.plugin.views.snyktoolview.filters.SeverityFilter;
import io.snyk.languageserver.protocolextension.messageObjects.scanResults.Issue;

public class TreeFilterManager {
Expand All @@ -27,38 +30,32 @@ public synchronized static TreeFilterManager getInstance() {
return filterManager;
}
filterManager = new TreeFilterManager();

setupFilters();
return filterManager;
}

private static void setupFilters() {
// Severity filters
new SeverityCriticalFilter(TreeFilterManager.getInstance(), Preferences.getInstance(),
Preferences.FILTER_CRITICAL).applyFilter();
new SeverityHighFilter(TreeFilterManager.getInstance(), Preferences.getInstance(), Preferences.FILTER_HIGH)
.applyFilter();
new SeverityMediumFilter(TreeFilterManager.getInstance(), Preferences.getInstance(), Preferences.FILTER_MEDIUM)
.applyFilter();
new SeverityLowFilter(TreeFilterManager.getInstance(), Preferences.getInstance(), Preferences.FILTER_LOW)
.applyFilter();
new SeverityFilter(FILTER_SHOW_CRITICAL).applyFilter();
new SeverityFilter(FILTER_SHOW_HIGH).applyFilter();
new SeverityFilter(FILTER_SHOW_MEDIUM).applyFilter();
new SeverityFilter(FILTER_SHOW_LOW).applyFilter();

// Ignores filters
new IgnoresFilter(TreeFilterManager.getInstance(), Preferences.getInstance(),
Preferences.FILTER_IGNORES_SHOW_IGNORED_ISSUES).applyFilter();
new IgnoresOpenIssuesFilter(TreeFilterManager.getInstance(), Preferences.getInstance(),
Preferences.FILTER_IGNORES_SHOW_OPEN_ISSUES).applyFilter();
new IgnoresFilter(FILTER_IGNORES_SHOW_IGNORED_ISSUES).applyFilter();
new IgnoresOpenIssuesFilter(FILTER_IGNORES_SHOW_OPEN_ISSUES).applyFilter();

// Fix
new FixableFilter(TreeFilterManager.getInstance(), Preferences.getInstance(), Preferences.FILTER_FIXABLE_ISSUES)
.applyFilter();
new OssFixableFilter(TreeFilterManager.getInstance(), Preferences.getInstance(),
Preferences.FILTER_OSS_FIXABLE_ISSUES).applyFilter();
new FixableFilter(FILTER_FIXABLE_ISSUES).applyFilter();
}

private TreeFilterManager() {
public void reset() {
treeView = SnykStartup.getView().getTreeViewer();
filter = new TreeViewerFilter();
setupFilters();
}

private TreeFilterManager() {
reset();
}

public void addTreeFilter(String filterName, Predicate<? super Issue> filterPredicate) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
package io.snyk.eclipse.plugin.views.snyktoolview.filters;

public interface BaseFilter {
public void applyFilter();
import java.util.function.Predicate;

import io.snyk.eclipse.plugin.preferences.Preferences;
import io.snyk.eclipse.plugin.views.snyktoolview.TreeFilterManager;

@SuppressWarnings("rawtypes")
public abstract class BaseFilter {
private TreeFilterManager filterManager;
private Preferences preferences;
protected String preferenceKey;
protected Predicate predicate;

public BaseFilter(String preferenceKey, Predicate predicate) {
this.preferenceKey = preferenceKey;
this.predicate = predicate;
}

@SuppressWarnings("unchecked")
public void applyFilter() {
boolean booleanPref = this.preferences.getBooleanPref(this.preferenceKey);

if (booleanPref) {
this.filterManager.addTreeFilter(this.preferenceKey, predicate);
} else {
this.filterManager.removeTreeFilter(this.preferenceKey);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,13 @@
package io.snyk.eclipse.plugin.views.snyktoolview.filters;

import io.snyk.eclipse.plugin.preferences.Preferences;
import io.snyk.eclipse.plugin.views.snyktoolview.TreeFilterManager;
import java.util.function.Predicate;

public class FixableFilter implements BaseFilter {
private TreeFilterManager filterManager;
private Preferences preferences;
private String preferenceKey;
import io.snyk.languageserver.protocolextension.messageObjects.scanResults.Issue;

public FixableFilter(TreeFilterManager filterManager, Preferences preferences, String preferenceKey) {
this.filterManager = filterManager;
this.preferences = preferences;
this.preferenceKey = preferenceKey;

}

@Override
public void applyFilter() {
boolean booleanPref = this.preferences.getBooleanPref(this.preferenceKey);

if (booleanPref) {
this.filterManager.addTreeFilter(this.preferenceKey, issue -> issue.hasFix());
} else {
this.filterManager.removeTreeFilter(this.preferenceKey);
}
public class FixableFilter extends BaseFilter {
private static final Predicate<Issue> predicate = issue -> issue.hasFix();

public FixableFilter(String preferenceKey) {
super(preferenceKey, predicate);
}
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,14 @@
package io.snyk.eclipse.plugin.views.snyktoolview.filters;

import io.snyk.eclipse.plugin.preferences.Preferences;
import io.snyk.eclipse.plugin.views.snyktoolview.TreeFilterManager;
import java.util.function.Predicate;

public class IgnoresFilter implements BaseFilter {
private TreeFilterManager filterManager;
private Preferences preferences;
private String preferenceKey;
import io.snyk.languageserver.protocolextension.messageObjects.scanResults.Issue;

public IgnoresFilter(TreeFilterManager filterManager, Preferences preferences, String preferenceKey) {
this.filterManager = filterManager;
this.preferences = preferences;
this.preferenceKey = preferenceKey;
}

@Override
public void applyFilter() {
boolean booleanPref = this.preferences.getBooleanPref(this.preferenceKey);

if (booleanPref) {
filterManager.removeTreeFilter(preferenceKey);
} else {
filterManager.addTreeFilter(preferenceKey, issue -> !issue.isIgnored());
public class IgnoresFilter extends BaseFilter {
private static final Predicate<Issue> predicate = issue -> issue.isIgnored();


public IgnoresFilter(String preferenceKey) {
super(preferenceKey, predicate);
}

}
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,16 @@
package io.snyk.eclipse.plugin.views.snyktoolview.filters;

import java.util.function.Predicate;

import io.snyk.eclipse.plugin.preferences.Preferences;
import io.snyk.eclipse.plugin.views.snyktoolview.TreeFilterManager;
import io.snyk.languageserver.protocolextension.messageObjects.scanResults.Issue;

public class IgnoresOpenIssuesFilter implements BaseFilter {
private TreeFilterManager filterManager;
private Preferences preferences;
private String preferenceKey;

public IgnoresOpenIssuesFilter(TreeFilterManager filterManager, Preferences preferences, String preferenceKey) {
this.filterManager = filterManager;
this.preferences = preferences;
this.preferenceKey = preferenceKey;
}

@Override
public void applyFilter() {
boolean booleanPref = this.preferences.getBooleanPref(Preferences.FILTER_IGNORES_SHOW_OPEN_ISSUES);

if (booleanPref) {
filterManager.removeTreeFilter(preferenceKey);
} else {
filterManager.addTreeFilter(preferenceKey, issue -> issue.isIgnored());
}
public class IgnoresOpenIssuesFilter extends BaseFilter {
// FIXME think about what happens if this and ignores are both set
private static final Predicate<Issue> predicate = issue -> !issue.isIgnored();

public IgnoresOpenIssuesFilter(String preferenceKey) {
super(preferenceKey, predicate);
}
}
Loading
Loading