Skip to content

Commit

Permalink
Fixed Aarch64 support on source code scanning (#432)
Browse files Browse the repository at this point in the history
Resolved a macOS issue where the Aarch64 architecture was incorrectly fetching the AMD-64 binary. Now, the correct ARM-64 architecture binary is retrieved.
  • Loading branch information
noyshabtay authored Nov 8, 2023
1 parent 72a836e commit c0822e1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
3 changes: 2 additions & 1 deletion src/main/java/com/jfrog/ide/idea/scan/ScanUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.intellij.openapi.project.ProjectUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.jfrog.ide.idea.log.Logger;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.SystemUtils;

import java.io.IOException;
Expand Down Expand Up @@ -49,7 +50,7 @@ static String getOSAndArc() throws IOException {
}
// Mac
if (SystemUtils.IS_OS_MAC) {
if (arch.equals("arm64")) {
if (StringUtils.equalsAny(arch, "aarch64", "arm64")) {
return "mac-arm64";
} else {
return "mac-amd64";
Expand Down
29 changes: 15 additions & 14 deletions src/main/java/com/jfrog/ide/idea/scan/ScannerBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,12 @@ private void scanAndUpdate(ProgressIndicator indicator) {
* Walks through a {@link DepTree}'s nodes.
* Builds impact paths for {@link DependencyNode} objects and groups them in {@link DescriptorFileTreeNode}s.
*
* @param dependencies a map of component IDs and the DependencyNode object matching each of them.
* @param depTree the project's dependency tree to walk through.
* @param vulnerableDependencies a map of component IDs and the DependencyNode object matching each of them.
* @param depTree the project's dependency tree to walk through.
*/
private List<FileTreeNode> walkDepTree(Map<String, DependencyNode> dependencies, DepTree depTree) {
private List<FileTreeNode> walkDepTree(Map<String, DependencyNode> vulnerableDependencies, DepTree depTree) {
Map<String, DescriptorFileTreeNode> descriptorNodes = new HashMap<>();
visitDepTreeNode(dependencies, depTree, Collections.singletonList(depTree.getRootId()), descriptorNodes, new ArrayList<>(), new HashMap<>());
visitDepTreeNode(vulnerableDependencies, depTree, Collections.singletonList(depTree.getRootId()), descriptorNodes, new ArrayList<>(), new HashMap<>());
return new CopyOnWriteArrayList<>(descriptorNodes.values());
}

Expand All @@ -196,14 +196,14 @@ private List<FileTreeNode> walkDepTree(Map<String, DependencyNode> dependencies,
* Each impact path to a vulnerable dependency is added in its {@link DependencyNode}.
* Each DependencyNode is added to the relevant {@link DescriptorFileTreeNode}s.
*
* @param dependencies a map of {@link DependencyNode}s by their component IDs.
* @param depTree the project's dependency tree.
* @param path a path of nodes (represented by their component IDs) from the root to the current node.
* @param descriptorNodes a map of {@link DescriptorFileTreeNode}s by the descriptor file path. Missing DescriptorFileTreeNodes will be added to this map.
* @param descriptorPaths a list of descriptor file paths that their matching components are in the path to the current node.
* @param addedDeps a map of all {@link DependencyNode}s already grouped to {@link DescriptorFileTreeNode}s. Newly grouped DependencyNodes will be added to this map.
* @param vulnerableDependencies a map of {@link DependencyNode}s by their component IDs.
* @param depTree the project's dependency tree.
* @param path a path of nodes (represented by their component IDs) from the root to the current node.
* @param descriptorNodes a map of {@link DescriptorFileTreeNode}s by the descriptor file path. Missing DescriptorFileTreeNodes will be added to this map.
* @param descriptorPaths a list of descriptor file paths that their matching components are in the path to the current node.
* @param addedDeps a map of all {@link DependencyNode}s already grouped to {@link DescriptorFileTreeNode}s. Newly grouped DependencyNodes will be added to this map.
*/
private void visitDepTreeNode(Map<String, DependencyNode> dependencies, DepTree depTree, List<String> path,
private void visitDepTreeNode(Map<String, DependencyNode> vulnerableDependencies, DepTree depTree, List<String> path,
Map<String, DescriptorFileTreeNode> descriptorNodes, List<String> descriptorPaths,
Map<String, Map<String, DependencyNode>> addedDeps) {
String compId = path.get(path.size() - 1);
Expand All @@ -213,8 +213,8 @@ private void visitDepTreeNode(Map<String, DependencyNode> dependencies, DepTree
innerDescriptorPaths = new ArrayList<>(descriptorPaths);
innerDescriptorPaths.add(compNode.getDescriptorFilePath());
}
if (dependencies.containsKey(compId)) {
DependencyNode dependencyNode = dependencies.get(compId);
if (vulnerableDependencies.containsKey(compId)) {
DependencyNode dependencyNode = vulnerableDependencies.get(compId);
addImpactPathToDependencyNode(dependencyNode, path);

DepTreeNode parentCompNode = null;
Expand All @@ -240,6 +240,7 @@ private void visitDepTreeNode(Map<String, DependencyNode> dependencies, DepTree
// The solution for this is to clone the dependency before adding it as a child of the POM.
DependencyNode clonedDep = (DependencyNode) dependencyNode.clone();
clonedDep.setIndirect(indirect);

descriptorNodes.get(descriptorPath).addDependency(clonedDep);
addedDeps.get(descriptorPath).put(compId, clonedDep);
}
Expand All @@ -249,7 +250,7 @@ private void visitDepTreeNode(Map<String, DependencyNode> dependencies, DepTree
List<String> pathToChild = new ArrayList<>(path);
pathToChild.add(childId);
if (!path.contains(childId)) {
visitDepTreeNode(dependencies, depTree, pathToChild, descriptorNodes, innerDescriptorPaths, addedDeps);
visitDepTreeNode(vulnerableDependencies, depTree, pathToChild, descriptorNodes, innerDescriptorPaths, addedDeps);
}
}
}
Expand Down

0 comments on commit c0822e1

Please sign in to comment.