import * as vscode from "vscode" ; import { taskExecutor } from "../../taskExecutor" ; import { mavenExplorerProvider } from "../mavenExplorerProvider" ; import { pluginInfoProvider } from "../pluginInfoProvider" ; import { ITreeItem } from "./ITreeItem" ; import { MavenProject } from "./MavenProject" ; import { PluginGoal } from "./PluginGoal" ; const CONTEXT_VALUE = "maven:plugin" ; export class MavenPlugin implements ITreeItem { public project : MavenProject ; public groupId : string ; public artifactId : string ; public version : string ; public prefix : string | undefined ; public goals : string [ ] | undefined ; constructor ( project , groupId , artifactId , version ) { this . project = project ; this . groupId = groupId ; this . artifactId = artifactId ; this . version = version ; taskExecutor . execute ( async ( ) => await this . fetchPrefix ( ) ) ; } private get pluginId ( ) : string { let pluginId = `${ this . groupId }:${ this . artifactId }` ; if ( this . version !== undefined ) { pluginId += `:${ this . version }` ; } return pluginId ; } public getContextValue ( ) { return CONTEXT_VALUE ; } public async getTreeItem ( ) { const label = this . prefix || this . pluginId ; const treeItem = new vscode . TreeItem ( label , vscode . TreeItemCollapsibleState . Collapsed ) ; treeItem . iconPath = new vscode . ThemeIcon ( "symbol-property" ) ; if ( this . prefix ) { treeItem . description = this . pluginId ; } return treeItem ; } public async getChildren ( ) { try { await this . fetchGoals ( ) ; } catch ( error ) { return [ ] ; } return this . goals ? this . goals . map ( goal => new PluginGoal ( this , goal ) ) : [ ] ; } public async refresh ( ) { mavenExplorerProvider . refresh ( this ) ; } private async fetchPrefix ( ) { if ( this . prefix !== undefined ) { return ; } const prefix = await pluginInfoProvider . getPluginPrefix ( this . groupId , this . artifactId ) ; this . prefix = prefix ; mavenExplorerProvider . refresh ( this ) ; } private async fetchGoals ( ) { if ( this . goals !== undefined ) { return ; } const goals = await pluginInfoProvider . getPluginGoals ( this . project . pomPath , this . groupId , this . artifactId , this . version ) ; this . goals = goals ; } }