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

Improve performance and memory consumption #55

Merged
merged 1 commit into from
Oct 28, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ private void populateTreeWithUnknownIssues() {
Enumeration<?> bfs = depthFirstEnumeration();
while (bfs.hasMoreElements()) {
DependencyTree node = (DependencyTree) bfs.nextElement();
node.setIssues(Sets.newHashSet(new org.jfrog.build.extractor.scan.Issue("", "", "", "", Severity.Unknown, "", null)));
node.setIssues(Sets.newHashSet(new org.jfrog.build.extractor.scan.Issue("", Severity.Unknown, "", null)));
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/main/java/com/jfrog/ide/common/go/GoTreeBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,7 @@ private void setGeneralInfo(DependencyTree rootNode) {
rootNode.setGeneralInfo(new GeneralInfo()
.componentId(rootNode.getUserObject().toString())
.pkgType("go")
.path(projectDir.toString())
.artifactId(rootNode.getUserObject().toString())
.version(""));
.path(projectDir.toString()));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import java.util.Set;
import java.util.stream.Collectors;

import static com.jfrog.ide.common.utils.Utils.createComponentId;

/**
* Build Gradle dependency tree before the Xray scan.
*
Expand Down Expand Up @@ -97,11 +99,8 @@ private void populateDependencyTree(DependencyTree node, GradleDependencyNode gr
}

private GeneralInfo createGeneralInfo(GradleDependencyNode node) {
return new GeneralInfo()
.groupId(node.getGroupId())
.artifactId(node.getArtifactId())
.version(node.getVersion())
.pkgType("gradle");
return new GeneralInfo().pkgType("gradle")
.componentId(createComponentId(node.getGroupId(), node.getArtifactId(), node.getVersion()));
}

/**
Expand Down
8 changes: 2 additions & 6 deletions src/main/java/com/jfrog/ide/common/npm/NpmTreeBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.Map;

import static com.jfrog.ide.common.log.Utils.logError;
import static com.jfrog.ide.common.utils.Utils.createComponentId;

/**
* Build npm dependency tree before the Xray scan.
Expand Down Expand Up @@ -144,11 +145,6 @@ private String getPostfix(Log logger, JsonNode npmLsResults, boolean shouldToast
}

private GeneralInfo createGeneralInfo(String packageName, String packageVersion) {
return new GeneralInfo()
.componentId(packageName + ":" + packageVersion)
.pkgType("npm")
.path(projectDir.toString())
.artifactId(packageName)
.version(packageVersion);
return new GeneralInfo().path(projectDir.toString()).componentId(createComponentId(packageName, packageVersion)).pkgType("npm");
}
}
23 changes: 12 additions & 11 deletions src/main/java/com/jfrog/ide/common/persistency/ScanCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@

import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
* Cache for Xray scan.
Expand All @@ -37,13 +40,11 @@ public void add(Artifact artifact) {
}

public void add(Violation violation, String packageType) {
addComponents(violation.getComponents(), violation.getViolationType(), Severity.valueOf(violation.getSeverity()),
violation.getSummary(), packageType);
addComponents(violation.getComponents(), Severity.valueOf(violation.getSeverity()), violation.getSummary(), packageType);
}

public void add(Vulnerability vulnerability, String packageType) {
addComponents(vulnerability.getComponents(), "vulnerability",
Severity.valueOf(vulnerability.getSeverity()), vulnerability.getSummary(), packageType);
addComponents(vulnerability.getComponents(), Severity.valueOf(vulnerability.getSeverity()), vulnerability.getSummary(), packageType);
}

public void add(License license, String packageType, boolean violation) {
Expand All @@ -65,8 +66,8 @@ public void add(License license, String packageType, boolean violation) {
continue;
}
// If not exist, creates a new data object.
GeneralInfo info = new GeneralInfo(id, "", component.getImpactPaths().get(0).get(0).getFullPath(), packageType);
Artifact artifact = new Artifact(info, new HashSet<>(), new HashSet<org.jfrog.build.extractor.scan.License>() {{
GeneralInfo info = new GeneralInfo(id, component.getImpactPaths().get(0).get(0).getFullPath(), packageType);
Artifact artifact = new Artifact(info, new HashSet<>(), new HashSet<>() {{
add(issue);
}});
this.add(artifact);
Expand All @@ -90,12 +91,12 @@ void setScanCacheMap(ScanCacheMap scanCacheMap) {
this.scanCacheMap = scanCacheMap;
}

private void addComponents(Map<String, ? extends Component> components, String issueType, Severity severity, String summary, String packageType) {
private void addComponents(Map<String, ? extends Component> components, Severity severity, String summary, String packageType) {
for (Map.Entry<String, ? extends Component> entry : components.entrySet()) {
String id = entry.getKey();
id = id.substring(id.indexOf("://") + 3);
Component component = entry.getValue();
Issue issue = new Issue("", "", issueType, "", severity, summary, component.getFixedVersions());
Issue issue = new Issue("", severity, summary, component.getFixedVersions());

if (this.contains(id)) {
Artifact artifact = get(id);
Expand All @@ -107,8 +108,8 @@ private void addComponents(Map<String, ? extends Component> components, String i
continue;
}
// If not exist, creates a new data object.
GeneralInfo info = new GeneralInfo(id, "", component.getImpactPaths().get(0).get(0).getFullPath(), packageType);
Artifact artifact = new Artifact(info, new HashSet<Issue>() {{
GeneralInfo info = new GeneralInfo(id, component.getImpactPaths().get(0).get(0).getFullPath(), packageType);
Artifact artifact = new Artifact(info, new HashSet<>() {{
add(issue);
}}, new HashSet<>());
this.add(artifact);
Expand Down
15 changes: 11 additions & 4 deletions src/main/java/com/jfrog/ide/common/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import java.util.Set;
import java.util.stream.Collectors;

import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL;
import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_EMPTY;
import static com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES;

/**
Expand All @@ -29,10 +29,18 @@ public class Utils {
public static ObjectMapper createMapper() {
return new ObjectMapper()
.configure(FAIL_ON_UNKNOWN_PROPERTIES, false)
.setSerializationInclusion(NON_NULL)
.setSerializationInclusion(NON_EMPTY)
.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
}

public static String createComponentId(String artifactId, String version) {
return String.join(":", artifactId, version);
}

public static String createComponentId(String groupId, String artifactId, String version) {
return String.join(":", groupId, artifactId, version);
}

public static String createLicenseString(License license) {
if (license.isFullNameEmpty() || StringUtils.isBlank(license.getName())) {
return license.getName();
Expand All @@ -42,7 +50,6 @@ public static String createLicenseString(License license) {

public static GeneralInfo getGeneralInfo(General other) {
return new GeneralInfo().componentId(other.getComponentId())
.name(other.getName())
.path(other.getPath())
.pkgType(other.getPkgType());
}
Expand All @@ -60,7 +67,7 @@ public static Issue toIssue(com.jfrog.xray.client.services.summary.Issue other)
VulnerableComponents vulnerableComponents = vulnerableComponentsList.get(0);
fixedVersions = vulnerableComponents.getFixedVersions();
}
return new Issue(other.getCreated(), other.getDescription(), other.getIssueType(), other.getProvider(), severity, other.getSummary(), fixedVersions);
return new Issue(other.getDescription(), severity, other.getSummary(), fixedVersions);
}

public static Artifact getArtifact(com.jfrog.xray.client.services.summary.Artifact other) {
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/jfrog/ide/common/filter/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class Utils {
* @return the random issue
*/
static Issue createIssue(Severity severity) {
return new Issue(generateUID(), generateUID(), generateUID(), generateUID(), severity, generateUID(), Lists.newArrayList());
return new Issue(generateUID(), severity, generateUID(), Lists.newArrayList());
}

/**
Expand Down