src/Tools/jEdit/lib/Tools/jedit
author wenzelm
Thu Nov 02 10:16:22 2017 +0100 (17 months ago)
changeset 66987 352b23c97ac8
parent 66977 fa79f18eadc7
child 66988 7f8c1dd7576a
permissions -rwxr-xr-x
support focus_session, for much faster startup of Isabelle/jEdit;
more options for "isabelle jedit";
     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_BASE=(
    11   "src-base/dockable.scala"
    12   "src-base/isabelle_encoding.scala"
    13   "src-base/jedit_lib.scala"
    14   "src-base/pide_docking_framework.scala"
    15   "src-base/plugin.scala"
    16   "src-base/syntax_style.scala"
    17 )
    18 
    19 declare -a RESOURCES_BASE=(
    20   "src-base/Isabelle_Base.props"
    21   "src-base/services.xml"
    22 )
    23 
    24 declare -a SOURCES=(
    25   "src/active.scala"
    26   "src/completion_popup.scala"
    27   "src/context_menu.scala"
    28   "src/debugger_dockable.scala"
    29   "src/document_model.scala"
    30   "src/document_view.scala"
    31   "src/documentation_dockable.scala"
    32   "src/fold_handling.scala"
    33   "src/font_info.scala"
    34   "src/graphview_dockable.scala"
    35   "src/info_dockable.scala"
    36   "src/isabelle.scala"
    37   "src/isabelle_encoding.scala"
    38   "src/isabelle_options.scala"
    39   "src/isabelle_sidekick.scala"
    40   "src/jedit_bibtex.scala"
    41   "src/jedit_editor.scala"
    42   "src/jedit_lib.scala"
    43   "src/jedit_options.scala"
    44   "src/jedit_rendering.scala"
    45   "src/jedit_resources.scala"
    46   "src/jedit_sessions.scala"
    47   "src/jedit_spell_checker.scala"
    48   "src/keymap_merge.scala"
    49   "src/monitor_dockable.scala"
    50   "src/output_dockable.scala"
    51   "src/plugin.scala"
    52   "src/pretty_text_area.scala"
    53   "src/pretty_tooltip.scala"
    54   "src/process_indicator.scala"
    55   "src/protocol_dockable.scala"
    56   "src/query_dockable.scala"
    57   "src/raw_output_dockable.scala"
    58   "src/rich_text_area.scala"
    59   "src/scala_console.scala"
    60   "src/session_build.scala"
    61   "src/simplifier_trace_dockable.scala"
    62   "src/simplifier_trace_window.scala"
    63   "src/sledgehammer_dockable.scala"
    64   "src/state_dockable.scala"
    65   "src/symbols_dockable.scala"
    66   "src/syntax_style.scala"
    67   "src/syslog_dockable.scala"
    68   "src/text_overview.scala"
    69   "src/text_structure.scala"
    70   "src/theories_dockable.scala"
    71   "src/timing_dockable.scala"
    72   "src/token_markup.scala"
    73 )
    74 
    75 declare -a RESOURCES=(
    76   "src/actions.xml"
    77   "src/dockables.xml"
    78   "src/Isabelle.props"
    79   "src/jEdit.props"
    80   "src/services.xml"
    81   "src/modes/isabelle-ml.xml"
    82   "src/modes/isabelle-news.xml"
    83   "src/modes/isabelle-options.xml"
    84   "src/modes/isabelle-root.xml"
    85   "src/modes/isabelle.xml"
    86   "src/modes/sml.xml"
    87 )
    88 
    89 
    90 ## diagnostics
    91 
    92 PRG="$(basename "$0")"
    93 
    94 function usage()
    95 {
    96   echo
    97   echo "Usage: isabelle $PRG [OPTIONS] [FILES ...]"
    98   echo
    99   echo "  Options are:"
   100   echo "    -B           use base session image, with theories from other sessions"
   101   echo "    -F           focus on selected logic session: ignore unrelated theories"
   102   echo "    -D NAME=X    set JVM system property"
   103   echo "    -J OPTION    add JVM runtime option"
   104   echo "                 (default $JEDIT_JAVA_SYSTEM_OPTIONS $JEDIT_JAVA_OPTIONS)"
   105   echo "    -P           use parent session image"
   106   echo "    -R           open ROOT entry of logic session"
   107   echo "    -S NAME      edit specified logic session, same as abbreviates -B -F -R -l NAME"
   108   echo "    -b           build only"
   109   echo "    -d DIR       include session directory"
   110   echo "    -f           fresh build"
   111   echo "    -j OPTION    add jEdit runtime option"
   112   echo "                 (default $JEDIT_OPTIONS)"
   113   echo "    -l NAME      logic session name"
   114   echo "    -m MODE      add print mode for output"
   115   echo "    -n           no build of session image on startup"
   116   echo "    -p CMD       ML process command prefix (process policy)"
   117   echo "    -s           system build mode for session image"
   118   echo
   119   echo "  Start jEdit with Isabelle plugin setup and open FILES"
   120   echo "  (default \"$USER_HOME/Scratch.thy\" or \":\" for empty buffer)."
   121   echo
   122   exit 1
   123 }
   124 
   125 function fail()
   126 {
   127   echo "$1" >&2
   128   exit 2
   129 }
   130 
   131 function failed()
   132 {
   133   fail "Failed!"
   134 }
   135 
   136 
   137 ## process command line
   138 
   139 # options
   140 
   141 BUILD_ONLY=false
   142 BUILD_JARS="jars"
   143 ML_PROCESS_POLICY=""
   144 JEDIT_LOGIC_BASE=""
   145 JEDIT_LOGIC_FOCUS=""
   146 JEDIT_SESSION_DIRS=""
   147 JEDIT_LOGIC_ROOT=""
   148 JEDIT_LOGIC_PARENT=""
   149 JEDIT_LOGIC=""
   150 JEDIT_PRINT_MODE=""
   151 JEDIT_BUILD_MODE="normal"
   152 
   153 function getoptions()
   154 {
   155   OPTIND=1
   156   while getopts "BFD:J:PRS:bd:fj:l:m:np:s" OPT
   157   do
   158     case "$OPT" in
   159       B)
   160         JEDIT_LOGIC_BASE="true"
   161         JEDIT_LOGIC_PARENT=""
   162         ;;
   163       D)
   164         JAVA_ARGS["${#JAVA_ARGS[@]}"]="-D$OPTARG"
   165         ;;
   166       F)
   167         JEDIT_LOGIC_FOCUS="true"
   168         ;;
   169       J)
   170         JAVA_ARGS["${#JAVA_ARGS[@]}"]="$OPTARG"
   171         ;;
   172       P)
   173         JEDIT_LOGIC_PARENT="true"
   174         JEDIT_LOGIC_BASE=""
   175         ;;
   176       R)
   177         JEDIT_LOGIC_ROOT="true"
   178         ;;
   179       S)
   180         JEDIT_LOGIC="$OPTARG"
   181         JEDIT_LOGIC_BASE="true"
   182         JEDIT_LOGIC_PARENT=""
   183         JEDIT_LOGIC_FOCUS="true"
   184         JEDIT_LOGIC_ROOT="true"
   185         ;;
   186       b)
   187         BUILD_ONLY=true
   188         ;;
   189       d)
   190         if [ -z "$JEDIT_SESSION_DIRS" ]; then
   191           JEDIT_SESSION_DIRS="$OPTARG"
   192         else
   193           JEDIT_SESSION_DIRS="$JEDIT_SESSION_DIRS:$OPTARG"
   194         fi
   195         ;;
   196       f)
   197         BUILD_JARS="jars_fresh"
   198         ;;
   199       j)
   200         ARGS["${#ARGS[@]}"]="$OPTARG"
   201         ;;
   202       l)
   203         JEDIT_LOGIC="$OPTARG"
   204         ;;
   205       m)
   206         if [ -z "$JEDIT_PRINT_MODE" ]; then
   207           JEDIT_PRINT_MODE="$OPTARG"
   208         else
   209           JEDIT_PRINT_MODE="$JEDIT_PRINT_MODE,$OPTARG"
   210         fi
   211         ;;
   212       n)
   213         JEDIT_BUILD_MODE="none"
   214         ;;
   215       p)
   216         ML_PROCESS_POLICY="$OPTARG"
   217         ;;
   218       s)
   219         JEDIT_BUILD_MODE="system"
   220         ;;
   221       \?)
   222         usage
   223         ;;
   224     esac
   225   done
   226 }
   227 
   228 eval "declare -a JAVA_ARGS=($JEDIT_JAVA_SYSTEM_OPTIONS $JEDIT_JAVA_OPTIONS)"
   229 
   230 declare -a ARGS=()
   231 
   232 declare -a OPTIONS; eval "OPTIONS=($ISABELLE_JEDIT_OPTIONS)"
   233 getoptions "${OPTIONS[@]}"
   234 
   235 getoptions "$@"
   236 shift $(($OPTIND - 1))
   237 
   238 
   239 # args
   240 
   241 while [ "$#" -gt 0 ]; do
   242   ARGS["${#ARGS[@]}"]="$(platform_path "$1")"
   243   shift
   244 done
   245 
   246 
   247 ## dependencies
   248 
   249 if [ -e "$ISABELLE_HOME/Admin/build" ]; then
   250   isabelle browser -b || exit $?
   251   "$ISABELLE_HOME/Admin/build" "$BUILD_JARS" || exit $?
   252 fi
   253 
   254 PURE_JAR="$ISABELLE_HOME/lib/classes/Pure.jar"
   255 
   256 pushd "$JEDIT_HOME" >/dev/null || failed
   257 
   258 JEDIT_JAR="$ISABELLE_JEDIT_BUILD_HOME/contrib/$ISABELLE_JEDIT_BUILD_VERSION/jedit.jar"
   259 
   260 JEDIT_JARS=(
   261   "$ISABELLE_JEDIT_BUILD_HOME/contrib/Code2HTML.jar"
   262   "$ISABELLE_JEDIT_BUILD_HOME/contrib/CommonControls.jar"
   263   "$ISABELLE_JEDIT_BUILD_HOME/contrib/Console.jar"
   264   "$ISABELLE_JEDIT_BUILD_HOME/contrib/ErrorList.jar"
   265   "$ISABELLE_JEDIT_BUILD_HOME/contrib/Highlight.jar"
   266   "$ISABELLE_JEDIT_BUILD_HOME/contrib/kappalayout.jar"
   267   "$ISABELLE_JEDIT_BUILD_HOME/contrib/MacOSX.jar"
   268   "$ISABELLE_JEDIT_BUILD_HOME/contrib/Navigator.jar"
   269   "$ISABELLE_JEDIT_BUILD_HOME/contrib/SideKick.jar"
   270   "$ISABELLE_JEDIT_BUILD_HOME/contrib/idea-icons.jar"
   271   "$ISABELLE_JEDIT_BUILD_HOME/contrib/jsr305-2.0.0.jar"
   272 )
   273 
   274 
   275 # target
   276 
   277 TARGET_BASE="dist/jars/Isabelle-jEdit-base.jar"
   278 TARGET="dist/jars/Isabelle-jEdit.jar"
   279 
   280 declare -a UPDATED=()
   281 
   282 if [ "$BUILD_JARS" = jars_fresh ]; then
   283   OUTDATED=true
   284 else
   285   OUTDATED=false
   286   if [ ! -e "$TARGET_BASE" -a ! -e "$TARGET" ]; then
   287     OUTDATED=true
   288   else
   289     if [ -n "$ISABELLE_JEDIT_BUILD_HOME" ]; then
   290       declare -a DEPS=(
   291         "$JEDIT_JAR" "${JEDIT_JARS[@]}" "$PURE_JAR"
   292         "${SOURCES_BASE[@]}" "${RESOURCES_BASE[@]}"
   293         "${SOURCES[@]}" "${RESOURCES[@]}"
   294       )
   295     elif [ -e "$ISABELLE_HOME/Admin/build" ]; then
   296       declare -a DEPS=(
   297         "$PURE_JAR"
   298         "${SOURCES_BASE[@]}" "${RESOURCES_BASE[@]}"
   299         "${SOURCES[@]}" "${RESOURCES[@]}"
   300       )
   301     else
   302       declare -a DEPS=()
   303     fi
   304     for DEP in "${DEPS[@]}"
   305     do
   306       [ ! -e "$DEP" ] && fail "Missing file: $DEP"
   307       [ "$DEP" -nt "$TARGET_BASE" -o "$DEP" -nt "$TARGET" ] && {
   308         OUTDATED=true
   309         UPDATED["${#UPDATED[@]}"]="$DEP"
   310       }
   311     done
   312   fi
   313 fi
   314 
   315 
   316 # build
   317 
   318 function init_resources ()
   319 {
   320   mkdir -p dist/classes || failed
   321   cp -p -R -f "$@" dist/classes/.
   322 }
   323 
   324 function compile_sources ()
   325 {
   326   (
   327     #FIXME workarounds for scalac 2.11.0
   328     export CYGWIN="nodosfilewarning"
   329     function stty() { :; }
   330     export -f stty
   331 
   332     for JAR in "$JEDIT_JAR" "${JEDIT_JARS[@]}" "$PURE_JAR"
   333     do
   334       classpath "$JAR"
   335     done
   336     export CLASSPATH="$(platform_path "$ISABELLE_CLASSPATH")"
   337     isabelle_scala scalac $ISABELLE_SCALAC_OPTIONS -d dist/classes "$@"
   338   ) || fail "Failed to compile sources"
   339 }
   340 
   341 function make_jar ()
   342 {
   343   cd dist/classes
   344   isabelle_jdk jar cf "../../$1" * || failed
   345   cd ../..
   346   rm -rf dist/classes
   347 }
   348 
   349 if [ "$OUTDATED" = true ]
   350 then
   351   echo "### Building Isabelle/jEdit ..."
   352 
   353   [ "${#UPDATED[@]}" -gt 0 ] && {
   354     echo "Changed files:"
   355     for FILE in "${UPDATED[@]}"
   356     do
   357       echo "  $FILE"
   358     done
   359   }
   360 
   361   [ -z "$ISABELLE_JEDIT_BUILD_HOME" ] && \
   362     fail "Unknown ISABELLE_JEDIT_BUILD_HOME -- missing auxiliary component"
   363 
   364   rm -rf dist || failed
   365   mkdir -p dist || failed
   366 
   367   cp -p -R -f "$ISABELLE_JEDIT_BUILD_HOME/contrib/$ISABELLE_JEDIT_BUILD_VERSION/." dist/.
   368 
   369   init_resources "${RESOURCES_BASE[@]}"
   370   compile_sources "${SOURCES_BASE[@]}"
   371   make_jar "$TARGET_BASE"
   372   classpath "$PWD/$TARGET_BASE"
   373 
   374   init_resources "${RESOURCES[@]}"
   375   cp src/jEdit.props dist/properties/.
   376   cp -p -R -f src/modes/. dist/modes/.
   377 
   378   perl -i -e 'while (<>) {
   379     if (m/FILE="ml.xml"/ or m/FILE_NAME_GLOB="...sml,ml."/) { }
   380     elsif (m/NAME="javacc"/) {
   381       print qq!<MODE NAME="isabelle" FILE="isabelle.xml" FILE_NAME_GLOB="{*.thy,ROOT0.ML,ROOT.ML}"/>\n\n!;
   382       print qq!<MODE NAME="isabelle-ml" FILE="isabelle-ml.xml" FILE_NAME_GLOB="*.ML"/>\n\n!;
   383       print qq!<MODE NAME="isabelle-news" FILE="isabelle-news.xml"/>\n\n!;
   384       print qq!<MODE NAME="isabelle-options" FILE="isabelle-options.xml"/>\n\n!;
   385       print qq!<MODE NAME="isabelle-root" FILE="isabelle-root.xml" FILE_NAME_GLOB="ROOT"/>\n\n!;
   386       print;
   387     }
   388     elsif (m/NAME="sqr"/) {
   389       print qq!<MODE NAME="sml" FILE="sml.xml" FILE_NAME_GLOB="*.{sml,sig}"/>\n\n!;
   390       print;
   391     }
   392     else { print; }
   393   }' dist/modes/catalog
   394 
   395   cd dist
   396   isabelle_jdk jar xf jedit.jar
   397   cp "$ISABELLE_HOME/lib/logo/isabelle_transparent-32.gif" \
   398     "org/gjt/sp/jedit/icons/themes/classic/32x32/apps/isabelle.gif" || failed
   399   cp "$ISABELLE_HOME/lib/logo/isabelle_transparent-32.gif" \
   400     "org/gjt/sp/jedit/icons/themes/tango/32x32/apps/isabelle.gif" || failed
   401   isabelle_jdk jar cfe jedit.jar org.gjt.sp.jedit.jEdit org || failed
   402   rm -rf META-INF org
   403   cd ..
   404 
   405   cp -p -R -f "${JEDIT_JARS[@]}" dist/jars/. || failed
   406   compile_sources "${SOURCES[@]}"
   407   make_jar "$TARGET"
   408 
   409   cp "$ISABELLE_JEDIT_BUILD_HOME/doc/jedit5.4.0manual-a4.pdf" dist/doc/jedit-manual.pdf
   410   cp dist/doc/CHANGES.txt dist/doc/jedit-changes
   411   cat > dist/doc/Contents <<EOF
   412 Original jEdit Documentation
   413   jedit-manual    jEdit 5.4 User's Guide
   414   jedit-changes   jEdit 5.4 Version History
   415 
   416 EOF
   417 
   418 fi
   419 
   420 popd >/dev/null
   421 
   422 
   423 ## main
   424 
   425 if [ "$BUILD_ONLY" = false ]
   426 then
   427   export JEDIT_SESSION_DIRS JEDIT_LOGIC JEDIT_LOGIC_BASE JEDIT_LOGIC_FOCUS \
   428     JEDIT_LOGIC_PARENT JEDIT_LOGIC_ROOT JEDIT_PRINT_MODE JEDIT_BUILD_MODE
   429   export JEDIT_ML_PROCESS_POLICY="$ML_PROCESS_POLICY"
   430   classpath "$JEDIT_HOME/dist/jedit.jar"
   431   exec isabelle java "${JAVA_ARGS[@]}" isabelle.Main "${ARGS[@]}"
   432 fi