Skip to content

Commit

Permalink
Add NuGet support
Browse files Browse the repository at this point in the history
  • Loading branch information
RobiNino authored Sep 1, 2020
1 parent b8c109c commit 671da7d
Show file tree
Hide file tree
Showing 20 changed files with 627 additions and 7 deletions.
141 changes: 139 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@
"dependencies": {
"fs-extra": "~9.0.0",
"keytar": "~5.6.0",
"nuget-deps-tree": "~0.1.0",
"semver": "~7.3.2",
"typescript-collections": "~1.3.3",
"xmlbuilder2": "~2.1.2",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import * as Collections from 'typescript-collections';
import * as vscode from 'vscode';
import { ComponentDetails } from 'xray-client-js';
import { DependenciesTreeNode } from '../dependenciesTreeNode';
import { TreesManager } from '../../treesManager';
import { GeneralInfo } from '../../../types/generalInfo';
import { NugetUtils } from '../../../utils/nugetUtils';

export class NugetTreeNode extends DependenciesTreeNode {
private static readonly COMPONENT_PREFIX: string = 'nuget://';

constructor(
private _workspaceFolder: string,
private _componentsToScan: Collections.Set<ComponentDetails>,
private _treesManager: TreesManager,
parent?: DependenciesTreeNode
) {
super(new GeneralInfo('', '', _workspaceFolder, ''), vscode.TreeItemCollapsibleState.Expanded, parent, '');
}

public async refreshDependencies(quickScan: boolean, project: any) {
this.generalInfo = new GeneralInfo(project.name, '', this._workspaceFolder, NugetUtils.PKG_TYPE);
this.label = project.name;
this.populateDependenciesTree(this, project.dependencies, quickScan);
}

private populateDependenciesTree(dependenciesTreeNode: DependenciesTreeNode, dependencies: any, quickScan: boolean) {
if (!dependencies) {
return;
}
for (let key in dependencies) {
let dependency: any = dependencies[key];
let nameVersionTuple: string[] = this.getNameVersionTuple(dependency.dependency.id);
let name: string = nameVersionTuple[0];
let version: string = nameVersionTuple[1];
if (version) {
let childDependencies: any = dependency.directDependencies;
let generalInfo: GeneralInfo = new GeneralInfo(name, version, '', NugetUtils.PKG_TYPE);
let treeCollapsibleState: vscode.TreeItemCollapsibleState =
childDependencies.length > 0 ? vscode.TreeItemCollapsibleState.Collapsed : vscode.TreeItemCollapsibleState.None;
let child: DependenciesTreeNode = new DependenciesTreeNode(generalInfo, treeCollapsibleState, dependenciesTreeNode, '');
if (!quickScan || !this._treesManager.scanCacheManager.validateOrDelete(dependency.dependency.id)) {
this._componentsToScan.add(new ComponentDetails(NugetTreeNode.COMPONENT_PREFIX + dependency.dependency.id));
}
this.populateDependenciesTree(child, childDependencies, quickScan);
}
}
}

private getNameVersionTuple(value: string): string[] {
let split: string[] = value.split(':');
return [split[0], split[1]];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { PypiUtils } from '../../utils/pypiUtils';
import { DependenciesTreeNode } from './dependenciesTreeNode';
import { TreesManager } from '../treesManager';
import { MavenUtils } from '../../utils/mavenUtils';
import { NugetUtils } from '../../utils/nugetUtils';

export class DependenciesTreesFactory {
public static async createDependenciesTrees(
Expand All @@ -22,6 +23,7 @@ export class DependenciesTreesFactory {
await NpmUtils.createDependenciesTrees(workspaceFolders, componentsToScan, treesManager, parent, quickScan);
await PypiUtils.createDependenciesTrees(workspaceFolders, componentsToScan, treesManager, parent, quickScan);
await MavenUtils.createMavenDependenciesTrees(workspaceFolders, componentsToScan, treesManager, parent, quickScan);
await NugetUtils.createDependenciesTrees(workspaceFolders, componentsToScan, treesManager, parent, quickScan);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ export class DependenciesTreeNode extends vscode.TreeItem {
this.iconPath = IconsPaths.NORMAL_SEVERITY;
this.description = this.generalInfo.version;
this.tooltip = this.componentId;
this.contextValue = contextValue || ContextKeys.SHOW_IN_PROJECT_DESC_ENABLED;
if (contextValue === undefined) {
this.contextValue = ContextKeys.SHOW_IN_PROJECT_DESC_ENABLED;
}
if (_parent) {
_parent.children.push(this);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/utils/goUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class GoUtils {
public static async locateGoMods(workspaceFolders: vscode.WorkspaceFolder[], logManager: LogManager): Promise<Collections.Set<vscode.Uri>> {
let goMods: Collections.Set<vscode.Uri> = new Collections.Set();
for (let workspace of workspaceFolders) {
logManager.logMessage('Locating go.mod files in workspace' + workspace.name, 'INFO');
logManager.logMessage('Locating go.mod files in workspace "' + workspace.name + '".', 'INFO');
let wsGoMods: vscode.Uri[] = await vscode.workspace.findFiles(
{ base: workspace.uri.fsPath, pattern: '**/go.mod' },
ScanUtils.getScanExcludePattern(workspace)
Expand Down
2 changes: 1 addition & 1 deletion src/main/utils/mavenUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export class MavenUtils {
public static async locatePomXmls(workspaceFolders: vscode.WorkspaceFolder[], logManager: LogManager): Promise<vscode.Uri[]> {
let pomXmls: Collections.Set<vscode.Uri> = new Collections.Set();
for (let workspace of workspaceFolders) {
logManager.logMessage('Locating pom.xml files in workspace ' + workspace.name, 'INFO');
logManager.logMessage('Locating pom.xml files in workspace "' + workspace.name + '".', 'INFO');
let wsPomXmls: vscode.Uri[] = await vscode.workspace.findFiles(
{ base: workspace.uri.fsPath, pattern: '**/pom.xml' },
ScanUtils.getScanExcludePattern(workspace)
Expand Down
2 changes: 1 addition & 1 deletion src/main/utils/npmUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class NpmUtils {
public static async locatePackageJsons(workspaceFolders: vscode.WorkspaceFolder[], logManager: LogManager): Promise<Collections.Set<vscode.Uri>> {
let packageJsons: Collections.Set<vscode.Uri> = new Collections.Set();
for (let workspace of workspaceFolders) {
logManager.logMessage('Locating package json files in workspace' + workspace.name, 'INFO');
logManager.logMessage('Locating package json files in workspace "' + workspace.name + '".', 'INFO');
let wsPackageJsons: vscode.Uri[] = await vscode.workspace.findFiles(
{ base: workspace.uri.fsPath, pattern: '**/package.json' },
ScanUtils.getScanExcludePattern(workspace)
Expand Down
Loading

0 comments on commit 671da7d

Please sign in to comment.