From 3239961b540703dc5c0cf3b6d67c7f26720266c6 Mon Sep 17 00:00:00 2001 From: Asaf Gabai Date: Thu, 27 Jul 2023 16:54:07 +0300 Subject: [PATCH 1/2] Created the ImpactTree class, that contains the impact tree itself and metadata about it. --- .../ide/common/nodes/DependencyNode.java | 12 +++--- .../common/nodes/subentities/ImpactTree.java | 37 +++++++++++++++++++ 2 files changed, 43 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/jfrog/ide/common/nodes/subentities/ImpactTree.java diff --git a/src/main/java/com/jfrog/ide/common/nodes/DependencyNode.java b/src/main/java/com/jfrog/ide/common/nodes/DependencyNode.java index 567f11ab..6aec1f71 100644 --- a/src/main/java/com/jfrog/ide/common/nodes/DependencyNode.java +++ b/src/main/java/com/jfrog/ide/common/nodes/DependencyNode.java @@ -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; @@ -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 licenses; @@ -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) { diff --git a/src/main/java/com/jfrog/ide/common/nodes/subentities/ImpactTree.java b/src/main/java/com/jfrog/ide/common/nodes/subentities/ImpactTree.java new file mode 100644 index 00000000..6546a4cb --- /dev/null +++ b/src/main/java/com/jfrog/ide/common/nodes/subentities/ImpactTree.java @@ -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++; + } +} From 7f40a4bcc5b48a6b960cc40349a01a79dc140053 Mon Sep 17 00:00:00 2001 From: Asaf Gabai Date: Tue, 1 Aug 2023 09:35:53 +0300 Subject: [PATCH 2/2] Increased cache version. --- .../java/com/jfrog/ide/common/persistency/ScanCache.java | 9 ++++----- .../jfrog/ide/common/persistency/ScanCacheObject.java | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/jfrog/ide/common/persistency/ScanCache.java b/src/main/java/com/jfrog/ide/common/persistency/ScanCache.java index 51a5142b..64f0d1c0 100644 --- a/src/main/java/com/jfrog/ide/common/persistency/ScanCache.java +++ b/src/main/java/com/jfrog/ide/common/persistency/ScanCache.java @@ -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; @@ -27,6 +28,7 @@ public class ScanCache { private final File file; private final ObjectMapper objectMapper; + @Getter private ScanCacheObject scanCacheObject; /** @@ -68,10 +70,6 @@ public void cacheNodes(List nodes) throws IOException { objectMapper.writeValue(file, scanCacheObject); } - public ScanCacheObject getScanCacheObject() { - return scanCacheObject; - } - public void deleteScanCacheObject() throws IOException { if (file.exists()) { if (!file.delete()) { @@ -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); diff --git a/src/main/java/com/jfrog/ide/common/persistency/ScanCacheObject.java b/src/main/java/com/jfrog/ide/common/persistency/ScanCacheObject.java index 6e9e4e5a..1733613e 100644 --- a/src/main/java/com/jfrog/ide/common/persistency/ScanCacheObject.java +++ b/src/main/java/com/jfrog/ide/common/persistency/ScanCacheObject.java @@ -12,7 +12,7 @@ */ @Getter public class ScanCacheObject { - static int CACHE_VERSION = 4; + static int CACHE_VERSION = 5; @JsonProperty("version") int version = CACHE_VERSION;