From 1165716c72d643f07c915436d8b66bc99f1e103d Mon Sep 17 00:00:00 2001 From: Greg Villicana <58237075+grvillic@users.noreply.github.com> Date: Mon, 25 Mar 2024 10:39:26 -0700 Subject: [PATCH] Update VCPKG component identifier in detector (#1046) --- .../TypedComponent/VcpkgComponent.cs | 13 +++++++++---- .../VcpkgComponentDetectorTests.cs | 3 +++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.ComponentDetection.Contracts/TypedComponent/VcpkgComponent.cs b/src/Microsoft.ComponentDetection.Contracts/TypedComponent/VcpkgComponent.cs index 2f7f24eae..64105d404 100644 --- a/src/Microsoft.ComponentDetection.Contracts/TypedComponent/VcpkgComponent.cs +++ b/src/Microsoft.ComponentDetection.Contracts/TypedComponent/VcpkgComponent.cs @@ -42,14 +42,19 @@ public override string Id { get { - if (this.PortVersion > 0) + var componentLocationPrefix = string.Empty; + if (!string.IsNullOrWhiteSpace(this.DownloadLocation) && !this.DownloadLocation.Trim().Equals("NONE", System.StringComparison.InvariantCultureIgnoreCase)) { - return $"{this.Name} {this.Version}#{this.PortVersion} - {this.Type}"; + componentLocationPrefix = $"{this.DownloadLocation} : "; } - else + + var componentPortVersionSuffix = " "; + if (this.PortVersion > 0) { - return $"{this.Name} {this.Version} - {this.Type}"; + componentPortVersionSuffix = $"#{this.PortVersion} "; } + + return $"{componentLocationPrefix}{this.Name} {this.Version}{componentPortVersionSuffix}- {this.Type}"; } } diff --git a/test/Microsoft.ComponentDetection.Detectors.Tests/VcpkgComponentDetectorTests.cs b/test/Microsoft.ComponentDetection.Detectors.Tests/VcpkgComponentDetectorTests.cs index 8659fed92..8256b2981 100644 --- a/test/Microsoft.ComponentDetection.Detectors.Tests/VcpkgComponentDetectorTests.cs +++ b/test/Microsoft.ComponentDetection.Detectors.Tests/VcpkgComponentDetectorTests.cs @@ -79,6 +79,7 @@ public async Task TestNlohmannAsync() } components.Should().ContainSingle(); + sbomComponent.Id.Should().Be("git+https://github.com/Microsoft/vcpkg#ports/nlohmann-json : nlohmann-json 3.10.4#5 - Vcpkg"); sbomComponent.Name.Should().Be("nlohmann-json"); sbomComponent.Version.Should().Be("3.10.4"); sbomComponent.PortVersion.Should().Be(5); @@ -134,12 +135,14 @@ public async Task TestTinyxmlAndResourceAsync() components.Should().HaveCount(2); var sbomComponent = (VcpkgComponent)components.FirstOrDefault(c => ((VcpkgComponent)c?.Component).SPDXID.Equals("SPDXRef-binary")).Component; sbomComponent.Should().NotBeNull(); + sbomComponent.Id.Should().Be("tinyxml2:x64-linux 5c7679507def92c5c71df44aec08a90a5c749f7f805b3f0e8e70f5e8a5b1b8d0 - Vcpkg"); sbomComponent.Name.Should().Be("tinyxml2:x64-linux"); sbomComponent.Version.Should().Be("5c7679507def92c5c71df44aec08a90a5c749f7f805b3f0e8e70f5e8a5b1b8d0"); sbomComponent.SPDXID.Should().Be("SPDXRef-binary"); sbomComponent.DownloadLocation.Should().Be("NONE"); sbomComponent = (VcpkgComponent)components.FirstOrDefault(c => ((VcpkgComponent)c.Component).SPDXID.Equals("SPDXRef-resource-1")).Component; + sbomComponent.Id.Should().Be("git+https://github.com/leethomason/tinyxml2 : leethomason/tinyxml2 9.0.0 - Vcpkg"); sbomComponent.Name.Should().Be("leethomason/tinyxml2"); sbomComponent.Version.Should().Be("9.0.0"); sbomComponent.SPDXID.Should().Be("SPDXRef-resource-1");