Skip to content

Commit

Permalink
Update VCPKG component identifier in detector (#1046)
Browse files Browse the repository at this point in the history
  • Loading branch information
grvillic authored Mar 25, 2024
1 parent c06abda commit 1165716
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}";
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 1165716

Please sign in to comment.