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