Skip to content

Commit

Permalink
fix: gradle - fix crash and remove dep without ver from sbom (#132)
Browse files Browse the repository at this point in the history
Signed-off-by: Zvi Grinberg <[email protected]>
  • Loading branch information
zvigrinberg authored May 1, 2024
1 parent 09459d0 commit bfccccf
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/providers/java_gradle.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ function removeDuplicateIfExists(arrayForSbom,theContent) {
/** @typedef {PackageUrl}
*/
let depUrl = this.parseDep(dependency)
let depVersion = depUrl.version.trim()
let depVersion
if(depUrl.version) {
depVersion = depUrl.version.trim()
}
let indexOfDuplicate = arrayForSbom.map(dep => this.parseDep(dep))
.findIndex(dep => dep.namespace === depUrl.namespace && dep.name === depUrl.name && dep.version !== depVersion)
let selfIndex = arrayForSbom.map(dep => this.parseDep(dep))
Expand Down Expand Up @@ -255,13 +258,13 @@ export default class Java_gradle extends Base_java {
sbom.addRoot(rootPurl)
let lines = this.#extractLines(content, configName)
// transform gradle dependency tree to the form of maven dependency tree to use common sbom build algorithm in Base_java parent */
let arrayForSbom = lines.map(dependency => dependency.replaceAll("---", "-").replaceAll(" ", " "))
let arrayForSbom = lines.filter(dep => dep.trim() !== "").map(dependency => dependency.replaceAll("---", "-").replaceAll(" ", " "))
.map(dependency => dependency.replaceAll(/:(.*):(.*) -> (.*)$/g, ":$1:$3"))
.map(dependency => dependency.replaceAll(/:(.*)\W*->\W*(.*)$/g, ":$1:$2"))
.map(dependency => dependency.replaceAll(/(.*):(.*):(.*)$/g, "$1:$2:jar:$3"))
.map(dependency => dependency.replaceAll(/(n)$/g), "")
.map(dependency => `${dependency}:compile`);
if(!containsVersion(arrayForSbom[0])) {
if(arrayForSbom.length > 0 && !containsVersion(arrayForSbom[0])) {
arrayForSbom = arrayForSbom.slice(1)
}
if( ["api", "implementation", "compile"].includes(configName) ) {
Expand Down Expand Up @@ -290,7 +293,7 @@ export default class Java_gradle extends Base_java {
}

if (startFound && dependency.trim() !== "") {
if(startMarker === 'runtimeClasspath' || containsVersion(dependenciesList[dependency])) {
if(startMarker === 'runtimeClasspath' || containsVersion(dependenciesList[dependency]) ) {
resultList.push(dependenciesList[dependency])
}
}
Expand Down

0 comments on commit bfccccf

Please sign in to comment.