Skip to content

Commit bfccccf

Browse files
authored
fix: gradle - fix crash and remove dep without ver from sbom (#132)
Signed-off-by: Zvi Grinberg <[email protected]>
1 parent 09459d0 commit bfccccf

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/providers/java_gradle.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ function removeDuplicateIfExists(arrayForSbom,theContent) {
5656
/** @typedef {PackageUrl}
5757
*/
5858
let depUrl = this.parseDep(dependency)
59-
let depVersion = depUrl.version.trim()
59+
let depVersion
60+
if(depUrl.version) {
61+
depVersion = depUrl.version.trim()
62+
}
6063
let indexOfDuplicate = arrayForSbom.map(dep => this.parseDep(dep))
6164
.findIndex(dep => dep.namespace === depUrl.namespace && dep.name === depUrl.name && dep.version !== depVersion)
6265
let selfIndex = arrayForSbom.map(dep => this.parseDep(dep))
@@ -255,13 +258,13 @@ export default class Java_gradle extends Base_java {
255258
sbom.addRoot(rootPurl)
256259
let lines = this.#extractLines(content, configName)
257260
// transform gradle dependency tree to the form of maven dependency tree to use common sbom build algorithm in Base_java parent */
258-
let arrayForSbom = lines.map(dependency => dependency.replaceAll("---", "-").replaceAll(" ", " "))
261+
let arrayForSbom = lines.filter(dep => dep.trim() !== "").map(dependency => dependency.replaceAll("---", "-").replaceAll(" ", " "))
259262
.map(dependency => dependency.replaceAll(/:(.*):(.*) -> (.*)$/g, ":$1:$3"))
260263
.map(dependency => dependency.replaceAll(/:(.*)\W*->\W*(.*)$/g, ":$1:$2"))
261264
.map(dependency => dependency.replaceAll(/(.*):(.*):(.*)$/g, "$1:$2:jar:$3"))
262265
.map(dependency => dependency.replaceAll(/(n)$/g), "")
263266
.map(dependency => `${dependency}:compile`);
264-
if(!containsVersion(arrayForSbom[0])) {
267+
if(arrayForSbom.length > 0 && !containsVersion(arrayForSbom[0])) {
265268
arrayForSbom = arrayForSbom.slice(1)
266269
}
267270
if( ["api", "implementation", "compile"].includes(configName) ) {
@@ -290,7 +293,7 @@ export default class Java_gradle extends Base_java {
290293
}
291294

292295
if (startFound && dependency.trim() !== "") {
293-
if(startMarker === 'runtimeClasspath' || containsVersion(dependenciesList[dependency])) {
296+
if(startMarker === 'runtimeClasspath' || containsVersion(dependenciesList[dependency]) ) {
294297
resultList.push(dependenciesList[dependency])
295298
}
296299
}

0 commit comments

Comments
 (0)