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 , cmd , folder , uri , xArgs ) { return undefined ; } public getDefaultDefinition ( target , folder , uri ) { const def = { 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 , documentText ) { return 0 ; } public async readTasks ( logPad = "" ) { log . methodStart ( "detect maven files" , 1 , logPad , true ) ; const allTasks = [ ] ; const visitedFiles = 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 ( ) { let mvn = "mvn" ; if ( configuration . get ( "pathToMaven" ) ) { mvn = configuration . get ( "pathToMaven" ) ; } return mvn ; } public async readUriTasks ( uri , wsFolder ? , logPad = "" ) { const cwd = path . dirname ( uri . fsPath ) , folder = wsFolder || workspace . getWorkspaceFolder ( uri ) , args = [ ] ; if ( ! folder ) { return [ ] ; } const defaultDef = this . getDefaultDefinition ( undefined , folder , uri ) , options = { cwd } ; log . methodStart ( "read maven file uri task" , 1 , logPad , true , [ [ "path" , uri ?. fsPath ] , [ "project folder" , folder ?. name ] ] ) ; const kindClean = { ... defaultDef , ... { cmdLine : this . getCommand ( ) + " clean -f " + defaultDef . fileName } } ; const kindCompile = { ... defaultDef , ... { cmdLine : this . getCommand ( ) + " compile -f " + defaultDef . fileName } } ; const kindDeploy = { ... defaultDef , ... { cmdLine : this . getCommand ( ) + " deploy -f " + defaultDef . fileName } } ; const kindInstall = { ... defaultDef , ... { cmdLine : this . getCommand ( ) + " install -f " + defaultDef . fileName , } } ; const kindPackage = { ... defaultDef , ... { cmdLine : this . getCommand ( ) + " package -f " + defaultDef . fileName , } } ; const kindTest = { ... defaultDef , ... { cmdLine : this . getCommand ( ) + " test -f " + defaultDef . fileName , } } ; const kindValidate = { ... defaultDef , ... { cmdLine : this . getCommand ( ) + " valudate -f " + defaultDef . fileName , } } ; const kindVerify = { ... defaultDef , ... { cmdLine : this . getCommand ( ) + " verify -f " + defaultDef . fileName , } } ; 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 ) ] ; } }