Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Binary file modified bundle/icons/critical.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bundle/icons/criticalnotapplic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified bundle/icons/high.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bundle/icons/highnotapplic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified bundle/icons/low.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bundle/icons/lownotapplic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified bundle/icons/medium.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bundle/icons/mediumnotapplic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified bundle/icons/unknown.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bundle/icons/unknownnotapplic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 12 additions & 7 deletions bundle/src/main/java/com/jfrog/ide/eclipse/scan/ScanManager.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.jfrog.ide.eclipse.scan;

import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CancellationException;
Expand Down Expand Up @@ -32,7 +30,6 @@
* @author yahavi
*/
public class ScanManager {
static final Path HOME_PATH = Paths.get(System.getProperty("user.home"), ".jfrog-eclipse-plugin");
private static ScanManager instance;
private IProgressMonitor monitor;
private IWorkspace iworkspace;
Expand Down Expand Up @@ -177,10 +174,18 @@ public void run(IProgressMonitor monitor) throws CoreException {
log.info("Finished audit scan successfully.\n" + auditResults.getRes());
log.debug(auditResults.getErr());

log.debug("Updating scan cache.");
ScanCache.getInstance().updateScanResults(sarifParser.parse(auditResults.getRes()));

// TODO: update issues tree
log.debug("Updating scan results in UI.");
issuesTree.addScanResults(sarifParser.parse(auditResults.getRes()));
// update the issues tree in the UI with the scan results
parent.getDisplay().syncExec(new Runnable() {
@Override
public void run() {
if (monitor.isCanceled()) {
return;
}
issuesTree.showResultsOnTree();
}
});
}
} catch (CancellationException ce) {
log.info(ce.getMessage());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package com.jfrog.ide.eclipse.ui;

import java.util.List;
import javax.swing.tree.TreeNode;

import org.eclipse.jface.viewers.ITreeContentProvider;
import org.jfrog.build.extractor.scan.DependencyTree;

import com.jfrog.ide.common.nodes.FileIssueNode;
import com.jfrog.ide.common.nodes.FileTreeNode;

/**
* Content provider for DependenciesTree.
*
* @author yahavi
*/
public class ScanTreeContentProvider implements ITreeContentProvider {
private static final DependencyTree[] EMPTY_NODE = new DependencyTree[0];

@Override
public Object[] getElements(Object element) {
Expand All @@ -18,16 +22,38 @@ public Object[] getElements(Object element) {

@Override
public Object[] getChildren(Object element) {
return (((DependencyTree) element).getChildren()).toArray(EMPTY_NODE);
if (element instanceof FileTreeNode) {
List<TreeNode> children = ((FileTreeNode) element).getChildren();
return children.toArray();
} else if (element instanceof List) {
List<?> elementList = (List<?>) element;
// Verify the element is a List of FileTreeNode, then return its elements
if(!elementList.isEmpty() && elementList.get(0) instanceof FileTreeNode) {
return elementList.toArray();
}
}
return new Object[0];
}

@Override
public Object getParent(Object element) {
return ((DependencyTree) element).getParent();
if (element instanceof FileTreeNode) {
return ((FileTreeNode) element).getParent();
}
if (element instanceof FileIssueNode) {
return ((FileIssueNode) element).getParent();
}
return null;
}

@Override
public boolean hasChildren(Object element) {
return !((DependencyTree) element).isLeaf();
if (element instanceof FileTreeNode) {
return !((FileTreeNode) element).isLeaf();
}
if (element instanceof FileIssueNode) {
return ((FileIssueNode) element).isLeaf();
}
return false;
}
}
18 changes: 11 additions & 7 deletions bundle/src/main/java/com/jfrog/ide/eclipse/ui/SearchableTree.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.jfrog.ide.eclipse.ui;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
Expand All @@ -19,6 +20,7 @@
import org.jfrog.build.extractor.scan.DependencyTree;

import com.google.common.collect.Lists;
import com.jfrog.ide.common.nodes.FileTreeNode;
import com.jfrog.ide.eclipse.utils.ProjectsMap;

/**
Expand All @@ -28,9 +30,9 @@
*/
public abstract class SearchableTree extends FilteredTree {

protected ProjectsMap projects = new ProjectsMap();
protected ComponentDetails componentDetails;
private TreeColumnLayout treeLayout = new TreeColumnLayout();
protected ComponentDetails componentDetails;
protected List<FileTreeNode> scanResults = new ArrayList<FileTreeNode>();

public SearchableTree(Composite parent, ColumnLabelProvider labelProvider) {
super(parent, true);
Expand Down Expand Up @@ -106,14 +108,16 @@ public void expandAll() {
}

public void reset() {
projects.clear();
scanResults.clear();
}

public void addScanResults(String projectName, DependencyTree dependencyTree) {
projects.put(projectName, dependencyTree);
public void addScanResults(List<FileTreeNode> results) {
scanResults.addAll(results);
}

public void showResultsOnTree() {
treeViewer.setInput(scanResults);
}

public abstract void applyFilters(ProjectsMap.ProjectKey projectName);

public abstract void applyFiltersForAllProjects();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;

import com.jfrog.ide.eclipse.ui.actions.CollapseAll;
import com.jfrog.ide.eclipse.ui.actions.ExpandAll;
import com.jfrog.ide.eclipse.ui.actions.Filter;
Expand All @@ -14,18 +16,25 @@
public class XrayScanToolbar extends Panel {

private Filter filter;
private final int SPACER_WIDTH = 20;

public XrayScanToolbar(Composite parent) {
super(parent);
ToolBar toolBar = new ToolBar(this, SWT.NONE);
new Refresh(toolBar);
createSeparator(toolBar, SPACER_WIDTH);
new CollapseAll(toolBar);
createSeparator(toolBar, SPACER_WIDTH);
new ExpandAll(toolBar);
filter = new Filter(toolBar);
toolBar.pack();
}

public void setFilterType(Filter.FilterType filterType) {
filter.setFilterType(filterType);
}

private void createSeparator(ToolBar toolBar, int width) {
ToolItem sep = new ToolItem(toolBar, SWT.SEPARATOR);
sep.setWidth(width);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.widgets.Composite;
import org.jfrog.build.extractor.scan.DependencyTree;

import com.jfrog.ide.common.nodes.FileTreeNode;

/**
* The issues count component in the issues tree.
Expand All @@ -22,7 +23,10 @@ public IssueCountColumnLabelProvider(Composite parent) {

@Override
public String getText(Object element) {
int issueCount = ((DependencyTree) element).getIssueCount();
int issueCount = 0;
if (element instanceof FileTreeNode) {
issueCount = ((FileTreeNode) element).getChildCount();
}
return issueCount == 0 ? "" : "(" + issueCount + ")";
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
package com.jfrog.ide.eclipse.ui.issues;

import java.util.Map.Entry;
import java.util.ArrayList;

import org.eclipse.jface.viewers.TreeViewerColumn;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.jfrog.build.extractor.scan.DependencyTree;

import com.google.common.collect.Lists;
import com.jfrog.ide.common.filter.FilterManager;
import com.jfrog.ide.eclipse.ui.FilterManagerSingleton;
import com.jfrog.ide.common.nodes.FileTreeNode;
import com.jfrog.ide.eclipse.ui.SearchableTree;
import com.jfrog.ide.eclipse.utils.ProjectsMap.ProjectKey;

/**
* @author yahavi
*/
public class IssuesTree extends SearchableTree {

private static IssuesTree instance;

private DependencyTree root = new DependencyTree();
private ComponentIssueTable componentIssueTable;
private TreeViewerColumn issuesCountColumn;

Expand All @@ -34,8 +30,7 @@ public static IssuesTree getInstance() {

private IssuesTree(Composite parent) {
super(parent, new IssuesTreeColumnLabelProvider());
issuesCountColumn = createColumn("Issues (0)", new IssueCountColumnLabelProvider(this), SWT.RIGHT, 0);
applyFiltersForAllProjects();
issuesCountColumn = createColumn("Issues", new IssueCountColumnLabelProvider(this), SWT.RIGHT, 0);
}

@Override
Expand All @@ -48,40 +43,16 @@ public void setComponentIssueTable(ComponentIssueTable componentIssueTable) {
this.componentIssueTable = componentIssueTable;
}

@Override
public void applyFilters(ProjectKey projectKey) {
DependencyTree project = projects.get(projectKey);
if (project != null) {
FilterManager filterManager = FilterManagerSingleton.getInstance();
DependencyTree filteredRoot = filterManager.applyFilters(project);
filteredRoot.setIssues(filteredRoot.processTreeIssues());
root.add(filteredRoot);
if (root.getChildCount() == 1) {
// If there is only one project - Show only its dependencies in the tree viewer.
treeViewer.setInput(filteredRoot);
} else {
treeViewer.setInput(root);
}
long totalIssues = root.getChildren().stream().mapToInt(DependencyTree::getIssueCount).sum();
issuesCountColumn.getColumn().setText("Issues (" + totalIssues + ")");
}
}

@Override
public void applyFiltersForAllProjects() {
root = new DependencyTree();
for (Entry<ProjectKey, DependencyTree> entry : projects.entrySet()) {
applyFilters(entry.getKey());
}
}

@Override
public void reset() {
super.reset();
componentIssueTable.updateIssuesTable(Lists.newArrayList());
issuesCountColumn.getColumn().setText("Issues (0)");
root = new DependencyTree();
treeViewer.setInput(root);
issuesCountColumn.getColumn().setText("Issues");
treeViewer.setInput(new ArrayList<FileTreeNode>());
}

public static void disposeTree() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.swt.graphics.Image;
import org.jfrog.build.extractor.scan.DependencyTree;
import org.jfrog.build.extractor.scan.Severity;
import com.jfrog.ide.common.nodes.subentities.Severity;

import com.jfrog.ide.common.nodes.FileIssueNode;
import com.jfrog.ide.common.nodes.FileTreeNode;
import com.jfrog.ide.common.nodes.ScaIssueNode;
import com.jfrog.ide.common.parse.Applicability;
import com.jfrog.ide.eclipse.ui.IconManager;

/**
Expand All @@ -15,8 +19,18 @@ public class IssuesTreeColumnLabelProvider extends ColumnLabelProvider {

@Override
public Image getImage(Object element) {
DependencyTree scanTreeNode = (DependencyTree) element;
Severity severity = scanTreeNode.getTopIssue().getSeverity();
return IconManager.load(severity.name().toLowerCase());
Severity severity = null;
if (element instanceof FileTreeNode) {
severity = ((FileTreeNode) element).getSeverity();
} else if (element instanceof ScaIssueNode) {
ScaIssueNode issueNode = (ScaIssueNode) element;
severity = issueNode.getSeverity();
if (Applicability.NOT_APPLICABLE.equals(issueNode.getApplicability())) {
severity = Severity.getNotApplicableSeverity(severity);
}
} else if (element instanceof FileIssueNode) {
severity = ((FileIssueNode) element).getSeverity();
}
return IconManager.load(severity.name().toLowerCase());
}
}