src/Tools/jEdit/lib/Tools/jedit
author wenzelm
Fri Nov 30 21:30:24 2012 +0100 (2012-11-30)
changeset 50299 f70b3712040f
parent 50208 1382ad6d4774
child 50306 b655d2d0406d
permissions -rwxr-xr-x
renamed dockable "Prover Session" to "Theories";
more uniform Library.lowercase/uppercase;
     1 #!/usr/bin/env bash
     2 #
     3 # Author: Makarius
     4 #
     5 # DESCRIPTION: Isabelle/jEdit interface wrapper
     6 
     7 
     8 ## sources
     9 
    10 declare -a SOURCES=(
    11   "src/dockable.scala"
    12   "src/document_model.scala"
    13   "src/document_view.scala"
    14   "src/graphview_dockable.scala"
    15   "src/html_panel.scala"
    16   "src/hyperlink.scala"
    17   "src/info_dockable.scala"
    18   "src/isabelle.scala"
    19   "src/isabelle_encoding.scala"
    20   "src/isabelle_logic.scala"
    21   "src/isabelle_options.scala"
    22   "src/isabelle_sidekick.scala"
    23   "src/jedit_lib.scala"
    24   "src/jedit_main.scala"
    25   "src/jedit_options.scala"
    26   "src/jedit_thy_load.scala"
    27   "src/output_dockable.scala"
    28   "src/plugin.scala"
    29   "src/pretty_text_area.scala"
    30   "src/pretty_tooltip.scala"
    31   "src/protocol_dockable.scala"
    32   "src/raw_output_dockable.scala"
    33   "src/readme_dockable.scala"
    34   "src/rendering.scala"
    35   "src/rich_text_area.scala"
    36   "src/scala_console.scala"
    37   "src/sendback.scala"
    38   "src/symbols_dockable.scala"
    39   "src/syslog_dockable.scala"
    40   "src/text_overview.scala"
    41   "src/theories_dockable.scala"
    42   "src/token_markup.scala"
    43 )
    44 
    45 declare -a RESOURCES=(
    46   "src/actions.xml"
    47   "src/dockables.xml"
    48   "src/Isabelle.props"
    49   "src/services.xml"
    50 )
    51 
    52 
    53 ## diagnostics
    54 
    55 PRG="$(basename "$0")"
    56 
    57 function usage()
    58 {
    59   echo
    60   echo "Usage: isabelle $PRG [OPTIONS] [FILES ...]"
    61   echo
    62   echo "  Options are:"
    63   echo "    -J OPTION    add JVM runtime option"
    64   echo "                 (default JEDIT_JAVA_OPTIONS=$JEDIT_JAVA_OPTIONS)"
    65   echo "    -b           build only"
    66   echo "    -d DIR       include session directory"
    67   echo "    -f           fresh build"
    68   echo "    -j OPTION    add jEdit runtime option"
    69   echo "                 (default JEDIT_OPTIONS=$JEDIT_OPTIONS)"
    70   echo "    -l NAME      logic image name (default ISABELLE_LOGIC=$ISABELLE_LOGIC)"
    71   echo "    -m MODE      add print mode for output"
    72   echo
    73   echo "Start jEdit with Isabelle plugin setup and opens theory FILES"
    74   echo "(default \"$USER_HOME/Scratch.thy\")."
    75   echo
    76   exit 1
    77 }
    78 
    79 function fail()
    80 {
    81   echo "$1" >&2
    82   exit 2
    83 }
    84 
    85 function failed()
    86 {
    87   fail "Failed!"
    88 }
    89 
    90 
    91 ## process command line
    92 
    93 # options
    94 
    95 BUILD_ONLY=false
    96 BUILD_JARS="jars"
    97 JEDIT_SESSION_DIRS=""
    98 JEDIT_LOGIC="$ISABELLE_LOGIC"
    99 JEDIT_PRINT_MODE=""
   100 
   101 function getoptions()
   102 {
   103   OPTIND=1
   104   while getopts "J:bd:fj:l:m:" OPT
   105   do
   106     case "$OPT" in
   107       J)
   108         JAVA_ARGS["${#JAVA_ARGS[@]}"]="$OPTARG"
   109         ;;
   110       b)
   111         BUILD_ONLY=true
   112         ;;
   113       d)
   114         if [ -z "$JEDIT_SESSION_DIRS" ]; then
   115           JEDIT_SESSION_DIRS="$OPTARG"
   116         else
   117           JEDIT_SESSION_DIRS="$JEDIT_SESSION_DIRS:$OPTARG"
   118         fi
   119         ;;
   120       f)
   121         BUILD_JARS="jars_fresh"
   122         ;;
   123       j)
   124         ARGS["${#ARGS[@]}"]="$OPTARG"
   125         ;;
   126       l)
   127         JEDIT_LOGIC="$OPTARG"
   128         ;;
   129       m)
   130         if [ -z "$JEDIT_PRINT_MODE" ]; then
   131           JEDIT_PRINT_MODE="$OPTARG"
   132         else
   133           JEDIT_PRINT_MODE="$JEDIT_PRINT_MODE,$OPTARG"
   134         fi
   135         ;;
   136       \?)
   137         usage
   138         ;;
   139     esac
   140   done
   141 }
   142 
   143 declare -a JAVA_ARGS; eval "JAVA_ARGS=($JEDIT_JAVA_OPTIONS $JEDIT_SYSTEM_OPTIONS)"
   144 [ -n "$SCALA_HOME" ] && JAVA_ARGS["${#JAVA_ARGS[@]}"]="-Dscala.home=$SCALA_HOME"
   145 
   146 declare -a ARGS; eval "ARGS=($JEDIT_OPTIONS)"
   147 
   148 declare -a OPTIONS; eval "OPTIONS=($ISABELLE_JEDIT_OPTIONS)"
   149 getoptions "${OPTIONS[@]}"
   150 
   151 getoptions "$@"
   152 shift $(($OPTIND - 1))
   153 
   154 
   155 # args
   156 
   157 if [ "$#" -eq 0 ]; then
   158   ARGS["${#ARGS[@]}"]="$(jvmpath "$USER_HOME/Scratch.thy")"
   159 else
   160   while [ "$#" -gt 0 ]; do
   161     ARGS["${#ARGS[@]}"]="$(jvmpath "$1")"
   162     shift
   163   done
   164 fi
   165 
   166 
   167 ## dependencies
   168 
   169 if [ -e "$ISABELLE_HOME/Admin/build" ]; then
   170   if [ "$BUILD_JARS" = jars_fresh ]; then
   171     "$ISABELLE_TOOL" graphview -b -f || exit $?
   172   else
   173     "$ISABELLE_HOME/Admin/build" "$BUILD_JARS" || exit $?
   174     "$ISABELLE_TOOL" graphview -b || exit $?
   175   fi
   176 fi
   177 
   178 PURE_JAR="$ISABELLE_HOME/lib/classes/ext/Pure.jar"
   179 GRAPHVIEW_JAR="$ISABELLE_HOME/lib/classes/ext/Graphview.jar"
   180 
   181 pushd "$JEDIT_HOME" >/dev/null || failed
   182 
   183 JEDIT_JAR="$ISABELLE_JEDIT_BUILD_HOME/contrib/$ISABELLE_JEDIT_BUILD_VERSION/jedit.jar"
   184 
   185 JEDIT_JARS=(
   186   "$ISABELLE_JEDIT_BUILD_HOME/contrib/Console.jar"
   187   "$ISABELLE_JEDIT_BUILD_HOME/contrib/ErrorList.jar"
   188   "$ISABELLE_JEDIT_BUILD_HOME/contrib/SideKick.jar"
   189   "$ISABELLE_JEDIT_BUILD_HOME/contrib/cobra.jar"
   190   "$ISABELLE_JEDIT_BUILD_HOME/contrib/js.jar"
   191 )
   192 
   193 
   194 # target
   195 
   196 TARGET="dist/jars/Isabelle-jEdit.jar"
   197 
   198 declare -a UPDATED=()
   199 
   200 if [ "$BUILD_JARS" = jars_fresh ]; then
   201   OUTDATED=true
   202 else
   203   OUTDATED=false
   204   if [ ! -e "$TARGET" ]; then
   205     OUTDATED=true
   206   else
   207     if [ -n "$ISABELLE_JEDIT_BUILD_HOME" ]; then
   208       declare -a DEPS=(
   209         "$JEDIT_JAR" "${JEDIT_JARS[@]}"
   210         "$PURE_JAR" "$GRAPHVIEW_JAR" "${SOURCES[@]}" "${RESOURCES[@]}"
   211       )
   212     elif [ -e "$ISABELLE_HOME/Admin/build" ]; then
   213       declare -a DEPS=("$PURE_JAR" "$GRAPHVIEW_JAR" "${SOURCES[@]}" "${RESOURCES[@]}")
   214     else
   215       declare -a DEPS=()
   216     fi
   217     for DEP in "${DEPS[@]}"
   218     do
   219       [ ! -e "$DEP" ] && fail "Missing file: $DEP"
   220       [ "$DEP" -nt "$TARGET" ] && {
   221         OUTDATED=true
   222         UPDATED["${#UPDATED[@]}"]="$DEP"
   223       }
   224     done
   225   fi
   226 fi
   227 
   228 
   229 # build
   230 
   231 if [ "$OUTDATED" = true ]
   232 then
   233   echo "### Building Isabelle/jEdit ..."
   234 
   235   [ "${#UPDATED[@]}" -gt 0 ] && {
   236     echo "Changed files:"
   237     for FILE in "${UPDATED[@]}"
   238     do
   239       echo "  $FILE"
   240     done
   241   }
   242 
   243   [ -z "$ISABELLE_JEDIT_BUILD_HOME" ] && \
   244     fail "Unknown ISABELLE_JEDIT_BUILD_HOME -- missing auxiliary component"
   245 
   246   rm -rf dist || failed
   247   mkdir -p dist dist/classes || failed
   248 
   249   cp -p -R -f "$ISABELLE_JEDIT_BUILD_HOME/contrib/$ISABELLE_JEDIT_BUILD_VERSION/." dist/.
   250   cp -p -R -f "${RESOURCES[@]}" dist/classes/.
   251   cp src/jEdit.props dist/properties/.
   252   cp -p -R -f src/modes/. dist/modes/.
   253 
   254   perl -i -e 'while (<>) {
   255     if (m/NAME="javacc"/) {
   256       print qq,<MODE NAME="isabelle" FILE="isabelle.xml" FILE_NAME_GLOB="*.thy"/>\n\n,;
   257       print qq,<MODE NAME="isabelle-options" FILE="isabelle-options.xml"/>\n\n,;
   258       print qq,<MODE NAME="isabelle-root" FILE="isabelle-root.xml" FILE_NAME_GLOB="ROOT"/>\n\n,; }
   259     elsif (m/NAME="scheme"/) {
   260       print qq,<MODE NAME="scala" FILE="scala.xml" FILE_NAME_GLOB="*.scala" />\n\n,; }
   261     print; }' dist/modes/catalog
   262 
   263   cp -p -R -f "${JEDIT_JARS[@]}" dist/jars/. || failed
   264   (
   265     for JAR in "$JEDIT_JAR" "${JEDIT_JARS[@]}" "$PURE_JAR" "$GRAPHVIEW_JAR" \
   266       "$SCALA_HOME/lib/scala-compiler.jar"
   267     do
   268       CLASSPATH="$CLASSPATH:$JAR"
   269     done
   270     CLASSPATH="$(jvmpath "$CLASSPATH")"
   271     exec "$SCALA_HOME/bin/scalac" $ISABELLE_SCALA_BUILD_OPTIONS -d dist/classes "${SOURCES[@]}"
   272   ) || fail "Failed to compile sources"
   273 
   274   cd dist/classes
   275   isabelle_jdk jar cf "../jars/Isabelle-jEdit.jar" * || failed
   276   cd ../..
   277   rm -rf dist/classes
   278 fi
   279 
   280 popd >/dev/null
   281 
   282 
   283 ## main
   284 
   285 # perspective
   286 
   287 mkdir -p "$JEDIT_SETTINGS/DockableWindowManager"
   288 
   289 if [ ! -e "$JEDIT_SETTINGS/perspective.xml" ]; then
   290   cat > "$JEDIT_SETTINGS/DockableWindowManager/perspective-view0.xml" <<EOF
   291 <DOCKING LEFT="" TOP="" RIGHT="" BOTTOM="isabelle-readme" LEFT_POS="0" TOP_POS="0" RIGHT_POS="250" BOTTOM_POS="250" />
   292 EOF
   293   cat > "$JEDIT_SETTINGS/perspective.xml" <<EOF
   294 <?xml version="1.0" encoding="UTF-8" ?>
   295 <!DOCTYPE PERSPECTIVE SYSTEM "perspective.dtd">
   296 <PERSPECTIVE>
   297 <VIEW PLAIN="FALSE">
   298 <GEOMETRY X="0" Y="35" WIDTH="1072" HEIGHT="787" EXT_STATE="0" />
   299 </VIEW>
   300 </PERSPECTIVE>
   301 EOF
   302 fi
   303 
   304 
   305 # run
   306 
   307 [ "$BUILD_ONLY" = true ] || {
   308   case "$JEDIT_LOGIC" in
   309     /*)
   310       ;;
   311     */*)
   312       JEDIT_LOGIC="$(pwd -P)/$JEDIT_LOGIC"
   313       ;;
   314   esac
   315 
   316   export JEDIT_SESSION_DIRS JEDIT_LOGIC JEDIT_PRINT_MODE
   317 
   318   exec "$ISABELLE_TOOL" java "${JAVA_ARGS[@]}" \
   319     -jar "$(jvmpath "$JEDIT_HOME/dist/jedit.jar")" \
   320     "-settings=$(jvmpath "$JEDIT_SETTINGS")" "${ARGS[@]}"
   321 }