33
44import * as fs from 'fs' ;
55import * as semver from 'semver' ;
6- import * as glob from 'glob' ;
7- import { promisify } from 'util' ;
6+ import { globby } from 'globby' ;
87
9- const globAsync = promisify ( glob ) ;
108import { Uri } from 'vscode' ;
119import { Jdtls } from "../java/jdtls" ;
1210import { NodeKind , type INodeData } from "../java/nodeData" ;
@@ -153,13 +151,19 @@ async function getDependencyIssues(dependencies: PackageDescription[]): Promise<
153151async function getWorkspaceIssues ( projectDeps :{ projectNode : INodeData , dependencies : PackageDescription [ ] } [ ] ) : Promise < UpgradeIssue [ ] > {
154152
155153 const issues : UpgradeIssue [ ] = [ ] ;
156- const dependenciesSet : Set < PackageDescription > = new Set ( ) ;
154+ const dependencyMap : Map < string , PackageDescription > = new Map ( ) ;
157155 for ( const { projectNode, dependencies } of projectDeps ) {
158156 issues . push ( ...getJavaIssues ( projectNode ) ) ;
159- dependencies . forEach ( dep => dependenciesSet . add ( dep ) ) ;
157+ for ( const dep of dependencies ) {
158+ const key = `${ dep . groupId } :${ dep . artifactId } :${ dep . version ?? "" } ` ;
159+ if ( ! dependencyMap . has ( key ) ) {
160+ dependencyMap . set ( key , dep ) ;
161+ }
162+ }
160163 }
161- issues . push ( ...await getCVEIssues ( Array . from ( dependenciesSet ) ) ) ;
162- issues . push ( ...await getDependencyIssues ( Array . from ( dependenciesSet ) ) ) ;
164+ const uniqueDependencies = Array . from ( dependencyMap . values ( ) ) ;
165+ issues . push ( ...await getCVEIssues ( uniqueDependencies ) ) ;
166+ issues . push ( ...await getDependencyIssues ( uniqueDependencies ) ) ;
163167 return issues ;
164168}
165169
@@ -168,10 +172,9 @@ async function getWorkspaceIssues(projectDeps:{projectNode: INodeData, dependenc
168172 */
169173async function findAllPomFiles ( dir : string ) : Promise < string [ ] > {
170174 try {
171- return await globAsync ( '**/pom.xml' , {
175+ return await globby ( '**/pom.xml' , {
172176 cwd : dir ,
173177 absolute : true ,
174- nodir : true ,
175178 ignore : [ '**/node_modules/**' , '**/target/**' , '**/.git/**' , '**/.idea/**' , '**/.vscode/**' ]
176179 } ) ;
177180 } catch {
@@ -183,6 +186,7 @@ async function findAllPomFiles(dir: string): Promise<string[]> {
183186 * Parse dependencies from a single pom.xml file
184187 */
185188function parseDependenciesFromSinglePom ( pomPath : string ) : Set < string > {
189+ //TODO : Use a proper XML parser if needed
186190 const directDeps = new Set < string > ( ) ;
187191 try {
188192 const pomContent = fs . readFileSync ( pomPath , 'utf-8' ) ;
@@ -233,10 +237,9 @@ async function parseDirectDependenciesFromPom(projectPath: string): Promise<Set<
233237 */
234238async function findAllGradleFiles ( dir : string ) : Promise < string [ ] > {
235239 try {
236- return await globAsync ( '**/{build.gradle,build.gradle.kts}' , {
240+ return await globby ( '**/{build.gradle,build.gradle.kts}' , {
237241 cwd : dir ,
238242 absolute : true ,
239- nodir : true ,
240243 ignore : [ '**/node_modules/**' , '**/build/**' , '**/.git/**' , '**/.idea/**' , '**/.vscode/**' , '**/.gradle/**' ]
241244 } ) ;
242245 } catch {
@@ -340,7 +343,7 @@ export async function getDirectDependencies(projectNode: INodeData): Promise<Pac
340343
341344 let dependencies = fulfilled . map ( x => x . value ) . flat ( ) ;
342345
343- if ( ! dependencies ) {
346+ if ( ! dependencies || dependencies . length === 0 ) {
344347 sendInfo ( "" , {
345348 operationName : "java.dependency.assessmentManager.getDirectDependencies.noDependencyInfo"
346349 } ) ;
@@ -364,19 +367,17 @@ export async function getDirectDependencies(projectNode: INodeData): Promise<Pac
364367 }
365368 }
366369
367- if ( ! directDependencyIds ) {
370+ if ( ! directDependencyIds || directDependencyIds . size === 0 ) {
368371 sendInfo ( "" , {
369372 operationName : "java.dependency.assessmentManager.getDirectDependencies.noDirectDependencyInfo"
370373 } ) ;
371374 //TODO: fallback to return all dependencies if we cannot parse direct dependencies or just return empty?
372375 return dependencies ;
373376 }
374377 // Filter to only direct dependencies if we have build file info
375- if ( directDependencyIds && directDependencyIds . size > 0 ) {
376- dependencies = dependencies . filter ( pkg =>
377- directDependencyIds ! . has ( `${ pkg . groupId } :${ pkg . artifactId } ` )
378- ) ;
379- }
378+ dependencies = dependencies . filter ( pkg =>
379+ directDependencyIds ! . has ( `${ pkg . groupId } :${ pkg . artifactId } ` )
380+ ) ;
380381
381382 return dependencies ;
382383}
0 commit comments