Skip to content

Commit

Permalink
Merge pull request #59 from CycloneDX/spdx
Browse files Browse the repository at this point in the history
  • Loading branch information
coderpatros authored Dec 24, 2021
2 parents 32c6f6e + 40ba65c commit 8791310
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
2 changes: 2 additions & 0 deletions local-build.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
#!/usr/bin/env bash
dotnet publish --configuration Release --output ./gh-pages src/CycloneDX.WebTool
cd gh-pages/wwwroot
python3 -m http.server 8000
3 changes: 2 additions & 1 deletion src/CycloneDX.WebTool/CycloneDX.WebTool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CycloneDX.Utils" Version="4.0.0" />
<PackageReference Include="CycloneDX.Utils" Version="4.2.0" />
<PackageReference Include="CycloneDX.Spdx.Interop" Version="4.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.1" PrivateAssets="all" />
</ItemGroup>
Expand Down
31 changes: 27 additions & 4 deletions src/CycloneDX.WebTool/Pages/Convert.razor
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
@using CycloneDX.Models
@using CycloneDX.Xml
@using CycloneDX.Json
@using CycloneDX.Spdx.Interop

@inject IJSRuntime _jsRuntime;

Expand All @@ -42,6 +43,7 @@
<option value="json">JSON</option>
<option value="xml">XML</option>
<option value="bin">Protobuf</option>
<option value="spdxjson">SPDX JSON</option>
</select>
</label>

Expand All @@ -51,11 +53,12 @@
<option value="json" selected="selected">JSON</option>
<option value="xml">XML</option>
<option value="bin">Protobuf</option>
<option value="spdxjson">SPDX JSON</option>
</select>
</label>

<label>
Version
Version (ignored for SPDX output)
<select id="outputVersion" @bind="_outputVersion">
<option value="v1.3" selected="selected">v1.3</option>
<option value="v1.2">v1.2</option>
Expand Down Expand Up @@ -100,7 +103,20 @@
private async Task ConvertBOM()
{
Models.v1_3.Bom bom;
if (_inputFormat == "json" || _inputFormat == "autodetect" && _userInputFilename.EndsWith(".json"))
if (_inputFormat == "spdxjson" || _inputFormat == "autodetect" && _userInputFilename.EndsWith(".spdx.json"))
{
try
{
var spdxDoc = CycloneDX.Spdx.Serialization.JsonSerializer.Deserialize(Encoding.UTF8.GetString(_inputFileContents));
bom = spdxDoc.ToCycloneDX();
}
catch (Exception e)
{
await Alert("Error deserializing BOM: " + e.Message);
return;
}
}
else if (_inputFormat == "json" || _inputFormat == "autodetect" && _userInputFilename.EndsWith(".json"))
{
try
{
Expand Down Expand Up @@ -144,7 +160,13 @@

byte[] output;

if (_outputFormat == "json")
if (_outputFormat == "spdxjson")
{
var spdxDoc = bom.ToSpdx();
var stringOutput = CycloneDX.Spdx.Serialization.JsonSerializer.Serialize(spdxDoc);
output = Encoding.UTF8.GetBytes(stringOutput);
}
else if (_outputFormat == "json")
{
string stringOutput;
if (_outputVersion == "v1.2")
Expand Down Expand Up @@ -205,6 +227,7 @@

var outputBom64 = System.Convert.ToBase64String(output);

await _jsRuntime.InvokeVoidAsync("cdxFileDownload", Path.GetFileNameWithoutExtension(_userInputFilename) + "." + _outputFormat, outputBom64);
var fileExtension = _outputFormat == "spdxjson" ? "spdx.json": _outputFormat;
await _jsRuntime.InvokeVoidAsync("cdxFileDownload", Path.GetFileNameWithoutExtension(_userInputFilename) + "." + fileExtension, outputBom64);
}
}

0 comments on commit 8791310

Please sign in to comment.