From 25f7f44602d0b790e6d6e25b70863d59d473a4a4 Mon Sep 17 00:00:00 2001 From: Eyal Kapon Date: Tue, 17 Sep 2024 13:52:40 +0300 Subject: [PATCH 1/6] fixed for npm/yarn maven gradle and go (pyton is not implemented) --- .../idea/inspections/AbstractInspection.java | 17 ++++++++++-- .../inspections/GradleGroovyInspection.java | 12 ++++++--- .../inspections/GradleKotlinInspection.java | 6 ++--- .../ide/idea/inspections/MavenInspection.java | 9 ++++--- .../idea/navigation/NavigationService.java | 2 ++ .../jfrog/ide/idea/scan/GradleScanner.java | 6 ++++- .../com/jfrog/ide/idea/ui/ComponentPath.java | 7 +++++ .../ide/idea/ui/LocalComponentsTree.java | 26 +++++++++++++------ 8 files changed, 64 insertions(+), 21 deletions(-) create mode 100644 src/main/java/com/jfrog/ide/idea/ui/ComponentPath.java diff --git a/src/main/java/com/jfrog/ide/idea/inspections/AbstractInspection.java b/src/main/java/com/jfrog/ide/idea/inspections/AbstractInspection.java index cdf9570b..9dd4cf7b 100644 --- a/src/main/java/com/jfrog/ide/idea/inspections/AbstractInspection.java +++ b/src/main/java/com/jfrog/ide/idea/inspections/AbstractInspection.java @@ -27,6 +27,7 @@ import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.ListUtils; import org.apache.commons.lang3.StringUtils; +import org.jetbrains.idea.maven.execution.SoutMavenConsole; import javax.swing.tree.TreeNode; import java.util.*; @@ -180,6 +181,7 @@ boolean isShowInspection(PsiElement element) { return false; // File is not a package descriptor file } + ScannerBase scanner = getScanner(project, editorFile.getParent().getPath()); if (scanner == null) { return false; // Scan manager for this project not yet created @@ -234,7 +236,7 @@ private List getMatchDependencies(DescriptorFileTreeNode file, S boolean isNodeMatch(DependencyNode node, String componentName) { String artifactID = node.getComponentIdWithoutPrefix(); ImpactTree impactTree = node.getImpactTree(); - return StringUtils.equals(artifactID, componentName) || impactTree.contains(componentName); + return StringUtils.equals(extractArtifactIdWithoutVersion(artifactID), componentName) || impactTree.contains(componentName+":"); } abstract UpgradeVersion getUpgradeVersion(String componentName, String fixVersion, Collection issues, String descriptorPath); @@ -296,4 +298,15 @@ protected static String convertFixVersionStringToMinFixVersion(String fixVersion fixVersion = StringUtils.strip(fixVersion, "]"); return fixVersion; } -} + + + private String extractArtifactIdWithoutVersion(String artifact) { + int versionIndex = artifact.lastIndexOf(':'); + + if (versionIndex != -1) { + return artifact.substring(0, versionIndex); + } else { + return artifact; + } + } + } \ No newline at end of file diff --git a/src/main/java/com/jfrog/ide/idea/inspections/GradleGroovyInspection.java b/src/main/java/com/jfrog/ide/idea/inspections/GradleGroovyInspection.java index d627bc7b..cee96881 100644 --- a/src/main/java/com/jfrog/ide/idea/inspections/GradleGroovyInspection.java +++ b/src/main/java/com/jfrog/ide/idea/inspections/GradleGroovyInspection.java @@ -43,7 +43,12 @@ public GradleGroovyInspection() { * @return the value of the literal */ public static String getLiteralValue(GrLiteral literal) { - return Objects.toString((literal).getValue(), ""); + String artifact = Objects.toString((literal).getValue(), ""); + int versionIndex = artifact.lastIndexOf(':'); + if (versionIndex == -1) { + return artifact; + } + return artifact.substring(0, versionIndex); } public static boolean isNamedArgumentComponent(PsiElement element) { @@ -113,13 +118,12 @@ List parseComponentElements(GrArgumentList element) { @Override String createComponentName(PsiElement element) { + //element.getText() if (isNamedArgumentComponent(element)) { // implementation group: 'j', name: 'k', version: 'l' return String.join(":", extractExpression(element, GRADLE_GROUP_KEY), - extractExpression(element, GRADLE_NAME_KEY), - extractExpression(element, GRADLE_VERSION_KEY) - ); + extractExpression(element, GRADLE_NAME_KEY)); } if (element instanceof GrLiteral) { // implementation 'g:h:i' diff --git a/src/main/java/com/jfrog/ide/idea/inspections/GradleKotlinInspection.java b/src/main/java/com/jfrog/ide/idea/inspections/GradleKotlinInspection.java index 38d33e9a..0287a1d9 100644 --- a/src/main/java/com/jfrog/ide/idea/inspections/GradleKotlinInspection.java +++ b/src/main/java/com/jfrog/ide/idea/inspections/GradleKotlinInspection.java @@ -80,11 +80,11 @@ String createComponentName(PsiElement element) { return extractArgument(argumentList.get(0)); } if (argumentList.size() >= 3) { - // "commons-collections", "commons-collections", "3.2.2" + // "commons-collections", "commons-collections" return String.join(":", extractArgument(argumentList.get(0)), - extractArgument(argumentList.get(1)), - extractArgument(argumentList.get(2))); + extractArgument(argumentList.get(1)) + ); } return ""; } diff --git a/src/main/java/com/jfrog/ide/idea/inspections/MavenInspection.java b/src/main/java/com/jfrog/ide/idea/inspections/MavenInspection.java index 993a6f76..949d94ee 100644 --- a/src/main/java/com/jfrog/ide/idea/inspections/MavenInspection.java +++ b/src/main/java/com/jfrog/ide/idea/inspections/MavenInspection.java @@ -17,11 +17,13 @@ import com.jfrog.ide.idea.scan.ScannerBase; import com.jfrog.ide.idea.utils.Descriptor; import org.apache.commons.lang3.StringUtils; +import org.apache.maven.model.Model; +import org.apache.maven.model.io.xpp3.MavenXpp3Reader; import org.jetbrains.annotations.NotNull; import org.jetbrains.idea.maven.dom.model.MavenDomArtifactCoordinates; +import org.jetbrains.idea.maven.project.MavenProject; import java.util.Collection; - /** * @author yahavi */ @@ -92,8 +94,7 @@ String createComponentName(PsiElement element) { } DomElement domElement = DomManager.getDomManager(element.getProject()).getDomElement((XmlTag) element); if (domElement instanceof MavenDomArtifactCoordinates) { - String version = ((MavenDomArtifactCoordinates) domElement).getVersion().getStringValue(); - return String.join(":", groupId.getValue().getText(), artifactId.getValue().getText(), version); + return String.join(":", groupId.getValue().getText(), artifactId.getValue().getText()); } return null; } @@ -102,4 +103,6 @@ String createComponentName(PsiElement element) { UpgradeVersion getUpgradeVersion(String componentName, String fixVersion, Collection issue, String descriptorPath) { return new MavenUpgradeVersion(componentName, fixVersion, issue); } + } + diff --git a/src/main/java/com/jfrog/ide/idea/navigation/NavigationService.java b/src/main/java/com/jfrog/ide/idea/navigation/NavigationService.java index 5b6af74e..4ed11d93 100644 --- a/src/main/java/com/jfrog/ide/idea/navigation/NavigationService.java +++ b/src/main/java/com/jfrog/ide/idea/navigation/NavigationService.java @@ -49,8 +49,10 @@ public void addNavigation(DependencyNode treeNode, PsiElement navigationTargetEl } NavigationTarget navigationTarget = new NavigationTarget(navigationTargetElement, document.getLineNumber(navigationTargetElement.getTextOffset()), componentName); Set navigationTargets = navigationMap.get(treeNode); + if (navigationTargets == null) { navigationTargets = new HashSet<>(Collections.singletonList(navigationTarget)); + navigationMap.put(treeNode, navigationTargets); return; } diff --git a/src/main/java/com/jfrog/ide/idea/scan/GradleScanner.java b/src/main/java/com/jfrog/ide/idea/scan/GradleScanner.java index e25b77ee..ce30abf9 100644 --- a/src/main/java/com/jfrog/ide/idea/scan/GradleScanner.java +++ b/src/main/java/com/jfrog/ide/idea/scan/GradleScanner.java @@ -12,6 +12,9 @@ import com.intellij.util.EnvironmentUtil; import com.jfrog.ide.common.deptree.DepTree; import com.jfrog.ide.common.gradle.GradleTreeBuilder; +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.scan.ComponentPrefix; import com.jfrog.ide.common.scan.ScanLogic; import com.jfrog.ide.idea.inspections.AbstractInspection; @@ -34,7 +37,8 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.Map; +import java.util.*; +import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.ExecutorService; import static com.jfrog.ide.common.log.Utils.logError; diff --git a/src/main/java/com/jfrog/ide/idea/ui/ComponentPath.java b/src/main/java/com/jfrog/ide/idea/ui/ComponentPath.java new file mode 100644 index 00000000..96db5e8a --- /dev/null +++ b/src/main/java/com/jfrog/ide/idea/ui/ComponentPath.java @@ -0,0 +1,7 @@ +package com.jfrog.ide.idea.ui; + +public class ComponentPath { + + public String fileName; + public String filePath; + } diff --git a/src/main/java/com/jfrog/ide/idea/ui/LocalComponentsTree.java b/src/main/java/com/jfrog/ide/idea/ui/LocalComponentsTree.java index a4a7688f..e18b1cc4 100644 --- a/src/main/java/com/jfrog/ide/idea/ui/LocalComponentsTree.java +++ b/src/main/java/com/jfrog/ide/idea/ui/LocalComponentsTree.java @@ -21,6 +21,7 @@ import javax.swing.*; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeModel; +import javax.swing.tree.TreeNode; import javax.swing.tree.TreePath; import java.awt.event.ActionEvent; import java.awt.event.MouseAdapter; @@ -108,24 +109,28 @@ private void handleContextMenu(ComponentsTree tree, MouseEvent e) { return; } // Event is right-click. + TreePath selectedPath = tree.getPathForRow(tree.getClosestRowForLocation(e.getX(), e.getY())); if (selectedPath == null) { return; } + Object selected = selectedPath.getLastPathComponent(); + if (selected instanceof DependencyNode) { - createNodePopupMenu((DependencyNode) selected); + + this.createNodePopupMenu("asd" ,(DependencyNode) selected); } else if (selected instanceof VulnerabilityNode) { createIgnoreRuleOption((VulnerabilityNode) selected, e); } else if (selected instanceof ApplicableIssueNode) { createIgnoreRuleOption(((ApplicableIssueNode) selected).getIssue(), e); } else { - // No context menu was created. return; } popupMenu.show(tree, e.getX(), e.getY()); } + private void createIgnoreRuleOption(VulnerabilityNode selectedIssue, MouseEvent mouseEvent) { popupMenu.removeAll(); popupMenu.add(new CreateIgnoreRuleAction(selectedIssue.getIgnoreRuleUrl(), mouseEvent)); @@ -134,20 +139,19 @@ private void createIgnoreRuleOption(VulnerabilityNode selectedIssue, MouseEvent toolTip.setEnabled(true); } - private void createNodePopupMenu(DependencyNode selectedNode) { + private void createNodePopupMenu(String path,DependencyNode selectedNode) { popupMenu.removeAll(); NavigationService navigationService = NavigationService.getInstance(project); Set navigationCandidates = navigationService.getNavigation(selectedNode); - - addNodeNavigation(navigationCandidates); + addNodeNavigation(path,navigationCandidates); } - private void addNodeNavigation(Set navigationCandidates) { + private void addNodeNavigation( String parent,Set navigationCandidates) { if (navigationCandidates == null) { return; } if (navigationCandidates.size() > 1) { - addMultiNavigation(navigationCandidates); + addMultiNavigation(parent,navigationCandidates); } else { addSingleNavigation(navigationCandidates.iterator().next()); } @@ -157,10 +161,14 @@ private void addSingleNavigation(NavigationTarget navigationTarget) { popupMenu.add(createNavigationMenuItem(navigationTarget, SHOW_IN_PROJECT_DESCRIPTOR + " (" + navigationTarget.getComponentName() + ")")); } - private void addMultiNavigation(Set navigationCandidates) { + private void addMultiNavigation(String parentFile,Set navigationCandidates) { JMenu multiMenu = new JBMenu(); multiMenu.setText(SHOW_IN_PROJECT_DESCRIPTOR); for (NavigationTarget navigationTarget : navigationCandidates) { +// if(parentFile.equals(navigationTarget.getElement().getContainingFile().getName())){ +// continue; +// } + multiMenu.add(createNavigationMenuItem(navigationTarget, navigationTarget.getComponentName())); } popupMenu.add(multiMenu); @@ -260,3 +268,5 @@ public void setScanErrorEmptyText() { SwingUtilities.invokeLater(() -> getEmptyText().setText(ERROR_WHILE_SCANNING)); } } + + From 27ca49f14e69ace0dc06b03995084348d1fbb492 Mon Sep 17 00:00:00 2001 From: Eyal Kapon Date: Tue, 17 Sep 2024 15:34:12 +0300 Subject: [PATCH 2/6] refined code --- .../idea/inspections/AbstractInspection.java | 1 - .../inspections/GradleGroovyInspection.java | 1 - .../ide/idea/inspections/MavenInspection.java | 4 ---- .../com/jfrog/ide/idea/scan/GradleScanner.java | 4 ---- .../com/jfrog/ide/idea/ui/ComponentPath.java | 7 ------- .../jfrog/ide/idea/ui/LocalComponentsTree.java | 17 ++++++----------- 6 files changed, 6 insertions(+), 28 deletions(-) delete mode 100644 src/main/java/com/jfrog/ide/idea/ui/ComponentPath.java diff --git a/src/main/java/com/jfrog/ide/idea/inspections/AbstractInspection.java b/src/main/java/com/jfrog/ide/idea/inspections/AbstractInspection.java index 9dd4cf7b..d64db12d 100644 --- a/src/main/java/com/jfrog/ide/idea/inspections/AbstractInspection.java +++ b/src/main/java/com/jfrog/ide/idea/inspections/AbstractInspection.java @@ -27,7 +27,6 @@ import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.ListUtils; import org.apache.commons.lang3.StringUtils; -import org.jetbrains.idea.maven.execution.SoutMavenConsole; import javax.swing.tree.TreeNode; import java.util.*; diff --git a/src/main/java/com/jfrog/ide/idea/inspections/GradleGroovyInspection.java b/src/main/java/com/jfrog/ide/idea/inspections/GradleGroovyInspection.java index cee96881..f09c6186 100644 --- a/src/main/java/com/jfrog/ide/idea/inspections/GradleGroovyInspection.java +++ b/src/main/java/com/jfrog/ide/idea/inspections/GradleGroovyInspection.java @@ -118,7 +118,6 @@ List parseComponentElements(GrArgumentList element) { @Override String createComponentName(PsiElement element) { - //element.getText() if (isNamedArgumentComponent(element)) { // implementation group: 'j', name: 'k', version: 'l' return String.join(":", diff --git a/src/main/java/com/jfrog/ide/idea/inspections/MavenInspection.java b/src/main/java/com/jfrog/ide/idea/inspections/MavenInspection.java index 949d94ee..eef7c463 100644 --- a/src/main/java/com/jfrog/ide/idea/inspections/MavenInspection.java +++ b/src/main/java/com/jfrog/ide/idea/inspections/MavenInspection.java @@ -17,12 +17,8 @@ import com.jfrog.ide.idea.scan.ScannerBase; import com.jfrog.ide.idea.utils.Descriptor; import org.apache.commons.lang3.StringUtils; -import org.apache.maven.model.Model; -import org.apache.maven.model.io.xpp3.MavenXpp3Reader; import org.jetbrains.annotations.NotNull; import org.jetbrains.idea.maven.dom.model.MavenDomArtifactCoordinates; -import org.jetbrains.idea.maven.project.MavenProject; - import java.util.Collection; /** * @author yahavi diff --git a/src/main/java/com/jfrog/ide/idea/scan/GradleScanner.java b/src/main/java/com/jfrog/ide/idea/scan/GradleScanner.java index ce30abf9..377153aa 100644 --- a/src/main/java/com/jfrog/ide/idea/scan/GradleScanner.java +++ b/src/main/java/com/jfrog/ide/idea/scan/GradleScanner.java @@ -12,9 +12,6 @@ import com.intellij.util.EnvironmentUtil; import com.jfrog.ide.common.deptree.DepTree; import com.jfrog.ide.common.gradle.GradleTreeBuilder; -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.scan.ComponentPrefix; import com.jfrog.ide.common.scan.ScanLogic; import com.jfrog.ide.idea.inspections.AbstractInspection; @@ -38,7 +35,6 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.*; -import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.ExecutorService; import static com.jfrog.ide.common.log.Utils.logError; diff --git a/src/main/java/com/jfrog/ide/idea/ui/ComponentPath.java b/src/main/java/com/jfrog/ide/idea/ui/ComponentPath.java deleted file mode 100644 index 96db5e8a..00000000 --- a/src/main/java/com/jfrog/ide/idea/ui/ComponentPath.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.jfrog.ide.idea.ui; - -public class ComponentPath { - - public String fileName; - public String filePath; - } diff --git a/src/main/java/com/jfrog/ide/idea/ui/LocalComponentsTree.java b/src/main/java/com/jfrog/ide/idea/ui/LocalComponentsTree.java index e18b1cc4..a2e9c1da 100644 --- a/src/main/java/com/jfrog/ide/idea/ui/LocalComponentsTree.java +++ b/src/main/java/com/jfrog/ide/idea/ui/LocalComponentsTree.java @@ -21,7 +21,6 @@ import javax.swing.*; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeModel; -import javax.swing.tree.TreeNode; import javax.swing.tree.TreePath; import java.awt.event.ActionEvent; import java.awt.event.MouseAdapter; @@ -119,7 +118,7 @@ private void handleContextMenu(ComponentsTree tree, MouseEvent e) { if (selected instanceof DependencyNode) { - this.createNodePopupMenu("asd" ,(DependencyNode) selected); + this.createNodePopupMenu((DependencyNode) selected); } else if (selected instanceof VulnerabilityNode) { createIgnoreRuleOption((VulnerabilityNode) selected, e); } else if (selected instanceof ApplicableIssueNode) { @@ -139,19 +138,19 @@ private void createIgnoreRuleOption(VulnerabilityNode selectedIssue, MouseEvent toolTip.setEnabled(true); } - private void createNodePopupMenu(String path,DependencyNode selectedNode) { + private void createNodePopupMenu(DependencyNode selectedNode) { popupMenu.removeAll(); NavigationService navigationService = NavigationService.getInstance(project); Set navigationCandidates = navigationService.getNavigation(selectedNode); - addNodeNavigation(path,navigationCandidates); + addNodeNavigation(navigationCandidates); } - private void addNodeNavigation( String parent,Set navigationCandidates) { + private void addNodeNavigation(Set navigationCandidates) { if (navigationCandidates == null) { return; } if (navigationCandidates.size() > 1) { - addMultiNavigation(parent,navigationCandidates); + addMultiNavigation(navigationCandidates); } else { addSingleNavigation(navigationCandidates.iterator().next()); } @@ -161,14 +160,10 @@ private void addSingleNavigation(NavigationTarget navigationTarget) { popupMenu.add(createNavigationMenuItem(navigationTarget, SHOW_IN_PROJECT_DESCRIPTOR + " (" + navigationTarget.getComponentName() + ")")); } - private void addMultiNavigation(String parentFile,Set navigationCandidates) { + private void addMultiNavigation(Set navigationCandidates) { JMenu multiMenu = new JBMenu(); multiMenu.setText(SHOW_IN_PROJECT_DESCRIPTOR); for (NavigationTarget navigationTarget : navigationCandidates) { -// if(parentFile.equals(navigationTarget.getElement().getContainingFile().getName())){ -// continue; -// } - multiMenu.add(createNavigationMenuItem(navigationTarget, navigationTarget.getComponentName())); } popupMenu.add(multiMenu); From 33369e61d5d63ae4eed478edd0045f959f2447c0 Mon Sep 17 00:00:00 2001 From: Eyal Kapon Date: Tue, 17 Sep 2024 15:36:18 +0300 Subject: [PATCH 3/6] refined code --- .../com/jfrog/ide/idea/inspections/AbstractInspection.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/jfrog/ide/idea/inspections/AbstractInspection.java b/src/main/java/com/jfrog/ide/idea/inspections/AbstractInspection.java index d64db12d..40a21fc3 100644 --- a/src/main/java/com/jfrog/ide/idea/inspections/AbstractInspection.java +++ b/src/main/java/com/jfrog/ide/idea/inspections/AbstractInspection.java @@ -235,7 +235,8 @@ private List getMatchDependencies(DescriptorFileTreeNode file, S boolean isNodeMatch(DependencyNode node, String componentName) { String artifactID = node.getComponentIdWithoutPrefix(); ImpactTree impactTree = node.getImpactTree(); - return StringUtils.equals(extractArtifactIdWithoutVersion(artifactID), componentName) || impactTree.contains(componentName+":"); + String versionPrefix = ":"; + return StringUtils.equals(extractArtifactIdWithoutVersion(artifactID), componentName) || impactTree.contains(componentName+versionPrefix); } abstract UpgradeVersion getUpgradeVersion(String componentName, String fixVersion, Collection issues, String descriptorPath); From b37a752105273664bf2492f5bdef4d39e6b99d5e Mon Sep 17 00:00:00 2001 From: Eyal Kapon Date: Tue, 17 Sep 2024 17:00:29 +0300 Subject: [PATCH 4/6] fixed tests --- .../idea/inspections/GradleKotlinInspection.java | 3 ++- .../inspections/GradleGroovyInspectionTest.java | 14 +++++++------- .../ide/idea/inspections/GradleInspectionTest.java | 2 +- .../inspections/GradleKotlinInspectionTest.java | 4 ++-- .../ide/idea/inspections/MavenInspectionTest.java | 6 +++--- 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/jfrog/ide/idea/inspections/GradleKotlinInspection.java b/src/main/java/com/jfrog/ide/idea/inspections/GradleKotlinInspection.java index 0287a1d9..77dbda1f 100644 --- a/src/main/java/com/jfrog/ide/idea/inspections/GradleKotlinInspection.java +++ b/src/main/java/com/jfrog/ide/idea/inspections/GradleKotlinInspection.java @@ -77,7 +77,8 @@ String createComponentName(PsiElement element) { List argumentList = ((KtValueArgumentList) element).getArguments(); if (argumentList.size() == 1) { // "commons-collections:commons-collections:3.2.2" - return extractArgument(argumentList.get(0)); + String artifactId = extractArgument(argumentList.get(0)); + return StringUtils.substringBeforeLast(artifactId, ":"); } if (argumentList.size() >= 3) { // "commons-collections", "commons-collections" diff --git a/src/test/java/com/jfrog/ide/idea/inspections/GradleGroovyInspectionTest.java b/src/test/java/com/jfrog/ide/idea/inspections/GradleGroovyInspectionTest.java index c1a29745..eb0fe149 100644 --- a/src/test/java/com/jfrog/ide/idea/inspections/GradleGroovyInspectionTest.java +++ b/src/test/java/com/jfrog/ide/idea/inspections/GradleGroovyInspectionTest.java @@ -17,13 +17,13 @@ public class GradleGroovyInspectionTest extends InspectionsTestBase { // files as groovy-script. private static final String PACKAGE_DESCRIPTOR = "build.groovy"; private final InspectionTestDependency[] DEPENDENCIES = { - new InspectionTestDependency(96, "a", "b:c"), - new InspectionTestDependency(139, "d", "e:f"), - new InspectionTestDependency(180, "g", "h:i"), - new InspectionTestDependency(200, "j", "k:l"), - new InspectionTestDependency(225, "m", "n:o"), - new InspectionTestDependency(320, "net.lingala.zip4j", "zip4j:2.3.0"), - new InspectionTestDependency(390, "org.codehaus.groovy", "groovy-all:3.0.5"), + new InspectionTestDependency(96, "a", "b"), + new InspectionTestDependency(139, "d", "e"), + new InspectionTestDependency(180, "g", "h"), + new InspectionTestDependency(200, "j", "k"), + new InspectionTestDependency(225, "m", "n"), + new InspectionTestDependency(320, "net.lingala.zip4j", "zip4j"), + new InspectionTestDependency(390, "org.codehaus.groovy", "groovy-all"), }; @SuppressWarnings("MethodDoesntCallSuperMethod") diff --git a/src/test/java/com/jfrog/ide/idea/inspections/GradleInspectionTest.java b/src/test/java/com/jfrog/ide/idea/inspections/GradleInspectionTest.java index cfd27862..27df7ab5 100644 --- a/src/test/java/com/jfrog/ide/idea/inspections/GradleInspectionTest.java +++ b/src/test/java/com/jfrog/ide/idea/inspections/GradleInspectionTest.java @@ -23,7 +23,7 @@ public static Collection data() { return Arrays.asList(new Object[][]{ {"a:b:c", "a:b"}, {"a:b:c:d", "a:b"}, - {"a:b", "a:b"}, + {"a", "a"}, {"xyz", "xyz"} }); } diff --git a/src/test/java/com/jfrog/ide/idea/inspections/GradleKotlinInspectionTest.java b/src/test/java/com/jfrog/ide/idea/inspections/GradleKotlinInspectionTest.java index f8543e33..64419792 100644 --- a/src/test/java/com/jfrog/ide/idea/inspections/GradleKotlinInspectionTest.java +++ b/src/test/java/com/jfrog/ide/idea/inspections/GradleKotlinInspectionTest.java @@ -11,8 +11,8 @@ public class GradleKotlinInspectionTest extends InspectionsTestBase { // files as groovy-script. private static final String PACKAGE_DESCRIPTOR = "build.gradle.kts"; private final InspectionTestDependency[] DEPENDENCIES = { - new InspectionTestDependency(119, "a", "b:c"), - new InspectionTestDependency(144, "d", "e:f"), + new InspectionTestDependency(119, "a", "b"), + new InspectionTestDependency(144, "d", "e"), }; private final int[] NON_DEPENDENCIES_POSITIONS = {273, 338}; diff --git a/src/test/java/com/jfrog/ide/idea/inspections/MavenInspectionTest.java b/src/test/java/com/jfrog/ide/idea/inspections/MavenInspectionTest.java index efee600c..32024b0f 100644 --- a/src/test/java/com/jfrog/ide/idea/inspections/MavenInspectionTest.java +++ b/src/test/java/com/jfrog/ide/idea/inspections/MavenInspectionTest.java @@ -9,9 +9,9 @@ public class MavenInspectionTest extends InspectionsTestBase { private static final String PACKAGE_DESCRIPTOR = "pom.xml"; private final InspectionTestDependency[] DEPENDENCIES = { - new InspectionTestDependency(550, "a", "b:c"), - new InspectionTestDependency(788, "d", "e:f"), - new InspectionTestDependency(990, "g", "h:i"), + new InspectionTestDependency(550, "a", "b"), + new InspectionTestDependency(788, "d", "e"), + new InspectionTestDependency(990, "g", "h"), }; private final int[] NON_DEPENDENCIES_POSITIONS = {397, 1197, 1258}; From 79cd857e4a4e6b74a7f38af3ccf2cd1ba4751b8a Mon Sep 17 00:00:00 2001 From: Eyal Kapon Date: Thu, 19 Sep 2024 12:22:40 +0300 Subject: [PATCH 5/6] added a filter for multi-module --- .../ide/idea/ui/LocalComponentsTree.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/jfrog/ide/idea/ui/LocalComponentsTree.java b/src/main/java/com/jfrog/ide/idea/ui/LocalComponentsTree.java index a2e9c1da..a5002e23 100644 --- a/src/main/java/com/jfrog/ide/idea/ui/LocalComponentsTree.java +++ b/src/main/java/com/jfrog/ide/idea/ui/LocalComponentsTree.java @@ -29,6 +29,7 @@ import java.io.IOException; import java.util.*; import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; /** * @author yahavi @@ -113,12 +114,12 @@ private void handleContextMenu(ComponentsTree tree, MouseEvent e) { if (selectedPath == null) { return; } - Object selected = selectedPath.getLastPathComponent(); if (selected instanceof DependencyNode) { - - this.createNodePopupMenu((DependencyNode) selected); + DescriptorFileTreeNode descriptorFileTreeNode = (DescriptorFileTreeNode) selectedPath.getParentPath().getLastPathComponent(); + String descriptorPath = descriptorFileTreeNode.getSubtitle(); + this.createNodePopupMenu((DependencyNode) selected, descriptorPath); } else if (selected instanceof VulnerabilityNode) { createIgnoreRuleOption((VulnerabilityNode) selected, e); } else if (selected instanceof ApplicableIssueNode) { @@ -138,11 +139,20 @@ private void createIgnoreRuleOption(VulnerabilityNode selectedIssue, MouseEvent toolTip.setEnabled(true); } - private void createNodePopupMenu(DependencyNode selectedNode) { + private void createNodePopupMenu(DependencyNode selectedNode, String descriptorPath) { popupMenu.removeAll(); NavigationService navigationService = NavigationService.getInstance(project); Set navigationCandidates = navigationService.getNavigation(selectedNode); - addNodeNavigation(navigationCandidates); + //filtering candidates in case of multi module project + Set filteredCandidates = navigationCandidates.stream() + .filter(navigationTarget -> + descriptorPath.equals(navigationTarget.getElement() + .getContainingFile() + .getVirtualFile() + .getPath())) + .collect(Collectors.toSet()); + + addNodeNavigation(filteredCandidates); } private void addNodeNavigation(Set navigationCandidates) { From 153fa48a776506203b000877faeedc564f9bd04b Mon Sep 17 00:00:00 2001 From: Eyal Kapon Date: Sun, 22 Sep 2024 15:40:27 +0300 Subject: [PATCH 6/6] cr fixes --- .../com/jfrog/ide/idea/navigation/NavigationService.java | 1 - src/main/java/com/jfrog/ide/idea/scan/GradleScanner.java | 2 +- .../java/com/jfrog/ide/idea/ui/LocalComponentsTree.java | 7 +++---- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/jfrog/ide/idea/navigation/NavigationService.java b/src/main/java/com/jfrog/ide/idea/navigation/NavigationService.java index 4ed11d93..8a3eb791 100644 --- a/src/main/java/com/jfrog/ide/idea/navigation/NavigationService.java +++ b/src/main/java/com/jfrog/ide/idea/navigation/NavigationService.java @@ -49,7 +49,6 @@ public void addNavigation(DependencyNode treeNode, PsiElement navigationTargetEl } NavigationTarget navigationTarget = new NavigationTarget(navigationTargetElement, document.getLineNumber(navigationTargetElement.getTextOffset()), componentName); Set navigationTargets = navigationMap.get(treeNode); - if (navigationTargets == null) { navigationTargets = new HashSet<>(Collections.singletonList(navigationTarget)); diff --git a/src/main/java/com/jfrog/ide/idea/scan/GradleScanner.java b/src/main/java/com/jfrog/ide/idea/scan/GradleScanner.java index 377153aa..e25b77ee 100644 --- a/src/main/java/com/jfrog/ide/idea/scan/GradleScanner.java +++ b/src/main/java/com/jfrog/ide/idea/scan/GradleScanner.java @@ -34,7 +34,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.*; +import java.util.Map; import java.util.concurrent.ExecutorService; import static com.jfrog.ide.common.log.Utils.logError; diff --git a/src/main/java/com/jfrog/ide/idea/ui/LocalComponentsTree.java b/src/main/java/com/jfrog/ide/idea/ui/LocalComponentsTree.java index a5002e23..5acb81e4 100644 --- a/src/main/java/com/jfrog/ide/idea/ui/LocalComponentsTree.java +++ b/src/main/java/com/jfrog/ide/idea/ui/LocalComponentsTree.java @@ -116,10 +116,11 @@ private void handleContextMenu(ComponentsTree tree, MouseEvent e) { } Object selected = selectedPath.getLastPathComponent(); + // Create the popup menu if clicked on a package. if it's a vulnerability, create ignore rule option. if (selected instanceof DependencyNode) { DescriptorFileTreeNode descriptorFileTreeNode = (DescriptorFileTreeNode) selectedPath.getParentPath().getLastPathComponent(); String descriptorPath = descriptorFileTreeNode.getSubtitle(); - this.createNodePopupMenu((DependencyNode) selected, descriptorPath); + createNodePopupMenu((DependencyNode) selected, descriptorPath); } else if (selected instanceof VulnerabilityNode) { createIgnoreRuleOption((VulnerabilityNode) selected, e); } else if (selected instanceof ApplicableIssueNode) { @@ -272,6 +273,4 @@ public void setNoIssuesEmptyText() { public void setScanErrorEmptyText() { SwingUtilities.invokeLater(() -> getEmptyText().setText(ERROR_WHILE_SCANNING)); } -} - - +} \ No newline at end of file