Skip to content

Commit e5a630a

Browse files
feat/IDE-712_populate-the-tree-view-with-publish-diagnostics-data-from-IaC,-Open-Source-and-Code,-using-a-local-cache (#215)
* chore: wip * fix: add info nodes for no issues found and no fixable issues found * fix: tests * feat: add initial tree filling impl * feat: display info nodes * feat: add generic filter method to cache * feat: show view when scanning
1 parent a460b03 commit e5a630a

12 files changed

Lines changed: 939 additions & 255 deletions

File tree

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,28 @@
11
package io.snyk.eclipse.plugin.domain;
22

3+
import java.util.Map;
4+
35
public interface ProductConstants {
4-
public static final String OSS = "oss";
5-
public static final String CODE = "code";
6-
public static final String IAC = "iac";
6+
String SCAN_STATE_IN_PROGRESS="inProgress";
7+
String SCAN_STATE_SUCCESS="success";
8+
String SCAN_STATE_ERROR="error";
9+
10+
String SCAN_PARAMS_OSS = "oss";
11+
String SCAN_PARAMS_CODE = "code";
12+
String SCAN_PARAMS_IAC = "iac";
13+
14+
String DIAGNOSTIC_SOURCE_SNYK_OSS = "Snyk Open Source";
15+
String DIAGNOSTIC_SOURCE_SNYK_CODE = "Snyk Code";
16+
String DIAGNOSTIC_SOURCE_SNYK_IAC = "Snyk Infrastructure";
17+
18+
String DISPLAYED_OSS = "Snyk Open Source";
19+
String DISPLAYED_CODE_SECURITY = "Code Security";
20+
String DISPLAYED_CODE_QUALITY = "Code Quality";
21+
String DISPLAYED_IAC = "Configuration";
22+
23+
Map<String, String> LSP_SOURCE_TO_SCAN_PARAMS = Map.of(DIAGNOSTIC_SOURCE_SNYK_CODE, SCAN_PARAMS_CODE,
24+
DIAGNOSTIC_SOURCE_SNYK_IAC, SCAN_PARAMS_IAC, DIAGNOSTIC_SOURCE_SNYK_OSS, SCAN_PARAMS_OSS);
25+
26+
// code cannot be mapped easily
27+
Map<String, String> SCAN_PARAMS_TO_DISPLAYED = Map.of(SCAN_PARAMS_OSS, DISPLAYED_OSS, SCAN_PARAMS_IAC, DISPLAYED_IAC);
728
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package io.snyk.eclipse.plugin.views.snyktoolview;
2+
3+
import java.util.ArrayList;
4+
import java.util.Arrays;
5+
import java.util.List;
6+
import java.util.stream.Collectors;
7+
8+
import org.eclipse.jface.resource.ImageDescriptor;
9+
import org.eclipse.jface.viewers.TreeNode;
10+
11+
public class BaseTreeNode extends TreeNode {
12+
private ImageDescriptor imageDescriptor;
13+
private String text = "";
14+
15+
public BaseTreeNode(Object value) {
16+
super(value);
17+
if (value instanceof String)
18+
this.text = value.toString();
19+
}
20+
21+
public void setValue(Object value) {
22+
this.value = value;
23+
}
24+
25+
public void addChild(BaseTreeNode child) {
26+
TreeNode[] children = getChildren();
27+
List<BaseTreeNode> list = new ArrayList<BaseTreeNode>();
28+
if (children != null) {
29+
var previousList = Arrays.asList(children).stream().map(it -> (BaseTreeNode) it)
30+
.collect(Collectors.toList());
31+
32+
list = new ArrayList<BaseTreeNode>(previousList);
33+
}
34+
list.add(child);
35+
this.setChildren(list.toArray(new BaseTreeNode[list.size()]));
36+
}
37+
38+
public void removeChildren() {
39+
setChildren(new BaseTreeNode[0]);
40+
}
41+
42+
public void setImageDescriptor(ImageDescriptor imageDescriptor) {
43+
this.imageDescriptor = imageDescriptor;
44+
}
45+
46+
public ImageDescriptor getImageDescriptor() {
47+
return this.imageDescriptor;
48+
}
49+
50+
public String getText() {
51+
return this.text;
52+
}
53+
54+
public void setText(String text) {
55+
this.text = text;
56+
}
57+
58+
@Override
59+
public String toString() {
60+
return this.value.toString();
61+
}
62+
63+
public void reset() {
64+
this.removeChildren();
65+
this.text = "";
66+
this.value = null;
67+
this.imageDescriptor = null;
68+
}
69+
70+
}
Lines changed: 76 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,89 @@
11
package io.snyk.eclipse.plugin.views.snyktoolview;
22

33
import org.eclipse.jface.resource.ImageDescriptor;
4-
import org.eclipse.jface.viewers.TreeNode;
54

5+
/**
6+
* This interface captures the externally used methods with the tool window.
7+
* Having it, should allow for easier testing of the business logic apart from
8+
* UI.
9+
*/
610
public interface ISnykToolView {
7-
abstract void setNodeText(TreeNode node, String text);
11+
String CONGRATS_NO_ISSUES_FOUND = "✅ Congrats! No issues found!";
12+
String NO_FIXABLE_ISSUES = "There are no issues automatically fixable.";
13+
String IGNORED_ISSUES_FILTERED_BUT_AVAILABLE = "Adjust your Issue View Options to see ignored issues.";
14+
String OPEN_ISSUES_FILTERED_BUT_AVAILABLE = "Adjust your Issue View Options to open issues.";
15+
16+
String NODE_TEXT_SCANNING = "Scanning...";
17+
String NODE_TEXT_NO_ISSUES_FOUND = "No issues found";
18+
String NODE_TEXT_EROR = "An error occurred";
819

20+
/**
21+
* Updates the text of the given node
22+
*
23+
* @param node
24+
* @param text
25+
*/
26+
abstract void setNodeText(BaseTreeNode node, String text);
27+
28+
/**
29+
* Sets the icon of the given node
30+
*
31+
* @param icon
32+
*/
933
abstract void setNodeIcon(ImageDescriptor icon);
1034

11-
abstract void addIssueNode(TreeNode parent, TreeNode toBeAdded);
35+
/**
36+
* Adds an issue node to the parent (usually a file node)
37+
*
38+
* @param parent
39+
* @param toBeAdded
40+
*/
41+
abstract void addIssueNode(BaseTreeNode parent, BaseTreeNode toBeAdded);
42+
43+
/**
44+
* Adds a file node (usually below the product node)
45+
*
46+
* @param parent
47+
* @param toBeAdded
48+
*/
49+
abstract void addFileNode(BaseTreeNode parent, BaseTreeNode toBeAdded);
50+
51+
/**
52+
* Adds an info node (usually below the product node)
53+
*
54+
* @param parent
55+
* @param toBeAdded
56+
*/
57+
abstract void addInfoNode(BaseTreeNode parent, BaseTreeNode toBeAdded);
1258

13-
abstract void addFileNode(TreeNode parent, TreeNode toBeAdded);
59+
/**
60+
* Returns the product node
61+
*
62+
* @param product the product. ProductConstants#DISPLAY_*
63+
* @return
64+
*/
65+
abstract BaseTreeNode getProductNode(String product);
66+
67+
/**
68+
* Resets a product node
69+
*/
70+
abstract void resetNode(BaseTreeNode node);
1471

15-
abstract void addInfoNode(TreeNode parent, TreeNode toBeAdded);
1672

17-
abstract TreeNode getProductNode(String product);
73+
/**
74+
* Refreshes the tree display
75+
*/
76+
abstract void refreshTree();
77+
78+
/**
79+
* Returns the tree root
80+
*
81+
* @return
82+
*/
83+
abstract BaseTreeNode getRoot();
1884

19-
abstract TreeNode getRoot();
85+
static String getPlural(long count) {
86+
return count > 1 ? "s" : "";
87+
}
88+
2089
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package io.snyk.eclipse.plugin.views.snyktoolview;
2+
3+
import org.eclipse.jface.resource.ImageDescriptor;
4+
5+
import io.snyk.eclipse.plugin.Activator;
6+
import io.snyk.eclipse.plugin.domain.ProductConstants;
7+
8+
public class ProductTreeNode extends BaseTreeNode {
9+
public static final ImageDescriptor OSS = Activator.getImageDescriptor("/icons/oss.png");
10+
public static final ImageDescriptor CODE = Activator.getImageDescriptor("/icons/code.png");
11+
public static final ImageDescriptor IAC = Activator.getImageDescriptor("/icons/iac.png");
12+
13+
private String product;
14+
15+
public ProductTreeNode(Object value) {
16+
super(value);
17+
this.setProduct(value.toString());
18+
19+
switch (value.toString()) {
20+
case ProductConstants.DISPLAYED_OSS:
21+
setImageDescriptor(OSS);
22+
break;
23+
case ProductConstants.DISPLAYED_IAC:
24+
setImageDescriptor(IAC);
25+
break;
26+
case ProductConstants.DISPLAYED_CODE_QUALITY:
27+
setImageDescriptor(CODE);
28+
break;
29+
case ProductConstants.DISPLAYED_CODE_SECURITY:
30+
setImageDescriptor(CODE);
31+
break;
32+
}
33+
}
34+
35+
36+
37+
@Override
38+
public void setText(String text) {
39+
this.setValue(text);
40+
}
41+
42+
43+
44+
@Override
45+
public void setValue(Object value) {
46+
if (!(value instanceof String)) throw new IllegalArgumentException("value of product node must be a string");
47+
var cleanedValue = removePrefix(value.toString());
48+
49+
// we don't want to override the product text
50+
if (!cleanedValue.isBlank()) {
51+
cleanedValue = product + " - " + cleanedValue;
52+
} else {
53+
cleanedValue = product;
54+
}
55+
super.setText(cleanedValue);
56+
super.setValue(cleanedValue);
57+
}
58+
59+
private String removePrefix(String value) {
60+
var cleanedValue = value.toString();
61+
cleanedValue = cleanedValue.replace(product, "");
62+
return cleanedValue.replace(" - ", "");
63+
}
64+
65+
@Override
66+
public void reset() {
67+
this.removeChildren();
68+
this.setValue(product);
69+
}
70+
71+
72+
73+
public String getProduct() {
74+
return product;
75+
}
76+
77+
78+
79+
public void setProduct(String product) {
80+
this.product = product;
81+
}
82+
}
Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
11
package io.snyk.eclipse.plugin.views.snyktoolview;
22

3-
import org.eclipse.jface.viewers.TreeNode;
3+
import static io.snyk.eclipse.plugin.domain.ProductConstants.DISPLAYED_CODE_QUALITY;
4+
import static io.snyk.eclipse.plugin.domain.ProductConstants.DISPLAYED_CODE_SECURITY;
5+
import static io.snyk.eclipse.plugin.domain.ProductConstants.DISPLAYED_IAC;
6+
import static io.snyk.eclipse.plugin.domain.ProductConstants.DISPLAYED_OSS;
47

5-
public class RootNode extends TreeNode {
6-
public static final String CONFIGURATION = "Configuration";
7-
public static final String CODE_SECURITY = "Code Security";
8-
public static final String OPEN_SOURCE = "Open Source";
9-
public static final String CODE_QUALITY = "Code Quality";
10-
private TreeNode ossRootNode;
11-
private TreeNode codeSecurityRootNode;
12-
private TreeNode codeQualityRootNode;
13-
private TreeNode iacRootNode;
8+
public class RootNode extends BaseTreeNode {
9+
private BaseTreeNode ossRootNode;
10+
private BaseTreeNode codeSecurityRootNode;
11+
private BaseTreeNode codeQualityRootNode;
12+
private BaseTreeNode iacRootNode;
1413

1514
public RootNode() {
1615
super("");
1716

18-
ossRootNode = new TreeNode(OPEN_SOURCE);
19-
codeSecurityRootNode = new TreeNode(CODE_SECURITY);
20-
codeQualityRootNode = new TreeNode(CODE_QUALITY);
21-
iacRootNode = new TreeNode(CONFIGURATION);
17+
ossRootNode = new ProductTreeNode(DISPLAYED_OSS);
18+
codeSecurityRootNode = new ProductTreeNode(DISPLAYED_CODE_SECURITY);
19+
codeQualityRootNode = new ProductTreeNode(DISPLAYED_CODE_QUALITY);
20+
iacRootNode = new ProductTreeNode(DISPLAYED_IAC);
2221

23-
TreeNode[] children = new TreeNode[] { ossRootNode, codeSecurityRootNode, codeQualityRootNode, iacRootNode, };
22+
BaseTreeNode[] children = new BaseTreeNode[] { ossRootNode, codeSecurityRootNode, codeQualityRootNode, iacRootNode, };
2423
setChildren(children);
2524
}
26-
}
25+
}

0 commit comments

Comments
 (0)