From 539e209bd5e6212cb495f048608c6de26abca614 Mon Sep 17 00:00:00 2001 From: Nicolas-Peiffer <102670102+Nicolas-Peiffer@users.noreply.github.com> Date: Thu, 29 Aug 2024 14:51:57 +0200 Subject: [PATCH] XML Schema HTML viewer now supports runing for only one version at a time Signed-off-by: Nicolas-Peiffer <102670102+Nicolas-Peiffer@users.noreply.github.com> --- docgen/xml/gen.sh | 69 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 61 insertions(+), 8 deletions(-) diff --git a/docgen/xml/gen.sh b/docgen/xml/gen.sh index 8a45597c..053c4191 100755 --- a/docgen/xml/gen.sh +++ b/docgen/xml/gen.sh @@ -5,19 +5,45 @@ THIS_PATH="$(realpath "$(dirname "$0")")" SCHEMA_PATH="$(realpath "$THIS_PATH/../../schema")" DOCS_PATH="$THIS_PATH/docs" +VALID_CYCLONEDX_VERSIONS=(1.0 1.1 1.2 1.3 1.4 1.5 1.6) +DRAFT_CYCLONEDX_VERSIONS=() + SAXON_JAR='Saxon-HE-9.9.1-8.jar' -rm -f -R docs +# Download the Saxon JAR if it doesn't exist if [ ! -f "$THIS_PATH/$SAXON_JAR" ]; then curl --output-dir "$THIS_PATH" -O \ "https://repo1.maven.org/maven2/net/sf/saxon/Saxon-HE/9.9.1-8/$SAXON_JAR" fi +# Function to check if a version is in an array +version_in_list() { + local version="$1" + shift + local list=("$@") + for item in "${list[@]}"; do + if [[ "$item" == "$version" ]]; then + return 0 + fi + done + return 1 +} + generate () { version="$1" + + # Check if the version match a valid CycloneDX version or a draft under development + if ! version_in_list "$version" "${VALID_CYCLONEDX_VERSIONS[@]}" && ! version_in_list "$version" "${DRAFT_CYCLONEDX_VERSIONS[@]}"; then + echo "Failed: wrong CycloneDX version: $version" + exit 1 + fi + title="CycloneDX v$version XML Reference" echo "Generating: $title" + echo "Create folder $DOCS_PATH/$version" + mkdir -p "$DOCS_PATH/$version" + java -jar "$THIS_PATH/$SAXON_JAR" \ -s:"$SCHEMA_PATH/bom-${version}.xsd" \ -xsl:"$THIS_PATH/xs3p.xsl" \ @@ -26,10 +52,37 @@ generate () { title="$title" } -generate 1.0 -generate 1.1 -generate 1.2 -generate 1.3 -generate 1.4 -generate 1.5 -generate 1.6 +USAGE_HELP="Generate HTML XML Schema navigator for CyccloneDX +Usage: $0 : runs only for + $0 : loops over all valid and draft CycloneDX versions" + +# Main logic to handle the argument using a switch case +case "$#" in + 0) + # No arguments provided: Loop over all VALID_CYCLONEDX_VERSIONS and DRAFT_CYCLONEDX_VERSIONS + echo "Deleting folder $DOCS_PATH" + rm -f -R "$DOCS_PATH" + for version in "${VALID_CYCLONEDX_VERSIONS[@]}" "${DRAFT_CYCLONEDX_VERSIONS[@]}"; do + generate "$version" + done + ;; + 1) + case "$1" in + "-h"|"--help") + echo "Usage: $USAGE_HELP" + exit 1 + ;; + *) + # One argument provided: Call generate with the specific version + echo "Deleting folder $DOCS_PATH" + rm -f -R "$DOCS_PATH" + generate "$1" + ;; + esac + ;; + *) + # More than one argument provided: Show usage help + echo "Usage: $USAGE_HELP" + exit 1 + ;; +esac