Skip to content

Optimized impact paths building #441

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
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Merge fixes
  • Loading branch information
asafgabai committed Nov 29, 2023
commit 306bcd0ca850bb8c8efca1d06634da17df9b8ea4
4 changes: 2 additions & 2 deletions src/main/java/com/jfrog/ide/idea/scan/MavenScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ protected List<FileTreeNode> groupDependenciesToDescriptorNodes(Collection<Depen
String vulnerableDepId = dependencyNode.getComponentIdWithoutPrefix();
Set<String> affectedModulesIds = getDependentModules(vulnerableDepId, depTree, parents, visitedComponents);
for (String descriptorId : affectedModulesIds) {
String descriptorPath = depTree.getNodes().get(descriptorId).getDescriptorFilePath();
String descriptorPath = depTree.nodes().get(descriptorId).getDescriptorFilePath();
descriptorMap.putIfAbsent(descriptorPath, new DescriptorFileTreeNode(descriptorPath));

// Each dependency might be a child of more than one POM file, but Artifact is a tree node, so it can have only one parent.
Expand All @@ -207,7 +207,7 @@ Set<String> getDependentModules(String compId, DepTree depTree, Map<String, Set<
return visitedComponents.get(compId);
}
Set<String> modulesIds = new HashSet<>();
if (depTree.getNodes().get(compId).getDescriptorFilePath() != null) {
if (depTree.nodes().get(compId).getDescriptorFilePath() != null) {
modulesIds.add(compId);
}
if (parents.containsKey(compId)) {
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/com/jfrog/ide/idea/scan/ScannerBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,7 @@ private void scanAndUpdate(ProgressIndicator indicator) {
// No violations/vulnerabilities or no components to scan or an error was thrown
return;
}

Map<String, Set<String>> parents = getParents(depTree);
ImpactTreeBuilder.populateImpactTrees(results, parents, depTree.getRootId());
List<FileTreeNode> fileTreeNodes = groupDependenciesToDescriptorNodes(results.values(), depTree, parents);
List<FileTreeNode> fileTreeNodes = buildImpactGraph(results, depTree);
addScanResults(fileTreeNodes);

// Contextual Analysis
Expand All @@ -188,6 +185,12 @@ private void scanAndUpdate(ProgressIndicator indicator) {
}
}

protected List<FileTreeNode> buildImpactGraph(Map<String, DependencyNode> vulnerableDependencies, DepTree depTree) throws IOException {
Map<String, Set<String>> parents = getParents(depTree);
ImpactTreeBuilder.populateImpactTrees(vulnerableDependencies, parents, depTree.rootId());
return groupDependenciesToDescriptorNodes(vulnerableDependencies.values(), depTree, parents);
}

/**
* Find the parents of each node in the given {@link DepTree}.
* Nodes without parents (the root) don't appear in the returned map.
Expand All @@ -197,7 +200,7 @@ private void scanAndUpdate(ProgressIndicator indicator) {
*/
static Map<String, Set<String>> getParents(DepTree depTree) {
Map<String, Set<String>> parents = new HashMap<>();
for (Map.Entry<String, DepTreeNode> node : depTree.getNodes().entrySet()) {
for (Map.Entry<String, DepTreeNode> node : depTree.nodes().entrySet()) {
String parentId = node.getKey();
for (String childId : node.getValue().getChildren()) {
parents.putIfAbsent(childId, new HashSet<>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected List<FileTreeNode> groupDependenciesToDescriptorNodes(Collection<Depen
for (DependencyNode dependency : depScanResults) {
boolean directDep = false;
for (String parentId : parents.get(dependency.getComponentIdWithoutPrefix())) {
DepTreeNode parent = depTree.getNodes().get(parentId);
DepTreeNode parent = depTree.nodes().get(parentId);
if (descriptorFilePath.equals(parent.getDescriptorFilePath())) {
directDep = true;
break;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/jfrog/ide/idea/scan/YarnScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.jfrog.ide.idea.inspections.AbstractInspection;
import com.jfrog.ide.idea.inspections.YarnInspection;
import com.jfrog.ide.idea.scan.data.PackageManagerType;
import com.jfrog.ide.idea.scan.utils.ImpactTreeBuilder;
import com.jfrog.ide.idea.ui.ComponentsTree;
import com.jfrog.ide.idea.ui.menus.filtermanager.ConsistentFilterManager;
import org.apache.commons.collections4.CollectionUtils;
Expand Down Expand Up @@ -102,7 +103,7 @@ private void buildImpactGraphFromPaths(DescriptorFileTreeNode descriptorNode, Ma

// build the impact graph for each vulnerable dependency out of its impact paths
for (List<String> impactPath : impactPaths) {
this.addImpactPathToDependencyNode(dependencyNode, impactPath);
ImpactTreeBuilder.addImpactPathToDependencyNode(dependencyNode, impactPath);
}

boolean direct = impactPaths.stream().map(List::size).anyMatch(size -> size == 2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private static void walkParents(DependencyNode depNode, Map<String, Set<String>>
}
}

static void addImpactPathToDependencyNode(DependencyNode dependencyNode, List<String> path) {
public static void addImpactPathToDependencyNode(DependencyNode dependencyNode, List<String> path) {
if (dependencyNode.getImpactTree() == null) {
dependencyNode.setImpactTree(new ImpactTree(new ImpactTreeNode(path.get(0))));
}
Expand Down