Skip to content

Commit

Permalink
Remove unused _dependencies and rename componentId to xray
Browse files Browse the repository at this point in the history
  • Loading branch information
Or-Geva committed Sep 18, 2023
1 parent e88a896 commit 13b96d1
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 41 deletions.
8 changes: 4 additions & 4 deletions src/main/scanLogic/scanGraphLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class GraphScanLogic {
*/
public async scan(graphRoot: RootNode, progress: XrayScanProgress, checkCanceled: () => void): Promise<IGraphResponse> {
let graphRequest: IGraphRequestModel = {
component_id: graphRoot.generalInfo.artifactId ?? graphRoot.dependencyId,
component_id: graphRoot.generalInfo.artifactId ?? graphRoot.xrayId,
nodes: this.getFlattenRequestModelNodes(graphRoot, new Set<string>())
} as IGraphRequestModel;
if (!graphRequest.nodes || graphRequest.nodes.length === 0) {
Expand All @@ -48,10 +48,10 @@ export class GraphScanLogic {
public getFlattenRequestModelNodes(dependency: DependenciesTreeNode, components: Set<string>): IGraphRequestModel[] | undefined {
let nodes: IGraphRequestModel[] = [];
for (let child of dependency.children) {
if (child.dependencyId && !components.has(child.dependencyId)) {
components.add(child.dependencyId);
if (child.xrayId && !components.has(child.xrayId)) {
components.add(child.xrayId);
nodes.push({
component_id: child.dependencyId
component_id: child.xrayId
} as IGraphRequestModel);
}
let childNodes: IGraphRequestModel[] | undefined = this.getFlattenRequestModelNodes(child, components);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,7 @@ export class GoTreeNode extends RootNode {

private addComponentToScan(dependenciesTreeNode: DependenciesTreeNode) {
let componentId: string = dependenciesTreeNode.generalInfo.artifactId + ':' + dependenciesTreeNode.generalInfo.version;
this.projectDetails.addDependency(GoTreeNode.COMPONENT_PREFIX + componentId);
dependenciesTreeNode.dependencyId = GoTreeNode.COMPONENT_PREFIX + componentId;
dependenciesTreeNode.xrayId = GoTreeNode.COMPONENT_PREFIX + componentId;
}

private getNameVersionTuple(value: string): string[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,8 @@ export class MavenTreeNode extends RootNode {
let child: DependenciesTreeNode = new DependenciesTreeNode(gavGeneralInfo, treeCollapsibleState, parent);
child.label = group + ':' + name;
let componentId: string = gavGeneralInfo.getComponentId();
this.projectDetails.addDependency(MavenTreeNode.COMPONENT_PREFIX + componentId);

child.dependencyId = MavenTreeNode.COMPONENT_PREFIX + componentId;
child.xrayId = MavenTreeNode.COMPONENT_PREFIX + componentId;
if (rawDependenciesPtr.index + 1 < rawDependenciesList.length) {
while (
rawDependenciesPtr.index + 1 < rawDependenciesList.length &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ export class NpmTreeNode extends RootNode {
: vscode.TreeItemCollapsibleState.None;
let child: DependenciesTreeNode = new DependenciesTreeNode(generalInfo, treeCollapsibleState, dependenciesTreeNode);
let componentId: string = key + ':' + version;
this.projectDetails.addDependency(NpmTreeNode.COMPONENT_PREFIX + componentId);
child.dependencyId = NpmTreeNode.COMPONENT_PREFIX + componentId;
child.xrayId = NpmTreeNode.COMPONENT_PREFIX + componentId;
this.populateDependenciesTree(child, childDependencies);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ export class NugetTreeNode extends RootNode {
childDependencies.length > 0 ? vscode.TreeItemCollapsibleState.Collapsed : vscode.TreeItemCollapsibleState.None;
let child: DependenciesTreeNode = new DependenciesTreeNode(generalInfo, treeCollapsibleState, dependenciesTreeNode, '');
let combined: string = id + ':' + version;
this.projectDetails.addDependency(NugetTreeNode.COMPONENT_PREFIX + combined);
child.dependencyId = NugetTreeNode.COMPONENT_PREFIX + combined;
child.xrayId = NugetTreeNode.COMPONENT_PREFIX + combined;
this.populateDependenciesTree(child, childDependencies);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ export class PypiTreeNode extends RootNode {
: vscode.TreeItemCollapsibleState.None;
let child: DependenciesTreeNode = new DependenciesTreeNode(generalInfo, treeCollapsibleState, dependenciesTreeNode);
let componentId: string = dependency.key + ':' + version;
this.projectDetails.addDependency(PypiTreeNode.COMPONENT_PREFIX + componentId);
child.dependencyId = PypiTreeNode.COMPONENT_PREFIX + componentId;
child.xrayId = PypiTreeNode.COMPONENT_PREFIX + componentId;
this.populateDependenciesTree(child, childDependencies);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ export class DependenciesTreeNode extends vscode.TreeItem {
}
}

public get dependencyId(): string {
public get xrayId(): string {
return this._dependencyId;
}

public set dependencyId(value: string) {
public set xrayId(value: string) {
this._dependencyId = value;
}

Expand Down
22 changes: 0 additions & 22 deletions src/main/types/projectDetails.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { ComponentDetails } from 'jfrog-client-js';
import * as path from 'path';
import { PackageType } from './projectType';
import Set from 'typescript-collections/dist/lib/Set';

export class ProjectDetails {
private _dependencies: Set<ComponentDetails> = new Set<ComponentDetails>();
private _name: string;

constructor(private _path: string, private _type: PackageType) {
Expand Down Expand Up @@ -34,23 +31,4 @@ export class ProjectDetails {
public set path(value: string) {
this._path = value;
}

public get dependencies(): Set<ComponentDetails> {
return this._dependencies;
}

public set dependencies(value: Set<ComponentDetails>) {
this._dependencies = value;
}

/**
* @param dependencyId - component id of the dependency
*/
public addDependency(dependencyId: string) {
this._dependencies.add(new ComponentDetails(dependencyId));
}

public toArray(): ComponentDetails[] {
return this._dependencies.toArray();
}
}
4 changes: 2 additions & 2 deletions src/test/tests/goUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ describe('Go Utils Tests', async () => {
let dependenciesTreeNode: DependenciesTreeNode = new DependenciesTreeNode(
new GeneralInfo('github.com/jfrog/jfrog-cli-core', '1.9.1', [], '', PackageType.Go)
);
let dependencyPos: vscode.Range[] = GoUtils.getDependencyPosition(textDocument, dependenciesTreeNode.dependencyId, FocusType.Dependency);
let dependencyPos: vscode.Range[] = GoUtils.getDependencyPosition(textDocument, dependenciesTreeNode.xrayId, FocusType.Dependency);
assert.deepEqual(dependencyPos[0].start, new vscode.Position(5, 1));
assert.deepEqual(dependencyPos[0].end, new vscode.Position(5, 39));

// Test 'resources/go/empty/go.mod'
goMod = vscode.Uri.file(path.join(commonProjDir.fsPath, 'empty', 'go.mod'));
textDocument = await vscode.workspace.openTextDocument(goMod);
dependencyPos = GoUtils.getDependencyPosition(textDocument, dependenciesTreeNode.dependencyId, FocusType.Dependency);
dependencyPos = GoUtils.getDependencyPosition(textDocument, dependenciesTreeNode.xrayId, FocusType.Dependency);
assert.isEmpty(dependencyPos);
});

Expand Down
2 changes: 1 addition & 1 deletion src/test/tests/utils/treeNodeUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export function createRootTestNode(pathOfWorkspace: string): IssuesRootTreeNode

export function createDependency(artifactId: string, version: string, parent?: DependenciesTreeNode): DependenciesTreeNode {
let dependenciesTreeNode: DependenciesTreeNode = new DependenciesTreeNode(new GeneralInfo(artifactId, version, [], '', PackageType.Unknown));
dependenciesTreeNode.dependencyId = artifactId + ':' + version;
dependenciesTreeNode.xrayId = artifactId + ':' + version;
parent?.addChild(dependenciesTreeNode);
return dependenciesTreeNode;
}
Expand Down

0 comments on commit 13b96d1

Please sign in to comment.