import * as vscode from 'vscode' ; import { ConnectionManager } from '../connect/connectionManager' ; import { DependencyUpdateManager } from '../dependencyUpdate/dependencyUpdateManager' ; import { ExclusionsManager } from '../exclusions/exclusionsManager' ; import { ExtensionComponent } from '../extensionComponent' ; import { FilterManager } from '../filter/filterManager' ; import { FocusType } from '../focus/abstractFocus' ; import { FocusManager } from '../focus/focusManager' ; import { LogManager } from '../log/logManager' ; import { DependenciesTreeNode } from '../treeDataProviders/dependenciesTree/dependenciesTreeNode' ; import { State , TreesManager } from '../treeDataProviders/treesManager' ; import { TreeDataHolder } from '../treeDataProviders/utils/treeDataHolder' ; import { ScanUtils } from '../utils/scanUtils' ; import { BuildsManager } from '../builds/buildsManager' ; import { Configuration } from '../utils/configuration' ; /**
 * Register and execute all commands in the extension.
 */ export class CommandManager implements ExtensionComponent { constructor ( private _logManager , private _connectionManager , private _treesManager , private _filterManager , private _focusManager , private _exclusionManager , private _DependencyUpdateManager , private _buildsManager ) { } public activate ( context ) { this . registerCommand ( context , 'jfrog.xray.showInProjectDesc' , dependenciesTreeNode => this . doShowInProjectDesc ( dependenciesTreeNode ) ) ; this . registerCommand ( context , 'jfrog.xray.excludeDependency' , dependenciesTreeNode => this . doExcludeDependency ( dependenciesTreeNode ) ) ; this . registerCommand ( context , 'jfrog.xray.updateDependency' , dependenciesTreeNode => this . doUpdateDependencyVersion ( dependenciesTreeNode ) ) ; this . registerCommand ( context , 'jfrog.xray.codeAction' , dependenciesTreeNode => this . doCodeAction ( dependenciesTreeNode ) ) ; this . registerCommand ( context , 'jfrog.xray.focus' , dependenciesTreeNode => this . doFocus ( dependenciesTreeNode ) ) ; this . registerCommand ( context , 'jfrog.xray.copyToClipboard' , node => this . doCopyToClipboard ( node ) ) ; this . registerCommand ( context , 'jfrog.xray.openLink' , url => this . doOpenLink ( url ) ) ; this . registerCommand ( context , 'jfrog.xray.disconnect' , ( ) => this . doDisconnect ( ) ) ; this . registerCommand ( context , 'jfrog.xray.showOutput' , ( ) => this . showOutput ( ) ) ; this . registerCommand ( context , 'jfrog.xray.refresh' , ( ) => this . doRefresh ( ) ) ; this . registerCommand ( context , 'jfrog.xray.connect' , ( ) => this . doConnect ( ) ) ; this . registerCommand ( context , 'jfrog.xray.filter' , ( ) => this . doFilter ( ) ) ; this . registerCommand ( context , 'jfrog.xray.local' , ( ) => this . doLocal ( ) ) ; this . registerCommand ( context , 'jfrog.xray.ci' , ( ) => this . doCi ( ) ) ; this . registerCommand ( context , 'jfrog.xray.builds' , ( ) => this . doBuildSelected ( ) ) ; this . updateLocalCiIcons ( ) ; } public doLocal ( ) { this . _treesManager . state = State . Local ; this . updateLocalCiIcons ( ) ; this . _treesManager . treeDataProviderManager . stateChange ( ) ; } public doCi ( ) { if ( ! this . areCiPreconditionsMet ( ) ) { return ; } this . _treesManager . state = State . CI ; this . updateLocalCiIcons ( ) ; this . _treesManager . treeDataProviderManager . stateChange ( ) ; } private areCiPreconditionsMet ( ) { if ( ! this . _treesManager . connectionManager . areCompleteCredentialsSet ( ) ) { vscode . window . showErrorMessage ( 'CI integration disabled - Artifactory server is not configured. ' + 'To use this section of the JFrog extension, please configure your JFrog platform details.' , ... [ 'Configure JFrog Details' ] ) . then ( async ( action ) => { if ( action ) { await this . doConnect ( ) ; } } ) ; return false ; } if ( ! Configuration . getBuildsPattern ( ) ) { vscode . window . showErrorMessage ( 'CI integration disabled - build name pattern is not set.' , ... [ 'Set Build Name Pattern' ] ) . then ( action => { if ( action ) { vscode . commands . executeCommand ( 'workbench.action.openSettings' , 'jfrog.xray.ciIntegration.buildNamePattern' ) ; } } ) ; return false ; } return true ; } private updateLocalCiIcons ( ) { vscode . commands . executeCommand ( 'setContext' , 'isLocal' , this . _treesManager . isLocalState ( ) ) ; vscode . commands . executeCommand ( 'setContext' , 'isCi' , this . _treesManager . isCiState ( ) ) ; } param dependenciesTreeNode private doShowInProjectDesc ( dependenciesTreeNode ) { this . _focusManager . focusOnDependency ( dependenciesTreeNode , FocusType . Dependency ) ; this . onSelectNode ( dependenciesTreeNode ) ; } param dependenciesTreeNode private doExcludeDependency ( dependenciesTreeNode ) { this . _exclusionManager . excludeDependency ( dependenciesTreeNode ) ; } param dependenciesTreeNode private async doUpdateDependencyVersion ( dependenciesTreeNode ) { await ScanUtils . scanWithProgress ( async ( ) : Promise < void > => { try { if ( ! ( await this . _DependencyUpdateManager . updateDependencyVersion ( dependenciesTreeNode ) ) ) { return ; } this . _focusManager . focusOnDependency ( dependenciesTreeNode , FocusType . DependencyVersion ) ; this . _treesManager . treeDataProviderManager . removeNode ( dependenciesTreeNode ) ; } catch ( error ) { vscode . window . showErrorMessage ( 'Could not update dependency version.' , < vscode . MessageOptions > { modal : false } ) ; this . _treesManager . logManager . logMessage ( ( < any > error ) . message , 'ERR' , true ) ; } } , 'Updating ' + dependenciesTreeNode . generalInfo . getComponentId ( ) ) ; } param url private doOpenLink ( url ) { if ( ! url ) { return ; } vscode . commands . executeCommand ( 'vscode.open' , vscode . Uri . parse ( url ) ) ; } param dependenciesTreeNode private doCodeAction ( dependenciesTreeNode ) { this . _treesManager . dependenciesTreeView . reveal ( dependenciesTreeNode , { focus : true } ) ; this . onSelectNode ( dependenciesTreeNode ) ; } param dependenciesTreeNode private doFocus ( dependenciesTreeNode ) { this . onSelectNode ( dependenciesTreeNode ) ; } param node private doCopyToClipboard ( node ) { let text ; if ( node instanceof TreeDataHolder ) { let treeDataHolder = node ; if ( treeDataHolder . value ) { text = node . value ; } else if ( treeDataHolder . key ) { text = node . key ; } } else if ( node . description ) { text = node . label + ':' + node . description ; } else if ( node . label ) { text = node . label ; } if ( text ) { vscode . env . clipboard . writeText ( text ) ; } } /**
     * Show JFrog Output tab.
     */ private showOutput ( ) { this . _logManager . showOutput ( ) ; } param quickScan private doRefresh ( quickScan = false ) { this . _treesManager . treeDataProviderManager . refresh ( quickScan ) ; } /**
     * Connect to Xray server. If connection success, perform a quick scan.
     */ private async doConnect ( ) { let credentialsSet = await this . _connectionManager . connect ( ) ; if ( credentialsSet ) { this . doRefresh ( true ) ; } } /**
     * Disconnect from Xray server. Delete the URL, username & password from FS.
     */ private async doDisconnect ( ) { if ( await this . _connectionManager . disconnect ( ) ) { this . doRefresh ( true ) ; } } /**
     * Show the filter menu.
     */ private doFilter ( ) { this . _filterManager . showFilterMenu ( ) ; } /**
     * Show the builds menu.
     */ private doBuildSelected ( ) { this . _buildsManager . showBuildsMenu ( ) ; } param command param callback private registerCommand ( context , command , callback ) { context . subscriptions . push ( vscode . commands . registerCommand ( command , callback ) ) ; } param dependenciesTreeNode private onSelectNode ( dependenciesTreeNode ) { this . _treesManager . componentDetailsDataProvider . selectNode ( dependenciesTreeNode ) ; this . _treesManager . issuesDataProvider . selectNode ( dependenciesTreeNode ) ; } }