Skip to content

Commit

Permalink
Fix codacy issues Signed-off-by: Carolina Oliveira <61292734+Carolina…
Browse files Browse the repository at this point in the history
[email protected]>

Signed-off-by: Carolina Oliveira <[email protected]>
  • Loading branch information
CarolinaOliiveira committed Sep 9, 2024
1 parent 6e4e87b commit 315ba64
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,9 @@ public static void AddSpdxCreators(this Bom bom, List<string> creators)
var toolMatch = toolRegex.Match(creator);
if (toolMatch.Success)
{
if (bom.Metadata == null) bom.Metadata = new Metadata();
if (bom.Metadata == null) { bom.Metadata = new Metadata(); }
#pragma warning disable 618
if (bom.Metadata?.Tools?.Tools == null)
bom.Metadata.Tools = new ToolChoices { Tools = new List<Tool>() };
if (bom.Metadata?.Tools?.Tools == null) { bom.Metadata.Tools = new ToolChoices { Tools = new List<Tool>() }; }
bom.Metadata.Tools.Tools.Add(new Tool {
Name = toolMatch.Groups["name"].ToString(),
Version = toolMatch.Groups["version"].ToString(),
Expand All @@ -81,7 +80,7 @@ public static void AddSpdxCreators(this Bom bom, List<string> creators)
var nonToolMatch = nonToolRegex.Match(creator);
if (nonToolMatch.Success)
{
if (bom.Metadata.Authors == null) bom.Metadata.Authors = new List<OrganizationalContact>();
if (bom.Metadata.Authors == null) { bom.Metadata.Authors = new List<OrganizationalContact>(); }
bom.Metadata.Authors.Add(new OrganizationalContact
{
Name = nonToolMatch.Groups["name"].ToString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ public static List<File> GetSpdxFiles(this Bom bom)

public static void AddSpdxFiles(this Bom bom, List<File> files)
{
if (files != null && files.Count > 0)
{
if (bom.Components == null) bom.Components = new List<Component>();
if (files != null && files.Count > 0) { bom.Components = new List<Component>(); }
foreach (var file in files)
{
var component = new Component
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ public static void AddSpdxChecksums(this Component component, List<Checksum> che
{
if (checksums != null && checksums.Count > 0)
{
if (component.Properties == null) component.Properties = new List<Property>();
if (component.Hashes == null) component.Hashes = new List<Hash>();
if (component.Properties == null) { component.Properties = new List<Property>(); }
if (component.Hashes == null) {component.Hashes = new List<Hash>();}
foreach (var checksum in checksums)
{
switch (checksum.Algorithm)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,36 +40,38 @@ public static List<ExternalRef> GetSpdxExternalRefs(this Component component)
extRef.ReferenceCategory = ExternalRefCategory.OTHER;
extRef.ReferenceType = extRefProp.Name.Substring(PropertyTaxonomy.EXTERNAL_REFERENCE_OTHER.Length + 1);
}
else switch (extRefProp.Name)
{
case PropertyTaxonomy.EXTERNAL_REFERENCE_SECURITY_CPE22:
extRef.ReferenceCategory = ExternalRefCategory.SECURITY;
extRef.ReferenceType = "cpe22Type";
break;
case PropertyTaxonomy.EXTERNAL_REFERENCE_SECURITY_CPE23:
extRef.ReferenceCategory = ExternalRefCategory.SECURITY;
extRef.ReferenceType = "cpe23Type";
break;
case PropertyTaxonomy.EXTERNAL_REFERENCE_PACKAGE_MANAGER_MAVEN_CENTRAL:
extRef.ReferenceCategory = ExternalRefCategory.PACKAGE_MANAGER;
extRef.ReferenceType = "maven-central";
break;
case PropertyTaxonomy.EXTERNAL_REFERENCE_PACKAGE_MANAGER_NPM:
extRef.ReferenceCategory = ExternalRefCategory.PACKAGE_MANAGER;
extRef.ReferenceType = "npm";
break;
case PropertyTaxonomy.EXTERNAL_REFERENCE_PACKAGE_MANAGER_NUGET:
extRef.ReferenceCategory = ExternalRefCategory.PACKAGE_MANAGER;
extRef.ReferenceType = "nuget";
break;
case PropertyTaxonomy.EXTERNAL_REFERENCE_PACKAGE_MANAGER_BOWER:
extRef.ReferenceCategory = ExternalRefCategory.PACKAGE_MANAGER;
extRef.ReferenceType = "bower";
break;
case PropertyTaxonomy.EXTERNAL_REFERENCE_PACKAGE_MANAGER_PURL:
extRef.ReferenceCategory = ExternalRefCategory.PACKAGE_MANAGER;
extRef.ReferenceType = "purl";
break;
else {
switch (extRefProp.Name)
{
case PropertyTaxonomy.EXTERNAL_REFERENCE_SECURITY_CPE22:
extRef.ReferenceCategory = ExternalRefCategory.SECURITY;
extRef.ReferenceType = "cpe22Type";
break;
case PropertyTaxonomy.EXTERNAL_REFERENCE_SECURITY_CPE23:
extRef.ReferenceCategory = ExternalRefCategory.SECURITY;
extRef.ReferenceType = "cpe23Type";
break;
case PropertyTaxonomy.EXTERNAL_REFERENCE_PACKAGE_MANAGER_MAVEN_CENTRAL:
extRef.ReferenceCategory = ExternalRefCategory.PACKAGE_MANAGER;
extRef.ReferenceType = "maven-central";
break;
case PropertyTaxonomy.EXTERNAL_REFERENCE_PACKAGE_MANAGER_NPM:
extRef.ReferenceCategory = ExternalRefCategory.PACKAGE_MANAGER;
extRef.ReferenceType = "npm";
break;
case PropertyTaxonomy.EXTERNAL_REFERENCE_PACKAGE_MANAGER_NUGET:
extRef.ReferenceCategory = ExternalRefCategory.PACKAGE_MANAGER;
extRef.ReferenceType = "nuget";
break;
case PropertyTaxonomy.EXTERNAL_REFERENCE_PACKAGE_MANAGER_BOWER:
extRef.ReferenceCategory = ExternalRefCategory.PACKAGE_MANAGER;
extRef.ReferenceType = "bower";
break;
case PropertyTaxonomy.EXTERNAL_REFERENCE_PACKAGE_MANAGER_PURL:
extRef.ReferenceCategory = ExternalRefCategory.PACKAGE_MANAGER;
extRef.ReferenceType = "purl";
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:
Expand All @@ -95,7 +97,7 @@ public static void AddSpdxExternalRefs(this Component component, List<ExternalRe
{
if (externalRefs != null && externalRefs.Count > 0)
{
if (component.Properties == null) component.Properties = new List<Property>();
if (component.Properties == null) { component.Properties = new List<Property>(); }
foreach (var extRef in externalRefs)
{
string refPropName = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static class CycloneDXBomHelpers
public static void AddSpdxPackages(this Bom bom, SpdxDocument doc)
{
if (doc.Packages == null || doc.Packages.Count == 0) { return; }
if (bom.Components == null) bom.Components = new List<Component>();
if (bom.Components == null) { bom.Components = new List<Component>(); }
foreach (var package in doc.Packages)
{
var component = new Component
Expand Down Expand Up @@ -88,8 +88,8 @@ public static void AddSpdxPackages(this Bom bom, SpdxDocument doc)

if (package.LicenseInfoFromFiles != null && package.LicenseInfoFromFiles.Count > 0)
{
if (component.Evidence == null) component.Evidence = new Evidence();
if (component.Evidence.Licenses == null) component.Evidence.Licenses = new List<LicenseChoice>();
if (component.Evidence == null) { component.Evidence = new Evidence(); }
if (component.Evidence.Licenses == null) { component.Evidence.Licenses = new List<LicenseChoice>(); }
foreach (var licenseInfo in package.LicenseInfoFromFiles)
{
if (licenseInfo.StartsWith("LicenseRef-")
Expand Down Expand Up @@ -211,7 +211,7 @@ public static void AddSpdxPackages(this Bom bom, SpdxDocument doc)

if (package.DownloadLocation != null)
{
if (component.ExternalReferences == null) component.ExternalReferences = new List<ExternalReference>();
if (component.ExternalReferences == null) { component.ExternalReferences = new List<ExternalReference>(); }
component.ExternalReferences.Add(new ExternalReference
{
Type = ExternalReference.ExternalReferenceType.Distribution,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public static void AddCycloneDXComponents(this SpdxDocument doc, Bom bom)
// LicenseInfoFromFiles
if (component.Evidence?.Licenses != null && component.Evidence.Licenses.Count > 0)
{
if (package.LicenseInfoFromFiles == null) package.LicenseInfoFromFiles = new List<string>();
if (package.LicenseInfoFromFiles == null) { package.LicenseInfoFromFiles = new List<string>(); }
foreach (var license in component.Evidence.Licenses)
{
if (license.Expression != null)
Expand All @@ -128,7 +128,7 @@ public static void AddCycloneDXComponents(this SpdxDocument doc, Bom bom)
}
else
{
if (doc.HasExtractedLicensingInfos == null) doc.HasExtractedLicensingInfos = new List<ExtractedLicensingInfo>();
if (doc.HasExtractedLicensingInfos == null) { doc.HasExtractedLicensingInfos = new List<ExtractedLicensingInfo>(); }
var extLicInfo = new ExtractedLicensingInfo
{
LicenseId = $"LicenseRef-{doc.HasExtractedLicensingInfos.Count + 1}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static class SpdxDocumentConverters
{
public static SpdxDocument ToSpdx(this Bom bom)
{
var doc = new SpdxDocument()
var doc = new SpdxDocument
{
CreationInfo = new CreationInfo(),
};
Expand Down Expand Up @@ -90,7 +90,7 @@ public static SpdxDocument ToSpdx(this Bom bom)

public static Bom ToCycloneDX(this SpdxDocument doc)
{
var bom = new Bom()
var bom = new Bom
{
Metadata = new Metadata
{
Expand Down

0 comments on commit 315ba64

Please sign in to comment.