basic functionality
This commit is contained in:
Родитель
504bd01746
Коммит
d68723e324
|
@ -2,3 +2,4 @@ out
|
|||
node_modules
|
||||
.vscode-test/
|
||||
.vsix
|
||||
yarn.lock
|
||||
|
|
102
package.json
102
package.json
|
@ -1,38 +1,74 @@
|
|||
{
|
||||
"name": "vscode-maven",
|
||||
"displayName": "vscode-maven",
|
||||
"description": "vscode maven extension",
|
||||
"version": "0.0.1",
|
||||
"publisher": "yanzh",
|
||||
"engines": {
|
||||
"vscode": "^1.18.0"
|
||||
},
|
||||
"categories": [
|
||||
"Other"
|
||||
"name": "vscode-maven",
|
||||
"displayName": "vscode-maven",
|
||||
"description": "vscode maven extension",
|
||||
"version": "0.0.1",
|
||||
"publisher": "yanzh",
|
||||
"engines": {
|
||||
"vscode": "^1.18.0"
|
||||
},
|
||||
"categories": [
|
||||
"Other"
|
||||
],
|
||||
"activationEvents": [
|
||||
"*"
|
||||
],
|
||||
"main": "./out/extension",
|
||||
"contributes": {
|
||||
"commands": [
|
||||
{
|
||||
"command": "mavenProjects.refresh",
|
||||
"title": "Refresh",
|
||||
"icon": {
|
||||
"light": "resources/light/refresh.svg",
|
||||
"dark": "resources/dark/refresh.svg"
|
||||
}
|
||||
}
|
||||
],
|
||||
"activationEvents": [
|
||||
"onCommand:extension.sayHello"
|
||||
],
|
||||
"main": "./out/extension",
|
||||
"contributes": {
|
||||
"commands": [
|
||||
{
|
||||
"command": "extension.sayHello",
|
||||
"title": "Hello World"
|
||||
}
|
||||
]
|
||||
"views": {
|
||||
"explorer": [
|
||||
{
|
||||
"id": "mavenProjects",
|
||||
"name": "Maven Projects"
|
||||
}
|
||||
]
|
||||
},
|
||||
"scripts": {
|
||||
"vscode:prepublish": "npm run compile",
|
||||
"compile": "tsc -p ./",
|
||||
"watch": "tsc -watch -p ./",
|
||||
"postinstall": "node ./node_modules/vscode/bin/install",
|
||||
"test": "npm run compile && node ./node_modules/vscode/bin/test"
|
||||
"menus": {
|
||||
"view/title": [
|
||||
{
|
||||
"command": "mavenProjects.refresh",
|
||||
"when": "view == mavenProjects",
|
||||
"group": "navigation"
|
||||
}
|
||||
]
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^2.6.1",
|
||||
"vscode": "^1.1.6",
|
||||
"@types/node": "^7.0.43",
|
||||
"@types/mocha": "^2.2.42"
|
||||
}
|
||||
"configuration": [
|
||||
{
|
||||
"title": "Maven Projects",
|
||||
"properties": {
|
||||
"mavenProjects.showExplorer": {
|
||||
"type": "boolean",
|
||||
"default": true
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"scripts": {
|
||||
"vscode:prepublish": "npm run compile",
|
||||
"compile": "tsc -p ./",
|
||||
"watch": "tsc -watch -p ./",
|
||||
"postinstall": "node ./node_modules/vscode/bin/install",
|
||||
"test": "npm run compile && node ./node_modules/vscode/bin/test"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^2.6.1",
|
||||
"vscode": "^1.1.6",
|
||||
"@types/node": "^7.0.43",
|
||||
"@types/mocha": "^2.2.42"
|
||||
},
|
||||
"dependencies": {
|
||||
"readdirp": "^2.1.0",
|
||||
"xml-parser": "^1.2.1"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"><path d="M13.451 5.609l-.579-.939-1.068.812-.076.094c-.335.415-.927 1.341-1.124 2.876l-.021.165.033.163.071.345c0 1.654-1.346 3-3 3-.795 0-1.545-.311-2.107-.868-.563-.567-.873-1.317-.873-2.111 0-1.431 1.007-2.632 2.351-2.929v2.926s2.528-2.087 2.984-2.461h.012l3.061-2.582-4.919-4.1h-1.137v2.404c-3.429.318-6.121 3.211-6.121 6.721 0 1.809.707 3.508 1.986 4.782 1.277 1.282 2.976 1.988 4.784 1.988 3.722 0 6.75-3.028 6.75-6.75 0-1.245-.349-2.468-1.007-3.536z" fill="#2D2D30"/><path d="M12.6 6.134l-.094.071c-.269.333-.746 1.096-.91 2.375.057.277.092.495.092.545 0 2.206-1.794 4-4 4-1.098 0-2.093-.445-2.817-1.164-.718-.724-1.163-1.718-1.163-2.815 0-2.206 1.794-4 4-4l.351.025v1.85s1.626-1.342 1.631-1.339l1.869-1.577-3.5-2.917v2.218l-.371-.03c-3.176 0-5.75 2.574-5.75 5.75 0 1.593.648 3.034 1.695 4.076 1.042 1.046 2.482 1.694 4.076 1.694 3.176 0 5.75-2.574 5.75-5.75-.001-1.106-.318-2.135-.859-3.012z" fill="#C5C5C5"/></svg>
|
После Ширина: | Высота: | Размер: 986 B |
|
@ -0,0 +1 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"><path d="M13.451 5.609l-.579-.939-1.068.812-.076.094c-.335.415-.927 1.341-1.124 2.876l-.021.165.033.163.071.345c0 1.654-1.346 3-3 3-.795 0-1.545-.311-2.107-.868-.563-.567-.873-1.317-.873-2.111 0-1.431 1.007-2.632 2.351-2.929v2.926s2.528-2.087 2.984-2.461h.012l3.061-2.582-4.919-4.1h-1.137v2.404c-3.429.318-6.121 3.211-6.121 6.721 0 1.809.707 3.508 1.986 4.782 1.277 1.282 2.976 1.988 4.784 1.988 3.722 0 6.75-3.028 6.75-6.75 0-1.245-.349-2.468-1.007-3.536z" fill="#F6F6F6"/><path d="M12.6 6.134l-.094.071c-.269.333-.746 1.096-.91 2.375.057.277.092.495.092.545 0 2.206-1.794 4-4 4-1.098 0-2.093-.445-2.817-1.164-.718-.724-1.163-1.718-1.163-2.815 0-2.206 1.794-4 4-4l.351.025v1.85s1.626-1.342 1.631-1.339l1.869-1.577-3.5-2.917v2.218l-.371-.03c-3.176 0-5.75 2.574-5.75 5.75 0 1.593.648 3.034 1.695 4.076 1.042 1.046 2.482 1.694 4.076 1.694 3.176 0 5.75-2.574 5.75-5.75-.001-1.106-.318-2.135-.859-3.012z" fill="#424242"/></svg>
|
После Ширина: | Высота: | Размер: 986 B |
|
@ -2,26 +2,24 @@
|
|||
// The module 'vscode' contains the VS Code extensibility API
|
||||
// Import the module and reference it with the alias vscode in your code below
|
||||
import * as vscode from 'vscode';
|
||||
import { MavenProjectsTreeDataProvider } from './mavenProjectsTreeDataProvider';
|
||||
|
||||
// this method is called when your extension is activated
|
||||
// your extension is activated the very first time the command is executed
|
||||
export function activate(context: vscode.ExtensionContext) {
|
||||
|
||||
// Use the console to output diagnostic information (console.log) and errors (console.error)
|
||||
// This line of code will only be executed once when your extension is activated
|
||||
console.log('Congratulations, your extension "vscode-maven" is now active!');
|
||||
|
||||
const mavenProjectsTreeDataProvider = new MavenProjectsTreeDataProvider(context);
|
||||
vscode.window.registerTreeDataProvider("mavenProjects", mavenProjectsTreeDataProvider);
|
||||
|
||||
// The command has been defined in the package.json file
|
||||
// Now provide the implementation of the command with registerCommand
|
||||
// The commandId parameter must match the command field in package.json
|
||||
let disposable = vscode.commands.registerCommand('extension.sayHello', () => {
|
||||
// The code you place here will be executed every time your command is executed
|
||||
|
||||
// Display a message box to the user
|
||||
let commandMavenProjectsRefresh = vscode.commands.registerCommand('mavenProjects.refresh', () => {
|
||||
vscode.window.showInformationMessage('Hello World!');
|
||||
});
|
||||
|
||||
context.subscriptions.push(disposable);
|
||||
context.subscriptions.push(commandMavenProjectsRefresh);
|
||||
}
|
||||
|
||||
// this method is called when your extension is deactivated
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
import * as vscode from "vscode";
|
||||
import { TreeItemCollapsibleState } from "vscode";
|
||||
|
||||
export class MavenProjectTreeItem extends vscode.TreeItem {
|
||||
public pomXmlFilePath: string;
|
||||
|
||||
constructor(label: string, pomXmlFilePath: string) {
|
||||
super(label, TreeItemCollapsibleState.Collapsed);
|
||||
this.pomXmlFilePath = pomXmlFilePath;
|
||||
this.contextValue = 'mavenProject';
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
import * as vscode from "vscode";
|
||||
import { MavenProjectTreeItem } from "./mavenProjectTreeItem";
|
||||
import { TreeItem, TreeItemCollapsibleState } from "vscode";
|
||||
import { Utils } from "./utils";
|
||||
|
||||
export class MavenProjectsTreeDataProvider implements vscode.TreeDataProvider<vscode.TreeItem> {
|
||||
constructor(protected context: vscode.ExtensionContext) {
|
||||
}
|
||||
|
||||
public getTreeItem(element: vscode.TreeItem): vscode.TreeItem {
|
||||
return element;
|
||||
}
|
||||
|
||||
public getChildren(element?: vscode.TreeItem) : Thenable<vscode.TreeItem[]> {
|
||||
if (element == undefined) {
|
||||
const projects: MavenProjectTreeItem[] = [];
|
||||
vscode.workspace.getWorkspaceFolder;
|
||||
const pomXmlFilePaths: string[] = Utils.getPomXmlFilePaths();
|
||||
pomXmlFilePaths.forEach(pomXmlFilePath => {
|
||||
const name = Utils.getProjectName(pomXmlFilePath);
|
||||
projects.push(new MavenProjectTreeItem(name, pomXmlFilePath));
|
||||
});
|
||||
return Promise.resolve(projects);
|
||||
}
|
||||
else if (element.contextValue == 'mavenProject') {
|
||||
const items = [];
|
||||
['Lifecycle', 'Dependencies'].forEach(name => {
|
||||
const item = new TreeItem(name, TreeItemCollapsibleState.Collapsed);
|
||||
item.contextValue = name;
|
||||
items.push(item);
|
||||
});
|
||||
return Promise.resolve(items);
|
||||
}
|
||||
else if (element.contextValue == 'Lifecycle') {
|
||||
const items = [];
|
||||
['clean', 'validate', 'compile', 'test', 'package', 'verify', 'install', 'site', 'deploy'].forEach(phase => {
|
||||
const item = new TreeItem(phase);
|
||||
items.push(item);
|
||||
});
|
||||
return Promise.resolve(items);
|
||||
}
|
||||
else if (element.contextValue == 'Dependencies') {
|
||||
const items = [];
|
||||
// TODO
|
||||
return Promise.resolve(items);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
import * as vscode from "vscode";
|
||||
import { execSync } from 'child_process';
|
||||
import * as fs from 'fs';
|
||||
import * as xmlParser from 'xml-parser';
|
||||
|
||||
export class Utils {
|
||||
private static terminals: { [id: string]: vscode.Terminal } = {};
|
||||
|
||||
public static runInTerminal(command: string, addNewLine: boolean = true, terminal: string = "Maven"): void {
|
||||
if (this.terminals[terminal] === undefined) {
|
||||
this.terminals[terminal] = vscode.window.createTerminal(terminal);
|
||||
}
|
||||
this.terminals[terminal].show();
|
||||
this.terminals[terminal].sendText(command, addNewLine);
|
||||
}
|
||||
|
||||
public static getPomXmlFilePaths(): string[] {
|
||||
const filename: string = 'pom.xml';
|
||||
const ret = [];
|
||||
const stdout = execSync(`find ${vscode.workspace.rootPath} -name '${filename}'`);
|
||||
stdout.toString().split('\n').forEach(f => {
|
||||
if (f) {
|
||||
ret.push(f);
|
||||
}
|
||||
})
|
||||
return ret;
|
||||
}
|
||||
|
||||
static getProjectName(pomXmlFilePath: string): string {
|
||||
const xml = fs.readFileSync(pomXmlFilePath, 'utf8');
|
||||
let ret = `Location: ${pomXmlFilePath}`;
|
||||
xmlParser(xml).root.children.forEach(entry => {
|
||||
if (entry.name == 'name') {
|
||||
ret = entry.content;
|
||||
}
|
||||
})
|
||||
return ret;
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче