Repository navigation
Add support for SPDX JSON, XML, and YAML output formats - #5590
Open
chinyeungli wants to merge 3 commits into
Open
chinyeungli wants to merge 3 commits into
chinyeungli wants to merge 3 commits into
Conversation
* Use `spdx-tools` to support additional SPDX output formats. * Update tests, test fixtures, and CLI documentation. * Remove the "No results for package" message to ensure empty scans produce valid SPDX documents across all output formats. * Update CHANGELOG Signed-off-by: Chin Yeung Li <tli@nexb.com>
* Add `_safe_test_path()` to validate test fixture and temporary file paths. Signed-off-by: Chin Yeung Li <tli@nexb.com>
| content = strip_variable_text(content) | ||
| data = xmltodict.parse(content, dict_constructor=dict) | ||
| return sort_nested(data) | ||
|
|
| @@ -158,26 +180,99 @@ def load_and_clean_tv(location): | |||
| # only keep the left side of | |||
|
|
||
| return _clean_spdx_mapping(data) | ||
|
|
||
|
|
|
|
||
| return _clean_spdx_mapping(data) | ||
|
|
||
|
|
|
|
||
| data = xmltodict.parse(content, dict_constructor=dict) | ||
|
|
||
| return _clean_spdx_mapping(data, doc_root='Document') |
Signed-off-by: Chin Yeung Li <tli@nexb.com>
| safe_result_file = _safe_test_path(result_file, roots=('temp',)) | ||
| safe_expected_file = _safe_test_path(expected_file, roots=('data',)) | ||
|
|
||
| shutil.copyfile(safe_result_file, safe_expected_file) |
| safe_result_file = _safe_test_path(result_file, roots=('temp',)) | ||
| safe_expected_file = _safe_test_path(expected_file, roots=('data',)) | ||
|
|
||
| shutil.copyfile(safe_result_file, safe_expected_file) |
| result_file = test_env.get_temp_file(extension='spdx', file_name='test_spdx') | ||
| run_scan_click(['--from-json', test_file, '--spdx-rdf', result_file]) | ||
| with io.open(result_file, encoding='utf-8') as res: | ||
| with io.open(_safe_test_path(result_file, roots=('temp',)), encoding='utf-8') as res: |
| result_file = test_env.get_temp_file(extension='spdx', file_name='test_spdx') | ||
| run_scan_click(['--from-json', test_file, '--spdx-tv', result_file]) | ||
| with io.open(result_file, encoding='utf-8') as res: | ||
| with io.open(_safe_test_path(result_file, roots=('temp',)), encoding='utf-8') as res: |
| result_file = test_env.get_temp_file(extension='json', file_name='test_spdx') | ||
| run_scan_click(['--from-json', test_file, '--spdx-json', result_file]) | ||
|
|
||
| with io.open(_safe_test_path(result_file, roots=('temp',)), encoding='utf-8') as res: |
| result_file = test_env.get_temp_file(extension='spdx', file_name='test_spdx') | ||
| run_scan_click([test_dir, '-clip', '--spdx-tv', result_file]) | ||
| with io.open(result_file, encoding='utf-8') as res: | ||
| with io.open(_safe_test_path(result_file, roots=('temp',)), encoding='utf-8') as res: |
| test_dir = test_env.get_test_loc('spdx/empty/scan/somefile') | ||
| result_file = test_env.get_temp_file('rdf') | ||
| run_scan_click([test_dir, '-clip', '--spdx-rdf', result_file]) | ||
| with io.open(_safe_test_path(result_file, roots=('temp',)), encoding='utf-8') as res: |
| test_dir = test_env.get_test_loc('spdx/empty/scan/somefile') | ||
| result_file = test_env.get_temp_file('json') | ||
| run_scan_click([test_dir, '-clip', '--spdx-json', result_file]) | ||
| with io.open(_safe_test_path(result_file, roots=('temp',)), encoding='utf-8') as res: |
| test_dir = test_env.get_test_loc('spdx/empty/scan/somefile') | ||
| result_file = test_env.get_temp_file('yaml') | ||
| run_scan_click([test_dir, '-clip', '--spdx-yaml', result_file]) | ||
| with io.open(_safe_test_path(result_file, roots=('temp',)), encoding='utf-8') as res: |
| test_dir = test_env.get_test_loc('spdx/empty/scan/somefile') | ||
| result_file = test_env.get_temp_file('xml') | ||
| run_scan_click([test_dir, '-clip', '--spdx-xml', result_file]) | ||
| with io.open(_safe_test_path(result_file, roots=('temp',)), encoding='utf-8') as res: |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
spdx-toolsto support additional SPDX output formats.Fixes #3698
Tasks
Run tests locally to check for errors.
Signed-off-by: Chin Yeung Li tli@nexb.com