Skip to content
This repository has been archived by the owner on Dec 12, 2023. It is now read-only.

update shell and readme based on feedback #29

Merged
merged 35 commits into from
Nov 12, 2020
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
8dd88f7
flail
mike-stern Nov 5, 2020
28bfc18
try figuring out class invocation
Nov 5, 2020
be390a9
specify xsl as input
Nov 5, 2020
b7b4b0e
reexport saxon in following job step
Nov 5, 2020
0f12473
contextualize file reference
Nov 5, 2020
e3610a3
further qualified
Nov 5, 2020
5d2bcb0
missing slash
Nov 5, 2020
c14d21b
add debugging
Nov 5, 2020
65be44d
missed a subdir
Nov 5, 2020
e9245db
remove
Nov 5, 2020
c0e59ef
define report name
Nov 5, 2020
6bc2165
superfolus quote
Nov 5, 2020
76665d2
superfulous monkey bun
Nov 5, 2020
9cb3121
double slash issue
Nov 5, 2020
b125adb
proper qualify target
Nov 5, 2020
becaf66
barf
Nov 5, 2020
e9b9137
less incorrect parts
Nov 5, 2020
2a3adcb
avoid DS_Store
Nov 10, 2020
c36ef29
fix pathing for html report and java command
Nov 10, 2020
d3f511f
fix path in readme
Nov 10, 2020
68bf94b
add cache
Nov 10, 2020
2823fa2
add key with hash
Nov 10, 2020
520330e
debug
Nov 10, 2020
1f675ad
missing multi line continuance
Nov 10, 2020
4db2518
ignore jars in the lib directory
Nov 11, 2020
9138dc1
be more defensive of how to download saxon jar
Nov 11, 2020
460ff33
make instructions more clear with dependencies stated
Nov 11, 2020
4ae6768
Merge branch 'master' into tasks/issue-16
Nov 11, 2020
fdf9e9a
stylistic consistency changes, hard fail if no saxon specified or abi…
Nov 11, 2020
9463a5e
remove testing names
Nov 11, 2020
0ad9b3c
add command line argument processing rather than positional parameter…
Nov 11, 2020
75ec8dd
clarify options
Nov 12, 2020
2ae6aec
-h for usage instructions
Nov 12, 2020
1ab3e8d
intentionally allow globbing
Nov 12, 2020
882c48a
add safety checks that saxon jar is a file and it has the Trasform we…
Nov 12, 2020
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
33 changes: 26 additions & 7 deletions .github/workflows/runSchematronValidation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ jobs:
steps:
# Check-out the repository under $GITHUB_WORKSPACE
- uses: actions/checkout@v2

- name: Cache
uses: actions/cache@v2.1.3
with:
path: |
~/resources/validations/lib/
~/oscal/
/tmp/saxon/
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
ohsh6o marked this conversation as resolved.
Show resolved Hide resolved

