can remove imported project
This commit is contained in:
Родитель
ec5f6a92a6
Коммит
7079a878df
11
package.json
11
package.json
|
@ -36,6 +36,7 @@
|
|||
"onCommand:maven.goal.custom",
|
||||
"onCommand:maven.project.effectivePom",
|
||||
"onCommand:maven.project.import",
|
||||
"onCommand:maven.project.remove",
|
||||
"onCommand:maven.project.openPom",
|
||||
"onCommand:maven.archetype.generate",
|
||||
"onView:mavenProjects"
|
||||
|
@ -121,6 +122,11 @@
|
|||
"title": "Open POM file",
|
||||
"category": "Maven"
|
||||
},
|
||||
{
|
||||
"command": "maven.project.remove",
|
||||
"title": "Remove Maven Project",
|
||||
"category": "Maven"
|
||||
},
|
||||
{
|
||||
"command": "maven.archetype.generate",
|
||||
"title": "Generate from Maven Archetype",
|
||||
|
@ -238,6 +244,11 @@
|
|||
"command": "maven.project.effectivePom",
|
||||
"when": "view == mavenProjects && viewItem == mavenProject",
|
||||
"group": "0-pom@1"
|
||||
},
|
||||
{
|
||||
"command": "maven.project.remove",
|
||||
"when": "view == mavenProjects && viewItem == mavenProject",
|
||||
"group": "2-ops@0"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
|
|
@ -30,15 +30,7 @@ export class ProjectDataProvider implements TreeDataProvider<TreeItem> {
|
|||
if (element === undefined) {
|
||||
this.cachedItems = [];
|
||||
const todolist: Promise<ProjectItem>[] = [];
|
||||
const pomXmlFilePaths: string[] = [];
|
||||
if (workspace.workspaceFolders) {
|
||||
const test: WorkspaceFolder[] = workspace.workspaceFolders;
|
||||
workspace.workspaceFolders.forEach((wf: WorkspaceFolder) => {
|
||||
Utils.findAllInDir(wf.uri.fsPath, "pom.xml", 1).forEach((pomxml: string) => {
|
||||
pomXmlFilePaths.push(pomxml);
|
||||
});
|
||||
});
|
||||
}
|
||||
const pomXmlFilePaths: string[] = this.getRootPomPaths();
|
||||
|
||||
const pinnedPomPaths: string[] = workspace.getConfiguration("maven.projects").get<string[]>("pinnedPomPaths") || [];
|
||||
pinnedPomPaths.filter(
|
||||
|
@ -113,7 +105,6 @@ export class ProjectDataProvider implements TreeDataProvider<TreeItem> {
|
|||
}
|
||||
|
||||
public async effectivePom(item: Uri | ProjectItem | undefined): Promise<void> {
|
||||
let pomXmlFilePath: string = null;
|
||||
if (!item) {
|
||||
item = await VSCodeUI.getQuickPick<ProjectItem>(
|
||||
this.cachedItems,
|
||||
|
@ -121,13 +112,14 @@ export class ProjectDataProvider implements TreeDataProvider<TreeItem> {
|
|||
(x: ProjectItem) => x.pomXmlFilePath
|
||||
);
|
||||
}
|
||||
let pomXmlFilePath: string = null;
|
||||
if (item instanceof Uri) {
|
||||
pomXmlFilePath = item.fsPath;
|
||||
} else if (item instanceof ProjectItem) {
|
||||
pomXmlFilePath = item.pomXmlFilePath;
|
||||
}
|
||||
if (!pomXmlFilePath) {
|
||||
return Promise.reject("Effective Failure");
|
||||
return Promise.resolve();
|
||||
}
|
||||
const promise: Promise<string> = new Promise<string>(
|
||||
(resolve: (value: string) => void, reject: (e: Error) => void): void => {
|
||||
|
@ -160,7 +152,7 @@ export class ProjectDataProvider implements TreeDataProvider<TreeItem> {
|
|||
(x: ProjectItem) => x.pomXmlFilePath);
|
||||
}
|
||||
if (!item || !item.pomXmlFilePath) {
|
||||
return Promise.reject("customGoal");
|
||||
return Promise.resolve();
|
||||
}
|
||||
const cmdlist: string[] = Utils.loadCmdHistory(item.pomXmlFilePath);
|
||||
const selectedGoal: string = await window.showQuickPick(cmdlist.concat([ENTRY_NEW_GOALS, ENTRY_OPEN_HIST]), {
|
||||
|
@ -189,16 +181,16 @@ export class ProjectDataProvider implements TreeDataProvider<TreeItem> {
|
|||
}
|
||||
|
||||
public async importProject(entry: Uri | undefined): Promise<void> {
|
||||
let currentPomXml: string = null;
|
||||
if (!entry) {
|
||||
entry = await VSCodeUI.openDialogForFile({ filters: { "POM File": ["xml"] }, openLabel: "Import" });
|
||||
}
|
||||
if (entry && entry.scheme === "file") {
|
||||
currentPomXml = entry.fsPath;
|
||||
|
||||
const currentPomXml: string = entry && entry.fsPath;
|
||||
if (!currentPomXml) {
|
||||
return Promise.resolve();
|
||||
} else if (this.getRootPomPaths().indexOf(currentPomXml) >= 0) {
|
||||
window.showWarningMessage("Already imported.");
|
||||
} else {
|
||||
return Promise.reject("pinProject");
|
||||
}
|
||||
if (currentPomXml) {
|
||||
const config: WorkspaceConfiguration = workspace.getConfiguration("maven.projects");
|
||||
const pomXmls: string[] = config.get<string[]>("pinnedPomPaths");
|
||||
if (pomXmls.indexOf(currentPomXml) < 0) {
|
||||
|
@ -210,13 +202,14 @@ export class ProjectDataProvider implements TreeDataProvider<TreeItem> {
|
|||
}
|
||||
|
||||
public async searchAndImportProjects(): Promise<void> {
|
||||
const res: Uri = await VSCodeUI.openDialogForFolder({openLabel: "Import All"});
|
||||
const pomXmlFilePaths: string[] = this.getRootPomPaths();
|
||||
const res: Uri = await VSCodeUI.openDialogForFolder({ openLabel: "Import All" });
|
||||
if (res && res.fsPath) {
|
||||
const foundPomXmls: string[] = await Utils.findAllInDir(res.fsPath, "pom.xml", 99);
|
||||
const config: WorkspaceConfiguration = workspace.getConfiguration("maven.projects");
|
||||
const pomXmls: string[] = config.get<string[]>("pinnedPomPaths");
|
||||
foundPomXmls.forEach((currentPomXml: string) => {
|
||||
if (pomXmls.indexOf(currentPomXml) < 0) {
|
||||
if (pomXmlFilePaths.indexOf(currentPomXml) < 0 && pomXmls.indexOf(currentPomXml) < 0) {
|
||||
pomXmls.push(currentPomXml);
|
||||
}
|
||||
});
|
||||
|
@ -224,4 +217,38 @@ export class ProjectDataProvider implements TreeDataProvider<TreeItem> {
|
|||
this.refreshTree();
|
||||
}
|
||||
}
|
||||
|
||||
public async removeProject(item: ProjectItem | undefined): Promise<void> {
|
||||
if (!item) {
|
||||
item = await VSCodeUI.getQuickPick<ProjectItem>(
|
||||
this.cachedItems,
|
||||
(x: ProjectItem) => x.label,
|
||||
(x: ProjectItem) => x.pomXmlFilePath
|
||||
);
|
||||
}
|
||||
if (item) {
|
||||
const config: WorkspaceConfiguration = workspace.getConfiguration("maven.projects");
|
||||
const pomXmls: string[] = config.get<string[]>("pinnedPomPaths");
|
||||
const newPomXmls: string[] = pomXmls.filter((elem: string) => elem !== item.pomXmlFilePath);
|
||||
if (newPomXmls.length === pomXmls.length) {
|
||||
window.showWarningMessage("Cannot remove default projects under root folder.");
|
||||
} else {
|
||||
await config.update("pinnedPomPaths", newPomXmls, false);
|
||||
this.refreshTree();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private getRootPomPaths(): string[] {
|
||||
const ret: string[] = [];
|
||||
const depth: number = Math.max(workspace.getConfiguration("maven.projects").get<number>("maxDepthOfPom"), 1);
|
||||
if (workspace.workspaceFolders) {
|
||||
workspace.workspaceFolders.forEach((wf: WorkspaceFolder) => {
|
||||
Utils.findAllInDir(wf.uri.fsPath, "pom.xml", depth).forEach((pomxml: string) => {
|
||||
ret.push(pomxml);
|
||||
});
|
||||
});
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
|
20
src/Utils.ts
20
src/Utils.ts
|
@ -29,11 +29,11 @@ export namespace Utils {
|
|||
return Promise.resolve(null);
|
||||
}
|
||||
|
||||
export async function readXmlContent(xml: string, options?: {}) : Promise<{}> {
|
||||
export async function readXmlContent(xml: string, options?: {}): Promise<{}> {
|
||||
const opts: {} = Object.assign({ explicitArray: true }, options);
|
||||
return new Promise<{}>(
|
||||
(resolve: (value: {}) => void, reject: (e: Error) => void): void => {
|
||||
xml2js.parseString(xml, opts, (err: Error , res: {}) => {
|
||||
xml2js.parseString(xml, opts, (err: Error, res: {}) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
|
@ -140,16 +140,16 @@ export namespace Utils {
|
|||
const contentBlocks: string[] = [];
|
||||
return new Promise<string>(
|
||||
(resolve: (value: string) => void, reject: (e: Error) => void): void => {
|
||||
const request: http.ClientRequest = http.get(url, (response: http.IncomingMessage) => {
|
||||
response.pipe(file);
|
||||
response.on("end", () => {
|
||||
resolve(fs.readFileSync(filepath).toString());
|
||||
const request: http.ClientRequest = http.get(url, (response: http.IncomingMessage) => {
|
||||
response.pipe(file);
|
||||
response.on("end", () => {
|
||||
resolve(fs.readFileSync(filepath).toString());
|
||||
});
|
||||
});
|
||||
request.on("error", (e: Error) => {
|
||||
reject(e);
|
||||
});
|
||||
});
|
||||
request.on("error", (e: Error) => {
|
||||
reject(e);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export function findAllInDir(dirname: string, targetFileName: string, depth: number): string[] {
|
||||
|
|
|
@ -48,6 +48,10 @@ export function activate(context: vscode.ExtensionContext): void {
|
|||
mavenProjectsTreeDataProvider.searchAndImportProjects();
|
||||
}));
|
||||
|
||||
context.subscriptions.push(vscode.commands.registerCommand("maven.project.remove", (item: ProjectItem | undefined) => {
|
||||
mavenProjectsTreeDataProvider.removeProject(item);
|
||||
}));
|
||||
|
||||
context.subscriptions.push(vscode.window.onDidCloseTerminal((closedTerminal: vscode.Terminal) => {
|
||||
VSCodeUI.onDidCloseTerminal(closedTerminal);
|
||||
}));
|
||||
|
|
Загрузка…
Ссылка в новой задаче