Skip to content

Commit

Permalink
Merge branch 'master' into pr_fav
Browse files Browse the repository at this point in the history
  • Loading branch information
Eskibear authored Mar 4, 2019
2 parents 997c76d + f462c7a commit 3ffb574
Show file tree
Hide file tree
Showing 24 changed files with 594 additions and 541 deletions.
462 changes: 219 additions & 243 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 10 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@
{
"command": "maven.project.openPom",
"when": "never"
},
{
"command": "maven.plugin.execute",
"when": "never"
}
],
"explorer/context": [
Expand Down Expand Up @@ -460,18 +464,18 @@
},
"devDependencies": {
"@types/fs-extra": "^4.0.8",
"@types/lodash": "^4.14.120",
"@types/lodash": "^4.14.121",
"@types/md5": "^2.1.33",
"@types/minimatch": "^3.0.3",
"@types/node": "^8.10.39",
"@types/node": "^8.10.40",
"@types/xml2js": "^0.4.3",
"ts-loader": "^4.4.2",
"tslint": "^5.12.1",
"tslint": "^5.13.0",
"tslint-microsoft-contrib": "^5.0.1",
"typescript": "^2.9.2",
"vscode": "^1.1.27",
"webpack": "^4.29.0",
"webpack-cli": "^3.2.1"
"vscode": "^1.1.30",
"webpack": "^4.29.5",
"webpack-cli": "^3.2.3"
},
"dependencies": {
"fast-glob": "^2.2.4",
Expand Down
25 changes: 25 additions & 0 deletions src/Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,29 @@ export namespace Settings {
function _getMavenSection<T>(section: string, resource?: Uri): T {
return workspace.getConfiguration("maven", resource).get<T>(section);
}

export function getEnvironment(): {} {
const customEnv: any = _getJavaHomeEnvIfAvailable();
type EnvironmentSetting = {
environmentVariable: string;
value: string;
};
const environmentSettings: EnvironmentSetting[] = Terminal.customEnv();
environmentSettings.forEach((s: EnvironmentSetting) => {
customEnv[s.environmentVariable] = s.value;
});
return customEnv;
}

function _getJavaHomeEnvIfAvailable(): {} {
// Look for the java.home setting from the redhat.java extension. We can reuse it
// if it exists to avoid making the user configure it in two places.
const javaHome: string = External.javaHome();
const useJavaHome: boolean = Terminal.useJavaHome();
if (useJavaHome && javaHome) {
return { JAVA_HOME: javaHome };
} else {
return {};
}
}
}
7 changes: 4 additions & 3 deletions src/archetype/ArchetypeModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Uri, window, workspace } from "vscode";
import { instrumentOperationStep, sendInfo } from "vscode-extension-telemetry-wrapper";
import { OperationCanceledError } from "../Errors";
import { getPathToExtensionRoot } from "../utils/contextUtils";
import { executeInTerminal } from "../utils/mavenUtils";
import { openDialogForFolder } from "../utils/uiUtils";
import { Utils } from "../utils/Utils";
import { Archetype } from "./Archetype";
Expand Down Expand Up @@ -40,13 +41,13 @@ export namespace ArchetypeModule {
return cwd;
}