# Check-out submodules
- name: Checkout submodules
Expand All @@ -45,6 +54,7 @@ jobs:
# convert schematron to xsl and validate file with converted xsl
- name: Convert to XSL
run: |
export SAXON_CP=/tmp/saxon/Saxon-HE-10.2.jar
echo "convert to xsl"
# compute name without .sch
qualifiedSchematronName=${{ github.event.inputs.schematronFileName }}
Expand All @@ -55,16 +65,25 @@ jobs:
schematronRoot=${schematronName%.*}
echo "schematronRoot: ${schematronRoot}"
echo "schematron code ${{ github.workspace }}/resources/validations/lib/schematron/trunk/schematron/code/iso_svrl_for_xslt2.xsl"
mkdir /tmp/target
rm -rf /tmp/target/*.xsl;
`java -cp ${SAXON_CP} net.sf.saxon.Transform -o:/tmp/target/${schematronRoot}.xsl -s:${{ github.workspace }}${qualifiedSchematronName} ${{ github.workspace }}/resources/validations/lib/schematron/trunk/schematron/code/iso_svrl_for_xslt2.xsl`

rm -rf ${{ github.workspace }}/resources/validations/target/*.xsl

java -cp ${SAXON_CP} net.sf.saxon.Transform \
-o:"${{ github.workspace }}/resources/validations/target/${schematronRoot}".xsl \
-s:"${{ github.workspace }}/${qualifiedSchematronName}" \
${{ github.workspace }}/resources/validations/lib/schematron/trunk/schematron/code/iso_svrl_for_xslt2.xsl \
allow-foreign=true
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we going to parameterize this like the script?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, we will eventually just call the .sh as you suggested when we paired


reportName=${{ github.workspace }}/resources/validations/report/schematron${{ github.event.inputs.DOC_TO_VALIDATE }}__${schematronRoot}.results.xml

echo "delete pre-existing SVRL and HTML results"
rm -rf "${reportName}" "${htmlReportName}"

echo "validating doc: ${{ github.event.inputs.DOC_TO_VALIDATE }} with ${qualifiedSchematronName} output found in ${reportName}"
echo source
echo `ls -ltr ${{ github.workspace }}${{ github.event.inputs.DOC_TO_VALIDATE }}`

java -cp "${SAXON_CP}" net.sf.saxon.Transform \
-o:"${reportName}" -s:"${{ github.workspace }}/${{ github.event.inputs.DOC_TO_VALIDATE }}" \
target/"${schematronRoot}".xsl \
allow-foreign=true
-o:${reportName} \
-s:${{ github.workspace }}${{ github.event.inputs.DOC_TO_VALIDATE }} \
${{ github.workspace }}/resources/validations/target/${schematronRoot}.xsl \
allow-foreign=true
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ utils

resources/validations/src/ssp.xsl
resources/validations/report
resources/validations/target
resources/validations/target
*.DS_Store
resources/validations/lib/**.jar
21 changes: 17 additions & 4 deletions resources/validations/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,36 @@ project structure
To validate xml files using schematron
---

example
*Prerequesite
if you haven't done it previously: to add the needed dependencies (declared by .gitmodules), run the following:*

`-f` *\<required>* is the input file to be tested. ex: `-f test/demo/FedRAMP-SSP-OSCAL-Template.xml`

`./validate_with_schematron.sh test/demo/FedRAMP-SSP-OSCAL-Template.xml`
`-s` *\<optional>* schematron directory used to validate the file. Each .sch found will be compliled and generate a separate report. defaults to src/*.sch relative to this script. ex: `-o ~/mySchematronDirectory`
mike-stern marked this conversation as resolved.
Show resolved Hide resolved

you must pass in a file name you want validated as argument `$1`. by default it will compile and validate the input with all `src/*.sch` files.
`-o` *\<optional>* is an the root of the report output. ex: `-o ~/dev`

if you wish to override the default version (currently 10.2) of `SAXON HE`, you may pass it as the argument `$2`
`-v` *\<optional>* if you wish to override the default version (currently 10.2) of `SAXON HE`, that is downloaded and used if $SAXON_CP is not specified. ex: `-v 10.2.2`
mike-stern marked this conversation as resolved.
Show resolved Hide resolved

example

`./bin/validate_with_schematron.sh -f test/demo/FedRAMP-SSP-OSCAL-Template.xml -o ~/dev -v 10.2.2`

To Run Tests
---

*Prerequesite
if you haven't done it previously: to add the needed dependencies (declared by .gitmodules), run the following:*

`git submodule update --init --recursive`

```sh
cd /path/to/fedramp-automation/resources/validations
#if you have a preferred version of a saxon jar downloaded export SAXON_CP as so
export SAXON_CP=yourpath/Saxon-HE-X.Y.Z.jar
#set the test directory relative to project path, you may change if you prefer somehere else
export TEST_DIR=$(pwd)/report/test
#execute xpec with the test harness that runs all tests
lib/xspec/bin/xspec.sh -s -j test/test_all.xspec
```

Expand Down
103 changes: 80 additions & 23 deletions resources/validations/bin/validate_with_schematron.sh
Original file line number Diff line number Diff line change
@@ -1,69 +1,126 @@
#!/usr/bin/env bash

set -o pipefail

if [ ! -e "$1" ]; then
# output root defaults to report folder relative to this script
OUTPUT_ROOT="report/schematron"
# schematron directory validate the file with each .sch found defaults to src/*.sch relative to this script
SCHEMA_LOCATION_DIR="src"
##
## options ###################################################################
##
while echo "$1" | grep -- ^- > /dev/null 2>&1; do
case "$1" in
# input file to validate
-f)
shift
DOC_TO_VALIDATE="$1"
;;
# saxon version
-v)
if test -n "$SAXON_CP"; then
echo "SAXON_CP is set to ${SAXON_CP} as an environment variable setting version using -v is invalid"
exit 1
else
shift
SAXON_VERSION="$1"
fi
;;
# schema directory location
-s)
shift
SCHEMA_LOCATION_DIR="$1"
;;
# output directory root
-o)
shift
OUTPUT_ROOT="$1"
;;
# Unknown option!
-*)
usage "Error: Unknown option: $1"
exit 1
;;
mike-stern marked this conversation as resolved.
Show resolved Hide resolved
esac
shift
done

echo output dir "${OUTPUT_ROOT}"
echo to val "$DOC_TO_VALIDATE";
if test ! -e "$DOC_TO_VALIDATE" ; then
echo "no file input for report, exiting"
exit 1
else
echo "doc requested to be validated: ${DOC_TO_VALIDATE}"
fi
DOC_TO_VALIDATE="$1"
echo "doc requested to be validated: ${DOC_TO_VALIDATE}"

# Delete pre-existing XSLT report
rm -rf target/*.xsl;

SAXON_VERSION=$2
#if version not specified default
SAXON_VERSION=${SAXON_VERSION:-10.2}
SAXON_OPTS="${SAXON_OPTS:-allow-foreign=true}"

echo "using saxon version ${SAXON_VERSION}"

mvn -q org.apache.maven.plugins:maven-dependency-plugin:2.1:get \
-DrepoUrl=https://mvnrepository.com/ \
-DartifactId=Saxon-HE \
-DgroupId=net.sf.saxon \
-Dversion="${SAXON_VERSION}"
saxonLocation=saxon/Saxon-HE/"${SAXON_VERSION}"/Saxon-HE-"${SAXON_VERSION}".jar
if test -n "$SAXON_CP" ; then
echo SAXON_CP env variable used is "${SAXON_CP}"
elif command -v mvn &> /dev/null ;then
mvn -q org.apache.maven.plugins:maven-dependency-plugin:2.1:get \
-DrepoUrl=https://mvnrepository.com/ \
-DartifactId=Saxon-HE \
-DgroupId=net.sf.saxon \
-Dversion="${SAXON_VERSION}"
SAXON_CP=~/.m2/repository/net/sf/${saxonLocation}
elif command -v curl &> /dev/null; then
SAXON_CP=lib/Saxon-HE-"${SAXON_VERSION}".jar
mike-stern marked this conversation as resolved.
Show resolved Hide resolved
curl -H "Accept: application/zip" -o "${SAXON_CP}" https://repo1.maven.org/maven2/net/sf/"${saxonLocation}"
else
echo "SAXON_CP environment variable is not set. mvn or curl is required to download dependencies, neither found, please install one and retry"
exit 1
fi

# Delete pre-existing SVRL report
rm -rf report/schematron/*.results.xml
rm -rf "${OUTPUT_ROOT}/report/schematron/*.results.xml"
rm -rf "${OUTPUT_ROOT}/report/schematron/*.results.html"

for qualifiedSchematronName in src/*.sch; do
#in the future replace the for loop with an optional passed in directory or single schema file -f
for qualifiedSchematronName in "${SCHEMA_LOCATION_DIR}"/*.sch; do
[ -e "${qualifiedSchematronName}" ] || continue

# compute name without .sch
schematronName=${qualifiedSchematronName##*/}
schematronRoot=${schematronName%.*}

