Skip to content
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

support for dotnet based projects #1088

48 changes: 37 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4463,7 +4463,7 @@ export function createPHPBom(path, options) {
cwd: basePath,
encoding: "utf-8",
});
if (result.status !== 0 || result.error) {
if (result.status !== 0 || result.error) {
console.error("Error running composer:");
console.log(result.error, result.stderr);
options.failOnError && process.exit(1);
Expand Down Expand Up @@ -4822,6 +4822,7 @@ export async function createCsharpBom(path, options) {
}
} else if (pkgConfigFiles.length) {
manifestFiles = manifestFiles.concat(pkgConfigFiles);
const parentDependsOn = new Set();
// packages.config parsing
for (const f of pkgConfigFiles) {
if (DEBUG_MODE) {
Expand All @@ -4833,9 +4834,29 @@ export async function createCsharpBom(path, options) {
pkgData = pkgData.slice(1);
}
const dlist = parseCsPkgData(pkgData);
const deps = dlist;
if (dlist?.length) {
pkgList = pkgList.concat(dlist);
}
}
if (parentDependsOn.size) {
const depenciesSet = new Set();
const prefix = parentComponent["bom-ref"].split("/")[0];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If prefix is just pkg:nuget we can directly used that in 4723.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason this without this its not able to create the dependencies. I checked multiple times for this.

parentDependsOn.forEach((dependsOn) => {
if(dependsOn.name && dependsOn.version){
//console.log("prefix: ",prefix);
const dependcy = `${prefix}/${dependsOn.name}@${dependsOn.version}`;
depenciesSet.add(dependcy);
}
}
);

if(depenciesSet != null && depenciesSet.size > 0){
dependencies.splice(0, 0, {
ref: parentComponent["bom-ref"],
dependsOn: Array.from(depenciesSet),
});
}
}
}
if (paketLockFiles.length) {
Expand All @@ -4857,7 +4878,7 @@ export async function createCsharpBom(path, options) {
}
}
}
if (!pkgList.length && csProjFiles.length) {
if ( !pkgList.length && csProjFiles.length) {
manifestFiles = manifestFiles.concat(csProjFiles);
// .csproj parsing
for (const f of csProjFiles) {
Expand All @@ -4873,12 +4894,16 @@ export async function createCsharpBom(path, options) {
if (dlist?.length) {
pkgList = pkgList.concat(dlist);
}
if(DEBUG_MODE){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please run npm run lint which will fix the linting issues automatically. Thank you so much for your patience.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran the lint. For some reason on my machine its producing error for directory name.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you share the error?

@setchy any ideas?

Copy link
Author

@durga-pasupuleti durga-pasupuleti May 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Os error 123, the filename , directory name or volume label syntax is incorrect

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a strange error. Could you contribute a test repo to add to the repotests? I will take care of the linting errors.

console.log(`pkgList List Size :: ${pkgList.length}`);
}
}

if (pkgList.length) {
console.log(
`Found ${pkgList.length} components by parsing the ${csProjFiles.length} csproj files. The resulting SBOM will be incomplete.`,
);
options.failOnError && process.exit(1);
// console.log(
durga-pasupuleti marked this conversation as resolved.
Show resolved Hide resolved
// `Found ${pkgList.length} components by parsing the ${csProjFiles.length} csproj files. The resulting SBOM will be incomplete.`,
// );
//options.failOnError && process.exit(1);
}
}
if (pkgList.length) {
Expand All @@ -4902,7 +4927,8 @@ export async function createCsharpBom(path, options) {
}
if (FETCH_LICENSE) {
const retMap = await getNugetMetadata(pkgList, dependencies);
if (retMap.dependencies?.length) {

if (retMap.dependencies?.length > 0) {
dependencies = mergeDependencies(
dependencies,
retMap.dependencies,
Expand Down Expand Up @@ -5015,10 +5041,10 @@ export function mergeDependencies(
provides: Array.from(provides_map[akey]).sort(),
});
} else {
retlist.push({
ref: akey,
dependsOn: Array.from(deps_map[akey]).sort(),
});
retlist.push({
ref: akey,
dependsOn: Array.from(deps_map[akey]).sort(),
});
}
}
return retlist;
Expand Down
11 changes: 11 additions & 0 deletions test/sample_4x.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Reference Include="System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Memory.4.5.4\lib\net461\System.Memory.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http" />
<Reference Include="System.Net.Http.WebRequest" />
<Reference Include="System.Numerics" />
</ItemGroup>
</Project>
23 changes: 13 additions & 10 deletions utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3868,14 +3868,17 @@ test("parseCmakeLikeFile tests", () => {
});
expect(retMap.pkgList.length).toEqual(2);
});

test("parseMakeDFile tests", () => {
const pkgFilesMap = parseMakeDFile("test/data/zstd_sys-dc50c4de2e4e7df8.d");
expect(pkgFilesMap).toEqual({
zstd_sys: [
".cargo/registry/src/index.crates.io-hash/zstd-sys-2.0.10+zstd.1.5.6/src/lib.rs",
".cargo/registry/src/index.crates.io-hash/zstd-sys-2.0.10+zstd.1.5.6/src/bindings_zstd.rs",
".cargo/registry/src/index.crates.io-hash/zstd-sys-2.0.10+zstd.1.5.6/src/bindings_zdict.rs",
],
//To read the packages.configs
test("parse csproj", () => {
expect(parseCsProjData(null)).toEqual([]);
const dep_list = parseCsProjData(
readFileSync("./test/sample_4x.csproj", { encoding: "utf-8" }),
);
expect(dep_list.length).toEqual(4);

expect(dep_list[0]).toEqual({
group: "",
name: "System.Memory",
version: "4.0.1.1",
});
});
});
Loading