async function executeInTerminal(archetypeGroupId: string, archetypeArtifactId: string, cwd: string): Promise<void> {
async function executeInTerminalHandler(archetypeGroupId: string, archetypeArtifactId: string, cwd: string): Promise<void> {
const cmd: string = [
"archetype:generate",
`-DarchetypeArtifactId="${archetypeArtifactId}"`,
`-DarchetypeGroupId="${archetypeGroupId}"`
].join(" ");
await Utils.executeInTerminal(cmd, null, { cwd });
await executeInTerminal(cmd, null, { cwd });
}

export async function generateFromArchetype(entry: Uri | undefined, operationId: string | undefined): Promise<void> {
Expand All @@ -64,7 +65,7 @@ export namespace ArchetypeModule {
const cwd: string = await instrumentOperationStep(operationId, "chooseTargetFolder", chooseTargetFolder)(targetFolderHint);

// execute in terminal.
await instrumentOperationStep(operationId, "executeInTerminal", executeInTerminal)(groupId, artifactId, cwd);
await instrumentOperationStep(operationId, "executeInTerminal", executeInTerminalHandler)(groupId, artifactId, cwd);
}

export async function updateArchetypeCatalog(): Promise<void> {
Expand Down
12 changes: 6 additions & 6 deletions src/completion/completionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class CompletionProvider implements vscode.CompletionItemProvider {
case XmlTagName.GroupId: {
const siblingNodes: ElementNode[] = _.get(currentNode, "parent.children", []);
const artifactIdNode: ElementNode = siblingNodes.find(elem => elem.tag === XmlTagName.ArtifactId);
const groupIdHint: string = currentNode.text || "";
const artifactIdHint: string = artifactIdNode && artifactIdNode.text || "";
const groupIdHint: string = currentNode.text ? currentNode.text : "";
const artifactIdHint: string = artifactIdNode && artifactIdNode.text ? artifactIdNode.text : "";

const centralItems: vscode.CompletionItem[] = await centralProvider.getGroupIdCandidates(groupIdHint, artifactIdHint);
const localItems: vscode.CompletionItem[] = await localProvider.getGroupIdCandidates(groupIdHint, artifactIdHint);
Expand All @@ -54,8 +54,8 @@ class CompletionProvider implements vscode.CompletionItemProvider {
case XmlTagName.ArtifactId: {
const siblingNodes: ElementNode[] = _.get(currentNode, "parent.children", []);
const groupIdNode: ElementNode = siblingNodes.find(elem => elem.tag === XmlTagName.GroupId);
const groupIdHint: string = groupIdNode && groupIdNode.text || "";
const artifactIdHint: string = currentNode.text || "";
const groupIdHint: string = groupIdNode && groupIdNode.text ? groupIdNode.text : "";
const artifactIdHint: string = currentNode.text ? currentNode.text : "";

const centralItems: vscode.CompletionItem[] = await centralProvider.getArtifactIdCandidates(groupIdHint, artifactIdHint);
if (groupIdNode) {
Expand All @@ -76,8 +76,8 @@ class CompletionProvider implements vscode.CompletionItemProvider {
const siblingNodes: ElementNode[] = _.get(currentNode, "parent.children", []);
const groupIdNode: ElementNode = siblingNodes.find(elem => elem.tag === XmlTagName.GroupId);
const artifactIdNode: ElementNode = siblingNodes.find(elem => elem.tag === XmlTagName.ArtifactId);
const groupIdHint: string = groupIdNode && groupIdNode.text || "";
const artifactIdHint: string = artifactIdNode && artifactIdNode.text || "";
const groupIdHint: string = groupIdNode && groupIdNode.text ? groupIdNode.text : "";
const artifactIdHint: string = artifactIdNode && artifactIdNode.text ? artifactIdNode.text : "";

const centralItems: vscode.CompletionItem[] = await centralProvider.getVersionCandidates(groupIdHint, artifactIdHint);
const localItems: vscode.CompletionItem[] = await localProvider.getVersionCandidates(groupIdHint, artifactIdHint);
Expand Down
2 changes: 1 addition & 1 deletion src/explorer/mavenExplorerProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class MavenExplorerProvider implements TreeDataProvider<ITreeItem> {
}

public refresh(item?: ITreeItem): void {
return this._onDidChangeTreeData.fire(item);
this._onDidChangeTreeData.fire(item);
}
}

Expand Down
37 changes: 37 additions & 0 deletions src/explorer/model/EffectivePom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

import { rawEffectivePom } from "../../utils/mavenUtils";
import { Utils } from "../../utils/Utils";

export class EffectivePom {

public pomPath: string;
public raw: string;
public data: any;
private _updating: boolean;

constructor(pomPath: string) {
this.pomPath = pomPath;
this._updating = false;
}

/**
* Generate effective pom and parse the data
*/
public async update(silent?: boolean): Promise<void> {
if (this._updating) {
return;
}

this._updating = true;
try {
this.raw = silent ? await rawEffectivePom(this.pomPath) : await Utils.getEffectivePom(this.pomPath);
this.data = await Utils.parseXmlContent(this.raw);
} catch (error) {
console.error(error);
}
this._updating = false;

}
}
52 changes: 23 additions & 29 deletions src/explorer/model/MavenProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import * as _ from "lodash";
import * as path from "path";
import * as vscode from "vscode";
import { Settings } from "../../Settings";
import { taskExecutor } from "../../taskExecutor";
import { getPathToExtensionRoot } from "../../utils/contextUtils";
import { Utils } from "../../utils/Utils";
import { mavenExplorerProvider } from "../mavenExplorerProvider";
import { EffectivePom } from "./EffectivePom";
import { ITreeItem } from "./ITreeItem";
import { MavenPlugin } from "./MavenPlugin";
import { PluginsMenu } from "./PluginsMenu";
Expand All @@ -16,13 +18,14 @@ const CONTEXT_VALUE: string = "MavenProject";

export class MavenProject implements ITreeItem {
public parent?: MavenProject;
private _rawEffectivePom: string;
private _effectivePom: any;
private _effectivePom: EffectivePom;
private _pom: any;
private _pomPath: string;

constructor(pomPath: string) {
this._pomPath = pomPath;
this._effectivePom = new EffectivePom(pomPath);
taskExecutor.execute(async () => await this._effectivePom.update(true));
}

public get name(): string {
Expand All @@ -37,25 +40,21 @@ export class MavenProject implements ITreeItem {
return _.get(this._pom, "project.modules[0].module") || [];
}

public get rawEffectivePom(): string {
return this._rawEffectivePom;
}

public get effectivePom(): string {
public get effectivePom(): EffectivePom {
return this._effectivePom;
}

public get plugins(): MavenPlugin[] {
let plugins: any[];
if (_.get(this._effectivePom, "projects.project")) {
if (_.has(this._effectivePom.data, "projects.project")) {
// multi-module project
const project: any = (<any[]>this._effectivePom.projects.project).find((elem: any) => this.name === _.get(elem, "artifactId[0]"));
const project: any = (<any[]>this._effectivePom.data.projects.project).find((elem: any) => this.name === _.get(elem, "artifactId[0]"));
if (project) {
plugins = _.get(project, "build[0].plugins[0].plugin");
}
} else {
// single-project
plugins = _.get(this._effectivePom, "project.build[0].plugins[0].plugin");
plugins = _.get(this._effectivePom.data, "project.build[0].plugins[0].plugin");
}
return this._convertXmlPlugin(plugins);
}
Expand Down Expand Up @@ -92,30 +91,28 @@ export class MavenProject implements ITreeItem {
public getChildren(): vscode.ProviderResult<ITreeItem[]> {
const ret: ITreeItem[] = [];
ret.push(new PluginsMenu(this));
if (this.moduleNames.length > 0 && Settings.viewType() === "hierarchical" ) {
if (this.moduleNames.length > 0 && Settings.viewType() === "hierarchical") {
ret.push(...this.modules.map(m => mavenExplorerProvider.getMavenProject(m)));
}
return ret;
}

public async calculateEffectivePom(force?: boolean): Promise<void> {
if (!force && this._rawEffectivePom) {
return;
public async calculateEffectivePom(force?: boolean): Promise<string> {
if (!force && this._effectivePom.raw) {
return this._effectivePom.raw;
}

this._rawEffectivePom = await Utils.getEffectivePom(this);
await this._parseEffectivePom();
mavenExplorerProvider.refresh(this);
}

public async refreshPom(): Promise<void> {
await this.parsePom();
await this._effectivePom.update();
mavenExplorerProvider.refresh(this);
return this._effectivePom.raw;
}

public async refresh(): Promise<void> {
await this.refreshPom();
this._rawEffectivePom = undefined;
await this._refreshPom();
this._effectivePom.update()
.then(() => {
mavenExplorerProvider.refresh(this);
}).catch(console.error); // no await to unblock the thread.
}

public async parsePom(): Promise<void> {
Expand All @@ -126,12 +123,9 @@ export class MavenProject implements ITreeItem {
}
}

private async _parseEffectivePom(): Promise<void> {
try {
this._effectivePom = await Utils.parseXmlContent(this._rawEffectivePom);
} catch (error) {
this._effectivePom = undefined;
}
private async _refreshPom(): Promise<void> {
await this.parsePom();
mavenExplorerProvider.refresh(this);
}

private _convertXmlPlugin(plugins: any[]): MavenPlugin[] {
Expand Down
2 changes: 1 addition & 1 deletion src/explorer/model/WorkspaceFolder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class WorkspaceFolder implements ITreeItem {
allProjects.push(currentProject);
}

await Promise.all(newProjects.map(elem => elem.parsePom()));
await Promise.all(newProjects.map(async elem => elem.parsePom()));
mavenExplorerProvider.updateProjects(...newProjects);
newProjects.forEach(p => {
p.modules.forEach(m => {
Expand Down
11 changes: 6 additions & 5 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ import { mavenTerminal } from "./mavenTerminal";
import { Settings } from "./Settings";
import { taskExecutor } from "./taskExecutor";
import { getAiKey, getExtensionId, getExtensionVersion, loadPackageInfo } from "./utils/contextUtils";
import { executeInTerminal } from "./utils/mavenUtils";
import { openFileIfExists, showTroubleshootingDialog } from "./utils/uiUtils";
import { Utils } from "./utils/Utils";

export async function activate(context: vscode.ExtensionContext): Promise<void> {
await loadPackageInfo(context);
// Usage data statistics.
if (getAiKey()) {
await initialize(getExtensionId(), getExtensionVersion(), getAiKey());
initialize(getExtensionId(), getExtensionVersion(), getAiKey());
}
await instrumentOperation("activation", doActivate)(context);
}
Expand All @@ -45,7 +46,7 @@ function registerCommand(context: vscode.ExtensionContext, commandName: string,
if (error instanceof OperationCanceledError) {
// swallow
} else {
showTroubleshootingDialog(`Command "${commandName}" fails. ${error.message}`);
await showTroubleshootingDialog(`Command "${commandName}" fails. ${error.message}`);
}
throw error;
}
Expand All @@ -61,13 +62,13 @@ async function doActivate(_operationId: string, context: vscode.ExtensionContext
// pom.xml listener to refresh tree view
const watcher: vscode.FileSystemWatcher = vscode.workspace.createFileSystemWatcher("**/pom.xml");
watcher.onDidCreate((e: Uri) => mavenExplorerProvider.addProject(e.fsPath), null, context.subscriptions);
watcher.onDidChange((e: Uri) => mavenExplorerProvider.getMavenProject(e.fsPath).refresh(), null, context.subscriptions);
watcher.onDidChange(async (e: Uri) => mavenExplorerProvider.getMavenProject(e.fsPath).refresh(), null, context.subscriptions);
watcher.onDidDelete((e: Uri) => mavenExplorerProvider.removeProject(e.fsPath), null, context.subscriptions);
context.subscriptions.push(watcher);
context.subscriptions.push(mavenOutputChannel, mavenTerminal, taskExecutor);
// register commands.
["clean", "validate", "compile", "test", "package", "verify", "install", "site", "deploy"].forEach((goal: string) => {
registerCommand(context, `maven.goal.${goal}`, async (node: MavenProject) => Utils.executeInTerminal(goal, node.pomPath));
registerCommand(context, `maven.goal.${goal}`, async (node: MavenProject) => executeInTerminal(goal, node.pomPath));
});
registerCommand(context, "maven.explorer.refresh", async (item?: ITreeItem): Promise<void> => {
if (item && item.refresh) {
Expand Down Expand Up @@ -116,7 +117,7 @@ async function doActivate(_operationId: string, context: vscode.ExtensionContext
if (node &&
node.name &&
node.plugin && node.plugin.project && node.plugin.project.pomPath) {
Utils.executeInTerminal(node.name, node.plugin.project.pomPath);
await executeInTerminal(node.name, node.plugin.project.pomPath);
}
});
registerCommand(context, "maven.view.flat", () => Settings.changeToFlatView());
Expand Down
4 changes: 2 additions & 2 deletions src/handlers/addDependencyHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ async function addDependency(gid: string, aid: string, version: string): Promise
const proejctNode: ElementNode = projectNodes[0];
const dependenciesNode: ElementNode = proejctNode.children && proejctNode.children.find(node => node.tag === XmlTagName.Dependencies);
if (dependenciesNode !== undefined) {
insertDependency(dependenciesNode, gid, aid, version);
await insertDependency(dependenciesNode, gid, aid, version);
} else {
insertDependency(proejctNode, gid, aid, version);
await insertDependency(proejctNode, gid, aid, version);

}
}
Expand Down
4 changes: 2 additions & 2 deletions src/hover/hoverProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class HoverProvider implements vscode.HoverProvider {
const groupIdHint: string = groupIdNode && groupIdNode.text;
const artifactIdHint: string = artifactIdNode && artifactIdNode.text;
if (groupIdHint && artifactIdHint) {
const effectiveVersion: string = await getEffectiveVersion(document.uri, groupIdHint, artifactIdHint);
const effectiveVersion: string = getEffectiveVersion(document.uri, groupIdHint, artifactIdHint);
if (effectiveVersion) {
return new vscode.Hover([
`gourpId = ${groupIdHint}`,
Expand All @@ -47,7 +47,7 @@ function getEffectiveVersion(uri: vscode.Uri, gid: string, aid: string): string
return undefined;
}

const deps: {}[] = _.get(mavenProject.effectivePom, "project.dependencies[0].dependency", []);
const deps: {}[] = _.get(mavenProject.effectivePom.data, "project.dependencies[0].dependency", []);
const targetDep: {} = deps.find(elem => _.get(elem, "groupId[0]") === gid && _.get(elem, "artifactId[0]") === aid);
return targetDep && _.get(targetDep, "version[0]");

Expand Down
Loading

0 comments on commit 3ffb574

Please sign in to comment.