Skip to content
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

Limit Impact Graph size #383

Merged
merged 8 commits into from
Aug 9, 2023
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
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import java.net.http.HttpResponse
import java.nio.file.Paths

plugins {
id "org.jetbrains.intellij" version "1.14.2"
id "org.jetbrains.intellij" version "1.15.0"
id "java"
id "maven-publish"
id "de.undercouch.download" version "5.3.0"
Expand Down Expand Up @@ -57,7 +57,7 @@ dependencies {
implementation group: 'com.jfrog.xray.client', name: 'xray-client-java', version: '0.14.1'
implementation group: 'org.apache.commons', name: 'commons-collections4', version: '4.4'
implementation group: 'org.jfrog.filespecs', name: 'file-specs-java', version: '1.1.2'
implementation group: 'com.jfrog.ide', name: 'ide-plugins-common', version: '2.2.x-20230806.132528-2'
implementation group: 'com.jfrog.ide', name: 'ide-plugins-common', version: '2.2.x-20230809.153111-1'
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.11'
implementation group: 'com.google.guava', name: 'guava', version: '32.0.1-jre'
testImplementation group: 'org.mockito', name: 'mockito-inline', version: '4.2.0'
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
webviewVersion=0.2.2
webviewVersion=0.2.5
sandboxVersion=2022.3.2
webviewChecksum=a510a0961d55227ae1c737e0233d15b8d2990f48e23271c1f2adec1c7b7fb455
webviewChecksum=8317a24c2990311fa8d1427f8269e9559d58a2a1ffe7201fc0d452a92649667b
currentVersion=2.3.x-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import com.jfrog.ide.common.nodes.DescriptorFileTreeNode;
import com.jfrog.ide.common.nodes.SortableChildrenTreeNode;
import com.jfrog.ide.common.nodes.VulnerabilityNode;
import com.jfrog.ide.common.nodes.subentities.ImpactTreeNode;
import com.jfrog.ide.common.nodes.subentities.ImpactTree;
import com.jfrog.ide.idea.inspections.upgradeversion.UpgradeVersion;
import com.jfrog.ide.idea.navigation.NavigationService;
import com.jfrog.ide.idea.scan.ScannerBase;
Expand Down Expand Up @@ -233,8 +233,8 @@ private List<DependencyNode> getMatchDependencies(DescriptorFileTreeNode file, S
*/
boolean isNodeMatch(DependencyNode node, String componentName) {
String artifactID = node.getComponentIdWithoutPrefix();
ImpactTreeNode impactPath = node.getImpactPaths();
return StringUtils.equals(artifactID, componentName) || impactPath.contains(componentName);
ImpactTree impactTree = node.getImpactTree();
return StringUtils.equals(artifactID, componentName) || impactTree.contains(componentName);
}

abstract UpgradeVersion getUpgradeVersion(String componentName, String fixVersion, Collection<String> issues, String descriptorPath);
Expand Down
14 changes: 11 additions & 3 deletions src/main/java/com/jfrog/ide/idea/scan/ScannerBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.jfrog.ide.common.nodes.DependencyNode;
import com.jfrog.ide.common.nodes.DescriptorFileTreeNode;
import com.jfrog.ide.common.nodes.FileTreeNode;
import com.jfrog.ide.common.nodes.subentities.ImpactTree;
import com.jfrog.ide.common.nodes.subentities.ImpactTreeNode;
import com.jfrog.ide.common.scan.ComponentPrefix;
import com.jfrog.ide.common.scan.ScanLogic;
Expand Down Expand Up @@ -58,6 +59,8 @@
* Created by romang on 4/26/17.
*/
public abstract class ScannerBase {
public static final int IMPACT_PATHS_LIMIT = 50;

private final ServerConfig serverConfig;
private final ComponentPrefix prefix;
private final Log log;
Expand Down Expand Up @@ -244,10 +247,15 @@ private void visitDepTreeNode(Map<String, DependencyNode> dependencies, DepTree
}

private void addImpactPathToDependencyNode(DependencyNode dependencyNode, List<String> path) {
if (dependencyNode.getImpactPaths() == null) {
dependencyNode.setImpactPaths(new ImpactTreeNode(path.get(0)));
if (dependencyNode.getImpactTree() == null) {
dependencyNode.setImpactTree(new ImpactTree(new ImpactTreeNode(path.get(0))));
}
ImpactTree impactTree = dependencyNode.getImpactTree();
impactTree.incImpactPathsCount();
if (impactTree.getImpactPathsCount() > IMPACT_PATHS_LIMIT) {
return;
}
ImpactTreeNode parentImpactTreeNode = dependencyNode.getImpactPaths();
ImpactTreeNode parentImpactTreeNode = impactTree.getRoot();
for (int pathNodeIndex = 1; pathNodeIndex < path.size(); pathNodeIndex++) {
String currPathNode = path.get(pathNodeIndex);
// Find a child of parentImpactTreeNode with a name equals to currPathNode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.jfrog.ide.common.nodes.VulnerabilityNode;
import com.jfrog.ide.common.nodes.subentities.*;
import com.jfrog.ide.common.scan.ComponentPrefix;
import com.jfrog.ide.idea.scan.ScannerBase;
import com.jfrog.ide.idea.ui.webview.model.Cve;
import com.jfrog.ide.idea.ui.webview.model.Evidence;
import com.jfrog.ide.idea.ui.webview.model.License;
Expand Down Expand Up @@ -46,7 +47,7 @@ public static DependencyPage convertIssueToDepPage(VulnerabilityNode vulnerabili
.infectedVersion(convertVersionRanges(vulnerabilityNode.getInfectedVersions()))
.references(convertReferences(vulnerabilityNode.getReferences()))
.cve(convertCve(vulnerabilityNode.getCve(), convertApplicableDetails(vulnerabilityNode.getApplicableInfo())))
.impactGraph(convertImpactGraph(dependency.getImpactPaths()))
.impactGraph(convertImpactGraph(dependency.getImpactTree()))
.watchName(watchNames)
.edited(vulnerabilityNode.getLastUpdated())
.extendedInformation(extendedInformation);
Expand All @@ -63,14 +64,11 @@ public static IssuePage convertFileIssueToIssuePage(FileIssueNode fileIssueNodeN
}

private static String ConvertPageType(SourceCodeScanType reporterType) {
switch (reporterType) {
case SECRETS:
return "SECRETS";
case IAC:
return "IAC";
default:
return "EMPTY";
}
return switch (reporterType) {
case SECRETS -> "SECRETS";
case IAC -> "IAC";
default -> "EMPTY";
};
}

private static Location convertFileLocation(FileIssueNode fileIssueNodeNode) {
Expand Down Expand Up @@ -117,14 +115,18 @@ public static DependencyPage convertLicenseToDepPage(LicenseViolationNode licens
.version(dependency.getVersion())
.severity(license.getSeverity().name())
.references(convertReferences(license.getReferences()))
.impactGraph(convertImpactGraph(dependency.getImpactPaths()))
.impactGraph(convertImpactGraph(dependency.getImpactTree()))
.watchName(watchNames)
.edited(license.getLastUpdated());
}

private static ImpactGraph convertImpactGraph(ImpactTreeNode impactTreeNode) {
ImpactGraph[] children = impactTreeNode.getChildren().stream().map(WebviewObjectConverter::convertImpactGraph).toArray(ImpactGraph[]::new);
return new ImpactGraph(impactTreeNode.getName(), children);
private static ImpactGraph convertImpactGraph(ImpactTree impactTree) {
return new ImpactGraph(convertImpactGraphNode(impactTree.getRoot()), impactTree.getImpactPathsCount(), ScannerBase.IMPACT_PATHS_LIMIT);
}

private static ImpactGraphNode convertImpactGraphNode(ImpactTreeNode impactTreeNode) {
ImpactGraphNode[] children = impactTreeNode.getChildren().stream().map(WebviewObjectConverter::convertImpactGraphNode).toArray(ImpactGraphNode[]::new);
return new ImpactGraphNode(impactTreeNode.getName(), children);
}

private static Cve convertCve(com.jfrog.ide.common.nodes.subentities.Cve cve, ApplicableDetails applicableDetails) {
Expand Down
25 changes: 16 additions & 9 deletions src/main/java/com/jfrog/ide/idea/ui/webview/model/ImpactGraph.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
package com.jfrog.ide.idea.ui.webview.model;

public class ImpactGraph {
private final String name;
private final ImpactGraph[] children;
private final ImpactGraphNode root;
private final int pathsCount;
private final int pathsLimit;

public ImpactGraph(String name, ImpactGraph[] children) {
this.name = name;
this.children = children;
public ImpactGraph(ImpactGraphNode root, int pathsCount, int pathsLimit) {
this.root = root;
this.pathsCount = pathsCount;
this.pathsLimit = pathsLimit;
}

@SuppressWarnings("unused")
public String getName() {
return name;
public ImpactGraphNode getRoot() {
return root;
}

@SuppressWarnings("unused")
public ImpactGraph[] getChildren() {
return children;
public int getPathsCount() {
return pathsCount;
}

@SuppressWarnings("unused")
public int getPathsLimit() {
return pathsLimit;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.jfrog.ide.idea.ui.webview.model;

public class ImpactGraphNode {
private final String name;
private final ImpactGraphNode[] children;

public ImpactGraphNode(String name, ImpactGraphNode[] children) {
this.name = name;
this.children = children;
}

@SuppressWarnings("unused")
public String getName() {
return name;
}

@SuppressWarnings("unused")
public ImpactGraphNode[] getChildren() {
return children;
}
}