@@ -6,6 +6,7 @@ if [ -z ${OSCAL_SCRIPT_INIT+x} ]; then
66 source " $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " > /dev/null && pwd) /include/init-oscal.sh"
77fi
88source " $OSCALDIR /build/metaschema/scripts/include/init-validate-content.sh"
9+ source " $OSCALDIR /build/metaschema/scripts/include/init-schematron.sh"
910
1011# Option defaults
1112ARTIFACT_DIR=" ${OSCALDIR} "
@@ -23,10 +24,16 @@ Usage: $0 [options]
2324-o DIR, --oscal-dir DIR OSCAL schema are located in DIR.
2425-h, --help Display help
2526-v Provide verbose output
27+ --scratch-dir DIR Generate temporary artifacts in DIR
28+ If not provided a new directory will be
29+ created under \$ TMPDIR if set or in /tmp.
30+ --keep-temp-scratch-dir If a scratch directory is automatically
31+ created, it will not be automatically removed.
2632EOF
2733}
2834
29- if ! OPTS=$( getopt -o o:vhc:a: --long artifact-dir:,oscal-dir:,help,config-file: -n " $0 " -- " $@ " ) ; then echo " Failed parsing options." >&2 ; usage ; exit 1 ; fi
35+ OPTS=$( getopt -o o:vhc:a: --long artifact-dir:,oscal-dir:,help,config-file:,scratch-dir:,keep-temp-scratch-dir -n " $0 " -- " $@ " )
36+ if [ $? != 0 ] ; then echo " Failed parsing options." >&2 ; usage ; exit 1 ; fi
3037
3138# Process arguments
3239eval set -- " $OPTS "
@@ -45,6 +52,13 @@ while [ $# -gt 0 ]; do
4552 ARTIFACT_DIR=" $( realpath " $2 " ) "
4653 shift # past path
4754 ;;
55+ --scratch-dir)
56+ SCRATCH_DIR=" $( realpath " $2 " ) "
57+ shift # past path
58+ ;;
59+ --keep-temp-scratch-dir)
60+ KEEP_TEMP_SCRATCH_DIR=true
61+ ;;
4862 -v)
4963 VERBOSE=true
5064 ;;
@@ -76,6 +90,28 @@ if [ "$VERBOSE" = "true" ]; then
7690 echo -e " ${P_INFO} Using config file:${P_END} ${CONFIG_FILE} "
7791fi
7892
93+ if [ -z " ${SCRATCH_DIR+x} " ]; then
94+ SCRATCH_DIR=" $( mktemp -d) "
95+ if [ " $KEEP_TEMP_SCRATCH_DIR " != " true" ]; then
96+ function CleanupScratchDir() {
97+ rc=$?
98+ if [ " $VERBOSE " = " true" ]; then
99+ echo -e " "
100+ echo -e " ${P_INFO} Cleanup${P_END} "
101+ echo -e " ${P_INFO} =======${P_END} "
102+ echo -e " ${P_INFO} Deleting scratch directory:${P_END} ${SCRATCH_DIR} "
103+ fi
104+ rm -rf " ${SCRATCH_DIR} "
105+ exit $rc
106+ }
107+ trap CleanupScratchDir EXIT
108+ fi
109+ fi
110+
111+ profile_schematron=" oscal/src/utils/schematron/oscal-profile.sch"
112+ compiled_profile_schematron=" ${SCRATCH_DIR} /oscal-profile.xsl"
113+ build_schematron " ${profile_schematron} " " ${compiled_profile_schematron} "
114+
79115exitcode=0
80116shopt -s nullglob
81117shopt -s globstar
@@ -113,6 +149,21 @@ while IFS="|" read path format model converttoformats || [ -n "$path" ]; do
113149 else
114150 echo -e " ${P_OK} XML Schema validation passed for '${P_END}${file_relative}${P_OK} ' using schema '${P_END}${schema_relative}${P_OK} '.${P_END} "
115151 fi
152+
153+ if [ " ${model} " == " profile" ]; then
154+ echo -e " ${P_INFO} Validating profile with Schematron for project's requirements and recommendations.${P_INFO}${P_END} "
155+ target_file=$( basename -- " ${file_relative} " )
156+ svrl_result=" /tmp/${target_file} .svrl"
157+ result=$( validate_with_schematron " ${SCRATCH_DIR} /oscal-profile.xsl" " ${file_relative} " " $svrl_result " 2>&1 )
158+ cmd_exitcode=$?
159+ if [ $cmd_exitcode -ne 0 ]; then
160+ echo -e " ${P_ERROR} Profile validation execution for '${P_END}${file_relative}${P_ERROR} ' with Schematron '${P_END}${profile_schematron}${P_ERROR} ' did not complete.${P_END} "
161+ echo -e " ${P_ERROR}${result}${P_END} "
162+ exitcode=1
163+ else
164+ echo -e " ${P_OK} Profile validation execution for '${P_END}${file_relative}${P_OK} ' with Schematron '${P_END}${profile_schematron}${P_OK} ' completed successfully.${P_END} "
165+ fi
166+ fi
116167 ;;
117168 json)
118169 schema=" $WORKING_DIR /json/schema/oscal_${model} _schema.json"
0 commit comments