private Collection < DependencyInfo > collectPackageJsonDependencies ( Collection < BomFile > packageJsons ) { Collection < DependencyInfo > dependencies = new LinkedList <> ( ) ; ConcurrentHashMap < DependencyInfo , BomFile > dependencyPackageJsonMap = new ConcurrentHashMap <> ( ) ; ExecutorService executorService = Executors . newWorkStealingPool ( NUM_THREADS ) ; Collection < EnrichDependency > threadsCollection = new LinkedList <> ( ) ; for ( BomFile packageJson : packageJsons ) { if ( packageJson != null && packageJson . isValid ( ) ) { // do not add new dependencies if 'npm ls' already returned all DependencyInfo dependency = new DependencyInfo ( ) ; dependencies . add ( dependency ) ; threadsCollection . add ( new EnrichDependency ( packageJson , dependency , dependencyPackageJsonMap , npmAccessToken ) ) ; logger . debug ( "Collect package.json of the dependency in the file: {}" , dependency . getFilename ( ) ) ; } } runThreadCollection ( executorService , threadsCollection ) ; logger . debug ( "set hierarchy of the dependencies" ) ; // remove duplicates dependencies Map < String , DependencyInfo > existDependencies = new HashMap <> ( ) ; Map < DependencyInfo , BomFile > dependencyPackageJsonMapWithoutDuplicates = new HashMap <> ( ) ; for ( Map . Entry < DependencyInfo , BomFile > entry : dependencyPackageJsonMap . entrySet ( ) ) { DependencyInfo keyDep = entry . getKey ( ) ; String key = keyDep . getSha1 ( ) + keyDep . getVersion ( ) + keyDep . getArtifactId ( ) ; if ( ! existDependencies . containsKey ( key ) ) { existDependencies . put ( key , keyDep ) ; dependencyPackageJsonMapWithoutDuplicates . put ( keyDep , entry . getValue ( ) ) ; } } setHierarchy ( dependencyPackageJsonMapWithoutDuplicates , existDependencies ) ; return existDependencies . values ( ) ; }
Collect dependencies from package . json files - without npm ls