import { ComponentDetails } from 'jfrog-client-js' ; import * as Collections from 'typescript-collections' ; import * as vscode from 'vscode' ; import { GavGeneralInfo } from '../../../types/gavGeneralinfo' ; import { MavenUtils } from '../../../utils/mavenUtils' ; import { PomTree } from '../../../utils/pomTree' ; import { TreesManager } from '../../treesManager' ; import { DependenciesTreeNode } from '../dependenciesTreeNode' ; import { RootNode } from './rootTree' ; export class MavenTreeNode extends RootNode { private static readonly COMPONENT_PREFIX : string = 'gav://' ; constructor ( workspaceFolder , private _componentsToScan , private _treesManager , parent ? ) { super ( workspaceFolder , parent ) ; MavenUtils . pathToNode . set ( workspaceFolder , this ) ; } param quickScan param prototypeTree public async refreshDependencies ( quickScan , prototypeTree , parentDependencies ? ) { const [ group , name , version ] = prototypeTree . pomGav . split ( ':' ) ; this . generalInfo = new GavGeneralInfo ( group , name , version , [ ] , this . workspaceFolder , MavenUtils . PKG_TYPE ) ; this . label = group + ':' + name ; let rawDependenciesList = await prototypeTree . getRawDependencies ( this . _treesManager ) ; if ( ! ! rawDependenciesList && rawDependenciesList . length > 0 ) { rawDependenciesList = MavenUtils . filterParentDependencies ( rawDependenciesList , parentDependencies ) || rawDependenciesList ; this . collapsibleState = vscode . TreeItemCollapsibleState . Collapsed ; this . populateDependenciesTree ( this , rawDependenciesList , { index : 0 } , quickScan ) ; } for ( const childPom of prototypeTree . children ) { const dependenciesTreeNode = new MavenTreeNode ( childPom . pomPath , this . _componentsToScan , this . _treesManager , this ) ; await dependenciesTreeNode . refreshDependencies ( quickScan , childPom , rawDependenciesList ) ; if ( dependenciesTreeNode . children . length === 0 ) { this . children . splice ( this . children . indexOf ( dependenciesTreeNode ) , 1 ) ; } } } param parent param rawDependenciesList param rawDependenciesPtr param quickScan private populateDependenciesTree ( parent , rawDependenciesList , rawDependenciesPtr , quickScan ) { for ( ; rawDependenciesPtr . index < rawDependenciesList . length ; rawDependenciesPtr . index ++ ) { let dependency = rawDependenciesList [ rawDependenciesPtr . index ] ; const [ group , name , version , scope ] = MavenUtils . getDependencyInfo ( dependency ) ; const gavGeneralInfo = new GavGeneralInfo ( group , name , version , [ scope ] , '' , MavenUtils . PKG_TYPE ) ; let treeCollapsibleState = this . isParent ( rawDependenciesList , rawDependenciesPtr . index ) ? vscode . TreeItemCollapsibleState . Collapsed : vscode . TreeItemCollapsibleState . None ; let child = new DependenciesTreeNode ( gavGeneralInfo , treeCollapsibleState , parent ) ; child . label = group + ':' + name ; let componentId = gavGeneralInfo . getComponentId ( ) ; if ( ! quickScan || ! this . _treesManager . scanCacheManager . isValid ( componentId ) ) { this . _componentsToScan . add ( new ComponentDetails ( MavenTreeNode . COMPONENT_PREFIX + componentId ) ) ; } if ( rawDependenciesPtr . index + 1 < rawDependenciesList . length ) { while ( rawDependenciesPtr . index + 1 < rawDependenciesList . length && this . isChild ( dependency , rawDependenciesList [ rawDependenciesPtr . index + 1 ] ) ) { rawDependenciesPtr . index ++ ; this . populateDependenciesTree ( child , rawDependenciesList , rawDependenciesPtr , quickScan ) ; } if ( ! this . isBrother ( dependency , rawDependenciesList [ rawDependenciesPtr . index + 1 ] ) ) { return ; } } } } @override  public shallowClone ( ) { const clone = new MavenTreeNode ( this . workspaceFolder , this . _componentsToScan , this . _treesManager , undefined ) ; clone . generalInfo = this . generalInfo ; clone . licenses = this . licenses ; clone . issues = this . issues ; clone . topSeverity = this . topSeverity ; clone . label = this . label ; clone . collapsibleState = this . collapsibleState ; return clone ; } param rawDependenciesLine returns private getDependenciesLevel ( rawDependenciesLine ) { return rawDependenciesLine ?. search ( /\w/ ) ; } private isEndOfDependenciesList ( rawDependenciesList , index ) { return rawDependenciesList . length <= index ; } private isParent ( rawDependenciesList , index ) { return ! this . isEndOfDependenciesList ( rawDependenciesList , index + 1 ) && this . isUpperInTree ( rawDependenciesList , index , index + 1 ) ; } private isChild ( toCompare , against ) { return this . getDependenciesLevel ( against ) > this . getDependenciesLevel ( toCompare ) ; } private isBrother ( toCompare , against ) { return this . getDependenciesLevel ( against ) === this . getDependenciesLevel ( toCompare ) ; } private isUpperInTree ( rawDependenciesList , toCompare , against ) { return this . getDependenciesLevel ( rawDependenciesList [ against ] ) > this . getDependenciesLevel ( rawDependenciesList [ toCompare ] ) ; } @override  public setUpgradableDependencies ( ) { this . children . forEach ( child => { if ( child instanceof RootNode ) { child . children . forEach ( c => this . upgradableDependencies ( this . _treesManager . scanCacheManager , c ) ) ; } else { this . upgradableDependencies ( this . _treesManager . scanCacheManager , child ) ; } } ) ; } }