@cyclonedx/cdxgen 9.9.2 → 9.9.3

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/bin/cdxgen.js CHANGED
@@ -150,6 +150,7 @@ const args = yargs(hideBin(process.argv))
150
150
  })
151
151
  .option("install-deps", {
152
152
  type: "boolean",
153
+ hidden: true,
153
154
  default: true,
154
155
  description:
155
156
  "Install dependencies automatically for some projects. Defaults to true but disabled for containers and oci scans. Use --no-install-deps to disable this feature."
@@ -215,10 +216,15 @@ const args = yargs(hideBin(process.argv))
215
216
  "generic"
216
217
  ]
217
218
  })
219
+ .option("exclude", {
220
+ description: "Additional glob pattern(s) to ignore",
221
+ hidden: true
222
+ })
218
223
  .completion("completion", "Generate bash/zsh completion")
219
224
  .array("filter")
220
225
  .array("only")
221
226
  .array("author")
227
+ .array("exclude")
222
228
  .option("auto-compositions", {
223
229
  type: "boolean",
224
230
  default: true,
package/evinser.js CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  collectMvnDependencies
8
8
  } from "./utils.js";
9
9
  import { tmpdir } from "node:os";
10
- import path, { basename } from "node:path";
10
+ import path from "node:path";
11
11
  import fs from "node:fs";
12
12
  import * as db from "./db.js";
13
13
  import { PackageURL } from "packageurl-js";
@@ -94,15 +94,30 @@ export const catalogMavenDeps = async (
94
94
  Namespaces,
95
95
  options = {}
96
96
  ) => {
97
- console.log("About to collect jar dependencies for the path", dirPath);
98
- const mavenCmd = getMavenCommand(dirPath, dirPath);
99
- // collect all jars including from the cache if data-flow mode is enabled
100
- const jarNSMapping = collectMvnDependencies(
101
- mavenCmd,
102
- dirPath,
103
- false,
104
- options.withDeepJarCollector
105
- );
97
+ let jarNSMapping = undefined;
98
+ if (fs.existsSync(path.join(dirPath, "bom.json.map"))) {
99
+ try {
100
+ const mapData = JSON.parse(
101
+ fs.readFileSync(path.join(dirPath, "bom.json.map"))
102
+ );
103
+ if (mapData && Object.keys(mapData).length) {
104
+ jarNSMapping = mapData;
105
+ }
106
+ } catch (err) {
107
+ // ignore
108
+ }
109
+ }
110
+ if (!jarNSMapping) {
111
+ console.log("About to collect jar dependencies for the path", dirPath);
112
+ const mavenCmd = getMavenCommand(dirPath, dirPath);
113
+ // collect all jars including from the cache if data-flow mode is enabled
114
+ jarNSMapping = collectMvnDependencies(
115
+ mavenCmd,
116
+ dirPath,
117
+ false,
118
+ options.withDeepJarCollector
119
+ );
120
+ }
106
121
  if (jarNSMapping) {
107
122
  for (const purl of Object.keys(jarNSMapping)) {
108
123
  purlsJars[purl] = jarNSMapping[purl].jarFile;
@@ -317,9 +332,6 @@ export const analyzeProject = async (dbObjMap, options) => {
317
332
  if (retMap && retMap.slicesFile && fs.existsSync(retMap.slicesFile)) {
318
333
  usageSlice = JSON.parse(fs.readFileSync(retMap.slicesFile, "utf-8"));
319
334
  usagesSlicesFile = retMap.slicesFile;
320
- console.log(
321
- `To speed up this step, cache ${usagesSlicesFile} and invoke evinse with the --usages-slices-file argument.`
322
- );
323
335
  }
324
336
  }
325
337
  if (usageSlice && Object.keys(usageSlice).length) {
@@ -349,9 +361,6 @@ export const analyzeProject = async (dbObjMap, options) => {
349
361
  if (retMap && retMap.slicesFile && fs.existsSync(retMap.slicesFile)) {
350
362
  dataFlowSlicesFile = retMap.slicesFile;
351
363
  dataFlowSlice = JSON.parse(fs.readFileSync(retMap.slicesFile, "utf-8"));
352
- console.log(
353
- `To speed up this step, cache ${dataFlowSlicesFile} and invoke evinse with the --data-flow-slices-file argument.`
354
- );
355
364
  }
356
365
  }
357
366
  }
@@ -381,9 +390,6 @@ export const analyzeProject = async (dbObjMap, options) => {
381
390
  reachablesSlice = JSON.parse(
382
391
  fs.readFileSync(retMap.slicesFile, "utf-8")
383
392
  );
384
- console.log(
385
- `To speed up this step, cache ${reachablesSlicesFile} and invoke evinse with the --reachables-slices-file argument.`
386
- );
387
393
  }
388
394
  }
389
395
  }
@@ -783,7 +789,7 @@ export const detectServicesFromUDT = (
783
789
  const endpoints = extractEndpoints(language, fields[0].name);
784
790
  let serviceName = "service";
785
791
  if (audt.fileName) {
786
- serviceName = `${basename(
792
+ serviceName = `${path.basename(
787
793
  audt.fileName.replace(".py", "")
788
794
  )}-service`;
789
795
  }
package/index.js CHANGED
@@ -1063,12 +1063,14 @@ export const createJarBom = async (path, options) => {
1063
1063
  } else {
1064
1064
  jarFiles = getAllFiles(
1065
1065
  path,
1066
- (options.multiProject ? "**/" : "") + "*.[jw]ar"
1066
+ (options.multiProject ? "**/" : "") + "*.[jw]ar",
1067
+ options
1067
1068
  );
1068
1069
  // Jenkins plugins
1069
1070
  const hpiFiles = getAllFiles(
1070
1071
  path,
1071
- (options.multiProject ? "**/" : "") + "*.hpi"
1072
+ (options.multiProject ? "**/" : "") + "*.hpi",
1073
+ options
1072
1074
  );
1073
1075
  if (hpiFiles.length) {
1074
1076
  jarFiles = jarFiles.concat(hpiFiles);
@@ -1143,7 +1145,8 @@ export const createJavaBom = async (path, options) => {
1143
1145
  // maven - pom.xml
1144
1146
  const pomFiles = getAllFiles(
1145
1147
  path,
1146
- (options.multiProject ? "**/" : "") + "pom.xml"
1148
+ (options.multiProject ? "**/" : "") + "pom.xml",
1149
+ options
1147
1150
  );
1148
1151
  let bomJsonFiles = [];
1149
1152
  if (
@@ -1179,15 +1182,15 @@ export const createJavaBom = async (path, options) => {
1179
1182
  const mavenCmd = getMavenCommand(basePath, path);
1180
1183
  // Should we attempt to resolve class names
1181
1184
  if (options.resolveClass || options.deep) {
1182
- console.log(
1183
- "Creating class names list based on available jars. This might take a few mins ..."
1184
- );
1185
- jarNSMapping = collectMvnDependencies(
1185
+ const tmpjarNSMapping = collectMvnDependencies(
1186
1186
  mavenCmd,
1187
1187
  basePath,
1188
1188
  true,
1189
1189
  false
1190
1190
  );
1191
+ if (tmpjarNSMapping && Object.keys(tmpjarNSMapping).length) {
1192
+ jarNSMapping = { ...jarNSMapping, ...tmpjarNSMapping };
1193
+ }
1191
1194
  }
1192
1195
  console.log(
1193
1196
  `Executing '${mavenCmd} ${mvnArgs.join(" ")}' in`,
@@ -1202,10 +1205,10 @@ export const createJavaBom = async (path, options) => {
1202
1205
  });
1203
1206
  // Check if the cyclonedx plugin created the required bom.xml file
1204
1207
  // Sometimes the plugin fails silently for complex maven projects
1205
- bomJsonFiles = getAllFiles(path, "**/target/*.json");
1208
+ bomJsonFiles = getAllFiles(path, "**/target/*.json", options);
1206
1209
  // Check if the bom json files got created in a directory other than target
1207
1210
  if (!bomJsonFiles.length) {
1208
- bomJsonFiles = getAllFiles(path, "**/bom*.json");
1211
+ bomJsonFiles = getAllFiles(path, "**/bom*.json", options);
1209
1212
  }
1210
1213
  const bomGenerated = bomJsonFiles.length;
1211
1214
  if (!bomGenerated || result.status !== 0 || result.error) {
@@ -1296,7 +1299,7 @@ export const createJavaBom = async (path, options) => {
1296
1299
  }
1297
1300
  }
1298
1301
  } // for
1299
- const bomFiles = getAllFiles(path, "**/target/bom.xml");
1302
+ const bomFiles = getAllFiles(path, "**/target/bom.xml", options);
1300
1303
  for (const abjson of bomJsonFiles) {
1301
1304
  let bomJsonObj = undefined;
1302
1305
  try {
@@ -1359,7 +1362,8 @@ export const createJavaBom = async (path, options) => {
1359
1362
  // gradle
1360
1363
  const gradleFiles = getAllFiles(
1361
1364
  path,
1362
- (options.multiProject ? "**/" : "") + "build.gradle*"
1365
+ (options.multiProject ? "**/" : "") + "build.gradle*",
1366
+ options
1363
1367
  );
1364
1368
  const allProjects = [];
1365
1369
  const allProjectsAddedPurls = [];
@@ -1541,9 +1545,6 @@ export const createJavaBom = async (path, options) => {
1541
1545
  }
1542
1546
  // Should we attempt to resolve class names
1543
1547
  if (options.resolveClass || options.deep) {
1544
- console.log(
1545
- "Creating class names list based on available jars. This might take a few mins ..."
1546
- );
1547
1548
  jarNSMapping = collectJarNS(GRADLE_CACHE_DIR);
1548
1549
  }
1549
1550
  pkgList = await getMvnMetadata(pkgList, jarNSMapping);
@@ -1558,7 +1559,7 @@ export const createJavaBom = async (path, options) => {
1558
1559
 
1559
1560
  // Bazel
1560
1561
  // Look for the BUILD file only in the root directory
1561
- const bazelFiles = getAllFiles(path, "BUILD");
1562
+ const bazelFiles = getAllFiles(path, "BUILD", options);
1562
1563
  if (
1563
1564
  bazelFiles &&
1564
1565
  bazelFiles.length &&
@@ -1665,7 +1666,8 @@ export const createJavaBom = async (path, options) => {
1665
1666
  let sbtProjectFiles = getAllFiles(
1666
1667
  path,
1667
1668
  (options.multiProject ? "**/" : "") +
1668
- "project/{build.properties,*.sbt,*.scala}"
1669
+ "project/{build.properties,*.sbt,*.scala}",
1670
+ options
1669
1671
  );
1670
1672
 
1671
1673
  let sbtProjects = [];
@@ -1680,7 +1682,8 @@ export const createJavaBom = async (path, options) => {
1680
1682
  if (!sbtProjects.length) {
1681
1683
  sbtProjectFiles = getAllFiles(
1682
1684
  path,
1683
- (options.multiProject ? "**/" : "") + "*.sbt"
1685
+ (options.multiProject ? "**/" : "") + "*.sbt",
1686
+ options
1684
1687
  );
1685
1688
  for (const i in sbtProjectFiles) {
1686
1689
  const baseDir = dirname(sbtProjectFiles[i]);
@@ -1693,7 +1696,8 @@ export const createJavaBom = async (path, options) => {
1693
1696
  );
1694
1697
  const sbtLockFiles = getAllFiles(
1695
1698
  path,
1696
- (options.multiProject ? "**/" : "") + "build.sbt.lock"
1699
+ (options.multiProject ? "**/" : "") + "build.sbt.lock",
1700
+ options
1697
1701
  );
1698
1702
 
1699
1703
  if (sbtProjects && sbtProjects.length) {
@@ -1827,9 +1831,6 @@ export const createJavaBom = async (path, options) => {
1827
1831
  }
1828
1832
  // Should we attempt to resolve class names
1829
1833
  if (options.resolveClass || options.deep) {
1830
- console.log(
1831
- "Creating class names list based on available jars. This might take a few mins ..."
1832
- );
1833
1834
  jarNSMapping = collectJarNS(SBT_CACHE_DIR);
1834
1835
  }
1835
1836
  pkgList = await getMvnMetadata(pkgList, jarNSMapping);
@@ -1859,7 +1860,7 @@ export const createNodejsBom = async (path, options) => {
1859
1860
  let ppurl = "";
1860
1861
  // Docker mode requires special handling
1861
1862
  if (["docker", "oci", "os"].includes(options.projectType)) {
1862
- const pkgJsonFiles = getAllFiles(path, "**/package.json");
1863
+ const pkgJsonFiles = getAllFiles(path, "**/package.json", options);
1863
1864
  // Are there any package.json files in the container?
1864
1865
  if (pkgJsonFiles.length) {
1865
1866
  for (const pj of pkgJsonFiles) {
@@ -1890,30 +1891,36 @@ export const createNodejsBom = async (path, options) => {
1890
1891
  }
1891
1892
  const yarnLockFiles = getAllFiles(
1892
1893
  path,
1893
- (options.multiProject ? "**/" : "") + "yarn.lock"
1894
+ (options.multiProject ? "**/" : "") + "yarn.lock",
1895
+ options
1894
1896
  );
1895
1897
  const shrinkwrapFiles = getAllFiles(
1896
1898
  path,
1897
- (options.multiProject ? "**/" : "") + "npm-shrinkwrap.json"
1899
+ (options.multiProject ? "**/" : "") + "npm-shrinkwrap.json",
1900
+ options
1898
1901
  );
1899
1902
  let pkgLockFiles = getAllFiles(
1900
1903
  path,
1901
- (options.multiProject ? "**/" : "") + "package-lock.json"
1904
+ (options.multiProject ? "**/" : "") + "package-lock.json",
1905
+ options
1902
1906
  );
1903
1907
  if (shrinkwrapFiles.length) {
1904
1908
  pkgLockFiles = pkgLockFiles.concat(shrinkwrapFiles);
1905
1909
  }
1906
1910
  const pnpmLockFiles = getAllFiles(
1907
1911
  path,
1908
- (options.multiProject ? "**/" : "") + "pnpm-lock.yaml"
1912
+ (options.multiProject ? "**/" : "") + "pnpm-lock.yaml",
1913
+ options
1909
1914
  );
1910
1915
  const minJsFiles = getAllFiles(
1911
1916
  path,
1912
- (options.multiProject ? "**/" : "") + "*min.js"
1917
+ (options.multiProject ? "**/" : "") + "*min.js",
1918
+ options
1913
1919
  );
1914
1920
  const bowerFiles = getAllFiles(
1915
1921
  path,
1916
- (options.multiProject ? "**/" : "") + "bower.json"
1922
+ (options.multiProject ? "**/" : "") + "bower.json",
1923
+ options
1917
1924
  );
1918
1925
  // Parse min js files
1919
1926
  if (minJsFiles && minJsFiles.length) {
@@ -2179,7 +2186,8 @@ export const createNodejsBom = async (path, options) => {
2179
2186
  if (!pkgList.length && existsSync(join(path, "node_modules"))) {
2180
2187
  const pkgJsonFiles = getAllFiles(
2181
2188
  join(path, "node_modules"),
2182
- "**/package.json"
2189
+ "**/package.json",
2190
+ options
2183
2191
  );
2184
2192
  manifestFiles = manifestFiles.concat(pkgJsonFiles);
2185
2193
  for (const pkgjf of pkgJsonFiles) {
@@ -2241,37 +2249,44 @@ export const createPythonBom = async (path, options) => {
2241
2249
  const pipenvMode = existsSync(join(path, "Pipfile"));
2242
2250
  let poetryFiles = getAllFiles(
2243
2251
  path,
2244
- (options.multiProject ? "**/" : "") + "poetry.lock"
2252
+ (options.multiProject ? "**/" : "") + "poetry.lock",
2253
+ options
2245
2254
  );
2246
2255
  const pdmLockFiles = getAllFiles(
2247
2256
  path,
2248
- (options.multiProject ? "**/" : "") + "pdm.lock"
2257
+ (options.multiProject ? "**/" : "") + "pdm.lock",
2258
+ options
2249
2259
  );
2250
2260
  if (pdmLockFiles && pdmLockFiles.length) {
2251
2261
  poetryFiles = poetryFiles.concat(pdmLockFiles);
2252
2262
  }
2253
2263
  let reqFiles = getAllFiles(
2254
2264
  path,
2255
- (options.multiProject ? "**/" : "") + "*requirements*.txt"
2265
+ (options.multiProject ? "**/" : "") + "*requirements*.txt",
2266
+ options
2256
2267
  );
2257
2268
  reqFiles = reqFiles.filter(
2258
2269
  (f) => !f.includes(join("mercurial", "helptext", "internals"))
2259
2270
  );
2260
2271
  const reqDirFiles = getAllFiles(
2261
2272
  path,
2262
- (options.multiProject ? "**/" : "") + "requirements/*.txt"
2273
+ (options.multiProject ? "**/" : "") + "requirements/*.txt",
2274
+ options
2263
2275
  );
2264
2276
  const metadataFiles = getAllFiles(
2265
2277
  path,
2266
- (options.multiProject ? "**/site-packages/**/" : "") + "METADATA"
2278
+ (options.multiProject ? "**/site-packages/**/" : "") + "METADATA",
2279
+ options
2267
2280
  );
2268
2281
  const whlFiles = getAllFiles(
2269
2282
  path,
2270
- (options.multiProject ? "**/" : "") + "*.whl"
2283
+ (options.multiProject ? "**/" : "") + "*.whl",
2284
+ options
2271
2285
  );
2272
2286
  const eggInfoFiles = getAllFiles(
2273
2287
  path,
2274
- (options.multiProject ? "**/" : "") + "*.egg-info"
2288
+ (options.multiProject ? "**/" : "") + "*.egg-info",
2289
+ options
2275
2290
  );
2276
2291
  const setupPy = join(path, "setup.py");
2277
2292
  const pyProjectFile = join(path, "pyproject.toml");
@@ -2609,7 +2624,8 @@ export const createGoBom = async (path, options) => {
2609
2624
  // Read in go.sum and merge all go.sum files.
2610
2625
  const gosumFiles = getAllFiles(
2611
2626
  path,
2612
- (options.multiProject ? "**/" : "") + "go.sum"
2627
+ (options.multiProject ? "**/" : "") + "go.sum",
2628
+ options
2613
2629
  );
2614
2630
 
2615
2631
  // If USE_GOSUM is true|1, generate BOM components only using go.sum.
@@ -2723,13 +2739,15 @@ export const createGoBom = async (path, options) => {
2723
2739
  // Read in data from Gopkg.lock files if they exist
2724
2740
  const gopkgLockFiles = getAllFiles(
2725
2741
  path,
2726
- (options.multiProject ? "**/" : "") + "Gopkg.lock"
2742
+ (options.multiProject ? "**/" : "") + "Gopkg.lock",
2743
+ options
2727
2744
  );
2728
2745
 
2729
2746
  // Read in go.mod files and parse BOM components with checksums from gosumData
2730
2747
  const gomodFiles = getAllFiles(
2731
2748
  path,
2732
- (options.multiProject ? "**/" : "") + "go.mod"
2749
+ (options.multiProject ? "**/" : "") + "go.mod",
2750
+ options
2733
2751
  );
2734
2752
  if (gomodFiles.length) {
2735
2753
  let shouldManuallyParse = false;
@@ -2925,11 +2943,13 @@ export const createRustBom = async (path, options) => {
2925
2943
  }
2926
2944
  let cargoLockFiles = getAllFiles(
2927
2945
  path,
2928
- (options.multiProject ? "**/" : "") + "Cargo.lock"
2946
+ (options.multiProject ? "**/" : "") + "Cargo.lock",
2947
+ options
2929
2948
  );
2930
2949
  const cargoFiles = getAllFiles(
2931
2950
  path,
2932
- (options.multiProject ? "**/" : "") + "Cargo.toml"
2951
+ (options.multiProject ? "**/" : "") + "Cargo.toml",
2952
+ options
2933
2953
  );
2934
2954
  const cargoMode = cargoFiles.length;
2935
2955
  const cargoLockMode = cargoLockFiles.length;
@@ -2952,7 +2972,8 @@ export const createRustBom = async (path, options) => {
2952
2972
  // Get the new lock files
2953
2973
  cargoLockFiles = getAllFiles(
2954
2974
  path,
2955
- (options.multiProject ? "**/" : "") + "Cargo.lock"
2975
+ (options.multiProject ? "**/" : "") + "Cargo.lock",
2976
+ options
2956
2977
  );
2957
2978
  if (cargoLockFiles.length) {
2958
2979
  for (const f of cargoLockFiles) {
@@ -2982,11 +3003,13 @@ export const createRustBom = async (path, options) => {
2982
3003
  export const createDartBom = async (path, options) => {
2983
3004
  const pubFiles = getAllFiles(
2984
3005
  path,
2985
- (options.multiProject ? "**/" : "") + "pubspec.lock"
3006
+ (options.multiProject ? "**/" : "") + "pubspec.lock",
3007
+ options
2986
3008
  );
2987
3009
  const pubSpecYamlFiles = getAllFiles(
2988
3010
  path,
2989
- (options.multiProject ? "**/" : "") + "pubspec.yaml"
3011
+ (options.multiProject ? "**/" : "") + "pubspec.yaml",
3012
+ options
2990
3013
  );
2991
3014
  let pkgList = [];
2992
3015
  if (pubFiles.length) {
@@ -3036,26 +3059,34 @@ export const createCppBom = (path, options) => {
3036
3059
  const addedParentComponentsMap = {};
3037
3060
  const conanLockFiles = getAllFiles(
3038
3061
  path,
3039
- (options.multiProject ? "**/" : "") + "conan.lock"
3062
+ (options.multiProject ? "**/" : "") + "conan.lock",
3063
+ options
3040
3064
  );
3041
3065
  const conanFiles = getAllFiles(
3042
3066
  path,
3043
- (options.multiProject ? "**/" : "") + "conanfile.txt"
3067
+ (options.multiProject ? "**/" : "") + "conanfile.txt",
3068
+ options
3044
3069
  );
3045
3070
  let cmakeLikeFiles = [];
3046
3071
  const mesonBuildFiles = getAllFiles(
3047
3072
  path,
3048
- (options.multiProject ? "**/" : "") + "meson.build"
3073
+ (options.multiProject ? "**/" : "") + "meson.build",
3074
+ options
3049
3075
  );
3050
3076
  if (mesonBuildFiles && mesonBuildFiles.length) {
3051
3077
  cmakeLikeFiles = cmakeLikeFiles.concat(mesonBuildFiles);
3052
3078
  }
3053
3079
  cmakeLikeFiles = cmakeLikeFiles.concat(
3054
- getAllFiles(path, (options.multiProject ? "**/" : "") + "CMakeLists.txt")
3080
+ getAllFiles(
3081
+ path,
3082
+ (options.multiProject ? "**/" : "") + "CMakeLists.txt",
3083
+ options
3084
+ )
3055
3085
  );
3056
3086
  const cmakeFiles = getAllFiles(
3057
3087
  path,
3058
- (options.multiProject ? "**/" : "") + "*.cmake"
3088
+ (options.multiProject ? "**/" : "") + "*.cmake",
3089
+ options
3059
3090
  );
3060
3091
  if (cmakeFiles && cmakeFiles.length) {
3061
3092
  cmakeLikeFiles = cmakeLikeFiles.concat(cmakeFiles);
@@ -3193,11 +3224,13 @@ export const createCppBom = (path, options) => {
3193
3224
  export const createClojureBom = (path, options) => {
3194
3225
  const ednFiles = getAllFiles(
3195
3226
  path,
3196
- (options.multiProject ? "**/" : "") + "deps.edn"
3227
+ (options.multiProject ? "**/" : "") + "deps.edn",
3228
+ options
3197
3229
  );
3198
3230
  const leinFiles = getAllFiles(
3199
3231
  path,
3200
- (options.multiProject ? "**/" : "") + "project.clj"
3232
+ (options.multiProject ? "**/" : "") + "project.clj",
3233
+ options
3201
3234
  );
3202
3235
  let pkgList = [];
3203
3236
  if (leinFiles.length) {
@@ -3313,7 +3346,8 @@ export const createClojureBom = (path, options) => {
3313
3346
  export const createHaskellBom = (path, options) => {
3314
3347
  const cabalFiles = getAllFiles(
3315
3348
  path,
3316
- (options.multiProject ? "**/" : "") + "cabal.project.freeze"
3349
+ (options.multiProject ? "**/" : "") + "cabal.project.freeze",
3350
+ options
3317
3351
  );
3318
3352
  let pkgList = [];
3319
3353
  if (cabalFiles.length) {
@@ -3344,7 +3378,8 @@ export const createHaskellBom = (path, options) => {
3344
3378
  export const createElixirBom = (path, options) => {
3345
3379
  const mixFiles = getAllFiles(
3346
3380
  path,
3347
- (options.multiProject ? "**/" : "") + "mix.lock"
3381
+ (options.multiProject ? "**/" : "") + "mix.lock",
3382
+ options
3348
3383
  );
3349
3384
  let pkgList = [];
3350
3385
  if (mixFiles.length) {
@@ -3373,7 +3408,11 @@ export const createElixirBom = (path, options) => {
3373
3408
  * @param options Parse options from the cli
3374
3409
  */
3375
3410
  export const createGitHubBom = (path, options) => {
3376
- const ghactionFiles = getAllFiles(path, ".github/workflows/" + "*.yml");
3411
+ const ghactionFiles = getAllFiles(
3412
+ path,
3413
+ ".github/workflows/" + "*.yml",
3414
+ options
3415
+ );
3377
3416
  let pkgList = [];
3378
3417
  if (ghactionFiles.length) {
3379
3418
  for (const f of ghactionFiles) {
@@ -3401,7 +3440,7 @@ export const createGitHubBom = (path, options) => {
3401
3440
  * @param options Parse options from the cli
3402
3441
  */
3403
3442
  export const createCloudBuildBom = (path, options) => {
3404
- const cbFiles = getAllFiles(path, "cloudbuild.yml");
3443
+ const cbFiles = getAllFiles(path, "cloudbuild.yml", options);
3405
3444
  let pkgList = [];
3406
3445
  if (cbFiles.length) {
3407
3446
  for (const f of cbFiles) {
@@ -3492,7 +3531,8 @@ export const createJenkinsBom = async (path, options) => {
3492
3531
  let pkgList = [];
3493
3532
  const hpiFiles = getAllFiles(
3494
3533
  path,
3495
- (options.multiProject ? "**/" : "") + "*.hpi"
3534
+ (options.multiProject ? "**/" : "") + "*.hpi",
3535
+ options
3496
3536
  );
3497
3537
  const tempDir = mkdtempSync(join(tmpdir(), "hpi-deps-"));
3498
3538
  if (hpiFiles.length) {
@@ -3506,7 +3546,7 @@ export const createJenkinsBom = async (path, options) => {
3506
3546
  }
3507
3547
  }
3508
3548
  }
3509
- const jsFiles = getAllFiles(tempDir, "**/*.js");
3549
+ const jsFiles = getAllFiles(tempDir, "**/*.js", options);
3510
3550
  if (jsFiles.length) {
3511
3551
  for (const f of jsFiles) {
3512
3552
  if (DEBUG_MODE) {
@@ -3540,7 +3580,8 @@ export const createHelmBom = (path, options) => {
3540
3580
  let pkgList = [];
3541
3581
  const yamlFiles = getAllFiles(
3542
3582
  path,
3543
- (options.multiProject ? "**/" : "") + "*.yaml"
3583
+ (options.multiProject ? "**/" : "") + "*.yaml",
3584
+ options
3544
3585
  );
3545
3586
  if (yamlFiles.length) {
3546
3587
  for (const f of yamlFiles) {
@@ -3570,11 +3611,13 @@ export const createHelmBom = (path, options) => {
3570
3611
  export const createSwiftBom = (path, options) => {
3571
3612
  const swiftFiles = getAllFiles(
3572
3613
  path,
3573
- (options.multiProject ? "**/" : "") + "Package*.swift"
3614
+ (options.multiProject ? "**/" : "") + "Package*.swift",
3615
+ options
3574
3616
  );
3575
3617
  const pkgResolvedFiles = getAllFiles(
3576
3618
  path,
3577
- (options.multiProject ? "**/" : "") + "Package.resolved"
3619
+ (options.multiProject ? "**/" : "") + "Package.resolved",
3620
+ options
3578
3621
  );
3579
3622
  let pkgList = [];
3580
3623
  let dependencies = [];
@@ -3667,19 +3710,23 @@ export const createContainerSpecLikeBom = async (path, options) => {
3667
3710
  const origProjectType = options.projectType;
3668
3711
  let dcFiles = getAllFiles(
3669
3712
  path,
3670
- (options.multiProject ? "**/" : "") + "*.yml"
3713
+ (options.multiProject ? "**/" : "") + "*.yml",
3714
+ options
3671
3715
  );
3672
3716
  const yamlFiles = getAllFiles(
3673
3717
  path,
3674
- (options.multiProject ? "**/" : "") + "*.yaml"
3718
+ (options.multiProject ? "**/" : "") + "*.yaml",
3719
+ options
3675
3720
  );
3676
3721
  let oapiFiles = getAllFiles(
3677
3722
  path,
3678
- (options.multiProject ? "**/" : "") + "open*.json"
3723
+ (options.multiProject ? "**/" : "") + "open*.json",
3724
+ options
3679
3725
  );
3680
3726
  const oapiYamlFiles = getAllFiles(
3681
3727
  path,
3682
- (options.multiProject ? "**/" : "") + "open*.yaml"
3728
+ (options.multiProject ? "**/" : "") + "open*.yaml",
3729
+ options
3683
3730
  );
3684
3731
  if (oapiYamlFiles && oapiYamlFiles.length) {
3685
3732
  oapiFiles = oapiFiles.concat(oapiYamlFiles);
@@ -3688,7 +3735,7 @@ export const createContainerSpecLikeBom = async (path, options) => {
3688
3735
  dcFiles = dcFiles.concat(yamlFiles);
3689
3736
  }
3690
3737
  // Privado.ai json files
3691
- const privadoFiles = getAllFiles(path, ".privado/" + "*.json");
3738
+ const privadoFiles = getAllFiles(path, ".privado/" + "*.json", options);
3692
3739
  // parse yaml manifest files
3693
3740
  if (dcFiles.length) {
3694
3741
  for (const f of dcFiles) {
@@ -3942,11 +3989,13 @@ export const createContainerSpecLikeBom = async (path, options) => {
3942
3989
  export const createPHPBom = (path, options) => {
3943
3990
  const composerJsonFiles = getAllFiles(
3944
3991
  path,
3945
- (options.multiProject ? "**/" : "") + "composer.json"
3992
+ (options.multiProject ? "**/" : "") + "composer.json",
3993
+ options
3946
3994
  );
3947
3995
  let composerLockFiles = getAllFiles(
3948
3996
  path,
3949
- (options.multiProject ? "**/" : "") + "composer.lock"
3997
+ (options.multiProject ? "**/" : "") + "composer.lock",
3998
+ options
3950
3999
  );
3951
4000
  let pkgList = [];
3952
4001
  const composerJsonMode = composerJsonFiles.length;
@@ -4002,7 +4051,8 @@ export const createPHPBom = (path, options) => {
4002
4051
  }
4003
4052
  composerLockFiles = getAllFiles(
4004
4053
  path,
4005
- (options.multiProject ? "**/" : "") + "composer.lock"
4054
+ (options.multiProject ? "**/" : "") + "composer.lock",
4055
+ options
4006
4056
  );
4007
4057
  if (composerLockFiles.length) {
4008
4058
  for (const f of composerLockFiles) {
@@ -4031,11 +4081,13 @@ export const createPHPBom = (path, options) => {
4031
4081
  export const createRubyBom = async (path, options) => {
4032
4082
  const gemFiles = getAllFiles(
4033
4083
  path,
4034
- (options.multiProject ? "**/" : "") + "Gemfile"
4084
+ (options.multiProject ? "**/" : "") + "Gemfile",
4085
+ options
4035
4086
  );
4036
4087
  let gemLockFiles = getAllFiles(
4037
4088
  path,
4038
- (options.multiProject ? "**/" : "") + "Gemfile.lock"
4089
+ (options.multiProject ? "**/" : "") + "Gemfile.lock",
4090
+ options
4039
4091
  );
4040
4092
  let pkgList = [];
4041
4093
  const gemFileMode = gemFiles.length;
@@ -4059,7 +4111,8 @@ export const createRubyBom = async (path, options) => {
4059
4111
  }
4060
4112
  gemLockFiles = getAllFiles(
4061
4113
  path,
4062
- (options.multiProject ? "**/" : "") + "Gemfile.lock"
4114
+ (options.multiProject ? "**/" : "") + "Gemfile.lock",
4115
+ options
4063
4116
  );
4064
4117
  if (gemLockFiles.length) {
4065
4118
  for (const f of gemLockFiles) {
@@ -4096,27 +4149,33 @@ export const createCsharpBom = async (
4096
4149
  let dependencies = [];
4097
4150
  const csProjFiles = getAllFiles(
4098
4151
  path,
4099
- (options.multiProject ? "**/" : "") + "*.csproj"
4152
+ (options.multiProject ? "**/" : "") + "*.csproj",
4153
+ options
4100
4154
  );
4101
4155
  const pkgConfigFiles = getAllFiles(
4102
4156
  path,
4103
- (options.multiProject ? "**/" : "") + "packages.config"
4157
+ (options.multiProject ? "**/" : "") + "packages.config",
4158
+ options
4104
4159
  );
4105
4160
  const projAssetsFiles = getAllFiles(
4106
4161
  path,
4107
- (options.multiProject ? "**/" : "") + "project.assets.json"
4162
+ (options.multiProject ? "**/" : "") + "project.assets.json",
4163
+ options
4108
4164
  );
4109
4165
  const pkgLockFiles = getAllFiles(
4110
4166
  path,
4111
- (options.multiProject ? "**/" : "") + "packages.lock.json"
4167
+ (options.multiProject ? "**/" : "") + "packages.lock.json",
4168
+ options
4112
4169
  );
4113
4170
  const paketLockFiles = getAllFiles(
4114
4171
  path,
4115
- (options.multiProject ? "**/" : "") + "paket.lock"
4172
+ (options.multiProject ? "**/" : "") + "paket.lock",
4173
+ options
4116
4174
  );
4117
4175
  const nupkgFiles = getAllFiles(
4118
4176
  path,
4119
- (options.multiProject ? "**/" : "") + "*.nupkg"
4177
+ (options.multiProject ? "**/" : "") + "*.nupkg",
4178
+ options
4120
4179
  );
4121
4180
  let pkgList = [];
4122
4181
  if (nupkgFiles.length && projAssetsFiles.length === 0) {
@@ -4891,17 +4950,20 @@ export const createXBom = async (path, options) => {
4891
4950
  // maven - pom.xml
4892
4951
  const pomFiles = getAllFiles(
4893
4952
  path,
4894
- (options.multiProject ? "**/" : "") + "pom.xml"
4953
+ (options.multiProject ? "**/" : "") + "pom.xml",
4954
+ options
4895
4955
  );
4896
4956
  // gradle
4897
4957
  const gradleFiles = getAllFiles(
4898
4958
  path,
4899
- (options.multiProject ? "**/" : "") + "build.gradle*"
4959
+ (options.multiProject ? "**/" : "") + "build.gradle*",
4960
+ options
4900
4961
  );
4901
4962
  // scala sbt
4902
4963
  const sbtFiles = getAllFiles(
4903
4964
  path,
4904
- (options.multiProject ? "**/" : "") + "{build.sbt,Build.scala}*"
4965
+ (options.multiProject ? "**/" : "") + "{build.sbt,Build.scala}*",
4966
+ options
4905
4967
  );
4906
4968
  if (pomFiles.length || gradleFiles.length || sbtFiles.length) {
4907
4969
  return await createJavaBom(path, options);
@@ -4916,17 +4978,20 @@ export const createXBom = async (path, options) => {
4916
4978
  }
4917
4979
  const reqFiles = getAllFiles(
4918
4980
  path,
4919
- (options.multiProject ? "**/" : "") + "*requirements*.txt"
4981
+ (options.multiProject ? "**/" : "") + "*requirements*.txt",
4982
+ options
4920
4983
  );
4921
4984
  const reqDirFiles = getAllFiles(
4922
4985
  path,
4923
- (options.multiProject ? "**/" : "") + "requirements/*.txt"
4986
+ (options.multiProject ? "**/" : "") + "requirements/*.txt",
4987
+ options
4924
4988
  );
4925
4989
  const requirementsMode =
4926
4990
  (reqFiles && reqFiles.length) || (reqDirFiles && reqDirFiles.length);
4927
4991
  const whlFiles = getAllFiles(
4928
4992
  path,
4929
- (options.multiProject ? "**/" : "") + "*.whl"
4993
+ (options.multiProject ? "**/" : "") + "*.whl",
4994
+ options
4930
4995
  );
4931
4996
  if (requirementsMode || whlFiles.length) {
4932
4997
  return await createPythonBom(path, options);
@@ -4934,15 +4999,18 @@ export const createXBom = async (path, options) => {
4934
4999
  // go
4935
5000
  const gosumFiles = getAllFiles(
4936
5001
  path,
4937
- (options.multiProject ? "**/" : "") + "go.sum"
5002
+ (options.multiProject ? "**/" : "") + "go.sum",
5003
+ options
4938
5004
  );
4939
5005
  const gomodFiles = getAllFiles(
4940
5006
  path,
4941
- (options.multiProject ? "**/" : "") + "go.mod"
5007
+ (options.multiProject ? "**/" : "") + "go.mod",
5008
+ options
4942
5009
  );
4943
5010
  const gopkgLockFiles = getAllFiles(
4944
5011
  path,
4945
- (options.multiProject ? "**/" : "") + "Gopkg.lock"
5012
+ (options.multiProject ? "**/" : "") + "Gopkg.lock",
5013
+ options
4946
5014
  );
4947
5015
  if (gomodFiles.length || gosumFiles.length || gopkgLockFiles.length) {
4948
5016
  return await createGoBom(path, options);
@@ -4951,11 +5019,13 @@ export const createXBom = async (path, options) => {
4951
5019
  // rust
4952
5020
  const cargoLockFiles = getAllFiles(
4953
5021
  path,
4954
- (options.multiProject ? "**/" : "") + "Cargo.lock"
5022
+ (options.multiProject ? "**/" : "") + "Cargo.lock",
5023
+ options
4955
5024
  );
4956
5025
  const cargoFiles = getAllFiles(
4957
5026
  path,
4958
- (options.multiProject ? "**/" : "") + "Cargo.toml"
5027
+ (options.multiProject ? "**/" : "") + "Cargo.toml",
5028
+ options
4959
5029
  );
4960
5030
  if (cargoLockFiles.length || cargoFiles.length) {
4961
5031
  return await createRustBom(path, options);
@@ -4964,11 +5034,13 @@ export const createXBom = async (path, options) => {
4964
5034
  // php
4965
5035
  const composerJsonFiles = getAllFiles(
4966
5036
  path,
4967
- (options.multiProject ? "**/" : "") + "composer.json"
5037
+ (options.multiProject ? "**/" : "") + "composer.json",
5038
+ options
4968
5039
  );
4969
5040
  const composerLockFiles = getAllFiles(
4970
5041
  path,
4971
- (options.multiProject ? "**/" : "") + "composer.lock"
5042
+ (options.multiProject ? "**/" : "") + "composer.lock",
5043
+ options
4972
5044
  );
4973
5045
  if (composerJsonFiles.length || composerLockFiles.length) {
4974
5046
  return createPHPBom(path, options);
@@ -4977,11 +5049,13 @@ export const createXBom = async (path, options) => {
4977
5049
  // Ruby
4978
5050
  const gemFiles = getAllFiles(
4979
5051
  path,
4980
- (options.multiProject ? "**/" : "") + "Gemfile"
5052
+ (options.multiProject ? "**/" : "") + "Gemfile",
5053
+ options
4981
5054
  );
4982
5055
  const gemLockFiles = getAllFiles(
4983
5056
  path,
4984
- (options.multiProject ? "**/" : "") + "Gemfile.lock"
5057
+ (options.multiProject ? "**/" : "") + "Gemfile.lock",
5058
+ options
4985
5059
  );
4986
5060
  if (gemFiles.length || gemLockFiles.length) {
4987
5061
  return await createRubyBom(path, options);
@@ -4990,7 +5064,8 @@ export const createXBom = async (path, options) => {
4990
5064
  // .Net
4991
5065
  const csProjFiles = getAllFiles(
4992
5066
  path,
4993
- (options.multiProject ? "**/" : "") + "*.csproj"
5067
+ (options.multiProject ? "**/" : "") + "*.csproj",
5068
+ options
4994
5069
  );
4995
5070
  if (csProjFiles.length) {
4996
5071
  return await createCsharpBom(path, options);
@@ -4999,11 +5074,13 @@ export const createXBom = async (path, options) => {
4999
5074
  // Dart
5000
5075
  const pubFiles = getAllFiles(
5001
5076
  path,
5002
- (options.multiProject ? "**/" : "") + "pubspec.lock"
5077
+ (options.multiProject ? "**/" : "") + "pubspec.lock",
5078
+ options
5003
5079
  );
5004
5080
  const pubSpecFiles = getAllFiles(
5005
5081
  path,
5006
- (options.multiProject ? "**/" : "") + "pubspec.yaml"
5082
+ (options.multiProject ? "**/" : "") + "pubspec.yaml",
5083
+ options
5007
5084
  );
5008
5085
  if (pubFiles.length || pubSpecFiles.length) {
5009
5086
  return await createDartBom(path, options);
@@ -5012,7 +5089,8 @@ export const createXBom = async (path, options) => {
5012
5089
  // Haskell
5013
5090
  const hackageFiles = getAllFiles(
5014
5091
  path,
5015
- (options.multiProject ? "**/" : "") + "cabal.project.freeze"
5092
+ (options.multiProject ? "**/" : "") + "cabal.project.freeze",
5093
+ options
5016
5094
  );
5017
5095
  if (hackageFiles.length) {
5018
5096
  return createHaskellBom(path, options);
@@ -5021,7 +5099,8 @@ export const createXBom = async (path, options) => {
5021
5099
  // Elixir
5022
5100
  const mixFiles = getAllFiles(
5023
5101
  path,
5024
- (options.multiProject ? "**/" : "") + "mix.lock"
5102
+ (options.multiProject ? "**/" : "") + "mix.lock",
5103
+ options
5025
5104
  );
5026
5105
  if (mixFiles.length) {
5027
5106
  return createElixirBom(path, options);
@@ -5030,19 +5109,23 @@ export const createXBom = async (path, options) => {
5030
5109
  // cpp
5031
5110
  const conanLockFiles = getAllFiles(
5032
5111
  path,
5033
- (options.multiProject ? "**/" : "") + "conan.lock"
5112
+ (options.multiProject ? "**/" : "") + "conan.lock",
5113
+ options
5034
5114
  );
5035
5115
  const conanFiles = getAllFiles(
5036
5116
  path,
5037
- (options.multiProject ? "**/" : "") + "conanfile.txt"
5117
+ (options.multiProject ? "**/" : "") + "conanfile.txt",
5118
+ options
5038
5119
  );
5039
5120
  const cmakeListFiles = getAllFiles(
5040
5121
  path,
5041
- (options.multiProject ? "**/" : "") + "CMakeLists.txt"
5122
+ (options.multiProject ? "**/" : "") + "CMakeLists.txt",
5123
+ options
5042
5124
  );
5043
5125
  const mesonBuildFiles = getAllFiles(
5044
5126
  path,
5045
- (options.multiProject ? "**/" : "") + "meson.build"
5127
+ (options.multiProject ? "**/" : "") + "meson.build",
5128
+ options
5046
5129
  );
5047
5130
  if (
5048
5131
  conanLockFiles.length ||
@@ -5056,18 +5139,24 @@ export const createXBom = async (path, options) => {
5056
5139
  // clojure
5057
5140
  const ednFiles = getAllFiles(
5058
5141
  path,
5059
- (options.multiProject ? "**/" : "") + "deps.edn"
5142
+ (options.multiProject ? "**/" : "") + "deps.edn",
5143
+ options
5060
5144
  );
5061
5145
  const leinFiles = getAllFiles(
5062
5146
  path,
5063
- (options.multiProject ? "**/" : "") + "project.clj"
5147
+ (options.multiProject ? "**/" : "") + "project.clj",
5148
+ options
5064
5149
  );
5065
5150
  if (ednFiles.length || leinFiles.length) {
5066
5151
  return createClojureBom(path, options);
5067
5152
  }
5068
5153
 
5069
5154
  // GitHub actions
5070
- const ghactionFiles = getAllFiles(path, ".github/workflows/" + "*.yml");
5155
+ const ghactionFiles = getAllFiles(
5156
+ path,
5157
+ ".github/workflows/" + "*.yml",
5158
+ options
5159
+ );
5071
5160
  if (ghactionFiles.length) {
5072
5161
  return createGitHubBom(path, options);
5073
5162
  }
@@ -5075,7 +5164,8 @@ export const createXBom = async (path, options) => {
5075
5164
  // Jenkins plugins
5076
5165
  const hpiFiles = getAllFiles(
5077
5166
  path,
5078
- (options.multiProject ? "**/" : "") + "*.hpi"
5167
+ (options.multiProject ? "**/" : "") + "*.hpi",
5168
+ options
5079
5169
  );
5080
5170
  if (hpiFiles.length) {
5081
5171
  return await createJenkinsBom(path, options);
@@ -5084,11 +5174,13 @@ export const createXBom = async (path, options) => {
5084
5174
  // Helm charts
5085
5175
  const chartFiles = getAllFiles(
5086
5176
  path,
5087
- (options.multiProject ? "**/" : "") + "Chart.yaml"
5177
+ (options.multiProject ? "**/" : "") + "Chart.yaml",
5178
+ options
5088
5179
  );
5089
5180
  const yamlFiles = getAllFiles(
5090
5181
  path,
5091
- (options.multiProject ? "**/" : "") + "values.yaml"
5182
+ (options.multiProject ? "**/" : "") + "values.yaml",
5183
+ options
5092
5184
  );
5093
5185
  if (chartFiles.length || yamlFiles.length) {
5094
5186
  return createHelmBom(path, options);
@@ -5097,15 +5189,18 @@ export const createXBom = async (path, options) => {
5097
5189
  // Docker compose, kubernetes and skaffold
5098
5190
  const dcFiles = getAllFiles(
5099
5191
  path,
5100
- (options.multiProject ? "**/" : "") + "docker-compose*.yml"
5192
+ (options.multiProject ? "**/" : "") + "docker-compose*.yml",
5193
+ options
5101
5194
  );
5102
5195
  const skFiles = getAllFiles(
5103
5196
  path,
5104
- (options.multiProject ? "**/" : "") + "skaffold.yaml"
5197
+ (options.multiProject ? "**/" : "") + "skaffold.yaml",
5198
+ options
5105
5199
  );
5106
5200
  const deplFiles = getAllFiles(
5107
5201
  path,
5108
- (options.multiProject ? "**/" : "") + "deployment.yaml"
5202
+ (options.multiProject ? "**/" : "") + "deployment.yaml",
5203
+ options
5109
5204
  );
5110
5205
  if (dcFiles.length || skFiles.length || deplFiles.length) {
5111
5206
  return await createContainerSpecLikeBom(path, options);
@@ -5114,7 +5209,8 @@ export const createXBom = async (path, options) => {
5114
5209
  // Google CloudBuild
5115
5210
  const cbFiles = getAllFiles(
5116
5211
  path,
5117
- (options.multiProject ? "**/" : "") + "cloudbuild.yaml"
5212
+ (options.multiProject ? "**/" : "") + "cloudbuild.yaml",
5213
+ options
5118
5214
  );
5119
5215
  if (cbFiles.length) {
5120
5216
  return createCloudBuildBom(path, options);
@@ -5123,11 +5219,13 @@ export const createXBom = async (path, options) => {
5123
5219
  // Swift
5124
5220
  const swiftFiles = getAllFiles(
5125
5221
  path,
5126
- (options.multiProject ? "**/" : "") + "Package*.swift"
5222
+ (options.multiProject ? "**/" : "") + "Package*.swift",
5223
+ options
5127
5224
  );
5128
5225
  const pkgResolvedFiles = getAllFiles(
5129
5226
  path,
5130
- (options.multiProject ? "**/" : "") + "Package.resolved"
5227
+ (options.multiProject ? "**/" : "") + "Package.resolved",
5228
+ options
5131
5229
  );
5132
5230
  if (swiftFiles.length || pkgResolvedFiles.length) {
5133
5231
  return createSwiftBom(path, options);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cyclonedx/cdxgen",
3
- "version": "9.9.2",
3
+ "version": "9.9.3",
4
4
  "description": "Creates CycloneDX Software Bill of Materials (SBOM) from source or container image",
5
5
  "homepage": "http://github.com/cyclonedx/cdxgen",
6
6
  "author": "Prabhu Subramanian <prabhu@appthreat.com>",
@@ -57,7 +57,7 @@
57
57
  "dependencies": {
58
58
  "@babel/parser": "^7.23.0",
59
59
  "@babel/traverse": "^7.23.2",
60
- "@npmcli/arborist": "^7.2.0",
60
+ "@npmcli/arborist": "7.2.0",
61
61
  "ajv": "^8.12.0",
62
62
  "ajv-formats": "^2.1.1",
63
63
  "cheerio": "^1.0.0-rc.12",
package/utils.js CHANGED
@@ -107,6 +107,8 @@ export const MAX_BUFFER =
107
107
 
108
108
  // Metadata cache
109
109
  export let metadata_cache = {};
110
+ // Speed up lookup namespaces for a given jar
111
+ const jarNSMapping_cache = {};
110
112
 
111
113
  // Whether test scope shall be included for java/maven projects; default, if unset shall be 'true'
112
114
  export const includeMavenTestScope =
@@ -140,20 +142,34 @@ export const cdxgenAgent = got.extend({
140
142
  * @param {string} dirPath Root directory for search
141
143
  * @param {string} pattern Glob pattern (eg: *.gradle)
142
144
  */
143
- export const getAllFiles = function (dirPath, pattern) {
145
+ export const getAllFiles = function (dirPath, pattern, options = {}) {
146
+ let ignoreList = [
147
+ "**/.hg/**",
148
+ "**/.git/**",
149
+ "**/venv/**",
150
+ "**/docs/**",
151
+ "**/examples/**",
152
+ "**/site-packages/**"
153
+ ];
154
+ // Only ignore node_modules if the caller is not looking for package.json
155
+ if (!pattern.includes("package.json")) {
156
+ ignoreList.push("**/node_modules/**");
157
+ }
158
+ if (options && options.exclude && Array.isArray(options.exclude)) {
159
+ ignoreList = ignoreList.concat(options.exclude);
160
+ }
161
+ return getAllFilesWithIgnore(dirPath, pattern, ignoreList);
162
+ };
163
+
164
+ /**
165
+ * Method to get files matching a pattern
166
+ *
167
+ * @param {string} dirPath Root directory for search
168
+ * @param {string} pattern Glob pattern (eg: *.gradle)
169
+ * @param {array} ignoreList Directory patterns to ignore
170
+ */
171
+ export const getAllFilesWithIgnore = function (dirPath, pattern, ignoreList) {
144
172
  try {
145
- const ignoreList = [
146
- "**/.hg/**",
147
- "**/.git/**",
148
- "**/venv/**",
149
- "**/docs/**",
150
- "**/examples/**",
151
- "**/site-packages/**"
152
- ];
153
- // Only ignore node_modules if the caller is not looking for package.json
154
- if (!pattern.includes("package.json")) {
155
- ignoreList.push("**/node_modules/**");
156
- }
157
173
  return globSync(pattern, {
158
174
  cwd: dirPath,
159
175
  absolute: true,
@@ -6072,7 +6088,7 @@ export const collectMvnDependencies = function (
6072
6088
  const MAVEN_CACHE_DIR =
6073
6089
  process.env.MAVEN_CACHE_DIR || join(homedir(), ".m2", "repository");
6074
6090
  const tempDir = mkdtempSync(join(tmpdir(), "mvn-deps-"));
6075
- const copyArgs = [
6091
+ let copyArgs = [
6076
6092
  "dependency:copy-dependencies",
6077
6093
  `-DoutputDirectory=${tempDir}`,
6078
6094
  "-U",
@@ -6082,6 +6098,10 @@ export const collectMvnDependencies = function (
6082
6098
  "-Dmdep.prependGroupId=" + (process.env.MAVEN_PREPEND_GROUP || "false"),
6083
6099
  "-Dmdep.stripVersion=" + (process.env.MAVEN_STRIP_VERSION || "false")
6084
6100
  ];
6101
+ if (process.env.MVN_ARGS) {
6102
+ const addArgs = process.env.MVN_ARGS.split(" ");
6103
+ copyArgs = copyArgs.concat(addArgs);
6104
+ }
6085
6105
  if (basePath && basePath !== MAVEN_CACHE_DIR) {
6086
6106
  console.log(`Executing '${mavenCmd} ${copyArgs.join(" ")}' in ${basePath}`);
6087
6107
  const result = spawnSync(mavenCmd, copyArgs, {
@@ -6282,51 +6302,59 @@ export const collectJarNS = function (jarPath, pomPathMap = {}) {
6282
6302
  purl = purlObj.toString();
6283
6303
  }
6284
6304
  }
6285
- if (DEBUG_MODE) {
6286
- console.log(`Executing 'jar tf ${jf}'`);
6287
- }
6288
-
6289
- const jarResult = spawnSync("jar", ["-tf", jf], {
6290
- encoding: "utf-8",
6291
- shell: isWin,
6292
- maxBuffer: 50 * 1024 * 1024,
6293
- env
6294
- });
6295
- if (
6296
- jarResult &&
6297
- jarResult.stderr &&
6298
- jarResult.stderr.includes(
6299
- "is not recognized as an internal or external command"
6300
- )
6301
- ) {
6302
- jarCommandAvailable = false;
6303
- console.log(
6304
- "jar command is not available in PATH. Ensure JDK >= 17 is installed and set the environment variables JAVA_HOME and PATH to the bin directory inside JAVA_HOME."
6305
- );
6306
- }
6307
- const consolelines = (jarResult.stdout || "").split("\n");
6308
- const nsList = consolelines
6309
- .filter((l) => {
6310
- return (
6311
- (l.includes(".class") ||
6312
- l.includes(".java") ||
6313
- l.includes(".kt")) &&
6314
- !l.includes("-INF") &&
6315
- !l.includes("module-info")
6316
- );
6317
- })
6318
- .map((e) => {
6319
- return e
6320
- .replace("\r", "")
6321
- .replace(/.(class|java|kt)/, "")
6322
- .replace(/\/$/, "")
6323
- .replace(/\//g, ".");
6305
+ // If we have a hit from the cache, use it.
6306
+ if (purl && jarNSMapping_cache[purl]) {
6307
+ jarNSMapping[purl] = jarNSMapping_cache[purl];
6308
+ } else {
6309
+ if (DEBUG_MODE) {
6310
+ console.log(`Executing 'jar tf ${jf}'`);
6311
+ }
6312
+ const jarResult = spawnSync("jar", ["-tf", jf], {
6313
+ encoding: "utf-8",
6314
+ shell: isWin,
6315
+ maxBuffer: 50 * 1024 * 1024,
6316
+ env
6324
6317
  });
6325
- jarNSMapping[purl || jf] = {
6326
- jarFile: jf,
6327
- pom: pomData,
6328
- namespaces: nsList
6329
- };
6318
+ if (
6319
+ jarResult &&
6320
+ jarResult.stderr &&
6321
+ jarResult.stderr.includes(
6322
+ "is not recognized as an internal or external command"
6323
+ )
6324
+ ) {
6325
+ jarCommandAvailable = false;
6326
+ console.log(
6327
+ "jar command is not available in PATH. Ensure JDK >= 17 is installed and set the environment variables JAVA_HOME and PATH to the bin directory inside JAVA_HOME."
6328
+ );
6329
+ }
6330
+ const consolelines = (jarResult.stdout || "").split("\n");
6331
+ const nsList = consolelines
6332
+ .filter((l) => {
6333
+ return (
6334
+ (l.includes(".class") ||
6335
+ l.includes(".java") ||
6336
+ l.includes(".kt")) &&
6337
+ !l.includes("-INF") &&
6338
+ !l.includes("module-info")
6339
+ );
6340
+ })
6341
+ .map((e) => {
6342
+ return e
6343
+ .replace("\r", "")
6344
+ .replace(/.(class|java|kt)/, "")
6345
+ .replace(/\/$/, "")
6346
+ .replace(/\//g, ".");
6347
+ });
6348
+ jarNSMapping[purl || jf] = {
6349
+ jarFile: jf,
6350
+ pom: pomData,
6351
+ namespaces: nsList
6352
+ };
6353
+ // Retain in the global cache to speed up future lookups
6354
+ if (purl) {
6355
+ jarNSMapping_cache[purl] = jarNSMapping[purl];
6356
+ }
6357
+ }
6330
6358
  }
6331
6359
  if (!jarNSMapping) {
6332
6360
  console.log(`Unable to determine class names for the jars in ${jarPath}`);