-
-
Notifications
You must be signed in to change notification settings - Fork 172
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
[Gradle] SBOM generation didn't work on Windows #1615
base: master
Are you sure you want to change the base?
Changes from all commits
027ccce
0f7525e
7d9b93e
3448dc5
64b497d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3782,43 +3782,50 @@ export function executeParallelGradleProperties(dir, allProjectsStr) { | |
process.env.GRADLE_ARGS_PROPERTIES | ||
? process.env.GRADLE_ARGS_PROPERTIES.split(" ") | ||
: [], | ||
gradleCmd.length, | ||
); | ||
const result = spawnSync(gradleCmd, gradleArgs, { | ||
cwd: dir, | ||
encoding: "utf-8", | ||
shell: isWin, | ||
maxBuffer: MAX_BUFFER, | ||
}); | ||
if (result.status !== 0 || result.error) { | ||
if (result.stderr) { | ||
console.error(result.stdout, result.stderr); | ||
console.log( | ||
"1. Check if the correct version of java and gradle are installed and available in PATH. For example, some project might require Java 11 with gradle 7.\n cdxgen container image bundles Java 23 with gradle 8 which might be incompatible.", | ||
); | ||
console.log( | ||
"2. Try running cdxgen with the custom JDK11-based image `ghcr.io/cyclonedx/cdxgen-java11:v11`.", | ||
); | ||
if (result.stderr?.includes("not get unknown property")) { | ||
const allOutputs = []; | ||
for (const gradleArg of gradleArgs) { | ||
console.log("Executing", gradleCmd, gradleArg.join(" "), "in", dir); | ||
const result = spawnSync(gradleCmd, gradleArg, { | ||
cwd: dir, | ||
encoding: "utf-8", | ||
shell: isWin, | ||
maxBuffer: MAX_BUFFER, | ||
}); | ||
if (result.status !== 0 || result.error) { | ||
if (result.stderr) { | ||
console.error(result.stdout, result.stderr); | ||
console.log( | ||
"3. Check if the SBOM is generated for the correct root project for your application.", | ||
"1. Check if the correct version of java and gradle are installed and available in PATH. For example, some project might require Java 11 with gradle 7.\n cdxgen container image bundles Java 23 with gradle 8 which might be incompatible.", | ||
); | ||
} else if ( | ||
result.stderr?.includes( | ||
"In version catalog libs, import of external catalog file failed", | ||
) | ||
) { | ||
console.log( | ||
"3. Catalog file is required for gradle dependency resolution to succeed.", | ||
"2. Try running cdxgen with the custom JDK11-based image `ghcr.io/cyclonedx/cdxgen-java11:v11`.", | ||
); | ||
} | ||
if (result.stderr.includes("does not exist")) { | ||
return ""; | ||
if (result.stderr?.includes("not get unknown property")) { | ||
console.log( | ||
"3. Check if the SBOM is generated for the correct root project for your application.", | ||
); | ||
} else if ( | ||
result.stderr?.includes( | ||
"In version catalog libs, import of external catalog file failed", | ||
) | ||
) { | ||
console.log( | ||
"3. Catalog file is required for gradle dependency resolution to succeed.", | ||
); | ||
} | ||
if (result.stderr.includes("does not exist")) { | ||
return ""; | ||
} | ||
} | ||
} | ||
allOutputs.push(result.stdout); | ||
} | ||
const stdout = result.stdout; | ||
if (stdout) { | ||
return Buffer.from(stdout).toString(); | ||
|
||
const sstdout = allOutputs.join("\n"); | ||
if (sstdout) { | ||
return Buffer.from(sstdout).toString(); | ||
} | ||
return ""; | ||
} | ||
|
@@ -11803,25 +11810,44 @@ export function getGradleCommand(srcPath, rootPath) { | |
* @param {string[]} gradleArguments The general gradle arguments, which must only be added once | ||
* @param {string[]} gradleSubCommands The sub-commands that are to be executed by gradle | ||
* @param {string[]} gradleSubCommandArguments The arguments specific to the sub-command(s), which much be added PER sub-command | ||
* @param {int} gradleCommandLength The length of the full gradle-command | ||
* | ||
* @returns {string[]} Array of arguments to be added to the gradle command | ||
* @returns {string[]} Array of arrays of arguments to be added to the gradle command | ||
*/ | ||
export function buildGradleCommandArguments( | ||
gradleArguments, | ||
gradleSubCommands, | ||
gradleSubCommandArguments, | ||
gradleCommandLength, | ||
) { | ||
let allGradleArguments = [ | ||
const mainGradleArguments = [ | ||
"--build-cache", | ||
"--console", | ||
"plain", | ||
"--no-parallel", | ||
].concat(gradleArguments); | ||
const maxCliArgsLength = isWin | ||
? 7500 - gradleCommandLength - mainGradleArguments.join(" ").length - 2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is 7500 the maximum gradle supports on windows? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am fine with creating a temporary powershell script and executing the same if it could yield good performance instead of batching. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I hadn't thought about that yet. Let me check that out, it might make this, and your question above, moot. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just can't figure out how to get powershell to return the output... @prabhu, do you have any idea/experience with powershell? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's new for me as well. May be ask Gemini or OpenAI? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
: -1; | ||
const splitArgs = []; | ||
let allGradleArguments = [].concat(mainGradleArguments); | ||
let remainingLength = maxCliArgsLength; | ||
for (const gradleSubCommand of gradleSubCommands) { | ||
const subCommandLength = | ||
[gradleSubCommand, ...gradleSubCommandArguments].join(" ").length + 1; | ||
if (maxCliArgsLength !== -1 && remainingLength - subCommandLength < 0) { | ||
splitArgs.push(allGradleArguments); | ||
allGradleArguments = [].concat(mainGradleArguments); | ||
remainingLength = maxCliArgsLength; | ||
} | ||
allGradleArguments.push(gradleSubCommand); | ||
allGradleArguments = allGradleArguments.concat(gradleSubCommandArguments); | ||
remainingLength -= subCommandLength; | ||
} | ||
if (allGradleArguments.length !== mainGradleArguments.length) { | ||
splitArgs.push(allGradleArguments); | ||
} | ||
return allGradleArguments; | ||
return splitArgs; | ||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How are we handling the case where stdout could be null?