Skip to content
Merged
Show file tree
Hide file tree
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
21 changes: 19 additions & 2 deletions src/providers/java_gradle.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ function stripString(depPart) {
return depPart.replaceAll(/["']/g,"")
}

/** this function checks whether a line from `gradle dependencies` output contains a version or not
*
* @param line the line from `gradle dependencies` output.
* @return {*|boolean}
*/
function containsVersion(line) {
let lineStriped = line.replace("(n)","").trim()
return (lineStriped.match(/\W*[a-z0-9.-]+:[a-z0-9.-]+:[0-9]+[.][0-9]+(.[0-9]+)?(.*)?.*/)
|| lineStriped.match(/.*version:\s?(')?[0-9]+[.][0-9]+(.[0-9]+)?(')?/)) && !lineStriped.includes("libs.")
}

export default class Java_gradle extends Base_java {

/**
Expand Down Expand Up @@ -210,10 +221,14 @@ export default class Java_gradle extends Base_java {
// 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(" ", " "))
.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`);
this.parseDependencyTree(root, 0, arrayForSbom.slice(1), sbom)
if(!containsVersion(arrayForSbom[0])) {
arrayForSbom = arrayForSbom.slice(1)
}
this.parseDependencyTree(root + ":compile", 0, arrayForSbom, sbom)
let ignoredDeps = this.#getIgnoredDeps(manifestPath)
return sbom.filterIgnoredDepsIncludingVersion(ignoredDeps).getAsJsonString();
}
Expand All @@ -236,7 +251,9 @@ export default class Java_gradle extends Base_java {
}

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

if (startFound && dependenciesList[dependency].trim() === "") {
Expand Down
3 changes: 2 additions & 1 deletion test/it/test_manifests/gradle/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ dependencies {
implementation "jakarta.validation:jakarta.validation-api:2.0.2"
implementation "io.quarkus:quarkus-resteasy-multipart:2.13.7.Final"
implementation "io.quarkus:quarkus-hibernate-orm-deployment:2.0.2.Final"
implementation "log4j:log4j:1.2.17" // exhortignore
implementation "log4j:log4j:1.2.17"
implementation group: 'log4j', name: 'log4j'
}
test {
useJUnitPlatform()
Expand Down