Skip to content

Commit

Permalink
Created ImpactTree class (#128)
Browse files Browse the repository at this point in the history
* Created the ImpactTree class, that contains the impact tree itself and metadata about it.
  • Loading branch information
asafgabai authored Aug 9, 2023
1 parent 3800d9b commit 70d210f
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 12 deletions.
12 changes: 6 additions & 6 deletions src/main/java/com/jfrog/ide/common/nodes/DependencyNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.fasterxml.jackson.annotation.JsonGetter;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.jfrog.ide.common.nodes.subentities.ImpactTreeNode;
import com.jfrog.ide.common.nodes.subentities.ImpactTree;
import com.jfrog.ide.common.nodes.subentities.License;
import com.jfrog.ide.common.nodes.subentities.Severity;
import org.apache.commons.lang3.StringUtils;
Expand All @@ -22,7 +22,7 @@ public class DependencyNode extends SortableChildrenTreeNode implements Subtitle
@JsonProperty()
private boolean indirect;
@JsonProperty()
private ImpactTreeNode impactPaths;
private ImpactTree impactTree;
@JsonProperty()
private List<License> licenses;

Expand Down Expand Up @@ -74,13 +74,13 @@ public Severity getSeverity() {

@JsonGetter()
@SuppressWarnings("unused")
public ImpactTreeNode getImpactPaths() {
return impactPaths;
public ImpactTree getImpactTree() {
return impactTree;
}

@SuppressWarnings("unused")
public void setImpactPaths(ImpactTreeNode impactPaths) {
this.impactPaths = impactPaths;
public void setImpactTree(ImpactTree impactTree) {
this.impactTree = impactTree;
}

public void addIssue(IssueNode issue) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.jfrog.ide.common.nodes.subentities;

import com.fasterxml.jackson.annotation.JsonProperty;

public class ImpactTree {
@JsonProperty
private ImpactTreeNode root;
@JsonProperty
private int impactPathsCount = 0;

// Empty constructor for deserialization
@SuppressWarnings("unused")
public ImpactTree() {
}

public ImpactTree(ImpactTreeNode root) {
this.root = root;
}

public boolean contains(String name) {
return root.contains(name);
}

public ImpactTreeNode getRoot() {
return root;
}

@SuppressWarnings("unused")
public int getImpactPathsCount() {
return impactPathsCount;
}

@SuppressWarnings("unused")
public void incImpactPathsCount() {
this.impactPathsCount++;
}
}
9 changes: 4 additions & 5 deletions src/main/java/com/jfrog/ide/common/persistency/ScanCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.fasterxml.jackson.databind.jsontype.PolymorphicTypeValidator;
import com.jfrog.ide.common.log.Utils;
import com.jfrog.ide.common.nodes.FileTreeNode;
import lombok.Getter;
import org.jfrog.build.api.util.Log;

import java.io.File;
Expand All @@ -27,6 +28,7 @@
public class ScanCache {
private final File file;
private final ObjectMapper objectMapper;
@Getter
private ScanCacheObject scanCacheObject;

/**
Expand Down Expand Up @@ -68,10 +70,6 @@ public void cacheNodes(List<FileTreeNode> nodes) throws IOException {
objectMapper.writeValue(file, scanCacheObject);
}

public ScanCacheObject getScanCacheObject() {
return scanCacheObject;
}

public void deleteScanCacheObject() throws IOException {
if (file.exists()) {
if (!file.delete()) {
Expand All @@ -84,7 +82,8 @@ private void readCachedNodes(Log logger) throws IOException {
try {
scanCacheObject = objectMapper.readValue(file, ScanCacheObject.class);
if (scanCacheObject.getVersion() != ScanCacheObject.CACHE_VERSION) {
logger.warn("Invalid cache version " + scanCacheObject.getVersion() + ". Ignoring the old cache and starting a new one.");
logger.info("Invalid cache version " + scanCacheObject.getVersion() + ". Ignoring the old cache and starting a new one.");
scanCacheObject = null;
}
} catch (JsonParseException | JsonMappingException e) {
Utils.logError(logger, "Failed reading cache file. Ignoring the old cache and starting a new one.", e, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
@Getter
public class ScanCacheObject {
static int CACHE_VERSION = 4;
static int CACHE_VERSION = 5;

@JsonProperty("version")
int version = CACHE_VERSION;
Expand Down

0 comments on commit 70d210f

Please sign in to comment.