Skip to content

Commit

Permalink
Add spdx reference type PERSISTENT_ID Signed-off-by: Carolina Oliveir…
Browse files Browse the repository at this point in the history
…a <[email protected]>

Signed-off-by: Carolina Oliveira <[email protected]>
  • Loading branch information
CarolinaOliiveira committed Sep 9, 2024
1 parent 4ff6d8d commit 4075c25
Show file tree
Hide file tree
Showing 9 changed files with 228 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,14 @@ public static List<ExternalRef> GetSpdxExternalRefs(this Component component)
extRef.ReferenceCategory = ExternalRefCategory.PACKAGE_MANAGER;
extRef.ReferenceType = "purl";
break;
case PropertyTaxonomy.EXTERNAL_REFERENCE_PERSISTENT_ID_SWH:
extRef.ReferenceCategory = ExternalRefCategory.PERSISTENT_ID;
extRef.ReferenceType = "swh";
break;
default:
break;
}
//TODO add this back in once the SPDX JSON schema is fixed https://github.com/spdx/spdx-spec/issues/612
//TODO and write corresponding code in AddExternalRefsToCDX
// case PropertyTaxonomy.EXTERNAL_REFERENCE_PERSISTENT_ID_SWH:
// extRef.ReferenceCategory = ExternalRefCategory.PERSISTENT_ID;
// extRef.ReferenceType = "swh";
// break;
}
if (extRef.ReferenceType != null)
{
Expand Down Expand Up @@ -131,6 +130,7 @@ public static void AddSpdxExternalRefs(this Component component, List<ExternalRe
break;
}
}
else if (extRef.ReferenceCategory == ExternalRefCategory.PERSISTENT_ID) { refPropName = PropertyTaxonomy.EXTERNAL_REFERENCE_PERSISTENT_ID_SWH; }
else if (extRef.ReferenceCategory == ExternalRefCategory.OTHER)
{
refPropName = $"{PropertyTaxonomy.EXTERNAL_REFERENCE_OTHER}:{extRef.ReferenceType}";
Expand Down
2 changes: 2 additions & 0 deletions src/CycloneDX.Spdx/Models/v2_3/ExternalRefCategory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,7 @@ public enum ExternalRefCategory
SECURITY,
[XmlEnum("PACKAGE-MANAGER")]
PACKAGE_MANAGER,
[XmlEnum("PERSISTENT-ID")]
PERSISTENT_ID,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
},
{
"comment": "This is the external ref for Acme",
"referenceCategory": "OTHER",
"referenceCategory": "PERSISTENT_ID",
"referenceLocator": "acmecorp/acmenator/4.1.3-alpha",
"referenceType": "http://spdx.org/spdxdocs/spdx-example-444504E0-4F89-41D3-9A0C-0305E82C3301#LocationRef-acmeforge"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@
"value": "cpe:2.3:a:pivotal_software:spring_framework:4.1.0:*:*:*:*:*:*:*"
},
{
"name": "spdx:external-reference:other:http://spdx.org/spdxdocs/spdx-example-444504E0-4F89-41D3-9A0C-0305E82C3301#LocationRef-acmeforge",
"name": "spdx:external-reference:persistent-id:swh",
"value": "acmecorp/acmenator/4.1.3-alpha This is the external ref for Acme"
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@
},
{
"comment": "This is the external ref for Acme",
"referenceCategory": "OTHER",
"referenceCategory": "PERSISTENT_ID",
"referenceLocator": "acmecorp/acmenator/4.1.3-alpha",
"referenceType": "http://spdx.org/spdxdocs/spdx-example-444504E0-4F89-41D3-9A0C-0305E82C3301#LocationRef-acmeforge"
"referenceType": "swh"
}
],
"filesAnalyzed": true,
Expand Down
14 changes: 14 additions & 0 deletions tests/CycloneDX.Spdx.Tests/CycloneDX.Spdx.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

<ItemGroup>
<None Remove="Resources\v2.3\document.xml" />
<None Remove="__snapshots__\JsonSerializerTests.JsonAsyncRoundTripTest_document.snap" />
<None Remove="__snapshots__\JsonSerializerTests.JsonRoundTripTest_document.snap" />
<None Remove="__snapshots__\XmlSerializerTests.XmlRoundTripTest_document.snap" />
</ItemGroup>

Expand All @@ -44,4 +46,16 @@
<Folder Include="__snapshots__\__mismatch__\" />
</ItemGroup>

<ItemGroup>
<Content Update="__snapshots__\JsonSerializerTests.JsonAsyncRoundTripTest_document.snap">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>

<ItemGroup>
<Content Update="__snapshots__\JsonSerializerTests.JsonRoundTripTest_document.snap">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion tests/CycloneDX.Spdx.Tests/Resources/v2.3/document.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
},
{
"comment": "This is the external ref for Acme",
"referenceCategory": "OTHER",
"referenceCategory": "PERSISTENT_ID",
"referenceLocator": "acmecorp/acmenator/4.1.3-alpha",
"referenceType": "http://spdx.org/spdxdocs/spdx-example-444504E0-4F89-41D3-9A0C-0305E82C3301#LocationRef-acmeforge"
}
Expand Down
Loading

0 comments on commit 4075c25

Please sign in to comment.