|
33 | 33 | <_CycloneDxValidationFailed>false</_CycloneDxValidationFailed> |
34 | 34 | </PropertyGroup> |
35 | 35 |
|
36 | | - <!-- Define valid output formats and spec versions --> |
37 | | - <ItemGroup> |
38 | | - <_ValidCycloneDxOutputFormat Include="json" /> |
39 | | - <_ValidCycloneDxOutputFormat Include="xml" /> |
40 | | - <_ValidCycloneDxSpecVersion Include="1.2" /> |
41 | | - <_ValidCycloneDxSpecVersion Include="1.3" /> |
42 | | - <_ValidCycloneDxSpecVersion Include="1.4" /> |
43 | | - <_ValidCycloneDxSpecVersion Include="1.5" /> |
44 | | - <_ValidCycloneDxSpecVersion Include="1.6" /> |
45 | | - </ItemGroup> |
46 | | - |
47 | 36 | <!-- Validate output format --> |
48 | 37 | <Warning |
49 | | - Condition="! $([MSBuild]::Contains('@(_ValidCycloneDxOutputFormat)', '$(CycloneDxOutputFormat)'))" |
50 | | - Text="[CycloneDX] Invalid output format '$(CycloneDxOutputFormat)'. Supported formats: @( _ValidCycloneDxOutputFormat->', ' ). Defaulting to json." /> |
| 38 | + Condition="'$(CycloneDxOutputFormat)' != 'json' AND '$(CycloneDxOutputFormat)' != 'xml'" |
| 39 | + Text="[CycloneDX] Invalid output format '$(CycloneDxOutputFormat)'. Supported formats: json, xml. Defaulting to json." /> |
51 | 40 |
|
52 | | - <PropertyGroup Condition="! $([MSBuild]::Contains('@(_ValidCycloneDxOutputFormat)', '$(CycloneDxOutputFormat)'))"> |
| 41 | + <PropertyGroup Condition="'$(CycloneDxOutputFormat)' != 'json' AND '$(CycloneDxOutputFormat)' != 'xml'"> |
53 | 42 | <CycloneDxOutputFormat>json</CycloneDxOutputFormat> |
54 | 43 | </PropertyGroup> |
55 | 44 |
|
56 | | - <!-- Validate spec version --> |
57 | | - <Warning |
58 | | - Condition="! $([MSBuild]::Contains('@(_ValidCycloneDxSpecVersion)', '$(CycloneDxSpecVersion)'))" |
59 | | - Text="[CycloneDX] Invalid spec version '$(CycloneDxSpecVersion)'. Supported: @( _ValidCycloneDxSpecVersion->', ' ). Defaulting to 1.6." /> |
60 | | - |
61 | | - <PropertyGroup Condition="! $([MSBuild]::Contains('@(_ValidCycloneDxSpecVersion)', '$(CycloneDxSpecVersion)'))"> |
62 | | - <CycloneDxSpecVersion>1.6</CycloneDxSpecVersion> |
63 | | - </PropertyGroup> |
64 | | - |
65 | 45 | <!-- Ensure output directory exists --> |
66 | 46 | <MakeDir Directories="$(CycloneDxOutputDirectory)" Condition="!Exists('$(CycloneDxOutputDirectory)')" /> |
67 | 47 |
|
|
125 | 105 |
|
126 | 106 | <Message Importance="high" Text="[CycloneDX] Generating SBOM for $(MSBuildProjectName)..." /> |
127 | 107 |
|
| 108 | + <!-- Set output directory default now, when $(OutputPath) is available --> |
| 109 | + <PropertyGroup> |
| 110 | + <CycloneDxOutputDirectory Condition="'$(CycloneDxOutputDirectory)' == ''">$(OutputPath)</CycloneDxOutputDirectory> |
| 111 | + <!-- Remove trailing backslash/slash to avoid escaping the closing quote in command-line arguments --> |
| 112 | + <CycloneDxOutputDirectory>$(CycloneDxOutputDirectory.TrimEnd('\\').TrimEnd('/'))</CycloneDxOutputDirectory> |
| 113 | + </PropertyGroup> |
| 114 | + |
128 | 115 | <PropertyGroup> |
129 | 116 | <!-- Build command line arguments --> |
130 | 117 | <_CycloneDxArgs></_CycloneDxArgs> |
131 | 118 | <_CycloneDxArgs>$(_CycloneDxArgs) "$(MSBuildProjectFullPath)"</_CycloneDxArgs> |
132 | | - <_CycloneDxArgs>$(_CycloneDxArgs) --output-directory "$(CycloneDxOutputDirectory)"</_CycloneDxArgs> |
133 | | - <_CycloneDxArgs>$(_CycloneDxArgs) --output-filename "$(CycloneDxOutputFilename)"</_CycloneDxArgs> |
134 | | - <_CycloneDxArgs>$(_CycloneDxArgs) --output-format $(CycloneDxOutputFormat)</_CycloneDxArgs> |
135 | | - <_CycloneDxArgs>$(_CycloneDxArgs) --spec-version $(CycloneDxSpecVersion)</_CycloneDxArgs> |
| 119 | + <_CycloneDxArgs>$(_CycloneDxArgs) -o "$(CycloneDxOutputDirectory)"</_CycloneDxArgs> |
| 120 | + |
| 121 | + <!-- Build full filename with extension based on format --> |
| 122 | + <_CycloneDxFullFilename Condition="'$(CycloneDxOutputFormat)' == 'json'">$(CycloneDxOutputFilename).json</_CycloneDxFullFilename> |
| 123 | + <_CycloneDxFullFilename Condition="'$(CycloneDxOutputFormat)' == 'xml'">$(CycloneDxOutputFilename).xml</_CycloneDxFullFilename> |
| 124 | + <!-- Fallback to json if format is invalid --> |
| 125 | + <_CycloneDxFullFilename Condition="'$(_CycloneDxFullFilename)' == ''">$(CycloneDxOutputFilename).json</_CycloneDxFullFilename> |
| 126 | + <_CycloneDxArgs>$(_CycloneDxArgs) -fn "$(_CycloneDxFullFilename)"</_CycloneDxArgs> |
| 127 | + |
| 128 | + <!-- Output format: json or xml (capitalize first letter for tool) --> |
| 129 | + <_CycloneDxOutputFormat Condition="'$(CycloneDxOutputFormat)' == 'json'">Json</_CycloneDxOutputFormat> |
| 130 | + <_CycloneDxOutputFormat Condition="'$(CycloneDxOutputFormat)' == 'xml'">Xml</_CycloneDxOutputFormat> |
| 131 | + <!-- Fallback to Json if format is invalid --> |
| 132 | + <_CycloneDxOutputFormat Condition="'$(_CycloneDxOutputFormat)' == ''">Json</_CycloneDxOutputFormat> |
| 133 | + <_CycloneDxArgs>$(_CycloneDxArgs) -F $(_CycloneDxOutputFormat)</_CycloneDxArgs> |
136 | 134 |
|
137 | 135 | <!-- Optional arguments --> |
138 | | - <_CycloneDxArgs Condition="'$(CycloneDxExcludeDev)' == 'true'">$(_CycloneDxArgs) --exclude-dev</_CycloneDxArgs> |
139 | | - <_CycloneDxArgs Condition="'$(CycloneDxExcludeTestProjects)' == 'true'">$(_CycloneDxArgs) --exclude-test-projects</_CycloneDxArgs> |
140 | | - <_CycloneDxArgs Condition="'$(CycloneDxIncludeLicenseText)' == 'true'">$(_CycloneDxArgs) --include-license-text</_CycloneDxArgs> |
141 | | - <_CycloneDxArgs Condition="'$(CycloneDxSerialNumber)' != ''">$(_CycloneDxArgs) --serial-number $(CycloneDxSerialNumber)</_CycloneDxArgs> |
| 136 | + <_CycloneDxArgs Condition="'$(CycloneDxExcludeDev)' == 'true'">$(_CycloneDxArgs) -ed</_CycloneDxArgs> |
| 137 | + <_CycloneDxArgs Condition="'$(CycloneDxExcludeTestProjects)' == 'true'">$(_CycloneDxArgs) -t</_CycloneDxArgs> |
| 138 | + <_CycloneDxArgs Condition="'$(CycloneDxDisableSerialNumber)' == 'true'">$(_CycloneDxArgs) -ns</_CycloneDxArgs> |
| 139 | + <_CycloneDxArgs Condition="'$(CycloneDxEnableGitHubLicenses)' == 'true'">$(_CycloneDxArgs) -egl</_CycloneDxArgs> |
| 140 | + <_CycloneDxArgs Condition="'$(CycloneDxGitHubUsername)' != ''">$(_CycloneDxArgs) -gu "$(CycloneDxGitHubUsername)"</_CycloneDxArgs> |
| 141 | + <_CycloneDxArgs Condition="'$(CycloneDxGitHubToken)' != ''">$(_CycloneDxArgs) -gt "$(CycloneDxGitHubToken)"</_CycloneDxArgs> |
142 | 142 | </PropertyGroup> |
143 | 143 |
|
144 | 144 | <!-- Execute CycloneDX tool --> |
|
0 commit comments