Skip to content

Commit

Permalink
feat: add support for maven - closes #107
Browse files Browse the repository at this point in the history
  • Loading branch information
spmeesseman committed May 31, 2021
1 parent 410ce3e commit 1f90d1b
Show file tree
Hide file tree
Showing 30 changed files with 330 additions and 21 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
[![GitHub last commit](https://img.shields.io/github/last-commit/spmeesseman/vscode%2dtaskexplorer.svg?logo=github)](https://github.com/spmeesseman/vscode-taskexplorer)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)

![src0](res/sources/npm.png?raw=true) ![src1](res/sources/ant.png?raw=true) ![src0y](res/sources/yarn.png?raw=true) ![src2](res/sources/grunt.png?raw=true) ![src3](res/sources/gulp.png?raw=true) ![src13](res/sources/gradle.png?raw=true) ![src4](res/sources/workspace.png?raw=true) ![src5](res/sources/make.png?raw=true) ![src6](res/sources/ts.png?raw=true) ![src7](res/sources/bat.png?raw=true) ![src8](res/sources/ruby.png?raw=true) ![src9](res/sources/powershell.png?raw=true) ![src10](res/sources/bash.png?raw=true) ![src11](res/sources/python.png?raw=true) ![src12](res/sources/nsis.png?raw=true)
![src0](res/sources/npm.png?raw=true) ![src1](res/sources/ant.png?raw=true) ![src0y](res/sources/yarn.png?raw=true) ![src2](res/sources/grunt.png?raw=true) ![src3](res/sources/gulp.png?raw=true) ![src13](res/sources/gradle.png?raw=true) ![src4](res/sources/workspace.png?raw=true) ![src5](res/sources/make.png?raw=true) ![src6](res/sources/ts.png?raw=true) ![src7](res/sources/bat.png?raw=true) ![src8](res/sources/ruby.png?raw=true) ![src9](res/sources/powershell.png?raw=true) ![src10](res/sources/bash.png?raw=true) ![src11](res/sources/python.png?raw=true) ![src12](res/sources/nsis.png?raw=true) ![src13](res/sources/maven.png?raw=true)

## Description

Expand Down Expand Up @@ -66,6 +66,8 @@ Provides a view in either (or both) the SideBar and/or Explorer that displays al

## Features by Version

- v2.2 - Support for Maven (closes [#107](https://github.com/spmeesseman/vscode-taskexplorer/issues/107))
- v2.1 - App Publisher changelog pull tasks
- v2.0 - All async-await processing, Favorites (closes [#101](https://github.com/spmeesseman/vscode-taskexplorer/issues/97)), Clear special task lists
- v1.30 - Configurable default click action (closes [#97](https://github.com/spmeesseman/vscode-taskexplorer/issues/97)), Add 'Run with Arguments' command (closes [#88](https://github.com/spmeesseman/vscode-taskexplorer/issues/88)), Add 'Run with NoTerminal' command (closes [#39](https://github.com/spmeesseman/vscode-taskexplorer/issues/39)) (note that as of VSCode 1.53, there seems to be a bug that prevents running tasks without showing the terminal).
- v1.29 - Support multi-level task groupings (closes [#129](https://github.com/spmeesseman/vscode-taskexplorer/issues/129)), Support user tasks (closes [#127](https://github.com/spmeesseman/vscode-taskexplorer/issues/127))
Expand Down
55 changes: 54 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1138,6 +1138,12 @@
"title": "%config.taskExplorer.enableMake%",
"description": "%config.taskExplorer.enableMakeDsc%"
},
"taskExplorer.enableMaven": {
"type": "boolean",
"default": true,
"title": "%config.taskExplorer.enableMaven%",
"description": "%config.taskExplorer.enableMavenDsc%"
},
"taskExplorer.enableWorkspace": {
"type": "boolean",
"default": true,
Expand Down Expand Up @@ -1209,6 +1215,12 @@
"title": "%config.taskExplorer.pathToMake%",
"description": "%config.taskExplorer.pathToMakeDsc%"
},
"taskExplorer.pathToMaven": {
"type": "string",
"default": "mvn",
"title": "%config.taskExplorer.pathToMaven%",
"description": "%config.taskExplorer.pathToMavenDsc%"
},
"taskExplorer.pathToNsis": {
"type": "string",
"default": "makensis",
Expand Down Expand Up @@ -1362,7 +1374,8 @@
"**/target/**",
"**/test/**",
"**/third_party/**",
"**/vendor/**"
"**/vendor/**",
"**/work/**"
],
"description": "%config.taskExplorer.exclude%"
},
Expand Down Expand Up @@ -1559,6 +1572,46 @@
}
}
},
{
"type": "maven",
"required": [
"cmdLine"
],
"properties": {
"script": {
"type": "string",
"description": "%taskdef.task.script%"
},
"target": {
"type": "string",
"description": "%taskdef.task.target%"
},
"path": {
"type": "string",
"description": "%taskdef.task.path%"
},
"fileName": {
"type": "string",
"description": "%taskdef.task.fileName%"
},
"uri": {
"type": "object",
"description": "%taskdef.task.fileUri%"
},
"taskItemId": {
"type": "string",
"description": "%taskdef.task.taskItemId%"
},
"takesArgs": {
"type": "boolean",
"description": "%taskdef.task.takesArgs%"
},
"cmdLine": {
"type": "string",
"description": "%taskdef.task.cmdLine%"
}
}
},
{
"type": "make",
"required": [],
Expand Down
7 changes: 6 additions & 1 deletion package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"config.taskExplorer.enableNsis": "Nullsoft Installer - Enable",
"config.taskExplorer.enableNsisDsc": "Enable/show Nullsoft Installer scripts as tasks.",
"config.taskExplorer.pathToNsis": "Nullsoft Installer - Path",
"config.taskExplorer.pathToNsisDsc": "The path to the nsis program, if not registered in system path.",
"config.taskExplorer.pathToNsisDsc": "The path to the makensis program, if not registered in system path.",

"config.taskExplorer.enablePowershell": "Powershell - Enable",
"config.taskExplorer.enablePowershellDsc": "Enable/show powershell scripts as tasks.",
Expand All @@ -93,6 +93,11 @@
"config.taskExplorer.pathToMake": "Make - Path",
"config.taskExplorer.pathToMakeDsc": "The path to the make program, if not registered in system path.",

"config.taskExplorer.enableMaven": "Maven - Enable",
"config.taskExplorer.enableMavrnDsc": "Enable/show maven lifecycle as tasks.",
"config.taskExplorer.pathToMaven": "Maven - Path",
"config.taskExplorer.pathToMavenDsc": "The path to the mvn program, if not registered in system path.",

"config.taskExplorer.enableTsc": "Typescript - Enable",
"config.taskExplorer.enableTscDsc": "Enable/show tsc node with npm tasks.",

Expand Down
1 change: 1 addition & 0 deletions res/dark/maven.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions res/light/maven.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/sources/ant.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/sources/bash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/sources/bat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/sources/gradle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/sources/grunt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/sources/gulp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/sources/make.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/sources/maven.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/sources/nsis.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/sources/perl.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/sources/powershell.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/sources/python.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/sources/ruby.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/sources/ts.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/sources/workspace.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/sources/yarn.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions src/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ export async function addFolderToCache(folder?: WorkspaceFolder | undefined)
await buildCache("make", constants.GLOB_MAKE, folder, false);
}
//
// Maven
//
if (!cancel && configuration.get<boolean>("enableMaven")) {
await buildCache("maven", constants.GLOB_MAVEN, folder, false);
}
//
// NPM
// Note that NPM tasks are provided by VSCode, not this extension
//
Expand Down
1 change: 1 addition & 0 deletions src/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const constants: IDictionary<string> =
USER_TASKS_LABEL: "User Tasks",
GLOB_ANT: "**/[Bb][Uu][Ii][Ll][Dd].[Xx][Mm][Ll]",
GLOB_APPPUBLISHER: "**/.publishrc*",
GLOB_MAVEN: "**/pom.xml",
GLOB_BASH: "**/*.[Ss][Hh]",
GLOB_BATCH: "**/*.{[Bb][Aa][Tt],[Cc][Mm][Dd]}",
GLOB_GULP: "**/[Gg][Uu][Ll][Pp][Ff][Ii][Ll][Ee].{[Jj][Ss],[Tt][Ss],[Mm][Jj][Ss],[Bb][Aa][Bb][Ee][Ll].[Jj][Ss]}",
Expand Down
12 changes: 5 additions & 7 deletions src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,11 @@ export function getAntGlobPattern(): string

export function getExcludesGlob(folder: string | WorkspaceFolder): RelativePattern
{
let relativePattern = new RelativePattern(folder, "**/node_modules/**");
let multiFilePattern = "{**/node_modules/**,**/work/**";
const excludes: string[] = configuration.get("exclude");

if (excludes && excludes.length > 0)
{
let multiFilePattern = "{**/node_modules/**";
if (Array.isArray(excludes))
{
for (const e of excludes) {
Expand All @@ -129,11 +128,10 @@ export function getExcludesGlob(folder: string | WorkspaceFolder): RelativePatte
multiFilePattern += ",";
multiFilePattern += excludes;
}
multiFilePattern += "}";
relativePattern = new RelativePattern(folder, multiFilePattern);
}
multiFilePattern += "}";

return relativePattern;
return new RelativePattern(folder, multiFilePattern);
}


Expand All @@ -158,8 +156,8 @@ export function getScriptTaskTypes(): string[]
export function getTaskTypes(): string[]
{
return [
"ant", "app-publisher", "bash", "batch", "gradle", "grunt", "gulp", "make", "npm",
"nsis", "perl", "powershell", "python", "ruby", "workspace"
"ant", "app-publisher", "bash", "batch", "gradle", "grunt", "gulp", "make",
"maven", "npm", "nsis", "perl", "powershell", "python", "ruby", "workspace"
];
}

Expand Down
4 changes: 3 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import { TaskTreeDataProvider } from "./tree/tree";
import { AntTaskProvider } from "./providers/ant";
import { MakeTaskProvider } from "./providers/make";
import { MavenTaskProvider } from "./providers/maven";
import { ScriptTaskProvider } from "./providers/script";
import { GradleTaskProvider } from "./providers/gradle";
import { GruntTaskProvider } from "./providers/grunt";
Expand Down Expand Up @@ -371,7 +372,7 @@ async function registerFileWatchers(context: ExtensionContext)

export async function refreshTree(taskType?: string, uri?: Uri)
{
let refreshedTasks = false;
// let refreshedTasks = false;
// window.setStatusBarMessage("$(loading) Task Explorer - Refreshing tasks...");

//
Expand Down Expand Up @@ -420,6 +421,7 @@ function registerTaskProviders(context: ExtensionContext)
registerTaskProvider("grunt", new GruntTaskProvider(), context); // Gulp JavaScript Toolkit
registerTaskProvider("gulp", new GulpTaskProvider(), context); // Grunt JavaScript Task Runner
registerTaskProvider("make", new MakeTaskProvider(), context); // C/C++ Makefile
registerTaskProvider("maven", new MavenTaskProvider(), context); // Apache Maven Toolset
//
// The 'script' provider handles all file based 'scripts', e.g. batch files, bash, powershell, etc
//
Expand Down
179 changes: 179 additions & 0 deletions src/providers/maven.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@

import { Task, WorkspaceFolder, ShellExecution, Uri, workspace, ShellExecutionOptions } from "vscode";
import * as path from "path";
import * as util from "../common/utils";
import * as log from "../common/log";
import { filesCache } from "../cache";
import { configuration } from "../common/configuration";
import { TaskExplorerProvider } from "./provider";
import { TaskExplorerDefinition } from "../taskDefinition";


export class MavenTaskProvider extends TaskExplorerProvider implements TaskExplorerProvider
{

constructor() { super("maven"); }


public createTask(target: string, cmd: string, folder: WorkspaceFolder, uri: Uri, xArgs: string[]): Task | undefined
{
return undefined;
}


public getDefaultDefinition(target: string | undefined, folder: WorkspaceFolder, uri: Uri): TaskExplorerDefinition
{
const def: TaskExplorerDefinition = {
type: "maven",
script: target,
target,
fileName: path.basename(uri.fsPath),
path: util.getRelativePath(folder, uri),
cmdLine: "mvn",
takesArgs: false,
uri
};
return def;
}


public getDocumentPosition(scriptName: string | undefined, documentText: string | undefined): number
{
return 0;
}


public async readTasks(logPad = ""): Promise<Task[]>
{
log.methodStart("detect maven files", 1, logPad, true);

const allTasks: Task[] = [];
const visitedFiles: Set<string> = new Set();
const paths = filesCache.get("maven");

if (workspace.workspaceFolders && paths)
{
for (const fobj of paths)
{
if (!util.isExcluded(fobj.uri.path) && !visitedFiles.has(fobj.uri.fsPath))
{
visitedFiles.add(fobj.uri.fsPath);
allTasks.push(...await this.readUriTasks(fobj.uri));
}
}
}

log.value(logPad + " # of tasks", allTasks.length, 2, logPad);
log.methodDone("detect maven files", 1, logPad, true);

return allTasks;
}


private getCommand(): string
{
let mvn = "mvn";
if (configuration.get("pathToMaven"))
{
mvn = configuration.get("pathToMaven");
}
return mvn;
}


public async readUriTasks(uri: Uri, wsFolder?: WorkspaceFolder, logPad = ""): Promise<Task[]>
{
const cwd = path.dirname(uri.fsPath),
folder = wsFolder || workspace.getWorkspaceFolder(uri),
args = [];

if (!folder) {
return [];
}

const defaultDef = this.getDefaultDefinition(undefined, folder, uri),
options: ShellExecutionOptions = { cwd };

log.methodStart("read maven file uri task", 1, logPad, true, [["path", uri?.fsPath], ["project folder", folder?.name]]);

const kindClean: TaskExplorerDefinition = {
...defaultDef,
...{
cmdLine: this.getCommand() + " clean -f " + defaultDef.fileName
}
};

const kindCompile: TaskExplorerDefinition = {
...defaultDef,
...{
cmdLine: this.getCommand() + " compile -f " + defaultDef.fileName
}
};

const kindDeploy: TaskExplorerDefinition = {
...defaultDef,
...{
cmdLine: this.getCommand() + " deploy -f " + defaultDef.fileName
}
};

const kindInstall: TaskExplorerDefinition = {
...defaultDef,
...{
cmdLine: this.getCommand() + " install -f " + defaultDef.fileName,
}
};

const kindPackage: TaskExplorerDefinition = {
...defaultDef,
...{
cmdLine: this.getCommand() + " package -f " + defaultDef.fileName,
}
};

const kindTest: TaskExplorerDefinition = {
...defaultDef,
...{
cmdLine: this.getCommand() + " test -f " + defaultDef.fileName,
}
};

const kindValidate: TaskExplorerDefinition = {
...defaultDef,
...{
cmdLine: this.getCommand() + " valudate -f " + defaultDef.fileName,
}
};

const kindVerify: TaskExplorerDefinition = {
...defaultDef,
...{
cmdLine: this.getCommand() + " verify -f " + defaultDef.fileName,
}
};

//
// Create the shell execution objects
//
const executionClean = kindClean.cmdLine ? new ShellExecution(kindClean.cmdLine, options) : undefined;
const executionCompile = kindCompile.cmdLine ? new ShellExecution(kindCompile.cmdLine, options) : undefined;
const executionDeploy = kindDeploy.cmdLine ? new ShellExecution(kindDeploy.cmdLine, options) : undefined;
const executionInstall = kindInstall.cmdLine ? new ShellExecution(kindInstall.cmdLine, options) : undefined;
const executionPackage = kindPackage.cmdLine ? new ShellExecution(kindPackage.cmdLine, options) : undefined;
const executionTest = kindTest.cmdLine ? new ShellExecution(kindTest.cmdLine, options) : undefined;
const executionValidate = kindValidate.cmdLine ? new ShellExecution(kindValidate.cmdLine, options) : undefined;
const executionVerify = kindVerify.cmdLine ? new ShellExecution(kindVerify.cmdLine, options) : undefined;

log.methodDone("read app-ublisher file uri tasks", 1, logPad, true);

return [ new Task(kindClean, folder, "Clean", "maven", executionClean, undefined),
new Task(kindCompile, folder, "Compile", "maven", executionCompile, undefined),
new Task(kindDeploy, folder, "Deploy", "maven", executionDeploy, undefined),
new Task(kindInstall, folder, "Install", "maven", executionInstall, undefined),
new Task(kindPackage, folder, "Package", "maven", executionPackage, undefined),
new Task(kindTest, folder, "Test", "maven", executionTest, undefined),
new Task(kindValidate, folder, "Validate", "maven", executionValidate, undefined),
new Task(kindVerify, folder, "Verify", "maven", executionVerify, undefined) ];
}

}
1 change: 1 addition & 0 deletions src/test/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ suite("Extension Tests", () =>
await configuration.updateWs("enableGrunt", enable);
await configuration.updateWs("enableGulp", enable);
await configuration.updateWs("enableMake", enable);
await configuration.updateWs("enableMaven", enable);
await configuration.updateWs("enableNpm", enable);
await configuration.updateWs("enableNsis", enable);
await configuration.updateWs("enablePowershell", enable);
Expand Down
Loading

0 comments on commit 1f90d1b

Please sign in to comment.