Skip to content

Commit

Permalink
dotnet 9 deep improvements (#1459)
Browse files Browse the repository at this point in the history
* Adds a case where the system dependencies may not include the .dll name in the slice

Signed-off-by: Prabhu Subramanian <[email protected]>

* Capture nuget tags

Signed-off-by: Prabhu Subramanian <[email protected]>

* Bump version

Signed-off-by: Prabhu Subramanian <[email protected]>

---------

Signed-off-by: Prabhu Subramanian <[email protected]>
  • Loading branch information
prabhu authored Nov 17, 2024
1 parent a07301b commit fdaf08d
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 16 deletions.
17 changes: 12 additions & 5 deletions data/component-tags.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@
"projections",
"performance",
"plugins",
"non-block",
"microsoft"
"non-block"
]
},
"properties": {
Expand Down Expand Up @@ -231,13 +230,21 @@
},
"name": {
"sbom": [
{ "test": ["(junit|xmlunit|testng|chai|mocha|jest|test4j)"] },
{
"security": ["(boringssl|openssl|libressl|libssl|gnutls|jose|keyutils)"]
"test": [
"(junit|xmlunit|testng|chai|mocha|jest|test4j|xunit|coverlet|Test\\.Sdk)"
]
},
{
"security": [
"(boringssl|openssl|libressl|libssl|gnutls|jose|keyutils|Azure\\.Security|System\\.Security)"
]
},
{ "native": ["(ffi|native)"] },
{ "parse": ["(parser)"] },
{ "transform": ["(transformer)"] }
{ "transform": ["(transformer)"] },
{ "telemetry": ["(OpenTelemetry)"] },
{ "logging": ["(Microsoft\\.Extensions\\.Logging|Log4net)"] }
],
"obom": [
{
Expand Down
4 changes: 3 additions & 1 deletion data/frameworks-list.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"System.Web",
"System.ServiceModel",
"System.Data",
"spring",
"Microsoft.AspNetCore",
"Microsoft.NETCore",
"springframework",
"pkg:pypi/flask",
"pkg:pypi/django",
"beego",
Expand Down
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cyclonedx/cdxgen",
"version": "11.0.1",
"version": "11.0.2",
"exports": "./lib/cli/index.js",
"compilerOptions": {
"lib": ["deno.window"],
Expand Down
2 changes: 1 addition & 1 deletion jsr.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cyclonedx/cdxgen",
"version": "11.0.1",
"version": "11.0.2",
"exports": "./lib/cli/index.js",
"include": ["*.js", "lib/**", "bin/**", "data/**", "types/**"],
"exclude": [
Expand Down
8 changes: 4 additions & 4 deletions lib/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import {
CARGO_CMD,
CLJ_CMD,
DEBUG_MODE,
FETCH_LICENSE,
LEIN_CMD,
MAX_BUFFER,
PREFER_MAVEN_DEPS_TREE,
Expand Down Expand Up @@ -146,6 +145,7 @@ import {
parseYarnLock,
readZipEntry,
recomputeScope,
shouldFetchLicense,
splitOutputByGradleProjects,
} from "../helpers/utils.js";
import {
Expand Down Expand Up @@ -3163,7 +3163,7 @@ export async function createPythonBom(path, options) {
}
// Re-compute the component scope
pkgList = recomputeScope(pkgList, dependencies);
if (FETCH_LICENSE) {
if (shouldFetchLicense()) {
pkgList = await getPyMetadata(pkgList, false);
}
return buildBomNSData(options, pkgList, "pypi", {
Expand Down Expand Up @@ -4425,7 +4425,7 @@ export async function createSwiftBom(path, options) {
}
}
}
if (FETCH_LICENSE) {
if (shouldFetchLicense()) {
pkgList = await getSwiftPackageMetadata(pkgList);
}
return buildBomNSData(options, pkgList, "swift", {
Expand Down Expand Up @@ -5370,7 +5370,7 @@ export async function createCsharpBom(path, options) {
dependsOn: Array.from(parentDependsOn).sort(),
});
}
if (FETCH_LICENSE) {
if (shouldFetchLicense()) {
const retMap = await getNugetMetadata(pkgList, dependencies);
if (retMap.dependencies?.length) {
dependencies = mergeDependencies(
Expand Down
27 changes: 26 additions & 1 deletion lib/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export const PREFER_MAVEN_DEPS_TREE = !["false", "0"].includes(
process.env?.PREFER_MAVEN_DEPS_TREE,
);

function shouldFetchLicense() {
export function shouldFetchLicense() {
return (
process.env.FETCH_LICENSE &&
["true", "1"].includes(process.env.FETCH_LICENSE)
Expand Down Expand Up @@ -12429,6 +12429,15 @@ export async function getNugetMetadata(pkgList, dependencies = undefined) {
(await getRepoLicense(p.license, undefined)) || p.license;
}
}
// Capture the tags
if (
body.catalogEntry?.tags?.length &&
Array.isArray(body.catalogEntry.tags)
) {
p.tags = body.catalogEntry.tags.map((t) =>
t.toLowerCase().replaceAll(" ", "-"),
);
}
if (body.catalogEntry.projectUrl) {
p.repository = { url: body.catalogEntry.projectUrl };
p.homepage = {
Expand Down Expand Up @@ -12513,12 +12522,28 @@ export function addEvidenceForDotnet(pkgList, slicesFile) {
if (slicesData && Object.keys(slicesData)) {
if (slicesData.Dependencies) {
for (const adep of slicesData.Dependencies) {
// Case 1: Dependencies slice has the .dll file
if (adep.Module?.endsWith(".dll") && pkgFilePurlMap[adep.Module]) {
const modPurl = pkgFilePurlMap[adep.Module];
if (!purlLocationMap[modPurl]) {
purlLocationMap[modPurl] = new Set();
}
purlLocationMap[modPurl].add(`${adep.Path}#${adep.LineNumber}`);
} else if (
adep?.Name &&
(adep?.Namespace?.startsWith("System") ||
adep?.Namespace?.startsWith("Microsoft"))
) {
// Case 2: System packages where the .dll information is missing
// In this case, the dll file name is the name followed by dll.
const moduleDll = `${adep.Name}.dll`;
if (pkgFilePurlMap[moduleDll]) {
const modPurl = pkgFilePurlMap[moduleDll];
if (!purlLocationMap[modPurl]) {
purlLocationMap[modPurl] = new Set();
}
purlLocationMap[modPurl].add(`${adep.Path}#${adep.LineNumber}`);
}
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions lib/helpers/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2570,6 +2570,15 @@ test("get nget metadata", async () => {
repository: {
url: "http://www.castleproject.org/",
},
tags: [
"castle",
"dynamicproxy",
"dynamic",
"proxy",
"dynamicproxy2",
"dictionaryadapter",
"emailsender",
],
version: "4.4.0",
},
{
Expand All @@ -2585,6 +2594,7 @@ test("get nget metadata", async () => {
repository: {
url: "https://serilog.net/",
},
tags: ["serilog", "logging", "semantic", "structured"],
version: "3.0.1",
},
]);
Expand Down
8 changes: 8 additions & 0 deletions lib/stages/postgen/annotator.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,14 @@ export function extractTags(
}
bomType = bomType?.toLowerCase();
const tags = new Set();
if (component?.type !== "library") {
tags.add(component.type);
}
(component?.tags || []).forEach((tag) => {
if (tag.length) {
tags.add(tag);
}
});
const desc = component?.description?.toLowerCase();
const compProps = component.properties || [];
// Collect both the BOM specific tags and all tags
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cyclonedx/cdxgen",
"version": "11.0.1",
"version": "11.0.2",
"description": "Creates CycloneDX Software Bill of Materials (SBOM) from source or container image",
"homepage": "http://github.com/cyclonedx/cdxgen",
"author": "Prabhu Subramanian <[email protected]>",
Expand Down
1 change: 1 addition & 0 deletions types/lib/helpers/utils.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export function shouldFetchLicense(): boolean;
export function getJavaCommand(): string;
export function getPythonCommand(): string;
/**
Expand Down
2 changes: 1 addition & 1 deletion types/lib/helpers/utils.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion types/lib/stages/postgen/annotator.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fdaf08d

Please sign in to comment.