Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 468 364 478 integration #492

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
108 commits
Select commit Hold shift + click to select a range
75dc9dc
Removed unnecessary metaschema check on json-value-key
wendellpiez Sep 3, 2019
b0b7716
Now implementing in-xml="with-wrapper | unwrapped" on markup multilin…
wendellpiez Sep 3, 2019
f203a91
Updating catalog and profile schemas for (prose) unwrapping behavior
wendellpiez Sep 4, 2019
9e4e78e
Renamed 'json-behavior' in Metaschema to 'in-json' for consistency wi…
wendellpiez Sep 4, 2019
7033621
Updating syntax in metaschemas 'in-json' for 'json-behavior'
wendellpiez Sep 4, 2019
74dfd9b
Updating json converter generator to provide in-xml behavior 'GROUPED'
wendellpiez Sep 4, 2019
767e4cd
Refining json converter production from Metaschema
wendellpiez Sep 4, 2019
a92c065
Repairing egregious syntax error
wendellpiez Sep 4, 2019
d5967bf
Rectify bug introduced with new feature
wendellpiez Sep 4, 2019
18fa7a1
Adding support for 'date' and 'dateTime' datatypes, with no time zone…
wendellpiez Sep 5, 2019
f7551f2
Improvements and corrections to datatypes docs
wendellpiez Sep 6, 2019
719a1b7
More small repairs on datatypes descriptions (table markup)
wendellpiez Sep 6, 2019
15febb2
Built out validations of allowed (enumerated) values, including Metas…
wendellpiez Sep 10, 2019
66ec426
Straightening kinks in datatype metaschema meta-validation
wendellpiez Sep 10, 2019
fe3b437
More special handling of recalcitrant datatypes, this time 'NMTOKENS'…
wendellpiez Sep 10, 2019
b084591
Addressing #463, adding `id`, `class` and `title` to `group` in profi…
wendellpiez Sep 11, 2019
8f9f9db
Schematron improvements; documentation revisions (removing references…
wendellpiez Sep 12, 2019
c67b5ce
New Schematron for SP800-53-style catalogs
wendellpiez Sep 12, 2019
ee44e3f
Removed using in implementation to new metaschema for storage. Starte…
david-waltermire Sep 4, 2019
de9de68
More work on an example, which is still not valid
david-waltermire Sep 6, 2019
8987efd
refactored schematron processing
david-waltermire Sep 9, 2019
4c9b563
more work on SSP example
david-waltermire Sep 9, 2019
80ed5f5
Refactored generate-schema.sh to allow a metaschema to be provided on…
david-waltermire Sep 12, 2019
2e6881d
refactored SSP model to be more flat, while allowing component refere…
david-waltermire Sep 12, 2019
c6a8ebd
slight cleanup
david-waltermire Sep 12, 2019
2e3d095
old example
david-waltermire Sep 12, 2019
d6eb2c9
Fixed content generation
david-waltermire Sep 12, 2019
af55608
updated metaschema to new specs
david-waltermire Sep 12, 2019
929a7a0
fixed content errors
david-waltermire Sep 13, 2019
6804128
added metaschema examples
david-waltermire Sep 18, 2019
b3578f5
Updated metaschema example.
david-waltermire Sep 18, 2019
41ba659
Added support for direct generation of schema and converters
david-waltermire Sep 23, 2019
7f8b4cd
Minor updates to SSP example and metaschema
david-waltermire Sep 23, 2019
482b7d8
Adding computer build metaschema examples
david-waltermire Sep 23, 2019
05fac54
Adding 'prop' and 'part' to Profile Metaschema per #463
wendellpiez Sep 13, 2019
4765b19
Added 'param' to profile 'group' model
wendellpiez Sep 13, 2019
658ab57
JSON converter now properly handling flags assigned to assemblies ide…
wendellpiez Sep 13, 2019
4cd03b8
Added 'sort-id' property to controls in SP800-53 catalog
wendellpiez Sep 13, 2019
95c3bff
Extending allowed-values support to fields; unit tests: #437
wendellpiez Sep 16, 2019
97d6fd0
More work on allowed-values, now in XSD with unit tests for #437
wendellpiez Sep 16, 2019
755a5de
Repairing small datatyping bug thanks to regression testing
wendellpiez Sep 16, 2019
5a86074
Further adjustment for allowed-values in docs
wendellpiez Sep 16, 2019
8a31f77
Renamed unit tests, now working
wendellpiez Sep 16, 2019
ac14e58
Adding allowed-values unit tests
wendellpiez Sep 17, 2019
2154192
Addressing #452: cleaned up character handling in XML-to-JSON convers…
wendellpiez Sep 17, 2019
11758a7
More adjustments in view of comments to #452
wendellpiez Sep 17, 2019
bf43072
Repairing more bugs in character handling in Markdown and plain text,…
wendellpiez Sep 17, 2019
c04df41
Improvements to Schematron for SP800-53 #400
wendellpiez Sep 18, 2019
584f960
For #452, modified copy-and-convert script to suppress character-leve…
wendellpiez Sep 20, 2019
b0e28f3
Edited docs, including datatypes page per #452 (regarding character e…
wendellpiez Sep 20, 2019
4280187
Cleanup metaschema valdiation errors
david-waltermire Sep 23, 2019
0fb89a2
changed use of the ID and IDREF datatype to NCName
david-waltermire Sep 23, 2019
f57572d
Removed ID and IDREF datatypes
david-waltermire Sep 23, 2019
e9a0029
refactored components out of ssp metaschema
david-waltermire Sep 23, 2019
028e990
Updated SP800-53 catalog and NIST profiles to current model
wendellpiez Sep 23, 2019
3e9ab74
Added name to information type.
david-waltermire Sep 23, 2019
2d1a362
Continued refinement of the SSP model
david-waltermire Sep 24, 2019
d83ec82
Updated metadata syntax
brian-ruf Sep 26, 2019
2cd5fc1
changing CM-6 constraint to guidance
brian-ruf Sep 26, 2019
e418d52
continued work on SSP
david-waltermire Sep 26, 2019
96718df
refactored responsible party to metadata
david-waltermire Sep 26, 2019
b065657
fixed validation issues
david-waltermire Sep 26, 2019
0933012
Fixed overriding enumerated values
david-waltermire Sep 27, 2019
2cf28fc
Fixed content validation errors based on latest metaschema changes
david-waltermire Sep 27, 2019
05752c7
Completed full pass through ssp model
david-waltermire Sep 29, 2019
8ed7c91
added prop to resource
david-waltermire Sep 29, 2019
2f64340
Fixed broken links in Markdown files. Small adjustments to SSP example.
david-waltermire Sep 30, 2019
99fc0de
FDixed relapath error caused when the generated schema directory does…
david-waltermire Sep 30, 2019
7194445
Fixed validation issue with component metaschema
david-waltermire Sep 30, 2019
1aa1a72
attempting to fix extra characters in CircleCI colorized messages
david-waltermire Sep 30, 2019
2144598
Updated enumerated values to remove values that should appear in a gi…
david-waltermire Sep 30, 2019
399add0
quick reordering of elements
david-waltermire Sep 30, 2019
052c2bb
hardcode ascii color codes
david-waltermire Sep 30, 2019
fac592e
added unit tests for bug
david-waltermire Sep 30, 2019
7f06113
fixed color escaping in scripts
david-waltermire Sep 30, 2019
84be025
Removed bogus unit test and fixed a small cardinality issue in the SS…
david-waltermire Sep 30, 2019
279b645
Fixing broken links in readmes; file name update for consistency
wendellpiez Sep 23, 2019
193bbee
Improvements to docs generation
wendellpiez Sep 25, 2019
6a64792
Added JSON value keys to fields with flags (that did not have them)
wendellpiez Sep 26, 2019
36b6331
Bug reduction in XSD production mainly related to datatypes and allow…
wendellpiez Sep 27, 2019
ef8114f
Fixing glitch in JSON converter generator
wendellpiez Sep 27, 2019
f48d84c
Adjustments repairing Metaschema issues
wendellpiez Sep 27, 2019
d54aac6
CSS tweak in docs (model maps to use USWDS font)
wendellpiez Sep 27, 2019
ae840be
Adding to Milestone 2 release notes (in progress)
wendellpiez Sep 27, 2019
5da15a8
Change to parameter setting in profile model (#494, #288); release no…
wendellpiez Sep 30, 2019
b9a1aeb
Small improvements to copy in release notes (draft)
wendellpiez Sep 30, 2019
1364f17
Updating metaschemas to latest syntax, with improved Metaschema Schem…
wendellpiez Sep 30, 2019
5b82900
Adjustments to flag unit test and release notes
wendellpiez Sep 30, 2019
92a2233
SSP Metaschema review and update
brian-ruf Sep 30, 2019
9f15ccc
cleanup of unused role-id field
david-waltermire Sep 30, 2019
3aa6eb1
reflactored role-id
david-waltermire Sep 30, 2019
bc1a6df
updated documentation for release.
david-waltermire Oct 1, 2019
3daf16a
cleanup of IDs
david-waltermire Oct 1, 2019
79fec5f
Minor schema and metaschema improvements
wendellpiez Sep 30, 2019
0e42c68
M1 to M2 content converter
wendellpiez Sep 30, 2019
7fa319a
Merging local and upstream changes to json example
wendellpiez Oct 1, 2019
e6467b0
Relaxing rule over 'ID' flag to accept any string not only XML NCName
wendellpiez Oct 1, 2019
0047fa9
reorganizing content for release
david-waltermire Oct 1, 2019
576852d
more file moves
david-waltermire Oct 1, 2019
3ef979e
Fixed changed path
david-waltermire Oct 1, 2019
e0986d5
Updated FedRAMP profiles and catalog to current models
wendellpiez Oct 1, 2019
7b2fe21
Bug fix to XML-to-JSON converter generator
wendellpiez Oct 1, 2019
729344c
Fixed copy script
david-waltermire Oct 1, 2019
1ad802a
Updated FedRAMP baselines and catalog to match new metaschema syntax
brian-ruf Oct 1, 2019
09d7c8d
fixed merge error
david-waltermire Oct 1, 2019
b2adfd2
fixed another merge error
david-waltermire Oct 1, 2019
805bb31
fixed spelling issues
david-waltermire Oct 1, 2019
c8c54c5
Fix from Wendell
david-waltermire Oct 1, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ jobs: # a collection of
- install-maven-dependencies
- install-jq
- install-prettyjson
- install-xmllint
- run:
name: Generate OSCAL converters
command: |
Expand Down
1 change: 1 addition & 0 deletions build/ci-cd/config/content
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# path to source|format of source|model of source|format(s) to convert to
src/content/ssp-example/ssp-example.json|json|ssp|xml
src/content/fedramp.gov/xml/*catalog.xml|xml|catalog|json
src/content/fedramp.gov/xml/*profile.xml|xml|profile|json
src/content/nist.gov/SP800-53/rev4/xml/*catalog.xml|xml|catalog|json
Expand Down
2 changes: 0 additions & 2 deletions build/ci-cd/config/metaschema
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@ src/metaschema/oscal_catalog_metaschema.xml|xml,json|xml,json|xml,json
src/metaschema/oscal_profile_metaschema.xml|xml,json|xml,json|xml,json
src/metaschema/oscal_component_metaschema.xml|xml,json|xml,json|xml,json
src/metaschema/oscal_ssp_metaschema.xml|xml,json|xml,json|xml,json


1 change: 1 addition & 0 deletions build/ci-cd/config/release-content
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ content/fedramp.gov/**/*.yaml
content/nist.gov/**/*.xml
content/nist.gov/**/*.json
content/nist.gov/**/*.yaml
content/ssp-example/ssp-example.json
xml/convert/*.xsl
xml/schema/*.xsd
json/convert/*.xsl
Expand Down
79 changes: 47 additions & 32 deletions build/ci-cd/copy-and-convert-content.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,18 @@ done

OTHER_ARGS=$@ # save the remaining args

echo ""
echo "${P_INFO}Copying and Converting Content${P_END}"
echo "${P_INFO}==============================${P_END}"
echo -e ""
echo -e "${P_INFO}Copying and Converting Content${P_END}"
echo -e "${P_INFO}==============================${P_END}"

if [ "$VERBOSE" = "true" ]; then
echo "${P_INFO}Using working directory:${P_END} ${WORKING_DIR}"
echo -e "${P_INFO}Using working directory:${P_END} ${WORKING_DIR}"
fi

# check for perl
result=$(which perl 2>&1)
if [ $? -ne 0 ]; then
echo "${P_ERROR}Perl is not installed. Perl is needed by this script.${P_END}"
echo -e "${P_ERROR}Perl is not installed. Perl is needed by this script.${P_END}"
exit 1
fi

Expand All @@ -92,16 +92,15 @@ while IFS="|" read path format model converttoformats || [[ -n "$path" ]]; do
file_relative=$(realpath --relative-to="${OSCALDIR}" "$file")
dest="$WORKING_DIR/${file/$OSCALDIR\/src\//}"
dest_dir=${dest%/*} # remove filename
dest_relative=$(realpath --relative-to="${WORKING_DIR}" "$dest")

mkdir -p "$dest_dir"
dest_relative=$(realpath --relative-to="${WORKING_DIR}" "$dest")
result=$(cp "$file" "$dest" 2>&1)
cmd_exitcode=$?
if [ $cmd_exitcode -ne 0 ]; then
echo "${P_ERROR}Unable to copy '${P_END}${file_relative}${P_ERROR}' to '${P_END}${dest_relative}${P_ERROR}'.${P_END}"
echo "${P_ERROR}${result}${P_END}"
echo -e "${P_ERROR}Unable to copy '${P_END}${file_relative}${P_ERROR}' to '${P_END}${dest_relative}${P_ERROR}'.${P_END}"
echo -e "${P_ERROR}${result}${P_END}"
else
echo "${P_OK}Copied '${P_END}${file_relative}${P_OK}' to '${P_END}${dest_relative}${P_OK}'.${P_END}"
echo -e "${P_OK}Copied '${P_END}${file_relative}${P_OK}' to '${P_END}${dest_relative}${P_OK}'.${P_END}"
fi

IFS=","
Expand All @@ -110,32 +109,48 @@ while IFS="|" read path format model converttoformats || [[ -n "$path" ]]; do
newpath="${newpath/\/$format\///$altformat/}" # change path from old to new format dir
newpath="${newpath%.*}" # strip extension

dest="$WORKING_DIR/${newpath}-min.${altformat}"
dest_relative=$(realpath --relative-to="${WORKING_DIR}" "$dest")
converter="$WORKING_DIR/$altformat/convert/oscal_${model}_${format}-to-${altformat}-converter.xsl"
converter_relative=$(realpath --relative-to="${WORKING_DIR}" "$converter")

if [ "$VERBOSE" = "true" ]; then
echo "${P_INFO}Generating ${altformat^^} file '${P_END}${dest_relative}${P_INFO}' from '${P_END}${file_relative}${P_INFO}' using converter '${P_END}${converter_relative}${P_INFO}'.${P_END}"
fi
result=$(xsl_transform "$converter" "$file" "$dest" 2>&1)

case $format in
xml)
dest="$WORKING_DIR/${newpath}-min.${altformat}"
dest_relative=$(realpath --relative-to="${WORKING_DIR}" "$dest")
if [ "$VERBOSE" = "true" ]; then
echo -e "${P_INFO}Generating ${altformat^^} file '${P_END}${dest_relative}${P_INFO}' from '${P_END}${file_relative}${P_INFO}' using converter '${P_END}${converter_relative}${P_INFO}'.${P_END}"
fi
result=$(xsl_transform "$converter" "$file" "$dest" 2>&1)
;;
json)
dest="$WORKING_DIR/${newpath}.${altformat}"
dest_relative=$(realpath --relative-to="${WORKING_DIR}" "$dest")
if [ "$VERBOSE" = "true" ]; then
echo -e "${P_INFO}Generating ${altformat^^} file '${P_END}${dest_relative}${P_INFO}' from '${P_END}${file_relative}${P_INFO}' using converter '${P_END}${converter_relative}${P_INFO}'.${P_END}"
fi
result=$(xsl_transform "$converter" "" "$dest" "-it" "json-file=${file}" 2>&1)
;;
*)
echo -e "${P_WARN}Conversion from '${format} to '${altformat^^}' is unsupported for '${P_END}${file_relative}${P_OK}'.${P_END}"
continue;
esac
cmd_exitcode=$?
if [ $cmd_exitcode -ne 0 ]; then
echo "${P_ERROR}Content conversion to ${altformat^^} failed for '${P_END}${file_relative}${P_ERROR}' using converter '${P_END}${converter_relative}${P_ERROR}'.${P_END}"
echo "${P_ERROR}${result}${P_END}"
echo -e "${P_ERROR}Content conversion to ${altformat^^} failed for '${P_END}${file_relative}${P_ERROR}' using converter '${P_END}${converter_relative}${P_ERROR}'.${P_END}"
echo -e "${P_ERROR}${result}${P_END}"
exitcode=1
continue
else
if [ "$VERBOSE" = "true" ]; then
echo "${P_OK}Content conversion to ${altformat^^} succeeded for '${P_END}${file_relative}${P_OK}'.${P_END}"
echo -e "${P_OK}Content conversion to ${altformat^^} succeeded for '${P_END}${file_relative}${P_OK}'.${P_END}"
fi
fi

# Format specific post-processing
case $altformat in
json)
# Remove extra slashes
perl -pi -e 's,\\/,/,g' "${dest}"
# perl -pi -e 's,\\/,/,g' "${dest}"
# translate OSCAL mime types
perl -pi -e 's,(application/oscal\.[a-z]+\+)xml\",\1json\",g' "${dest}"
# relative content paths
Expand All @@ -152,21 +167,21 @@ while IFS="|" read path format model converttoformats || [[ -n "$path" ]]; do
result=$(validate_json "$schema" "$dest")
cmd_exitcode=$?
if [ $cmd_exitcode -ne 0 ]; then
echo "${P_ERROR}JSON Schema validation failed for '${P_END}${dest_relative}${P_ERROR}' using schema '${P_END}${schema_relative}${P_ERROR}'.${P_END}"
echo "${P_ERROR}${result}${P_END}"
echo -e "${P_ERROR}JSON Schema validation failed for '${P_END}${dest_relative}${P_ERROR}' using schema '${P_END}${schema_relative}${P_ERROR}'.${P_END}"
echo -e "${P_ERROR}${result}${P_END}"
exitcode=1
continue
else
echo "${P_OK}JSON Schema validation passed for '${P_END}${dest_relative}${P_OK}' using schema '${P_END}${schema_relative}${P_OK}'.${P_END}"
echo -e "${P_OK}JSON Schema validation passed for '${P_END}${dest_relative}${P_OK}' using schema '${P_END}${schema_relative}${P_OK}'.${P_END}"
fi

# produce pretty JSON
dest_pretty="$WORKING_DIR/${newpath}.${altformat}"
dest_pretty_relative=$(realpath --relative-to="${WORKING_DIR}" "$dest_pretty")
result=$(jq . "$dest" > "$dest_pretty" 2>&1)
if [ $? -ne 0 ]; then
echo "${P_ERROR}Unable to execute jq on '${P_END}${dest_pretty_relative}${P_ERROR}' using schema '${P_END}${schema_relative}${P_ERROR}'.${P_END}"
echo "${P_ERROR}${result}${P_END}"
echo -e "${P_ERROR}Unable to execute jq on '${P_END}${dest_pretty_relative}${P_ERROR}' using schema '${P_END}${schema_relative}${P_ERROR}'.${P_END}"
echo -e "${P_ERROR}${result}${P_END}"
exitcode=1
continue
fi
Expand All @@ -176,12 +191,12 @@ while IFS="|" read path format model converttoformats || [[ -n "$path" ]]; do
result=$(validate_json "$schema" "$dest_pretty" 2>&1)
cmd_exitcode=$?
if [ $cmd_exitcode -ne 0 ]; then
echo "${P_ERROR}JSON Schema validation failed for '${P_END}${dest_pretty_relative}${P_ERROR}' using schema '${P_END}${schema_relative}${P_ERROR}'.${P_END}"
echo "${P_ERROR}${result}${P_END}"
echo -e "${P_ERROR}JSON Schema validation failed for '${P_END}${dest_pretty_relative}${P_ERROR}' using schema '${P_END}${schema_relative}${P_ERROR}'.${P_END}"
echo -e "${P_ERROR}${result}${P_END}"
exitcode=1
continue
else
echo "${P_OK}JSON Schema validation passed for '${P_END}${dest_pretty_relative}${P_OK}' using schema '${P_END}${schema_relative}${P_OK}'.${P_END}"
echo -e "${P_OK}JSON Schema validation passed for '${P_END}${dest_pretty_relative}${P_OK}' using schema '${P_END}${schema_relative}${P_OK}'.${P_END}"
fi

# produce yaml
Expand All @@ -198,15 +213,15 @@ while IFS="|" read path format model converttoformats || [[ -n "$path" ]]; do
result=$(xmllint --noout --schema "$schema" "$dest" 2>&1)
cmd_exitcode=$?
if [ $cmd_exitcode -ne 0 ]; then
echo "${P_ERROR}XML Schema validation failed for '${P_END}${dest_relative}${P_ERROR}' using schema '${P_END}${schema_relative}${P_ERROR}'.${P_END}"
echo "${P_ERROR}${result}${P_END}"
echo -e "${P_ERROR}XML Schema validation failed for '${P_END}${dest_relative}${P_ERROR}' using schema '${P_END}${schema_relative}${P_ERROR}'.${P_END}"
echo -e "${P_ERROR}${result}${P_END}"
exitcode=1
else
echo "${P_OK}XML Schema validation passed for '${P_END}${dest_relative}${P_OK}' using schema '${P_END}${schema_relative}${P_OK}'.${P_END}"
echo -e "${P_OK}XML Schema validation passed for '${P_END}${dest_relative}${P_OK}' using schema '${P_END}${schema_relative}${P_OK}'.${P_END}"
fi
;;
*)
echo "${P_WARN}Post processing of '${altformat^^}' is unsupported for '${P_END}${dest_relative}${P_OK}'.${P_END}"
echo -e "${P_WARN}Post processing of '${altformat^^}' is unsupported for '${P_END}${dest_relative}${P_OK}'.${P_END}"
continue;
esac
done
Expand Down
155 changes: 84 additions & 71 deletions build/ci-cd/generate-content-converters.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ HELP=false

usage() { # Function: Print a help message.
cat << EOF
Usage: $0 [options]
Usage: $0 [options] [metaschema paths]

-h, --help Display help
-w DIR, --working-dir DIR Generate artifacts in DIR
Expand Down Expand Up @@ -54,81 +54,94 @@ done

OTHER_ARGS=$@ # save the remaining args

echo ""
echo "${P_INFO}Generating XML <-> JSON Content Converters${P_END}"
echo "${P_INFO}==========================================${P_END}"
echo -e ""
echo -e "${P_INFO}Generating XML <-> JSON Content Converters${P_END}"
echo -e "${P_INFO}==========================================${P_END}"

if [ "$VERBOSE" = "true" ]; then
echo "${P_INFO}Using working directory:${P_END} ${WORKING_DIR}"
echo -e "${P_INFO}Using working directory:${P_END} ${WORKING_DIR}"
fi

exitcode=0
shopt -s nullglob
shopt -s globstar
while IFS="|" read path gen_schema gen_converter gen_docs || [[ -n "$path" ]]; do
shopt -s extglob
[[ "$path" =~ ^[[:space:]]*# ]] && continue
# remove leading space
path="${path##+([[:space:]])}"
# remove trailing space
gen_docs="${gen_docs%%+([[:space:]])}"
shopt -u extglob

([ -z "$path" ] || [ -z "$gen_converter" ]) && continue;

files_to_process="$OSCALDIR"/"$path"

IFS= # disable word splitting
for metaschema in $files_to_process
do
filename=$(basename -- "$metaschema")
extension="${filename##*.}"
filename="${filename%.*}"
model="${filename/_metaschema/}"
metaschema_relative=$(realpath --relative-to="${OSCALDIR}" "$metaschema")

#split on commas
IFS=, read -a formats <<< "$gen_converter"
for target_format in "${formats[@]}"; do
if [ -z "$target_format" ]; then
# skip blanks
continue;
fi

# Run the XSL template for the format
case $target_format in
xml)
source_format="json"
;;
json)
source_format="xml"
;;
*)
echo "${P_WARN}Generating converter from '${source_format^^}' to '${target_format^^}' is unsupported for '${P_END}${metaschema_relative}${P_WARN}'.${P_END}"
continue;
;;
esac

converter="$WORKING_DIR/${target_format}/convert/${model}_${source_format}-to-${target_format}-converter.xsl"
converter_relative=$(realpath --relative-to="${WORKING_DIR}" "$converter")

if [ "$VERBOSE" = "true" ]; then
echo "${P_INFO}Generating ${source_format^^} to ${target_format^^} converter for '${P_END}${metaschema_relative}${P_INFO}' as '${P_END}${converter_relative}${P_INFO}'.${P_END}"
fi

result=$(xsl_transform "$OSCALDIR/build/metaschema/$source_format/produce-${source_format}-converter.xsl" "$metaschema" "$converter" 2>&1)
cmd_exitcode=$?
if [ $cmd_exitcode -ne 0 ]; then
echo "${P_ERROR}Generating ${source_format^^} to ${target_format^^} converter failed for '${P_END}${metaschema_relative}${P_ERROR}'.${P_END}"
echo "${P_ERROR}${result}${P_END}"
exitcode=1
else
echo "${P_OK}Generating ${source_format^^} to ${target_format^^} converter passed for '${P_END}${metaschema_relative}${P_OK}'.${P_END}"
fi
declare -a paths
declare -a formats
if [ "$#" -ne 0 ]; then
paths=("$@")
for i in "${!paths[@]}"; do
formats[$i]="xml,json"
done
else
while IFS="|" read path gen_schema gen_converter gen_docs || [[ -n "$path" ]]; do
[[ "$path" =~ ^[[:space:]]*# ]] && continue
# remove leading space
path="${path##+([[:space:]])}"

([ -z "$path" ] || [ -z "$gen_converter" ]) && continue;

path_absolute="$OSCALDIR"/"$path"

IFS_OLD=$IFS
IFS= # disable word splitting
for metaschema in $path_absolute
do
paths+=("$metaschema")
formats+=("$gen_converter")
done
IFS=$IFS_OLD
done < "$OSCALDIR/build/ci-cd/config/metaschema"
fi

exitcode=0
for i in "${!paths[@]}"; do
metaschema="${paths[$i]}"
gen_converter="${formats[$i]}"

filename=$(basename -- "$metaschema")
extension="${filename##*.}"
filename="${filename%.*}"
model="${filename/_metaschema/}"
metaschema_relative=$(realpath --relative-to="${OSCALDIR}" "$metaschema")

#split on commas
IFS_OLD=$IFS
IFS=, #read -a formats <<< "$gen_schema"
for target_format in ${gen_converter}; do
if [ -z "$target_format" ]; then
# skip blanks
continue;
fi

# Run the XSL template for the format
case $target_format in
xml)
source_format="json"
;;
json)
source_format="xml"
;;
*)
echo -e "${P_WARN}Generating converter from '${source_format^^}' to '${target_format^^}' is unsupported for '${P_END}${metaschema_relative}${P_WARN}'.${P_END}"
continue;
;;
esac

converter="$WORKING_DIR/${target_format}/convert/${model}_${source_format}-to-${target_format}-converter.xsl"
converter_relative=$(realpath --relative-to="${WORKING_DIR}" "$converter")

if [ "$VERBOSE" = "true" ]; then
echo -e "${P_INFO}Generating ${source_format^^} to ${target_format^^} converter for '${P_END}${metaschema_relative}${P_INFO}' as '${P_END}${converter_relative}${P_INFO}'.${P_END}"
fi

result=$(xsl_transform "$OSCALDIR/build/metaschema/$source_format/produce-${source_format}-converter.xsl" "$metaschema" "$converter" 2>&1)
cmd_exitcode=$?
if [ $cmd_exitcode -ne 0 ]; then
echo -e "${P_ERROR}Generating ${source_format^^} to ${target_format^^} converter failed for '${P_END}${metaschema_relative}${P_ERROR}'.${P_END}"
echo -e "${P_ERROR}${result}${P_END}"
exitcode=1
else
echo -e "${P_OK}Generating ${source_format^^} to ${target_format^^} converter passed for '${P_END}${metaschema_relative}${P_OK}'.${P_END}"
fi
done
done < $OSCALDIR/build/ci-cd/config/metaschema
shopt -u nullglob
shopt -u globstar
IFS=$IFS_OLD
done

exit $exitcode
Loading