Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: gradle - fix crash and remove dep without ver from sbom #132

Merged
merged 1 commit into from
May 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading