src/Tools/jEdit/lib/Tools/jedit
author wenzelm
Mon Oct 17 11:24:22 2011 +0200 (2011-10-17 ago)
changeset 45158 db4bf4fb5492
parent 45069 981098cdbb3f
child 45665 129db1416717
permissions -rwxr-xr-x
always use sockets on Windows/Cygwin;
discontinued special raw_dump facility;
     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/html_panel.scala"
    15   "src/isabelle_encoding.scala"
    16   "src/isabelle_hyperlinks.scala"
    17   "src/isabelle_markup.scala"
    18   "src/isabelle_options.scala"
    19   "src/isabelle_sidekick.scala"
    20   "src/jedit_thy_load.scala"
    21   "src/output_dockable.scala"
    22   "src/plugin.scala"
    23   "src/protocol_dockable.scala"
    24   "src/raw_output_dockable.scala"
    25   "src/scala_console.scala"
    26   "src/session_dockable.scala"
    27   "src/text_area_painter.scala"
    28   "src/token_markup.scala"
    29 )
    30 
    31 declare -a RESOURCES=(
    32   "src/actions.xml"
    33   "src/dockables.xml"
    34   "src/Isabelle.props"
    35   "src/services.xml"
    36 )
    37 
    38 
    39 ## diagnostics
    40 
    41 PRG="$(basename "$0")"
    42 
    43 function usage()
    44 {
    45   echo
    46   echo "Usage: isabelle $PRG [OPTIONS] [FILES ...]"
    47   echo
    48   echo "  Options are:"
    49   echo "    -J OPTION    add JVM runtime option"
    50   echo "                 (default JEDIT_JAVA_OPTIONS=$JEDIT_JAVA_OPTIONS)"
    51   echo "    -b           build only"
    52   echo "    -d           enable debugger"
    53   echo "    -f           fresh build"
    54   echo "    -j OPTION    add jEdit runtime option"
    55   echo "                 (default JEDIT_OPTIONS=$JEDIT_OPTIONS)"
    56   echo "    -l NAME      logic image name (default ISABELLE_LOGIC=$ISABELLE_LOGIC)"
    57   echo "    -m MODE      add print mode for output"
    58   echo
    59   echo "Start jEdit with Isabelle plugin setup and opens theory FILES"
    60   echo "(default Scratch.thy)."
    61   echo
    62   exit 1
    63 }
    64 
    65 function fail()
    66 {
    67   echo "$1" >&2
    68   exit 2
    69 }
    70 
    71 function failed()
    72 {
    73   fail "Failed!"
    74 }
    75 
    76 
    77 ## process command line
    78 
    79 # options
    80 
    81 BUILD_ONLY=false
    82 BUILD_JARS="jars"
    83 JEDIT_LOGIC="$ISABELLE_LOGIC"
    84 JEDIT_PRINT_MODE=""
    85 
    86 function getoptions()
    87 {
    88   OPTIND=1
    89   while getopts "J:bdfj:l:m:" OPT
    90   do
    91     case "$OPT" in
    92       J)
    93         JAVA_ARGS["${#JAVA_ARGS[@]}"]="$OPTARG"
    94         ;;
    95       b)
    96         BUILD_ONLY=true
    97         ;;
    98       d)
    99         JAVA_ARGS["${#JAVA_ARGS[@]}"]="-Xdebug"
   100         JAVA_ARGS["${#JAVA_ARGS[@]}"]="-Xrunjdwp:transport=dt_socket,server=y,suspend=n"
   101         ;;
   102       f)
   103         BUILD_JARS="jars_fresh"
   104         ;;
   105       j)
   106         ARGS["${#ARGS[@]}"]="$OPTARG"
   107         ;;
   108       l)
   109         JEDIT_LOGIC="$OPTARG"
   110         ;;
   111       m)
   112         if [ -z "$JEDIT_PRINT_MODE" ]; then
   113           JEDIT_PRINT_MODE="$OPTARG"
   114         else
   115           JEDIT_PRINT_MODE="$JEDIT_PRINT_MODE,$OPTARG"
   116         fi
   117         ;;
   118       \?)
   119         usage
   120         ;;
   121     esac
   122   done
   123 }
   124 
   125 declare -a JAVA_ARGS; eval "JAVA_ARGS=($JEDIT_JAVA_OPTIONS $JEDIT_SYSTEM_OPTIONS)"
   126 [ -n "$SCALA_HOME" ] && JAVA_ARGS["${#JAVA_ARGS[@]}"]="-Dscala.home=$SCALA_HOME"
   127 
   128 declare -a ARGS; eval "ARGS=($JEDIT_OPTIONS)"
   129 
   130 declare -a OPTIONS; eval "OPTIONS=($ISABELLE_JEDIT_OPTIONS)"
   131 getoptions "${OPTIONS[@]}"
   132 
   133 getoptions "$@"
   134 shift $(($OPTIND - 1))
   135 
   136 
   137 # args
   138 
   139 if [ "$#" -eq 0 ]; then
   140   ARGS["${#ARGS[@]}"]="Scratch.thy"
   141 else
   142   while [ "$#" -gt 0 ]; do
   143     ARGS["${#ARGS[@]}"]="$(jvmpath "$1")"
   144     shift
   145   done
   146 fi
   147 
   148 
   149 ## dependencies
   150 
   151 [ -e "$ISABELLE_HOME/Admin/build" ] && \
   152   { "$ISABELLE_HOME/Admin/build" "$BUILD_JARS" || exit $?; }
   153 
   154 PURE_JAR="$ISABELLE_HOME/lib/classes/ext/Pure.jar"
   155 
   156 pushd "$JEDIT_HOME" >/dev/null || failed
   157 
   158 JEDIT_JAR="$ISABELLE_JEDIT_BUILD_HOME/contrib/$ISABELLE_JEDIT_BUILD_VERSION/jedit.jar"
   159 
   160 JEDIT_JARS=(
   161   "$ISABELLE_JEDIT_BUILD_HOME/contrib/Console.jar"
   162   "$ISABELLE_JEDIT_BUILD_HOME/contrib/ErrorList.jar"
   163   "$ISABELLE_JEDIT_BUILD_HOME/contrib/Hyperlinks.jar"
   164   "$ISABELLE_JEDIT_BUILD_HOME/contrib/SideKick.jar"
   165   "$ISABELLE_JEDIT_BUILD_HOME/contrib/cobra.jar"
   166   "$ISABELLE_JEDIT_BUILD_HOME/contrib/js.jar"
   167 )
   168 
   169 SCALA_JARS=(
   170   "$SCALA_HOME/lib/scala-compiler.jar"
   171   "$SCALA_HOME/lib/scala-library.jar"
   172   "$SCALA_HOME/lib/scala-swing.jar"
   173 )
   174 
   175 
   176 # target
   177 
   178 TARGET="dist/jars/Isabelle-jEdit.jar"
   179 
   180 declare -a UPDATED=()
   181 
   182 if [ "$BUILD_JARS" = jars_fresh ]; then
   183   OUTDATED=true
   184 else
   185   OUTDATED=false
   186   if [ ! -e "$TARGET" ]; then
   187     OUTDATED=true
   188   else
   189     if [ -n "$ISABELLE_JEDIT_BUILD_HOME" ]; then
   190       declare -a DEPS=("$JEDIT_JAR" "${JEDIT_JARS[@]}" "$PURE_JAR" "${SOURCES[@]}" "${RESOURCES[@]}")
   191     else
   192       declare -a DEPS=("$PURE_JAR" "${SOURCES[@]}" "${RESOURCES[@]}")
   193     fi
   194     for DEP in "${DEPS[@]}"
   195     do
   196       [ ! -e "$DEP" ] && fail "Missing file: $DEP"
   197       [ "$DEP" -nt "$TARGET" ] && {
   198         OUTDATED=true
   199         UPDATED["${#UPDATED[@]}"]="$DEP"
   200       }
   201     done
   202   fi
   203 fi
   204 
   205 
   206 # build
   207 
   208 if [ "$OUTDATED" = true ]
   209 then
   210   echo "### Building Isabelle/jEdit ..."
   211 
   212   [ "${#UPDATED[@]}" -gt 0 ] && {
   213     echo "Changed files:"
   214     for FILE in "${UPDATED[@]}"
   215     do
   216       echo "  $FILE"
   217     done
   218   }
   219 
   220   [ -z "$ISABELLE_JEDIT_BUILD_HOME" ] && \
   221     fail "Unknown ISABELLE_JEDIT_BUILD_HOME -- missing auxiliary component"
   222 
   223   rm -rf dist || failed
   224   mkdir -p dist dist/classes || failed
   225 
   226   cp -pR "$ISABELLE_JEDIT_BUILD_HOME/contrib/$ISABELLE_JEDIT_BUILD_VERSION/." dist/.
   227   cp -pR "${RESOURCES[@]}" dist/classes/.
   228   cp src/jEdit.props dist/properties/.
   229   cp -pR src/modes/. dist/modes/.
   230   cp -pR "$SCALA_HOME/misc/scala-tool-support/jedit/modes/scala.xml" dist/modes/.
   231 
   232   perl -i -e 'while (<>) {
   233     if (m/NAME="javacc"/) {
   234       print qq,<MODE NAME="isabelle" FILE="isabelle.xml" FILE_NAME_GLOB="*.thy"/>\n\n,;
   235       print qq,<MODE NAME="isabelle-session" FILE="isabelle-session.xml" FILE_NAME_GLOB="session.root"/>\n\n,; }
   236     elsif (m/NAME="scheme"/) {
   237       print qq,<MODE NAME="scala" FILE="scala.xml" FILE_NAME_GLOB="*.scala" />\n\n,; }
   238     print; }' dist/modes/catalog
   239 
   240   cp -pR "${JEDIT_JARS[@]}" "$SCALA_HOME/lib/scala-compiler.jar" dist/jars/. || failed
   241   (
   242     for JAR in "$JEDIT_JAR" "${JEDIT_JARS[@]}" "$PURE_JAR" "$SCALA_HOME/lib/scala-compiler.jar"
   243     do
   244       CLASSPATH="$CLASSPATH:$JAR"
   245     done
   246     CLASSPATH="$(jvmpath "$CLASSPATH")"
   247     exec "$SCALA_HOME/bin/scalac" -unchecked -deprecation \
   248       -d dist/classes -target:jvm-1.5 "${SOURCES[@]}"
   249   ) || fail "Failed to compile sources"
   250 
   251   cd dist/classes
   252   jar cf "../jars/Isabelle-jEdit.jar" * || failed
   253   cd ../..
   254   rm -rf dist/classes
   255 fi
   256 
   257 popd >/dev/null
   258 
   259 
   260 ## main
   261 
   262 # perspective
   263 
   264 mkdir -p "$JEDIT_SETTINGS/DockableWindowManager"
   265 
   266 if [ ! -e "$JEDIT_SETTINGS/perspective.xml" ]; then
   267   cat > "$JEDIT_SETTINGS/DockableWindowManager/perspective-view0.xml" <<EOF
   268 <DOCKING LEFT="" TOP="" RIGHT="" BOTTOM="isabelle-session" LEFT_POS="0" TOP_POS="0" RIGHT_POS="250" BOTTOM_POS="250" />
   269 EOF
   270   cat > "$JEDIT_SETTINGS/perspective.xml" <<EOF
   271 <?xml version="1.0" encoding="UTF-8" ?>
   272 <!DOCTYPE PERSPECTIVE SYSTEM "perspective.dtd">
   273 <PERSPECTIVE>
   274 <VIEW PLAIN="FALSE">
   275 <GEOMETRY X="0" Y="35" WIDTH="1072" HEIGHT="787" EXT_STATE="0" />
   276 </VIEW>
   277 </PERSPECTIVE>
   278 EOF
   279 fi
   280 
   281 
   282 # run
   283 
   284 [ "$BUILD_ONLY" = true ] || {
   285   case "$JEDIT_LOGIC" in
   286     /*)
   287       ;;
   288     */*)
   289       JEDIT_LOGIC="$(pwd -P)/$JEDIT_LOGIC"
   290       ;;
   291   esac
   292 
   293   export JEDIT_LOGIC JEDIT_PRINT_MODE
   294 
   295   exec "$ISABELLE_TOOL" java "${JAVA_ARGS[@]}" \
   296     -jar "$(jvmpath "$JEDIT_HOME/dist/jedit.jar")" \
   297     "-settings=$(jvmpath "$JEDIT_SETTINGS")" "${ARGS[@]}"
   298 }