-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathcontainerNode.ts
78 lines (68 loc) · 2.83 KB
/
containerNode.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
import { ThemeIcon, Uri } from "vscode";
import { Explorer } from "../constants";
import { Jdtls } from "../java/jdtls";
import { INodeData, NodeKind } from "../java/nodeData";
import { DataNode } from "./dataNode";
import { ExplorerNode } from "./explorerNode";
import { NodeFactory } from "./nodeFactory";
import { ProjectNode } from "./projectNode";
export class ContainerNode extends DataNode {
constructor(nodeData: INodeData, parent: DataNode, private readonly _project: ProjectNode) {
super(nodeData, parent);
}
public get projectBasePath() {
return this._project.uri && Uri.parse(this._project.uri).fsPath;
}
public getContainerType(): string {
const containerPath: string = this._nodeData.path || "";
if (containerPath.startsWith(ContainerPath.JRE)) {
return ContainerType.JRE;
} else if (containerPath.startsWith(ContainerPath.Maven)) {
return ContainerType.Maven;
} else if (containerPath.startsWith(ContainerPath.Gradle)) {
return ContainerType.Gradle;
} else if (containerPath.startsWith(ContainerPath.ReferencedLibrary) && this._project.isUnmanagedFolder()) {
// currently, we only support editing referenced libraries in unmanaged folders
return ContainerType.ReferencedLibrary;
}
return ContainerType.Unknown;
}
protected async loadData(): Promise<INodeData[]> {
return Jdtls.getPackageData({ kind: NodeKind.Container, projectUri: this._project.uri, path: this.path });
}
protected createChildNodeList(): ExplorerNode[] {
const result: (ExplorerNode | undefined)[] = [];
if (this.nodeData.children && this.nodeData.children.length) {
this.nodeData.children.forEach((nodeData) => {
result.push(NodeFactory.createNode(nodeData, this, this._project));
});
}
return result.filter(<T>(n?: T): n is T => Boolean(n));
}
protected get contextValue(): string {
let contextValue: string = Explorer.ContextValueType.Container;
const containerType: string = this.getContainerType();
if (containerType) {
contextValue += `+${containerType}`;
}
return contextValue;
}
protected get iconPath(): ThemeIcon {
return new ThemeIcon("folder-library");
}
}
export enum ContainerType {
JRE = "jre",
Maven = "maven",
Gradle = "gradle",
ReferencedLibrary = "referencedLibrary",
Unknown = "",
}
const enum ContainerPath {
JRE = "org.eclipse.jdt.launching.JRE_CONTAINER",
Maven = "org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER",
Gradle = "org.eclipse.buildship.core.gradleclasspathcontainer",
ReferencedLibrary = "REFERENCED_LIBRARIES_PATH",
}