# Use Saxon XSL transform to convert our Schematron to pure XSL 2.0 stylesheet
saxon_jar=~/.m2/repository/net/sf/saxon/Saxon-HE/"${SAXON_VERSION}"/Saxon-HE-"${SAXON_VERSION}".jar

java -cp "${saxon_jar}" net.sf.saxon.Transform \
java -cp "${SAXON_CP}" net.sf.saxon.Transform \
-o:target/"${schematronRoot}".xsl \
-s:"${qualifiedSchematronName}" \
lib/schematron/trunk/schematron/code/iso_svrl_for_xslt2.xsl \
$SAXON_OPTS
"$SAXON_OPTS"
mike-stern marked this conversation as resolved.
Show resolved Hide resolved

echo "compiling: ${qualifiedSchematronName} to: target/${schematronRoot}.xsl"

# Use Saxon XSL transform to use XSL-ified Schematron rules to analyze full FedRAMP-SSP-OSCAL template
# and dump the result into reports.
reportName="report/schematron/${DOC_TO_VALIDATE}__${schematronRoot}.results.xml"
htmlReportName="report/html/${DOC_TO_VALIDATE}__${schematronRoot}.results.html"
reportName="${OUTPUT_ROOT}/${DOC_TO_VALIDATE}__${schematronRoot}.results.xml"
htmlReportName="${OUTPUT_ROOT}/${DOC_TO_VALIDATE}__${schematronRoot}.results.html"

echo "delete pre-existing SVRL and HTML results"
rm -rf "${reportName}" "${htmlReportName}"

echo "validating doc: ${DOC_TO_VALIDATE} with ${qualifiedSchematronName} output found in ${reportName}"

java -cp "${saxon_jar}" net.sf.saxon.Transform \
-o:"${reportName}" -s:"${DOC_TO_VALIDATE}" \
java -cp "${SAXON_CP}" net.sf.saxon.Transform \
-o:"${reportName}" \
-s:"${DOC_TO_VALIDATE}" \
target/"${schematronRoot}".xsl \
$SAXON_OPTS
"$SAXON_OPTS"
mike-stern marked this conversation as resolved.
Show resolved Hide resolved

java -cp "${saxon_jar}" net.sf.saxon.Transform \
java -cp "${SAXON_CP}" net.sf.saxon.Transform \
-o:"${htmlReportName}" \
-s:"${reportName}" \
lib/svrl2html.xsl \
$SAXON_OPTS
"$SAXON_OPTS"
mike-stern marked this conversation as resolved.
Show resolved Hide resolved

done