diff --git a/.markdownlint.json b/.markdownlint.json new file mode 100644 index 00000000..ce6da782 --- /dev/null +++ b/.markdownlint.json @@ -0,0 +1,5 @@ +{ + "MD013": { + "code_blocks": false + } +} \ No newline at end of file diff --git a/benchmark/README.md b/benchmark/README.md index 4eb8d2cd..b934fc80 100644 --- a/benchmark/README.md +++ b/benchmark/README.md @@ -2,4 +2,4 @@ Just a little project to help with benchmarking and performance tuning. -`dotnet run --configuration Release` \ No newline at end of file +`dotnet run --configuration Release` diff --git a/docs/articles/getting-started.md b/docs/articles/getting-started.md index a9c48d1e..53967a0f 100644 --- a/docs/articles/getting-started.md +++ b/docs/articles/getting-started.md @@ -141,4 +141,4 @@ using (var outputFile = File.OpenWrite("bom-1.3.json")) bom.SpecVersion = SpecificationVersion.v1_3; Json.Serializer.Serialize(bom, outputFile); } -``` \ No newline at end of file +``` diff --git a/docs/index.md b/docs/index.md index 5aa1c289..d27fbfc0 100644 --- a/docs/index.md +++ b/docs/index.md @@ -56,4 +56,4 @@ Tests are automatically run on Windows, MacOS and Linux for every pull request. And build warnings will break the build. If you are having trouble debugging a test that is failing for a platform you -don't have access to please us know. \ No newline at end of file +don't have access to please us know. diff --git a/docs/namespaces/CycloneDX.Exceptions.md b/docs/namespaces/CycloneDX.Exceptions.md index ea82c772..953c15a0 100644 --- a/docs/namespaces/CycloneDX.Exceptions.md +++ b/docs/namespaces/CycloneDX.Exceptions.md @@ -2,4 +2,4 @@ uid: CycloneDX.Exceptions summary: *content --- -Namespace containing all custom exceptions the `CycloneDX.Core` library uses. \ No newline at end of file +Namespace containing all custom exceptions the `CycloneDX.Core` library uses. diff --git a/docs/namespaces/CycloneDX.Json.Converters.md b/docs/namespaces/CycloneDX.Json.Converters.md index ca9297b2..14bb2106 100644 --- a/docs/namespaces/CycloneDX.Json.Converters.md +++ b/docs/namespaces/CycloneDX.Json.Converters.md @@ -3,4 +3,4 @@ uid: CycloneDX.Json.Converters.v1_2 summary: *content --- Namespace containing all custom JSON converters required for serialization and -deserialization. \ No newline at end of file +deserialization. diff --git a/docs/namespaces/CycloneDX.Json.md b/docs/namespaces/CycloneDX.Json.md index 99c19e7b..a173c17e 100644 --- a/docs/namespaces/CycloneDX.Json.md +++ b/docs/namespaces/CycloneDX.Json.md @@ -2,4 +2,4 @@ uid: CycloneDX.Json summary: *content --- -Namespace containing all JSON specific functionality. Including serialization, deserialization, and validation. \ No newline at end of file +Namespace containing all JSON specific functionality. Including serialization, deserialization, and validation. diff --git a/docs/namespaces/CycloneDX.Models.md b/docs/namespaces/CycloneDX.Models.md index 7035d7bc..d6ba9966 100644 --- a/docs/namespaces/CycloneDX.Models.md +++ b/docs/namespaces/CycloneDX.Models.md @@ -2,4 +2,4 @@ uid: CycloneDX.Models summary: *content --- -Namespace containing all CycloneDX data models. \ No newline at end of file +Namespace containing all CycloneDX data models. diff --git a/docs/namespaces/CycloneDX.Protobuf.md b/docs/namespaces/CycloneDX.Protobuf.md index 5711f1bd..a5f07037 100644 --- a/docs/namespaces/CycloneDX.Protobuf.md +++ b/docs/namespaces/CycloneDX.Protobuf.md @@ -2,4 +2,4 @@ uid: CycloneDX.Json summary: *content --- -Namespace containing all Protocol Buffer specific functionality. Including serialization and deserialization. \ No newline at end of file +Namespace containing all Protocol Buffer specific functionality. Including serialization and deserialization. diff --git a/docs/namespaces/CycloneDX.Utils.Exceptions.md b/docs/namespaces/CycloneDX.Utils.Exceptions.md index 3ea9fe48..b6c0aa71 100644 --- a/docs/namespaces/CycloneDX.Utils.Exceptions.md +++ b/docs/namespaces/CycloneDX.Utils.Exceptions.md @@ -2,4 +2,4 @@ uid: CycloneDX.Utils.Exceptions summary: *content --- -Namespace containing all custom exceptions the `CycloneDX.Utils` library uses. \ No newline at end of file +Namespace containing all custom exceptions the `CycloneDX.Utils` library uses. diff --git a/docs/namespaces/CycloneDX.Utils.md b/docs/namespaces/CycloneDX.Utils.md index d6058ab3..27ee7313 100644 --- a/docs/namespaces/CycloneDX.Utils.md +++ b/docs/namespaces/CycloneDX.Utils.md @@ -2,4 +2,4 @@ uid: CycloneDX.Utils summary: *content --- -Namespace containing utility methods that operate on CycloneDX BOMs. \ No newline at end of file +Namespace containing utility methods that operate on CycloneDX BOMs. diff --git a/docs/namespaces/CycloneDX.Xml.md b/docs/namespaces/CycloneDX.Xml.md index 2932d9e3..0e7761e1 100644 --- a/docs/namespaces/CycloneDX.Xml.md +++ b/docs/namespaces/CycloneDX.Xml.md @@ -2,4 +2,4 @@ uid: CycloneDX.Xml summary: *content --- -Namespace containing all XML specific functionality. Including serialization, deserialization, and validation. \ No newline at end of file +Namespace containing all XML specific functionality. Including serialization, deserialization, and validation. diff --git a/docs/namespaces/CycloneDX.md b/docs/namespaces/CycloneDX.md index 402ddb4a..db8c26e6 100644 --- a/docs/namespaces/CycloneDX.md +++ b/docs/namespaces/CycloneDX.md @@ -2,4 +2,4 @@ uid: CycloneDX summary: *content --- -The base CycloneDX namespace. \ No newline at end of file +The base CycloneDX namespace. diff --git a/src/CycloneDX.Core/BomUtils.cs b/src/CycloneDX.Core/BomUtils.cs index 499c440d..d0a5b7a0 100644 --- a/src/CycloneDX.Core/BomUtils.cs +++ b/src/CycloneDX.Core/BomUtils.cs @@ -156,7 +156,10 @@ internal static Bom CopyBomAndDowngrade(Bom bom) bomCopy.Properties = null; bomCopy.Formulation = null; - if (bomCopy.Metadata != null) bomCopy.Metadata.Lifecycles = null; + if (bomCopy.Metadata != null) + { + bomCopy.Metadata.Lifecycles = null; + } if (bomCopy.Compositions != null) { @@ -177,7 +180,10 @@ internal static Bom CopyBomAndDowngrade(Bom bom) { component.ModelCard = null; component.Data = null; - if ((int)component.Type > 8) component.Type = Component.Classification.Library; + if ((int)component.Type > 8) + { + component.Type = Component.Classification.Library; + } }); EnumerateAllServices(bomCopy, (service) => @@ -425,7 +431,10 @@ public static void EnumerateAllEvidence(Bom bom, Action callback) { EnumerateAllComponents(bom, (component) => { - if (component.Evidence != null) callback(component.Evidence); + if (component.Evidence != null) + { + callback(component.Evidence); + } }); } @@ -433,7 +442,10 @@ public static void EnumerateAllLicenses(Bom bom, Action callback) { EnumerateAllLicenseChoices(bom, (licenseChoice) => { - if (licenseChoice.License != null) callback(licenseChoice.License); + if (licenseChoice.License != null) + { + callback(licenseChoice.License); + } }); } @@ -496,7 +508,9 @@ public static void EnumerateAllOrganizationalEntity(Bom bom, Action { - if (component.Supplier != null) callback(component.Supplier); + if (component.Supplier != null) + { + callback(component.Supplier); + } component.ModelCard?.Considerations?.EnvironmentalConsiderations?.EnergyConsumptions? @@ -529,7 +546,10 @@ public static void EnumerateAllOrganizationalEntity(Bom bom, Action { - if (service.Provider != null) callback(service.Provider); + if (service.Provider != null) + { + callback(service.Provider); + } }); } @@ -577,7 +597,9 @@ public static void EnumerateAllToolChoices(Bom bom, Action callback EnumerateAllVulnerabilities(bom, (vuln) => { if (vuln.Tools != null) + { callback(vuln.Tools); + } }); } diff --git a/src/CycloneDX.Core/Models/Annotation.cs b/src/CycloneDX.Core/Models/Annotation.cs index bf10b666..3a09b6a0 100644 --- a/src/CycloneDX.Core/Models/Annotation.cs +++ b/src/CycloneDX.Core/Models/Annotation.cs @@ -47,7 +47,10 @@ public List Subjects { if (XmlSubjects == null) return null; var result = new List(); - foreach (var subject in XmlSubjects) result.Add(subject.Ref); + foreach (var subject in XmlSubjects) + { + result.Add(subject.Ref); + } return result; } set @@ -59,7 +62,10 @@ public List Subjects else { XmlSubjects = new List(); - foreach (var subject in value) XmlSubjects.Add(new XmlAnnotationSubject() { Ref = subject}); + foreach (var subject in value) + { + XmlSubjects.Add(new XmlAnnotationSubject { Ref = subject }); + } } } } diff --git a/src/CycloneDX.Core/Models/Service.cs b/src/CycloneDX.Core/Models/Service.cs index 1248bd65..3f6b7209 100644 --- a/src/CycloneDX.Core/Models/Service.cs +++ b/src/CycloneDX.Core/Models/Service.cs @@ -120,10 +120,10 @@ public ServiceDataChoices XmlData { get { - if (Data == null) return null; + if (Data == null) { return null; } if (SpecVersion < SpecificationVersion.v1_5) { - var result = new ServiceDataChoices() + var result = new ServiceDataChoices { SpecVersion = SpecVersion, DataClassifications = new List() diff --git a/src/CycloneDX.Core/Models/ServiceDataChoices.cs b/src/CycloneDX.Core/Models/ServiceDataChoices.cs index 51a64076..295a34ec 100644 --- a/src/CycloneDX.Core/Models/ServiceDataChoices.cs +++ b/src/CycloneDX.Core/Models/ServiceDataChoices.cs @@ -50,14 +50,14 @@ public void ReadXml(XmlReader reader) { if (reader.LocalName == "classification") { - if (this.DataClassifications == null) this.DataClassifications = new List(); + if (this.DataClassifications == null) { this.DataClassifications = new List(); } var serializer = Xml.Serializer.GetElementSerializer(SpecVersion, "classification"); var dataClassification = (DataClassification)serializer.Deserialize(reader); this.DataClassifications.Add(dataClassification); } if (reader.LocalName == "dataflow") { - if (this.DataFlows == null) this.DataFlows = new List(); + if (this.DataFlows == null) { this.DataFlows = new List(); } var serializer = Xml.Serializer.GetElementSerializer(SpecVersion, "dataflow"); var dataflow = (DataFlow)serializer.Deserialize(reader); this.DataFlows.Add(dataflow); @@ -72,14 +72,18 @@ public void WriteXml(System.Xml.XmlWriter writer) { var serializer = Xml.Serializer.GetElementSerializer(SpecVersion, "classification"); foreach (var dc in this.DataClassifications) + { serializer.Serialize(writer, dc); + } } if (this.DataFlows != null) { var serializer = Xml.Serializer.GetElementSerializer(SpecVersion, "dataflow"); foreach (var df in this.DataFlows) + { serializer.Serialize(writer, df); + } } } diff --git a/src/CycloneDX.Core/Models/ToolChoices.cs b/src/CycloneDX.Core/Models/ToolChoices.cs index 567f7969..053c1fb9 100644 --- a/src/CycloneDX.Core/Models/ToolChoices.cs +++ b/src/CycloneDX.Core/Models/ToolChoices.cs @@ -61,7 +61,10 @@ public void ReadXml(XmlReader reader) if (reader.LocalName == "tool") { #pragma warning disable 618 - if (this.Tools == null) this.Tools = new List(); + if (this.Tools == null) + { + this.Tools = new List(); + } var serializer = Xml.Serializer.GetElementSerializer(SpecVersion, "tool"); var tool = (Tool)serializer.Deserialize(reader); #pragma warning restore 618 @@ -69,7 +72,10 @@ public void ReadXml(XmlReader reader) } if (reader.LocalName == "components") { - if (this.Components == null) this.Components = new List(); + if (this.Components == null) + { + this.Components = new List(); + } var serializer = Xml.Serializer.GetElementSerializer(SpecVersion, "component"); reader.ReadStartElement(); while (reader.LocalName == "component") @@ -81,7 +87,10 @@ public void ReadXml(XmlReader reader) } if (reader.LocalName == "services") { - if (this.Services == null) this.Services = new List(); + if (this.Services == null) + { + this.Services = new List(); + } var serializer = Xml.Serializer.GetElementSerializer(SpecVersion, "service"); reader.ReadStartElement(); while (reader.LocalName == "service") @@ -102,7 +111,9 @@ public void WriteXml(System.Xml.XmlWriter writer) { var serializer = Xml.Serializer.GetElementSerializer(SpecVersion, "tool"); #pragma warning restore 618 foreach (var tool in this.Tools) + { serializer.Serialize(writer, tool); + } } if (this.Components != null) @@ -110,7 +121,9 @@ public void WriteXml(System.Xml.XmlWriter writer) { writer.WriteStartElement("components"); var serializer = Xml.Serializer.GetElementSerializer(SpecVersion, "component"); foreach (var component in this.Components) + { serializer.Serialize(writer, component); + } writer.WriteEndElement(); } @@ -119,7 +132,9 @@ public void WriteXml(System.Xml.XmlWriter writer) { writer.WriteStartElement("services"); var serializer = Xml.Serializer.GetElementSerializer(SpecVersion, "service"); foreach (var service in this.Services) + { serializer.Serialize(writer, service); + } writer.WriteEndElement(); } } diff --git a/src/CycloneDX.Core/Protobuf/Serializer.Deserialization.cs b/src/CycloneDX.Core/Protobuf/Serializer.Deserialization.cs index 6d469481..2465ce0f 100644 --- a/src/CycloneDX.Core/Protobuf/Serializer.Deserialization.cs +++ b/src/CycloneDX.Core/Protobuf/Serializer.Deserialization.cs @@ -40,9 +40,9 @@ public static Bom Deserialize(Stream protobufStream) { bom.Metadata.Timestamp = DateTime.SpecifyKind(bom.Metadata.Timestamp.Value, DateTimeKind.Utc); } - + CleanupEmptyArrays(bom); - + return bom; } @@ -59,7 +59,7 @@ public static Bom Deserialize(byte[] bytes) var bom = Deserialize(ms); return bom; } - + private static void CleanupEmptyArrays(Bom bom) { if (bom.Metadata?.Authors?.Count == 0) @@ -115,7 +115,7 @@ private static void CleanupEmptyArrays(Bom bom) bom.Dependencies = null; } } - + private static void CleanupEmptyArrays(Component component) { if (component.Hashes?.Count == 0) @@ -166,23 +166,35 @@ private static void CleanupEmptyArrays(Service service) private static void CleanupEmptyArrays(Pedigree pedigree) { - if (pedigree.Commits?.Count == 0) pedigree.Commits = null; - if (pedigree.Patches?.Count == 0) pedigree.Patches = null; + if (pedigree.Commits?.Count == 0) { pedigree.Commits = null; } + if (pedigree.Patches?.Count == 0) { pedigree.Patches = null; } - if (pedigree.Ancestors?.Count == 0) pedigree.Ancestors = null; + if (pedigree.Ancestors?.Count == 0) { pedigree.Ancestors = null; } if (pedigree.Ancestors != null) - foreach (var component in pedigree.Ancestors) - CleanupEmptyArrays(component); + { + foreach (var component in pedigree.Ancestors) + { + CleanupEmptyArrays(component); + } + } - if (pedigree.Descendants?.Count == 0) pedigree.Descendants = null; + if (pedigree.Descendants?.Count == 0) { pedigree.Descendants = null; } if (pedigree.Descendants != null) - foreach (var component in pedigree.Descendants) - CleanupEmptyArrays(component); + { + foreach (var component in pedigree.Descendants) + { + CleanupEmptyArrays(component); + } + } - if (pedigree.Variants?.Count == 0) pedigree.Variants = null; + if (pedigree.Variants?.Count == 0) { pedigree.Variants = null; } if (pedigree.Variants != null) - foreach (var component in pedigree.Variants) - CleanupEmptyArrays(component); + { + foreach (var component in pedigree.Variants) + { + CleanupEmptyArrays(component); + } + } } } } diff --git a/src/CycloneDX.Core/Xml/OverrideXml.cs b/src/CycloneDX.Core/Xml/OverrideXml.cs index dfc371f3..6f5f6c4f 100644 --- a/src/CycloneDX.Core/Xml/OverrideXml.cs +++ b/src/CycloneDX.Core/Xml/OverrideXml.cs @@ -49,7 +49,10 @@ public OverrideXml Override() public OverrideXml Member(string name) { Commit(); - if (_currentType == null) throw new InvalidOperationException("Current type is not defined. Use Override() to define current type"); + if (_currentType == null) + { + throw new InvalidOperationException("Current type is not defined. Use Override() to define current type"); + } // attempt to verify that such member indeed exists const BindingFlags flags = BindingFlags.Instance | BindingFlags.Public; @@ -330,7 +333,10 @@ public OverrideXml Attr(XmlTypeAttribute attribute) private void Open() { - if (_attributes == null) _attributes = new XmlAttributes(); + if (_attributes == null) + { + _attributes = new XmlAttributes(); + } } } } diff --git a/src/CycloneDX.Core/Xml/Serializer.Deserialization.cs b/src/CycloneDX.Core/Xml/Serializer.Deserialization.cs index ec911c2f..193e0194 100644 --- a/src/CycloneDX.Core/Xml/Serializer.Deserialization.cs +++ b/src/CycloneDX.Core/Xml/Serializer.Deserialization.cs @@ -105,83 +105,122 @@ private static Bom Deserialize(MemoryStream xmlStream) private static void CleanupEmptyXmlArrays(Bom bom) { - if (bom.Metadata?.Authors?.Count == 0) bom.Metadata.Authors = null; - if (bom.Metadata?.Properties?.Count == 0) bom.Metadata.Properties = null; - if (bom.Components?.Count == 0) bom.Components = null; - if (bom.Services?.Count == 0) bom.Services = null; - if (bom.ExternalReferences?.Count == 0) bom.ExternalReferences = null; - if (bom.Dependencies?.Count == 0) bom.Dependencies = null; - if (bom.Compositions?.Count == 0) bom.Compositions = null; + if (bom.Metadata?.Authors?.Count == 0) { bom.Metadata.Authors = null; } + if (bom.Metadata?.Properties?.Count == 0) { bom.Metadata.Properties = null; } + if (bom.Components?.Count == 0) { bom.Components = null; } + if (bom.Services?.Count == 0) { bom.Services = null; } + if (bom.ExternalReferences?.Count == 0) { bom.ExternalReferences = null; } + if (bom.Dependencies?.Count == 0) { bom.Dependencies = null; } + if (bom.Compositions?.Count == 0) { bom.Compositions = null; } if (bom.Metadata?.Component != null) + { CleanupEmptyXmlArrays(bom.Metadata.Component); + } if (bom.Components != null) - foreach (var component in bom.Components) - CleanupEmptyXmlArrays(component); - + { + foreach (var component in bom.Components) + { + CleanupEmptyXmlArrays(component); + } + } + if (bom.Services != null) - foreach (var service in bom.Services) - CleanupEmptyXmlArrays(service); + { + foreach (var service in bom.Services) + { + CleanupEmptyXmlArrays(service); + } + } if (bom.Dependencies != null) - foreach (var dependency in bom.Dependencies) - if (dependency.Dependencies?.Count == 0) dependency.Dependencies = null; - + { + foreach (var dependency in bom.Dependencies) + { + if (dependency.Dependencies?.Count == 0) { dependency.Dependencies = null; } + } + } + if (bom.Compositions != null) + { foreach (var composition in bom.Compositions) { - if (composition.Assemblies?.Count == 0) composition.Assemblies = null; - if (composition.Dependencies?.Count == 0) composition.Dependencies = null; + if (composition.Assemblies?.Count == 0) { composition.Assemblies = null; } + if (composition.Dependencies?.Count == 0) { composition.Dependencies = null; } } + } } private static void CleanupEmptyXmlArrays(Component component) { - if (component.Hashes?.Count == 0) component.Hashes = null; - if (component.ExternalReferences?.Count == 0) component.ExternalReferences = null; - if (component.Components?.Count == 0) component.Components = null; - if (component.Properties?.Count == 0) component.Properties = null; - if (component.Evidence?.Copyright?.Count == 0) component.Evidence.Copyright = null; - if (component.Evidence?.Licenses?.Count == 0) component.Evidence.Licenses = null; + if (component.Hashes?.Count == 0) { component.Hashes = null; } + if (component.ExternalReferences?.Count == 0) { component.ExternalReferences = null; } + if (component.Components?.Count == 0) { component.Components = null; } + if (component.Properties?.Count == 0) { component.Properties = null; } + if (component.Evidence?.Copyright?.Count == 0) { component.Evidence.Copyright = null; } + if (component.Evidence?.Licenses?.Count == 0) { component.Evidence.Licenses = null; } if (component.Components != null) + { foreach (var subComponent in component.Components) + { CleanupEmptyXmlArrays(subComponent); - - if (component.Pedigree != null) CleanupEmptyXmlArrays(component.Pedigree); + } + } + + if (component.Pedigree != null) + { + CleanupEmptyXmlArrays(component.Pedigree); + } } private static void CleanupEmptyXmlArrays(Service service) { - if (service.Data?.Count == 0) service.Data = null; - if (service.ExternalReferences?.Count == 0) service.ExternalReferences = null; - if (service.Properties?.Count == 0) service.Properties = null; - if (service.Services?.Count == 0) service.Services = null; - + if (service.Data?.Count == 0) { service.Data = null; } + if (service.ExternalReferences?.Count == 0) { service.ExternalReferences = null; } + if (service.Properties?.Count == 0) { service.Properties = null; } + if (service.Services?.Count == 0) { service.Services = null; } + if (service.Services != null) + { foreach (var subComponent in service.Services) + { CleanupEmptyXmlArrays(subComponent); + } + } } private static void CleanupEmptyXmlArrays(Pedigree pedigree) { - if (pedigree.Commits?.Count == 0) pedigree.Commits = null; - if (pedigree.Patches?.Count == 0) pedigree.Patches = null; + if (pedigree.Commits?.Count == 0) { pedigree.Commits = null; } + if (pedigree.Patches?.Count == 0) { pedigree.Patches = null; } - if (pedigree.Ancestors?.Count == 0) pedigree.Ancestors = null; + if (pedigree.Ancestors?.Count == 0) { pedigree.Ancestors = null; } if (pedigree.Ancestors != null) - foreach (var component in pedigree.Ancestors) - CleanupEmptyXmlArrays(component); + { + foreach (var component in pedigree.Ancestors) + { + CleanupEmptyXmlArrays(component); + } + } - if (pedigree.Descendants?.Count == 0) pedigree.Descendants = null; + if (pedigree.Descendants?.Count == 0) { pedigree.Descendants = null; } if (pedigree.Descendants != null) - foreach (var component in pedigree.Descendants) - CleanupEmptyXmlArrays(component); + { + foreach (var component in pedigree.Descendants) + { + CleanupEmptyXmlArrays(component); + } + } - if (pedigree.Variants?.Count == 0) pedigree.Variants = null; + if (pedigree.Variants?.Count == 0) { pedigree.Variants = null; } if (pedigree.Variants != null) - foreach (var component in pedigree.Variants) - CleanupEmptyXmlArrays(component); + { + foreach (var component in pedigree.Variants) + { + CleanupEmptyXmlArrays(component); + } + } } } } diff --git a/src/CycloneDX.Core/Xml/Serializer.Serialization.cs b/src/CycloneDX.Core/Xml/Serializer.Serialization.cs index d59f360e..f7203e81 100644 --- a/src/CycloneDX.Core/Xml/Serializer.Serialization.cs +++ b/src/CycloneDX.Core/Xml/Serializer.Serialization.cs @@ -138,7 +138,9 @@ public static string Serialize(Bom bom) internal static XmlSerializer GetElementSerializer(SpecificationVersion specVersion, string elementName) { if (!_elementSerializers.ContainsKey(specVersion)) + { _elementSerializers[specVersion] = new Dictionary(); + } var serKey = $"{typeof(T).FullName}:{elementName}"; if (!_elementSerializers[specVersion].ContainsKey(serKey)) { diff --git a/src/CycloneDX.Spdx.Interop/Converters/v2_2/Helpers/Bom/Creators.cs b/src/CycloneDX.Spdx.Interop/Converters/v2_2/Helpers/Bom/Creators.cs index 7882b4bf..61f024ac 100644 --- a/src/CycloneDX.Spdx.Interop/Converters/v2_2/Helpers/Bom/Creators.cs +++ b/src/CycloneDX.Spdx.Interop/Converters/v2_2/Helpers/Bom/Creators.cs @@ -66,10 +66,12 @@ public static void AddSpdxCreators(this Bom bom, List 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() }; + } bom.Metadata.Tools.Tools.Add(new Tool { Name = toolMatch.Groups["name"].ToString(), Version = toolMatch.Groups["version"].ToString(), @@ -81,7 +83,7 @@ public static void AddSpdxCreators(this Bom bom, List creators) var nonToolMatch = nonToolRegex.Match(creator); if (nonToolMatch.Success) { - if (bom.Metadata.Authors == null) bom.Metadata.Authors = new List(); + if (bom.Metadata.Authors == null) { bom.Metadata.Authors = new List(); } bom.Metadata.Authors.Add(new OrganizationalContact { Name = nonToolMatch.Groups["name"].ToString(), diff --git a/src/CycloneDX.Spdx.Interop/Converters/v2_2/Helpers/Component/Checksums.cs b/src/CycloneDX.Spdx.Interop/Converters/v2_2/Helpers/Component/Checksums.cs index eb3e09c1..0b56d342 100644 --- a/src/CycloneDX.Spdx.Interop/Converters/v2_2/Helpers/Component/Checksums.cs +++ b/src/CycloneDX.Spdx.Interop/Converters/v2_2/Helpers/Component/Checksums.cs @@ -119,8 +119,8 @@ public static void AddSpdxChecksums(this Component component, List che { if (checksums != null && checksums.Count > 0) { - if (component.Properties == null) component.Properties = new List(); - if (component.Hashes == null) component.Hashes = new List(); + if (component.Properties == null) { component.Properties = new List(); } + if (component.Hashes == null) { component.Hashes = new List(); } foreach (var checksum in checksums) { switch (checksum.Algorithm) diff --git a/src/CycloneDX.Spdx.Interop/Converters/v2_2/Helpers/Component/ExternalRefs.cs b/src/CycloneDX.Spdx.Interop/Converters/v2_2/Helpers/Component/ExternalRefs.cs index 69f9099d..d3c23d8b 100644 --- a/src/CycloneDX.Spdx.Interop/Converters/v2_2/Helpers/Component/ExternalRefs.cs +++ b/src/CycloneDX.Spdx.Interop/Converters/v2_2/Helpers/Component/ExternalRefs.cs @@ -95,7 +95,7 @@ public static void AddSpdxExternalRefs(this Component component, List 0) { - if (component.Properties == null) component.Properties = new List(); + if (component.Properties == null) { component.Properties = new List(); } foreach (var extRef in externalRefs) { string refPropName = null; diff --git a/src/CycloneDX.Spdx.Interop/Converters/v2_2/Helpers/CycloneDXBomHelpers.cs b/src/CycloneDX.Spdx.Interop/Converters/v2_2/Helpers/CycloneDXBomHelpers.cs index 6ae485ba..3d244864 100644 --- a/src/CycloneDX.Spdx.Interop/Converters/v2_2/Helpers/CycloneDXBomHelpers.cs +++ b/src/CycloneDX.Spdx.Interop/Converters/v2_2/Helpers/CycloneDXBomHelpers.cs @@ -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(); + if (bom.Components == null) { bom.Components = new List(); } foreach (var package in doc.Packages) { var component = new Component @@ -55,8 +55,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(); + if (component.Evidence == null) { component.Evidence = new Evidence(); } + if (component.Evidence.Licenses == null) { component.Evidence.Licenses = new List(); } foreach (var licenseInfo in package.LicenseInfoFromFiles) { if (licenseInfo.StartsWith("LicenseRef-") diff --git a/src/CycloneDX.Spdx.Interop/Converters/v2_2/Helpers/SpdxDocumentHelpers.cs b/src/CycloneDX.Spdx.Interop/Converters/v2_2/Helpers/SpdxDocumentHelpers.cs index 682a3503..1acaed83 100644 --- a/src/CycloneDX.Spdx.Interop/Converters/v2_2/Helpers/SpdxDocumentHelpers.cs +++ b/src/CycloneDX.Spdx.Interop/Converters/v2_2/Helpers/SpdxDocumentHelpers.cs @@ -81,7 +81,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(); + if (package.LicenseInfoFromFiles == null) { package.LicenseInfoFromFiles = new List(); } foreach (var license in component.Evidence.Licenses) { if (license.Expression != null) diff --git a/src/CycloneDX.Spdx.Interop/Converters/v2_2/SpdxDocumentConverters.cs b/src/CycloneDX.Spdx.Interop/Converters/v2_2/SpdxDocumentConverters.cs index 45089e0d..84c7b8d4 100644 --- a/src/CycloneDX.Spdx.Interop/Converters/v2_2/SpdxDocumentConverters.cs +++ b/src/CycloneDX.Spdx.Interop/Converters/v2_2/SpdxDocumentConverters.cs @@ -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(), }; @@ -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 { diff --git a/src/CycloneDX.Utils/ComponentAnalysisIdentifier.cs b/src/CycloneDX.Utils/ComponentAnalysisIdentifier.cs index e43e97d9..15cb7234 100644 --- a/src/CycloneDX.Utils/ComponentAnalysisIdentifier.cs +++ b/src/CycloneDX.Utils/ComponentAnalysisIdentifier.cs @@ -36,7 +36,7 @@ public static partial class CycloneDXUtils public static string ComponentAnalysisIdentifier(Component component) { var componentIdentifier = $"{component.Group}:{component.Name}"; - if (componentIdentifier.StartsWith(":")) componentIdentifier = componentIdentifier.Substring(1); + if (componentIdentifier.StartsWith(":")) { componentIdentifier = componentIdentifier.Substring(1); } return componentIdentifier; } } diff --git a/src/CycloneDX.Utils/Merge.cs b/src/CycloneDX.Utils/Merge.cs index 80922bc6..689ec8f3 100644 --- a/src/CycloneDX.Utils/Merge.cs +++ b/src/CycloneDX.Utils/Merge.cs @@ -465,13 +465,13 @@ bom.SerialNumber is null } // cleanup empty top level elements - if (result.Metadata.Tools.Tools.Count == 0) result.Metadata.Tools.Tools = null; - if (result.Components.Count == 0) result.Components = null; - if (result.Services.Count == 0) result.Services = null; - if (result.ExternalReferences.Count == 0) result.ExternalReferences = null; - if (result.Dependencies.Count == 0) result.Dependencies = null; - if (result.Compositions.Count == 0) result.Compositions = null; - if (result.Vulnerabilities.Count == 0) result.Vulnerabilities = null; + if (result.Metadata.Tools.Tools.Count == 0) { result.Metadata.Tools.Tools = null; } + if (result.Components.Count == 0) { result.Components = null; } + if (result.Services.Count == 0) { result.Services = null; } + if (result.ExternalReferences.Count == 0) { result.ExternalReferences = null; } + if (result.Dependencies.Count == 0) { result.Dependencies = null; } + if (result.Compositions.Count == 0) { result.Compositions = null; } + if (result.Vulnerabilities.Count == 0) { result.Vulnerabilities = null; } return result; } @@ -654,16 +654,20 @@ private static void NamespaceCompositions(string bomRefNamespace, List - - - diff --git a/tests/CycloneDX.Core.Tests/Protobuf/v1.3/ValidationTests.cs b/tests/CycloneDX.Core.Tests/Protobuf/v1.3/ValidationTests.cs index e4190e2c..57f9ff0c 100644 --- a/tests/CycloneDX.Core.Tests/Protobuf/v1.3/ValidationTests.cs +++ b/tests/CycloneDX.Core.Tests/Protobuf/v1.3/ValidationTests.cs @@ -77,7 +77,7 @@ public void ValidProtobufTest(string filename) var protoBom = stream.ToArray(); var runner = new ProtocRunner(); - var result = runner.Run(tempDir.DirectoryPath, protoBom, new string[] + var result = runner.Run(tempDir.DirectoryPath, protoBom, new[] { "--proto_path=./", "--decode=cyclonedx.v1_3.Bom", diff --git a/tests/CycloneDX.Core.Tests/Protobuf/v1.4/ValidationTests.cs b/tests/CycloneDX.Core.Tests/Protobuf/v1.4/ValidationTests.cs index 4d006494..909c093e 100644 --- a/tests/CycloneDX.Core.Tests/Protobuf/v1.4/ValidationTests.cs +++ b/tests/CycloneDX.Core.Tests/Protobuf/v1.4/ValidationTests.cs @@ -79,7 +79,7 @@ public void ValidProtobufTest(string filename) var protoBom = stream.ToArray(); var runner = new ProtocRunner(); - var result = runner.Run(tempDir.DirectoryPath, protoBom, new string[] + var result = runner.Run(tempDir.DirectoryPath, protoBom, new[] { "--proto_path=./", "--decode=cyclonedx.v1_4.Bom", diff --git a/tests/CycloneDX.Core.Tests/Protobuf/v1.5/ValidationTests.cs b/tests/CycloneDX.Core.Tests/Protobuf/v1.5/ValidationTests.cs index a453cb76..fb3e34ef 100644 --- a/tests/CycloneDX.Core.Tests/Protobuf/v1.5/ValidationTests.cs +++ b/tests/CycloneDX.Core.Tests/Protobuf/v1.5/ValidationTests.cs @@ -87,7 +87,7 @@ public void ValidProtobufTest(string filename) var protoBom = stream.ToArray(); var runner = new ProtocRunner(); - var result = runner.Run(tempDir.DirectoryPath, protoBom, new string[] + var result = runner.Run(tempDir.DirectoryPath, protoBom, new[] { "--proto_path=./", "--decode=cyclonedx.v1_5.Bom",