import * as path from 'path' ; import { TreesManager } from '../treeDataProviders/treesManager' ; import { ScanUtils } from './scanUtils' ; export class PomTree { constructor ( private _pomGav = '' , private _pomPath = '' , private _children = [ ] , private _parent ? , private _parentGav = '' ) { } public get pomGav ( ) : string { return this . _pomGav ; } public set pomGav ( v ) { this . _pomGav = v ; } public get pomPath ( ) : string { return this . _pomPath ; } public set pomPath ( v ) { this . _pomPath = v ; } public get children ( ) : PomTree [ ] { return this . _children ; } public set children ( v ) { this . _children = v ; } public get parent ( ) : PomTree | undefined { return this . _parent ; } public set parent ( v ) { this . _parent = v ; } public get parentGav ( ) : string { return this . _parentGav ; } public set parentGav ( v ) { this . _parentGav = v ; } public addChild ( v ) { this . _children ?. push ( v ) ; } public deepSearch ( pomGav ) { if ( this . pomGav === pomGav ) { return this ; } for ( const pom of this . _children ) { return pom . deepSearch ( pomGav ) ; } return ; } public runMavenDependencyTree ( ) { ScanUtils . executeCmd ( `mvn dependency:tree -DappendOutput=true -DoutputFile=.jfrog_vscode/maven` , this . pomPath ) ; } public async getRawDependencies ( treesManager ) { const dependencyTreeFile = path . join ( this . _pomPath , '.jfrog_vscode' , 'maven' ) ; try { const pomContent = ScanUtils . readFileIfExists ( dependencyTreeFile ) ; if ( ! pomContent ) { throw new Error ( ) ; } const pomDependencies = pomContent ?. substring ( pomContent . indexOf ( '\n' ) + 1 ) ; return pomDependencies . split ( /\r?\n/ ) . filter ( line => line . trim ( ) !== '' ) ; } catch ( error ) { treesManager . logManager . logMessage ( 'Dependencies were not found at ' + path . join ( this . _pomPath , 'pom.xml' ) + '.\n' + "Hint: For projects which include the 'org.apache.maven.plugins:maven-dependency-plugin' the scanning functionality is disabled" , 'ERR' ) ; } finally { await ScanUtils . removeFolder ( path . join ( dependencyTreeFile , '..' ) ) ; } return ; } }