#!/bin/sh

# Insert annotations (from an annotation file) into a class file.
# For usage information, run: insert-annotations --help
# See the Annotation File Utilities documentation for more information.

# A few options are consumed by this script rather than being passed to the
# underlying Java program.  They must be the first command-line arguments
# provided.
DEBUG=0
# CLASSPATH=${CLASSPATH}
while [ "$#" -gt 0 ]; do
  case "$1" in
    --debug-script)
      # Debug this script
      DEBUG=1
      shift
      ;;
    -cp | -classpath)
      # Set the classpath
      CLASSPATH=$2
      shift 2
      ;;
    *)
      break
      ;;
  esac
done

AFU=${AFU:-$(dirname "$0")/..}
ANNOTATION_FILE_UTILS="${AFU}/dist/annotation-file-utilities-all.jar"

if [ "$DEBUG" = "1" ]; then
  echo "--- start of insert-annotations debugging output"
  echo "AFU=${AFU}"
  echo "ANNOTATION_FILE_UTILS=${ANNOTATION_FILE_UTILS}"
  # Keep this in sync with the actual command below.
  echo "java -ea -cp ${ANNOTATION_FILE_UTILS}:${CLASSPATH} org.checkerframework.afu.scenelib.io.classfile.ClassFileWriter" "$@"
  echo "--- end of insert-annotations debugging output"
fi

# Needs CLASSPATH to find user files
java -ea -cp "${ANNOTATION_FILE_UTILS}:${CLASSPATH}" org.checkerframework.afu.scenelib.io.classfile.ClassFileWriter "$@"
