@trustify-da/trustify-da-javascript-client 0.3.0-ea.b8af0f8 → 0.3.0-ea.bdaadb2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +250 -11
- package/dist/package.json +33 -25
- package/dist/src/analysis.d.ts +14 -7
- package/dist/src/analysis.js +32 -15
- package/dist/src/cli.js +156 -3
- package/dist/src/cyclone_dx_sbom.d.ts +27 -1
- package/dist/src/cyclone_dx_sbom.js +82 -9
- package/dist/src/index.d.ts +86 -11
- package/dist/src/index.js +102 -30
- package/dist/src/license/index.d.ts +3 -3
- package/dist/src/license/index.js +4 -1
- package/dist/src/license/license_utils.js +4 -1
- package/dist/src/license/licenses_api.d.ts +2 -2
- package/dist/src/oci_image/images.d.ts +1 -1
- package/dist/src/oci_image/images.js +15 -1
- package/dist/src/oci_image/utils.d.ts +5 -5
- package/dist/src/oci_image/utils.js +11 -2
- package/dist/src/package_version.d.ts +8 -0
- package/dist/src/package_version.js +31 -0
- package/dist/src/provider.d.ts +4 -3
- package/dist/src/provider.js +12 -2
- package/dist/src/providers/base_java.d.ts +67 -12
- package/dist/src/providers/base_java.js +82 -61
- package/dist/src/providers/base_javascript.d.ts +74 -9
- package/dist/src/providers/base_javascript.js +149 -9
- package/dist/src/providers/base_pyproject.d.ts +158 -0
- package/dist/src/providers/base_pyproject.js +322 -0
- package/dist/src/providers/containerfile_parser.d.ts +5 -0
- package/dist/src/providers/containerfile_parser.js +20 -0
- package/dist/src/providers/golang_gomodules.d.ts +23 -13
- package/dist/src/providers/golang_gomodules.js +207 -120
- package/dist/src/providers/gomod_parser.d.ts +4 -0
- package/dist/src/providers/gomod_parser.js +16 -0
- package/dist/src/providers/java_gradle.d.ts +67 -0
- package/dist/src/providers/java_gradle.js +310 -17
- package/dist/src/providers/java_gradle_groovy.d.ts +1 -1
- package/dist/src/providers/java_gradle_kotlin.d.ts +1 -1
- package/dist/src/providers/java_maven.d.ts +38 -5
- package/dist/src/providers/java_maven.js +261 -8
- package/dist/src/providers/javascript_bun.d.ts +22 -0
- package/dist/src/providers/javascript_bun.js +141 -0
- package/dist/src/providers/javascript_npm.d.ts +19 -0
- package/dist/src/providers/javascript_npm.js +61 -1
- package/dist/src/providers/javascript_pnpm.d.ts +13 -0
- package/dist/src/providers/javascript_pnpm.js +53 -3
- package/dist/src/providers/javascript_yarn.d.ts +12 -0
- package/dist/src/providers/javascript_yarn.js +75 -2
- package/dist/src/providers/manifest.d.ts +2 -0
- package/dist/src/providers/manifest.js +22 -4
- package/dist/src/providers/marker_evaluator.d.ts +14 -0
- package/dist/src/providers/marker_evaluator.js +191 -0
- package/dist/src/providers/oci_dockerfile.d.ts +51 -0
- package/dist/src/providers/oci_dockerfile.js +177 -0
- package/dist/src/providers/processors/yarn_berry_processor.d.ts +6 -2
- package/dist/src/providers/processors/yarn_berry_processor.js +91 -7
- package/dist/src/providers/processors/yarn_classic_processor.d.ts +6 -2
- package/dist/src/providers/processors/yarn_classic_processor.js +8 -6
- package/dist/src/providers/python_controller.d.ts +5 -1
- package/dist/src/providers/python_controller.js +69 -8
- package/dist/src/providers/python_pip.d.ts +5 -0
- package/dist/src/providers/python_pip.js +6 -6
- package/dist/src/providers/python_pip_pyproject.d.ts +61 -0
- package/dist/src/providers/python_pip_pyproject.js +146 -0
- package/dist/src/providers/python_poetry.d.ts +98 -0
- package/dist/src/providers/python_poetry.js +286 -0
- package/dist/src/providers/python_uv.d.ts +46 -0
- package/dist/src/providers/python_uv.js +269 -0
- package/dist/src/providers/rust_cargo.d.ts +6 -2
- package/dist/src/providers/rust_cargo.js +101 -33
- package/dist/src/providers/tree-sitter-containerfile.wasm +0 -0
- package/dist/src/providers/tree-sitter-gomod.wasm +0 -0
- package/dist/src/remediate.d.ts +21 -0
- package/dist/src/remediate.js +149 -0
- package/dist/src/remediation.d.ts +57 -0
- package/dist/src/remediation.js +436 -0
- package/dist/src/remediation_report.d.ts +40 -0
- package/dist/src/remediation_report.js +159 -0
- package/dist/src/sbom.d.ts +25 -1
- package/dist/src/sbom.js +23 -2
- package/dist/src/tools.d.ts +28 -2
- package/dist/src/tools.js +82 -1
- package/dist/src/updaters/maven_updater.d.ts +26 -0
- package/dist/src/updaters/maven_updater.js +322 -0
- package/dist/src/updaters/toml_updater.d.ts +33 -0
- package/dist/src/updaters/toml_updater.js +244 -0
- package/dist/src/workspace.d.ts +9 -0
- package/dist/src/workspace.js +1 -1
- package/package.json +34 -26
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
1
2
|
import fs from 'node:fs';
|
|
3
|
+
import os from 'node:os';
|
|
2
4
|
import path from 'node:path';
|
|
3
5
|
import { EOL } from 'os';
|
|
4
|
-
import
|
|
6
|
+
import { parse as parseToml } from 'smol-toml';
|
|
5
7
|
import { readLicenseFile } from '../license/license_utils.js';
|
|
6
8
|
import Sbom from '../sbom.js';
|
|
9
|
+
import { invokeCommand } from '../tools.js';
|
|
10
|
+
import { filterManifestPathsByDiscoveryIgnore, resolveWorkspaceDiscoveryIgnore } from '../workspace.js';
|
|
7
11
|
import Base_java, { ecosystem_gradle } from "./base_java.js";
|
|
8
12
|
/** @typedef {import('../provider.js').Provider} */
|
|
9
13
|
/** @typedef {import('../provider.js').Provided} Provided */
|
|
@@ -63,10 +67,10 @@ export default class Java_gradle extends Base_java {
|
|
|
63
67
|
* @param {{}} [opts={}] - optional various options to pass along the application
|
|
64
68
|
* @returns {Provided}
|
|
65
69
|
*/
|
|
66
|
-
provideStack(manifest, opts = {}) {
|
|
70
|
+
async provideStack(manifest, opts = {}) {
|
|
67
71
|
return {
|
|
68
72
|
ecosystem: ecosystem_gradle,
|
|
69
|
-
content: this.#createSbomStackAnalysis(manifest, opts),
|
|
73
|
+
content: await this.#createSbomStackAnalysis(manifest, opts),
|
|
70
74
|
contentType: 'application/vnd.cyclonedx+json'
|
|
71
75
|
};
|
|
72
76
|
}
|
|
@@ -76,10 +80,10 @@ export default class Java_gradle extends Base_java {
|
|
|
76
80
|
* @param {{}} [opts={}] - optional various options to pass along the application
|
|
77
81
|
* @returns {Provided}
|
|
78
82
|
*/
|
|
79
|
-
provideComponent(manifest, opts = {}) {
|
|
83
|
+
async provideComponent(manifest, opts = {}) {
|
|
80
84
|
return {
|
|
81
85
|
ecosystem: ecosystem_gradle,
|
|
82
|
-
content: this.#getSbomForComponentAnalysis(manifest, opts),
|
|
86
|
+
content: await this.#getSbomForComponentAnalysis(manifest, opts),
|
|
83
87
|
contentType: 'application/vnd.cyclonedx+json'
|
|
84
88
|
};
|
|
85
89
|
}
|
|
@@ -129,9 +133,10 @@ export default class Java_gradle extends Base_java {
|
|
|
129
133
|
* @param {Sbom} sbom - the SBOM object to add dependencies to
|
|
130
134
|
* @param {Set} processedDeps - set of already processed dependencies
|
|
131
135
|
* @param {string} scope - the dependency scope
|
|
136
|
+
* @param {Map<string, Array<{alg: string, content: string}>>} [hashMap] - map of "group:name@version" to CycloneDX hashes
|
|
132
137
|
* @private
|
|
133
138
|
*/
|
|
134
|
-
#processDependencyTree(config, parentPurl, sbom, processedDeps, scope) {
|
|
139
|
+
#processDependencyTree(config, parentPurl, sbom, processedDeps, scope, hashMap) {
|
|
135
140
|
const processedLines = this.#prepareLinesForParsingDependencyTree(config);
|
|
136
141
|
let parentStack = [parentPurl];
|
|
137
142
|
for (const { line, depth } of processedLines) {
|
|
@@ -149,7 +154,7 @@ export default class Java_gradle extends Base_java {
|
|
|
149
154
|
// Add dependency to SBOM if not already processed
|
|
150
155
|
if (!processedDeps.has(depKey)) {
|
|
151
156
|
processedDeps.add(depKey);
|
|
152
|
-
sbom.addDependency(currentParent, purl, scope);
|
|
157
|
+
sbom.addDependency(currentParent, purl, scope, hashMap?.get(purl.toString()));
|
|
153
158
|
}
|
|
154
159
|
parentStack.push(purl);
|
|
155
160
|
}
|
|
@@ -162,7 +167,7 @@ export default class Java_gradle extends Base_java {
|
|
|
162
167
|
* @returns {string} the Dot Graph content
|
|
163
168
|
* @private
|
|
164
169
|
*/
|
|
165
|
-
#buildSbom(content, properties, manifestPath, opts = {}) {
|
|
170
|
+
#buildSbom(content, properties, manifestPath, opts = {}, hashMap) {
|
|
166
171
|
let sbom = new Sbom();
|
|
167
172
|
let root = `${properties.group}:${properties[ROOT_PROJECT_KEY_NAME].match(/Root project '(.+)'/)[1]}:jar:${properties.version}`;
|
|
168
173
|
let rootPurl = this.parseDep(root);
|
|
@@ -171,8 +176,8 @@ export default class Java_gradle extends Base_java {
|
|
|
171
176
|
let ignoredDeps = this.#getIgnoredDeps(manifestPath);
|
|
172
177
|
const [runtimeConfig, compileConfig] = this.#extractConfigurations(content);
|
|
173
178
|
const processedDeps = new Set();
|
|
174
|
-
this.#processDependencyTree(runtimeConfig, rootPurl, sbom, processedDeps, 'required');
|
|
175
|
-
this.#processDependencyTree(compileConfig, rootPurl, sbom, processedDeps, 'optional');
|
|
179
|
+
this.#processDependencyTree(runtimeConfig, rootPurl, sbom, processedDeps, 'required', hashMap);
|
|
180
|
+
this.#processDependencyTree(compileConfig, rootPurl, sbom, processedDeps, 'optional', hashMap);
|
|
176
181
|
return sbom.filterIgnoredDepsIncludingVersion(ignoredDeps).getAsJsonString(opts);
|
|
177
182
|
}
|
|
178
183
|
/**
|
|
@@ -182,14 +187,15 @@ export default class Java_gradle extends Base_java {
|
|
|
182
187
|
* @returns {string} the Dot Graph content
|
|
183
188
|
* @private
|
|
184
189
|
*/
|
|
185
|
-
#createSbomStackAnalysis(manifest, opts = {}) {
|
|
190
|
+
async #createSbomStackAnalysis(manifest, opts = {}) {
|
|
186
191
|
let content = this.#getDependencies(manifest, opts);
|
|
187
192
|
let properties = this.#extractProperties(manifest, opts);
|
|
193
|
+
let hashMap = await this.parseGradleHashes(manifest, opts);
|
|
188
194
|
// read dependency tree from temp file
|
|
189
195
|
if (process.env["TRUSTIFY_DA_DEBUG"] === "true") {
|
|
190
196
|
console.log("Dependency tree that will be used as input for creating the BOM =>" + EOL + EOL + content);
|
|
191
197
|
}
|
|
192
|
-
let sbom = this.#buildSbom(content, properties, manifest, opts);
|
|
198
|
+
let sbom = this.#buildSbom(content, properties, manifest, opts, hashMap);
|
|
193
199
|
return sbom;
|
|
194
200
|
}
|
|
195
201
|
/**
|
|
@@ -234,10 +240,11 @@ export default class Java_gradle extends Base_java {
|
|
|
234
240
|
* @returns {string} - sbom string of the direct dependencies of build.gradle
|
|
235
241
|
* @private
|
|
236
242
|
*/
|
|
237
|
-
#getSbomForComponentAnalysis(manifestPath, opts = {}) {
|
|
243
|
+
async #getSbomForComponentAnalysis(manifestPath, opts = {}) {
|
|
238
244
|
let content = this.#getDependencies(manifestPath, opts);
|
|
239
245
|
let properties = this.#extractProperties(manifestPath, opts);
|
|
240
|
-
let
|
|
246
|
+
let hashMap = await this.parseGradleHashes(manifestPath, opts);
|
|
247
|
+
let sbom = this.#buildDirectDependenciesSbom(content, properties, manifestPath, opts, hashMap);
|
|
241
248
|
return sbom;
|
|
242
249
|
}
|
|
243
250
|
/**
|
|
@@ -256,6 +263,112 @@ export default class Java_gradle extends Base_java {
|
|
|
256
263
|
throw new Error(`Couldn't run gradle dependencies command, error message returned from gradle binary => ${EOL} ${error.message}`);
|
|
257
264
|
}
|
|
258
265
|
}
|
|
266
|
+
/**
|
|
267
|
+
* Hash a file using SHA-256 with streaming to handle large files efficiently.
|
|
268
|
+
* @param {string} filePath - path to the file to hash
|
|
269
|
+
* @returns {Promise<string>} hex-encoded SHA-256 digest
|
|
270
|
+
* @private
|
|
271
|
+
*/
|
|
272
|
+
#hashFileStream(filePath) {
|
|
273
|
+
return new Promise((resolve, reject) => {
|
|
274
|
+
const hash = crypto.createHash('sha256');
|
|
275
|
+
const stream = fs.createReadStream(filePath);
|
|
276
|
+
stream.on('data', chunk => hash.update(chunk));
|
|
277
|
+
stream.on('end', () => resolve(hash.digest('hex')));
|
|
278
|
+
stream.on('error', reject);
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Compute SHA-256 hashes for the resolved artifacts of a Gradle manifest.
|
|
283
|
+
*
|
|
284
|
+
* Rather than scanning the local Gradle cache, this asks Gradle itself for
|
|
285
|
+
* the resolved artifact files via an init script (mirroring the pattern used
|
|
286
|
+
* by {@link discoverGradleSubprojects}), then hashes each file with the
|
|
287
|
+
* Node.js `crypto` module. The result is keyed by the canonical PURL string
|
|
288
|
+
* built via {@link Base_java#toPurl} — the same builder {@link parseDep} uses
|
|
289
|
+
* for the lookup — so the stored key and the lookup key cannot drift.
|
|
290
|
+
*
|
|
291
|
+
* Degrades gracefully: if Gradle cannot be invoked, the init script fails, or
|
|
292
|
+
* an artifact has no readable file (e.g. BOM/`platform()` dependencies), the
|
|
293
|
+
* hash for that component is omitted rather than throwing. A warning is emitted
|
|
294
|
+
* on every degradation path so incomplete hash coverage is visible even without
|
|
295
|
+
* `TRUSTIFY_DA_DEBUG` (mirroring the pip/cargo providers).
|
|
296
|
+
*
|
|
297
|
+
* @param {string} manifest - path to build.gradle[.kts]
|
|
298
|
+
* @param {{}} [opts={}] - optional various options to pass along the application
|
|
299
|
+
* @returns {Promise<Map<string, Array<{alg: string, content: string}>>>} map of canonical PURL string to CycloneDX hashes
|
|
300
|
+
*/
|
|
301
|
+
async parseGradleHashes(manifest, opts = {}) {
|
|
302
|
+
const hashMap = new Map();
|
|
303
|
+
const debug = process.env["TRUSTIFY_DA_DEBUG"] === "true";
|
|
304
|
+
let gradle;
|
|
305
|
+
try {
|
|
306
|
+
gradle = this.selectToolBinary(manifest, opts);
|
|
307
|
+
}
|
|
308
|
+
catch (error) {
|
|
309
|
+
console.warn(`Gradle could not be invoked to compute artifact hashes, SBOM will be generated without hashes: ${error.stack || error.message}`);
|
|
310
|
+
return hashMap;
|
|
311
|
+
}
|
|
312
|
+
const initScriptPath = path.join(os.tmpdir(), `da-list-hashes-${crypto.randomUUID()}.gradle`);
|
|
313
|
+
try {
|
|
314
|
+
fs.writeFileSync(initScriptPath, GRADLE_HASH_INIT_SCRIPT);
|
|
315
|
+
let output;
|
|
316
|
+
try {
|
|
317
|
+
output = this._invokeCommand(gradle, [
|
|
318
|
+
'-q', '--no-daemon',
|
|
319
|
+
'--init-script', initScriptPath,
|
|
320
|
+
'daListHashes',
|
|
321
|
+
], { cwd: path.dirname(manifest) });
|
|
322
|
+
}
|
|
323
|
+
catch (error) {
|
|
324
|
+
console.warn(`Gradle hash init script failed, SBOM will be generated without hashes: ${error.stack || error.message}`);
|
|
325
|
+
return hashMap;
|
|
326
|
+
}
|
|
327
|
+
let attempted = 0;
|
|
328
|
+
let missed = 0;
|
|
329
|
+
for (const { id, file } of parseGradleHashScriptOutput(output.toString())) {
|
|
330
|
+
const coord = parseComponentId(id);
|
|
331
|
+
if (!coord) {
|
|
332
|
+
continue;
|
|
333
|
+
}
|
|
334
|
+
// Build the key with the same canonical PURL builder parseDep uses for
|
|
335
|
+
// the lookup, so the stored key and the lookup key cannot drift.
|
|
336
|
+
const key = this.toPurl(coord.group, coord.name, coord.version).toString();
|
|
337
|
+
if (hashMap.has(key)) {
|
|
338
|
+
continue;
|
|
339
|
+
}
|
|
340
|
+
attempted++;
|
|
341
|
+
try {
|
|
342
|
+
const digest = await this.#hashFileStream(file);
|
|
343
|
+
hashMap.set(key, [{ alg: 'SHA-256', content: digest }]);
|
|
344
|
+
}
|
|
345
|
+
catch (error) {
|
|
346
|
+
// artifact file missing/unreadable — omit the hash for this component
|
|
347
|
+
missed++;
|
|
348
|
+
if (debug) {
|
|
349
|
+
console.error(`Gradle hash: could not read artifact ${file} => ${error.message}`);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
if (missed > 0) {
|
|
354
|
+
console.warn(`Gradle hash: ${missed} of ${attempted} resolved artifacts could not be read, SBOM will be generated without hashes for those components`);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
catch (error) {
|
|
358
|
+
// Unexpected failure (e.g. a programming error) is degraded to keep SBOM
|
|
359
|
+
// generation working, but the error is surfaced so it is not mistaken
|
|
360
|
+
// for ordinary graceful degradation.
|
|
361
|
+
console.warn(`Gradle artifact hashing failed, SBOM will be generated without hashes: ${error.stack || error.message}`);
|
|
362
|
+
return hashMap;
|
|
363
|
+
}
|
|
364
|
+
finally {
|
|
365
|
+
try {
|
|
366
|
+
fs.unlinkSync(initScriptPath);
|
|
367
|
+
}
|
|
368
|
+
catch { /* ignore */ }
|
|
369
|
+
}
|
|
370
|
+
return hashMap;
|
|
371
|
+
}
|
|
259
372
|
/**
|
|
260
373
|
* Extracts runtime and compile configurations from the dependency tree
|
|
261
374
|
* @param {string} content - the dependency tree content
|
|
@@ -303,7 +416,7 @@ export default class Java_gradle extends Base_java {
|
|
|
303
416
|
* @param properties {Object} - properties of the gradle project.
|
|
304
417
|
* @return {string} return sbom json string of the build.gradle manifest file
|
|
305
418
|
*/
|
|
306
|
-
#buildDirectDependenciesSbom(content, properties, manifestPath, opts = {}) {
|
|
419
|
+
#buildDirectDependenciesSbom(content, properties, manifestPath, opts = {}, hashMap) {
|
|
307
420
|
let sbom = new Sbom();
|
|
308
421
|
let root = `${properties.group}:${properties[ROOT_PROJECT_KEY_NAME].match(/Root project '(.+)'/)[1]}:jar:${properties.version}`;
|
|
309
422
|
let rootPurl = this.parseDep(root);
|
|
@@ -317,7 +430,7 @@ export default class Java_gradle extends Base_java {
|
|
|
317
430
|
directDependencies.forEach((scope, dep) => {
|
|
318
431
|
const purl = this.parseDep(dep);
|
|
319
432
|
purl.scope = scope;
|
|
320
|
-
sbom.addDependency(rootPurl, purl, scope);
|
|
433
|
+
sbom.addDependency(rootPurl, purl, scope, hashMap?.get(purl.toString()));
|
|
321
434
|
});
|
|
322
435
|
return sbom.filterIgnoredDepsIncludingVersion(ignoredDeps).getAsJsonString(opts);
|
|
323
436
|
}
|
|
@@ -362,7 +475,7 @@ export default class Java_gradle extends Base_java {
|
|
|
362
475
|
// Read and parse the TOML file
|
|
363
476
|
let pathOfToml = path.join(path.dirname(manifestPath), "gradle", "libs.versions.toml");
|
|
364
477
|
const tomlString = fs.readFileSync(pathOfToml).toString();
|
|
365
|
-
let tomlObject =
|
|
478
|
+
let tomlObject = parseToml(tomlString);
|
|
366
479
|
let groupPlusArtifactObject = tomlObject.libraries[alias];
|
|
367
480
|
let parts = groupPlusArtifactObject.module.split(":");
|
|
368
481
|
let groupId = parts[0];
|
|
@@ -407,3 +520,183 @@ export default class Java_gradle extends Base_java {
|
|
|
407
520
|
return undefined;
|
|
408
521
|
}
|
|
409
522
|
}
|
|
523
|
+
const DEFAULT_GRADLE_DISCOVERY_IGNORE = [
|
|
524
|
+
'**/build/**',
|
|
525
|
+
'**/.gradle/**',
|
|
526
|
+
];
|
|
527
|
+
/** Gradle init script that emits structured project listing. */
|
|
528
|
+
const GRADLE_INIT_SCRIPT = `allprojects {
|
|
529
|
+
task daListProjects {
|
|
530
|
+
doLast {
|
|
531
|
+
println "::DA_PROJECT::\${project.path}::\${project.projectDir}"
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
`;
|
|
536
|
+
/**
|
|
537
|
+
* Gradle init script that emits, per resolved module artifact, a structured line
|
|
538
|
+
* of the form `::DA_HASH::group:name:version::/absolute/file/path`. It obtains
|
|
539
|
+
* files from Gradle's resolution API (the same approach as the CycloneDX Gradle
|
|
540
|
+
* plugin) so it is robust to cache-layout changes and correctly reports
|
|
541
|
+
* classifiers and non-jar artifacts. Uses a lenient artifact view so
|
|
542
|
+
* unresolved/fileless artifacts are skipped rather than failing the build.
|
|
543
|
+
*/
|
|
544
|
+
const GRADLE_HASH_INIT_SCRIPT = `allprojects {
|
|
545
|
+
task daListHashes {
|
|
546
|
+
doLast {
|
|
547
|
+
configurations.findAll { it.canBeResolved }.each { cfg ->
|
|
548
|
+
cfg.incoming.artifactView { lenient = true }.artifacts.each { artifact ->
|
|
549
|
+
def cid = artifact.id.componentIdentifier
|
|
550
|
+
if (cid instanceof org.gradle.api.artifacts.component.ModuleComponentIdentifier) {
|
|
551
|
+
println "::DA_HASH::\${cid.group}:\${cid.module}:\${cid.version}::\${artifact.file.absolutePath}"
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
`;
|
|
559
|
+
/**
|
|
560
|
+
* Discover all build.gradle[.kts] manifest paths in a Gradle multi-project build.
|
|
561
|
+
* Uses a custom init script to get structured project listing.
|
|
562
|
+
*
|
|
563
|
+
* @param {string} workspaceRoot - Absolute or relative path to workspace root (must contain settings.gradle[.kts])
|
|
564
|
+
* @param {import('../index.js').Options} [opts={}]
|
|
565
|
+
* @returns {Promise<string[]>} Paths to build.gradle[.kts] files (absolute)
|
|
566
|
+
*/
|
|
567
|
+
export async function discoverGradleSubprojects(workspaceRoot, opts = {}) {
|
|
568
|
+
const root = path.resolve(workspaceRoot);
|
|
569
|
+
const hasSettings = fs.existsSync(path.join(root, 'settings.gradle'))
|
|
570
|
+
|| fs.existsSync(path.join(root, 'settings.gradle.kts'));
|
|
571
|
+
if (!hasSettings) {
|
|
572
|
+
return [];
|
|
573
|
+
}
|
|
574
|
+
const manifestPaths = [];
|
|
575
|
+
const rootBuildKts = path.join(root, 'build.gradle.kts');
|
|
576
|
+
const rootBuild = path.join(root, 'build.gradle');
|
|
577
|
+
const rootManifest = fs.existsSync(rootBuildKts) ? rootBuildKts : fs.existsSync(rootBuild) ? rootBuild : null;
|
|
578
|
+
if (rootManifest) {
|
|
579
|
+
manifestPaths.push(rootManifest);
|
|
580
|
+
}
|
|
581
|
+
let gradleBin;
|
|
582
|
+
try {
|
|
583
|
+
gradleBin = new Java_gradle().selectToolBinary(rootManifest || rootBuild, opts);
|
|
584
|
+
}
|
|
585
|
+
catch {
|
|
586
|
+
const ignorePatterns = [...resolveWorkspaceDiscoveryIgnore(opts), ...DEFAULT_GRADLE_DISCOVERY_IGNORE];
|
|
587
|
+
return filterManifestPathsByDiscoveryIgnore(manifestPaths, root, ignorePatterns);
|
|
588
|
+
}
|
|
589
|
+
const initScriptPath = path.join(os.tmpdir(), `da-list-projects-${crypto.randomUUID()}.gradle`);
|
|
590
|
+
try {
|
|
591
|
+
fs.writeFileSync(initScriptPath, GRADLE_INIT_SCRIPT);
|
|
592
|
+
let output;
|
|
593
|
+
try {
|
|
594
|
+
output = invokeCommand(gradleBin, [
|
|
595
|
+
'-q', '--no-daemon',
|
|
596
|
+
'--init-script', initScriptPath,
|
|
597
|
+
'daListProjects',
|
|
598
|
+
], { cwd: root });
|
|
599
|
+
}
|
|
600
|
+
catch {
|
|
601
|
+
const ignorePatterns = [...resolveWorkspaceDiscoveryIgnore(opts), ...DEFAULT_GRADLE_DISCOVERY_IGNORE];
|
|
602
|
+
return filterManifestPathsByDiscoveryIgnore(manifestPaths, root, ignorePatterns);
|
|
603
|
+
}
|
|
604
|
+
const projects = parseGradleInitScriptOutput(output.toString());
|
|
605
|
+
for (const proj of projects) {
|
|
606
|
+
if (proj.path === ':') {
|
|
607
|
+
continue;
|
|
608
|
+
}
|
|
609
|
+
const projDir = path.resolve(proj.dir);
|
|
610
|
+
const buildKts = path.join(projDir, 'build.gradle.kts');
|
|
611
|
+
const buildGroovy = path.join(projDir, 'build.gradle');
|
|
612
|
+
if (fs.existsSync(buildKts)) {
|
|
613
|
+
manifestPaths.push(buildKts);
|
|
614
|
+
}
|
|
615
|
+
else if (fs.existsSync(buildGroovy)) {
|
|
616
|
+
manifestPaths.push(buildGroovy);
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
finally {
|
|
621
|
+
try {
|
|
622
|
+
fs.unlinkSync(initScriptPath);
|
|
623
|
+
}
|
|
624
|
+
catch { /* ignore */ }
|
|
625
|
+
}
|
|
626
|
+
const ignorePatterns = [...resolveWorkspaceDiscoveryIgnore(opts), ...DEFAULT_GRADLE_DISCOVERY_IGNORE];
|
|
627
|
+
return filterManifestPathsByDiscoveryIgnore(manifestPaths, root, ignorePatterns);
|
|
628
|
+
}
|
|
629
|
+
/**
|
|
630
|
+
* Parse the structured output from the Gradle init script.
|
|
631
|
+
*
|
|
632
|
+
* @param {string} raw - Raw stdout from gradle
|
|
633
|
+
* @returns {{ path: string, dir: string }[]}
|
|
634
|
+
*/
|
|
635
|
+
export function parseGradleInitScriptOutput(raw) {
|
|
636
|
+
const projects = [];
|
|
637
|
+
for (const rawLine of raw.split('\n')) {
|
|
638
|
+
const line = rawLine.trimEnd();
|
|
639
|
+
if (!line.startsWith('::DA_PROJECT::')) {
|
|
640
|
+
continue;
|
|
641
|
+
}
|
|
642
|
+
const prefix = '::DA_PROJECT::';
|
|
643
|
+
const remainder = line.substring(prefix.length);
|
|
644
|
+
const lastSep = remainder.lastIndexOf('::');
|
|
645
|
+
if (lastSep < 0) {
|
|
646
|
+
continue;
|
|
647
|
+
}
|
|
648
|
+
const projPath = remainder.substring(0, lastSep);
|
|
649
|
+
const dir = remainder.substring(lastSep + 2);
|
|
650
|
+
if (projPath && dir) {
|
|
651
|
+
projects.push({ path: projPath, dir });
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
return projects;
|
|
655
|
+
}
|
|
656
|
+
/**
|
|
657
|
+
* Parse the structured output from the Gradle hash init script.
|
|
658
|
+
* Each recognised line has the form `::DA_HASH::group:name:version::<file-path>`.
|
|
659
|
+
*
|
|
660
|
+
* @param {string} raw - Raw stdout from gradle
|
|
661
|
+
* @returns {{ id: string, file: string }[]} component id (`group:name:version`) and absolute artifact file path
|
|
662
|
+
*/
|
|
663
|
+
export function parseGradleHashScriptOutput(raw) {
|
|
664
|
+
const artifacts = [];
|
|
665
|
+
for (const rawLine of raw.split('\n')) {
|
|
666
|
+
const line = rawLine.trimEnd();
|
|
667
|
+
if (!line.startsWith('::DA_HASH::')) {
|
|
668
|
+
continue;
|
|
669
|
+
}
|
|
670
|
+
const prefix = '::DA_HASH::';
|
|
671
|
+
const remainder = line.substring(prefix.length);
|
|
672
|
+
const lastSep = remainder.lastIndexOf('::');
|
|
673
|
+
if (lastSep < 0) {
|
|
674
|
+
continue;
|
|
675
|
+
}
|
|
676
|
+
const id = remainder.substring(0, lastSep);
|
|
677
|
+
const file = remainder.substring(lastSep + 2);
|
|
678
|
+
if (id && file) {
|
|
679
|
+
artifacts.push({ id, file });
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
return artifacts;
|
|
683
|
+
}
|
|
684
|
+
/**
|
|
685
|
+
* Parse a Gradle module component id (`group:name:version`) into its coordinate
|
|
686
|
+
* parts. The caller builds the canonical PURL key from these parts using the same
|
|
687
|
+
* builder {@link parseDep} uses, so the stored key and the lookup key cannot drift.
|
|
688
|
+
*
|
|
689
|
+
* @param {string} id - the Gradle component id
|
|
690
|
+
* @returns {{group: string, name: string, version: string}|null} the parsed coordinate, or null when the id is malformed
|
|
691
|
+
*/
|
|
692
|
+
export function parseComponentId(id) {
|
|
693
|
+
const parts = id.split(':');
|
|
694
|
+
if (parts.length < 3) {
|
|
695
|
+
return null;
|
|
696
|
+
}
|
|
697
|
+
const [group, name, version] = parts;
|
|
698
|
+
if (!group || !name || !version) {
|
|
699
|
+
return null;
|
|
700
|
+
}
|
|
701
|
+
return { group, name, version };
|
|
702
|
+
}
|
|
@@ -3,5 +3,5 @@ export default class Java_gradle_groovy extends Java_gradle {
|
|
|
3
3
|
_parseAliasForLibsNotation(alias: any): any;
|
|
4
4
|
_extractDepToBeIgnored(dep: any): any;
|
|
5
5
|
}
|
|
6
|
-
export type Provided =
|
|
6
|
+
export type Provided = any;
|
|
7
7
|
import Java_gradle from './java_gradle.js';
|
|
@@ -7,5 +7,5 @@ export default class Java_gradle_kotlin extends Java_gradle {
|
|
|
7
7
|
_parseAliasForLibsNotation(alias: any): any;
|
|
8
8
|
_extractDepToBeIgnored(dep: any): string | null;
|
|
9
9
|
}
|
|
10
|
-
export type Provided =
|
|
10
|
+
export type Provided = any;
|
|
11
11
|
import Java_gradle from './java_gradle.js';
|
|
@@ -1,8 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Discover all pom.xml manifest paths in a Maven multi-module project.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} workspaceRoot - Absolute or relative path to workspace root (must contain pom.xml)
|
|
5
|
+
* @param {object} [opts={}]
|
|
6
|
+
* @returns {Promise<string[]>} Paths to pom.xml files (absolute)
|
|
7
|
+
*/
|
|
8
|
+
export function discoverMavenModules(workspaceRoot: string, opts?: object): Promise<string[]>;
|
|
1
9
|
/** @typedef {import('../provider').Provider} */
|
|
2
10
|
/** @typedef {import('../provider').Provided} Provided */
|
|
3
11
|
/** @typedef {{name: string, version: string}} Package */
|
|
4
12
|
/** @typedef {{groupId: string, artifactId: string, version: string, scope: string, ignore: boolean}} Dependency */
|
|
5
13
|
export default class Java_maven extends Base_java {
|
|
14
|
+
/** @type {Object<string, string>} Packaging types that produce .jar files despite non-jar packaging names. */
|
|
15
|
+
static PACKAGING_TO_JAR: {
|
|
16
|
+
[x: string]: string;
|
|
17
|
+
};
|
|
6
18
|
constructor();
|
|
7
19
|
/**
|
|
8
20
|
* @param {string} manifestName - the subject manifest name-type
|
|
@@ -17,9 +29,9 @@ export default class Java_maven extends Base_java {
|
|
|
17
29
|
* Provide content and content type for maven-maven stack analysis.
|
|
18
30
|
* @param {string} manifest - the manifest path or name
|
|
19
31
|
* @param {{}} [opts={}] - optional various options to pass along the application
|
|
20
|
-
* @returns {Provided}
|
|
32
|
+
* @returns {Promise<Provided>}
|
|
21
33
|
*/
|
|
22
|
-
provideStack(manifest: string, opts?: {}): Provided
|
|
34
|
+
provideStack(manifest: string, opts?: {}): Promise<Provided>;
|
|
23
35
|
/**
|
|
24
36
|
* Provide content and content type for maven-maven component analysis.
|
|
25
37
|
* @param {string} manifest - path to the manifest file
|
|
@@ -34,17 +46,38 @@ export default class Java_maven extends Base_java {
|
|
|
34
46
|
*/
|
|
35
47
|
readLicenseFromManifest(manifestPath: string): string | null;
|
|
36
48
|
/**
|
|
49
|
+
* Build a Map of PURL string → CycloneDX hash entries by reading artifact files from the local Maven repository.
|
|
50
|
+
*
|
|
51
|
+
* Both the artifact file path and the hash-map key are derived from the
|
|
52
|
+
* shared {@link Base_java#parseCoordinate} parser: the file path uses the
|
|
53
|
+
* resolved version and raw classifier, while the key uses the same canonical
|
|
54
|
+
* PURL builder as {@link Base_java#parseDep}. This guarantees the key always
|
|
55
|
+
* matches the PURL that {@link Base_java#parseDependencyTree} looks up.
|
|
37
56
|
*
|
|
57
|
+
* @param {string} depTreeText Raw dependency tree text from mvn dependency:tree
|
|
58
|
+
* @param {{}} [opts={}] Options bag (may contain TRUSTIFY_DA_MVN_REPO)
|
|
59
|
+
* @returns {Promise<Map<string, Array<{alg: string, content: string}>>>}
|
|
60
|
+
*/
|
|
61
|
+
_buildMavenHashMap(depTreeText: string, opts?: {}): Promise<Map<string, Array<{
|
|
62
|
+
alg: string;
|
|
63
|
+
content: string;
|
|
64
|
+
}>>>;
|
|
65
|
+
/**
|
|
38
66
|
* @param {String} textGraphList Text graph String of the manifest
|
|
39
67
|
* @param {[String]} ignoredDeps List of ignored dependencies to be omitted from sbom
|
|
68
|
+
* @param {{}} opts Options
|
|
40
69
|
* @param {String} manifestPath Path to the pom.xml manifest
|
|
70
|
+
* @param {Map<string, Array<{alg: string, content: string}>>} [hashMap] PURL→hashes map
|
|
41
71
|
* @return {String} formatted sbom Json String with all dependencies
|
|
42
72
|
*/
|
|
43
|
-
createSbomFileFromTextFormat(textGraphList: string, ignoredDeps: [string], opts:
|
|
73
|
+
createSbomFileFromTextFormat(textGraphList: string, ignoredDeps: [string], opts: {}, manifestPath: string, hashMap?: Map<string, Array<{
|
|
74
|
+
alg: string;
|
|
75
|
+
content: string;
|
|
76
|
+
}>>): string;
|
|
44
77
|
#private;
|
|
45
78
|
}
|
|
46
|
-
export type Java_maven =
|
|
47
|
-
export type Provided =
|
|
79
|
+
export type Java_maven = any;
|
|
80
|
+
export type Provided = any;
|
|
48
81
|
export type Package = {
|
|
49
82
|
name: string;
|
|
50
83
|
version: string;
|