-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* dependencies treeview * fix CI errors * fix other ci errors * refine the implementation by adding TreeNode between plaintext and vscode.TreeItem * fix CI, delete unread variables in class Dependency * Dependency entends TreeNode * delete unnecessary error message Co-authored-by: Yan Zhang <[email protected]>
- Loading branch information
1 parent
6fa0e46
commit 47b2964
Showing
7 changed files
with
167 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. | ||
|
||
import * as vscode from "vscode"; | ||
import { parseRawDependencyDataHandler } from "../../handlers/parseRawDependencyDataHandler"; | ||
import { Dependency } from "./Dependency"; | ||
import { ITreeItem } from "./ITreeItem"; | ||
import { MavenProject } from "./MavenProject"; | ||
import { Menu } from "./Menu"; | ||
|
||
export class DependenciesMenu extends Menu implements ITreeItem { | ||
constructor(project: MavenProject) { | ||
super(project); | ||
this.name = "Dependencies"; | ||
} | ||
|
||
public async getChildren() : Promise<Dependency[]> { | ||
const treeNodes = await parseRawDependencyDataHandler(this.project); | ||
return Promise.resolve(treeNodes); | ||
} | ||
|
||
public getTreeItem(): vscode.TreeItem | Thenable<vscode.TreeItem> { | ||
const treeItem: vscode.TreeItem = new vscode.TreeItem(this.name, vscode.TreeItemCollapsibleState.Collapsed); | ||
treeItem.iconPath = new vscode.ThemeIcon("library"); | ||
return treeItem; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. | ||
|
||
import * as vscode from "vscode"; | ||
import { ITreeItem } from "./ITreeItem"; | ||
import { TreeNode } from "./TreeNode"; | ||
|
||
const DUPLICATE_INDICATOR: string = "omitted for duplicate"; | ||
const CONFLICT_INDICATOR: string = "omitted for conflict"; | ||
|
||
export class Dependency extends TreeNode implements ITreeItem { | ||
private label: string = ""; // groupId:artifactId:version:scope | ||
private description: string = ""; | ||
constructor(value: string) { | ||
super(value); | ||
const indexCut: number = value.indexOf("("); | ||
if (indexCut !== -1) { | ||
this.description = value.substr(indexCut); | ||
this.label = value.substr(0, indexCut); | ||
} else { | ||
this.label = value; | ||
} | ||
} | ||
|
||
public getContextValue(): string { | ||
return "Dependencies"; | ||
} | ||
|
||
public async getChildren(): Promise<Dependency[] | undefined> { | ||
return Promise.resolve(<Dependency[]> this.children); | ||
} | ||
|
||
public getTreeItem(): vscode.TreeItem | Thenable<vscode.TreeItem> { | ||
const treeItem: vscode.TreeItem = new vscode.TreeItem(this.label); | ||
if (this.children.length !== 0) { | ||
treeItem.collapsibleState = vscode.TreeItemCollapsibleState.Collapsed; | ||
} else { | ||
treeItem.collapsibleState = vscode.TreeItemCollapsibleState.None; | ||
} | ||
|
||
if (this.description.indexOf(DUPLICATE_INDICATOR) !== -1) { | ||
treeItem.iconPath = new vscode.ThemeIcon("trash"); | ||
treeItem.description = this.description; | ||
} else if (this.description.indexOf(CONFLICT_INDICATOR) !== -1) { | ||
treeItem.iconPath = new vscode.ThemeIcon("warning"); | ||
treeItem.description = this.description; | ||
} else { | ||
treeItem.iconPath = new vscode.ThemeIcon("library"); | ||
} | ||
return treeItem; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. | ||
|
||
export class TreeNode { | ||
protected value: string; | ||
protected children: TreeNode[] = []; | ||
protected parent?: TreeNode | undefined; | ||
constructor(value: string) { | ||
this.value = value; | ||
} | ||
|
||
public addChild(valueOrNode: string | TreeNode): void { | ||
let child: TreeNode; | ||
if (typeof valueOrNode === "string") { | ||
child = new TreeNode(valueOrNode); | ||
} else { | ||
child = valueOrNode; | ||
} | ||
child.parent = this; | ||
this.children.push(child); | ||
} | ||
|
||
public addChildren(nodes: TreeNode[]): void { | ||
nodes.forEach(node => node.parent = this); | ||
this.children = this.children.concat(nodes); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. | ||
|
||
import { Dependency } from "../explorer/model/Dependency"; | ||
import { MavenProject } from "../explorer/model/MavenProject"; | ||
import { getDependencyTree } from "../handlers/showDependenciesHandler"; | ||
|
||
export async function parseRawDependencyDataHandler(project: MavenProject): Promise<Dependency[]> { | ||
const dependencyTree: string | undefined = await getDependencyTree(project.pomPath); | ||
if (dependencyTree === undefined) { | ||
throw new Error("Failed to generate dependency tree."); | ||
} | ||
let treeContent: string = dependencyTree.slice(0, -1); // delete last "\n" | ||
treeContent = treeContent.replace(/\|/g, " "); | ||
treeContent = treeContent.replace(/\\/g, "+"); | ||
treeContent = treeContent.replace(/\n/g, "\r\n"); | ||
// handle the version switch in conflict | ||
// input = (groupId:artifactId:)(version1)(:scope (omitted for conflict): (version2)) | ||
// output = (groupId:artifactId:)(version2)(:scope (omitted for conflict) with (version1)) | ||
const re = /([\w.]+:[\w.-]+:)([\w.-]+)(:[\w/.(\s]+):\s([\w.-]+)\)/gm; | ||
treeContent = treeContent.replace(re, "$1$4$3 with $2)"); | ||
|
||
const eol: string = "\r\n"; | ||
const indent: string = " "; // three spaces | ||
const separator: string = "\r\n"; | ||
const starter: string = "+- "; | ||
return parseTreeNodes(treeContent, separator, indent, starter, eol); | ||
} | ||
|
||
function parseTreeNodes(treecontent: string, separator: string, indent: string, starter: string, eol: string): Dependency[] { | ||
const treeNodes: Dependency[] = []; | ||
if (treecontent) { | ||
const treeChildren: string[] = treecontent.split(`${separator}${starter}`).splice(1); // delete first line | ||
const toTreeNode = (treeChild: string): Dependency => { | ||
let curNode: Dependency; | ||
if (treeChild.indexOf(eol) === -1) { | ||
curNode = new Dependency(treeChild); | ||
} else { | ||
const curValue: string = treeChild.split(separator, 1)[0]; | ||
curNode = new Dependency(curValue); | ||
const nextSeparator = `${separator}${indent}`; | ||
const childrenNodes: Dependency[] = parseTreeNodes(treeChild, nextSeparator, indent, starter, eol); | ||
curNode.addChildren(childrenNodes); | ||
} | ||
return curNode; | ||
}; | ||
treeChildren.forEach(treeChild => treeNodes.push(toTreeNode(treeChild))); | ||
} | ||
return treeNodes; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters