src/Tools/jEdit/lib/Tools/jedit
author wenzelm
Sun Oct 05 17:58:36 2014 +0200 (2014-10-05 ago)
changeset 58545 30b75b7958d6
parent 58529 cd4439d8799c
child 58546 72e2b2a609c4
permissions -rwxr-xr-x
citation tooltip/hyperlink based on open buffers with .bib files;
     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/active.scala"
    12   "src/bibtex_jedit.scala"
    13   "src/bibtex_token_markup.scala"
    14   "src/completion_popup.scala"
    15   "src/context_menu.scala"
    16   "src/dockable.scala"
    17   "src/document_model.scala"
    18   "src/document_view.scala"
    19   "src/documentation_dockable.scala"
    20   "src/fold_handling.scala"
    21   "src/font_info.scala"
    22   "src/graphview_dockable.scala"
    23   "src/info_dockable.scala"
    24   "src/isabelle.scala"
    25   "src/isabelle_encoding.scala"
    26   "src/isabelle_logic.scala"
    27   "src/isabelle_options.scala"
    28   "src/isabelle_sidekick.scala"
    29   "src/jedit_editor.scala"
    30   "src/jedit_lib.scala"
    31   "src/jedit_options.scala"
    32   "src/jedit_resources.scala"
    33   "src/monitor_dockable.scala"
    34   "src/output_dockable.scala"
    35   "src/pide_docking_framework.scala"
    36   "src/plugin.scala"
    37   "src/pretty_text_area.scala"
    38   "src/pretty_tooltip.scala"
    39   "src/process_indicator.scala"
    40   "src/protocol_dockable.scala"
    41   "src/query_dockable.scala"
    42   "src/raw_output_dockable.scala"
    43   "src/rendering.scala"
    44   "src/rich_text_area.scala"
    45   "src/scala_console.scala"
    46   "src/simplifier_trace_dockable.scala"
    47   "src/simplifier_trace_window.scala"
    48   "src/sledgehammer_dockable.scala"
    49   "src/spell_checker.scala"
    50   "src/symbols_dockable.scala"
    51   "src/syslog_dockable.scala"
    52   "src/text_overview.scala"
    53   "src/theories_dockable.scala"
    54   "src/timing_dockable.scala"
    55   "src/token_markup.scala"
    56 )
    57 
    58 declare -a RESOURCES=(
    59   "src/actions.xml"
    60   "src/dockables.xml"
    61   "src/Isabelle.props"
    62   "src/jEdit.props"
    63   "src/services.xml"
    64   "src/modes/isabelle-ml.xml"
    65   "src/modes/isabelle-news.xml"
    66   "src/modes/isabelle-options.xml"
    67   "src/modes/isabelle-root.xml"
    68   "src/modes/isabelle.xml"
    69   "src/modes/sml.xml"
    70 )
    71 
    72 
    73 ## diagnostics
    74 
    75 PRG="$(basename "$0")"
    76 
    77 function usage()
    78 {
    79   echo
    80   echo "Usage: isabelle $PRG [OPTIONS] [FILES ...]"
    81   echo
    82   echo "  Options are:"
    83   echo "    -J OPTION    add JVM runtime option"
    84   echo "                 (default JEDIT_JAVA_OPTIONS=$JEDIT_JAVA_OPTIONS)"
    85   echo "    -b           build only"
    86   echo "    -d DIR       include session directory"
    87   echo "    -f           fresh build"
    88   echo "    -j OPTION    add jEdit runtime option"
    89   echo "                 (default JEDIT_OPTIONS=$JEDIT_OPTIONS)"
    90   echo "    -l NAME      logic session name"
    91   echo "    -m MODE      add print mode for output"
    92   echo "    -n           no build of session image on startup"
    93   echo "    -s           system build mode for session image"
    94   echo
    95   echo "  Start jEdit with Isabelle plugin setup and open theory FILES"
    96   echo "  (default \"$USER_HOME/Scratch.thy\")."
    97   echo
    98   exit 1
    99 }
   100 
   101 function fail()
   102 {
   103   echo "$1" >&2
   104   exit 2
   105 }
   106 
   107 function failed()
   108 {
   109   fail "Failed!"
   110 }
   111 
   112 
   113 ## process command line
   114 
   115 # options
   116 
   117 BUILD_ONLY=false
   118 BUILD_JARS="jars"
   119 JEDIT_SESSION_DIRS=""
   120 JEDIT_LOGIC=""
   121 JEDIT_PRINT_MODE=""
   122 JEDIT_BUILD_MODE="normal"
   123 
   124 function getoptions()
   125 {
   126   OPTIND=1
   127   while getopts "J:bd:fj:l:m:ns" OPT
   128   do
   129     case "$OPT" in
   130       J)
   131         JAVA_ARGS["${#JAVA_ARGS[@]}"]="$OPTARG"
   132         ;;
   133       b)
   134         BUILD_ONLY=true
   135         ;;
   136       d)
   137         if [ -z "$JEDIT_SESSION_DIRS" ]; then
   138           JEDIT_SESSION_DIRS="$OPTARG"
   139         else
   140           JEDIT_SESSION_DIRS="$JEDIT_SESSION_DIRS:$OPTARG"
   141         fi
   142         ;;
   143       f)
   144         BUILD_JARS="jars_fresh"
   145         ;;
   146       j)
   147         ARGS["${#ARGS[@]}"]="$OPTARG"
   148         ;;
   149       l)
   150         JEDIT_LOGIC="$OPTARG"
   151         ;;
   152       m)
   153         if [ -z "$JEDIT_PRINT_MODE" ]; then
   154           JEDIT_PRINT_MODE="$OPTARG"
   155         else
   156           JEDIT_PRINT_MODE="$JEDIT_PRINT_MODE,$OPTARG"
   157         fi
   158         ;;
   159       n)
   160         JEDIT_BUILD_MODE="none"
   161         ;;
   162       s)
   163         JEDIT_BUILD_MODE="system"
   164         ;;
   165       \?)
   166         usage
   167         ;;
   168     esac
   169   done
   170 }
   171 
   172 declare -a JAVA_ARGS; eval "JAVA_ARGS=($JEDIT_JAVA_OPTIONS $JEDIT_SYSTEM_OPTIONS)"
   173 
   174 declare -a ARGS=()
   175 
   176 declare -a OPTIONS; eval "OPTIONS=($ISABELLE_JEDIT_OPTIONS)"
   177 getoptions "${OPTIONS[@]}"
   178 
   179 getoptions "$@"
   180 shift $(($OPTIND - 1))
   181 
   182 
   183 # args
   184 
   185 if [ "$#" -eq 0 ]; then
   186   ARGS["${#ARGS[@]}"]="$(jvmpath "$USER_HOME/Scratch.thy")"
   187 else
   188   while [ "$#" -gt 0 ]; do
   189     ARGS["${#ARGS[@]}"]="$(jvmpath "$1")"
   190     shift
   191   done
   192 fi
   193 
   194 
   195 ## dependencies
   196 
   197 if [ -e "$ISABELLE_HOME/Admin/build" ]; then
   198   "$ISABELLE_TOOL" browser -b || exit $?
   199   "$ISABELLE_HOME/Admin/build" "$BUILD_JARS" || exit $?
   200 fi
   201 
   202 PURE_JAR="$ISABELLE_HOME/lib/classes/Pure.jar"
   203 
   204 pushd "$JEDIT_HOME" >/dev/null || failed
   205 
   206 JEDIT_JAR="$ISABELLE_JEDIT_BUILD_HOME/contrib/$ISABELLE_JEDIT_BUILD_VERSION/jedit.jar"
   207 
   208 JEDIT_JARS=(
   209   "$ISABELLE_JEDIT_BUILD_HOME/contrib/Code2HTML.jar"
   210   "$ISABELLE_JEDIT_BUILD_HOME/contrib/CommonControls.jar"
   211   "$ISABELLE_JEDIT_BUILD_HOME/contrib/Console.jar"
   212   "$ISABELLE_JEDIT_BUILD_HOME/contrib/ErrorList.jar"
   213   "$ISABELLE_JEDIT_BUILD_HOME/contrib/Highlight.jar"
   214   "$ISABELLE_JEDIT_BUILD_HOME/contrib/kappalayout.jar"
   215   "$ISABELLE_JEDIT_BUILD_HOME/contrib/MacOSX.jar"
   216   "$ISABELLE_JEDIT_BUILD_HOME/contrib/Navigator.jar"
   217   "$ISABELLE_JEDIT_BUILD_HOME/contrib/SideKick.jar"
   218   "$ISABELLE_JEDIT_BUILD_HOME/contrib/idea-icons.jar"
   219   "$ISABELLE_JEDIT_BUILD_HOME/contrib/jsr305-2.0.0.jar"
   220 )
   221 
   222 
   223 # target
   224 
   225 TARGET="dist/jars/Isabelle-jEdit.jar"
   226 
   227 declare -a UPDATED=()
   228 
   229 if [ "$BUILD_JARS" = jars_fresh ]; then
   230   OUTDATED=true
   231 else
   232   OUTDATED=false
   233   if [ ! -e "$TARGET" ]; then
   234     OUTDATED=true
   235   else
   236     if [ -n "$ISABELLE_JEDIT_BUILD_HOME" ]; then
   237       declare -a DEPS=(
   238         "$JEDIT_JAR" "${JEDIT_JARS[@]}" "$PURE_JAR"
   239         "${SOURCES[@]}" "${RESOURCES[@]}"
   240       )
   241     elif [ -e "$ISABELLE_HOME/Admin/build" ]; then
   242       declare -a DEPS=("$PURE_JAR" "${SOURCES[@]}" "${RESOURCES[@]}")
   243     else
   244       declare -a DEPS=()
   245     fi
   246     for DEP in "${DEPS[@]}"
   247     do
   248       [ ! -e "$DEP" ] && fail "Missing file: $DEP"
   249       [ "$DEP" -nt "$TARGET" ] && {
   250         OUTDATED=true
   251         UPDATED["${#UPDATED[@]}"]="$DEP"
   252       }
   253     done
   254   fi
   255 fi
   256 
   257 
   258 # build
   259 
   260 if [ "$OUTDATED" = true ]
   261 then
   262   echo "### Building Isabelle/jEdit ..."
   263 
   264   [ "${#UPDATED[@]}" -gt 0 ] && {
   265     echo "Changed files:"
   266     for FILE in "${UPDATED[@]}"
   267     do
   268       echo "  $FILE"
   269     done
   270   }
   271 
   272   [ -z "$ISABELLE_JEDIT_BUILD_HOME" ] && \
   273     fail "Unknown ISABELLE_JEDIT_BUILD_HOME -- missing auxiliary component"
   274 
   275   rm -rf dist || failed
   276   mkdir -p dist dist/classes || failed
   277 
   278   cp -p -R -f "$ISABELLE_JEDIT_BUILD_HOME/contrib/$ISABELLE_JEDIT_BUILD_VERSION/." dist/.
   279   cp -p -R -f "${RESOURCES[@]}" dist/classes/.
   280   cp src/jEdit.props dist/properties/.
   281   cp -p -R -f src/modes/. dist/modes/.
   282 
   283   perl -i -e 'while (<>) {
   284     if (m/FILE="ml.xml"/ or m/FILE_NAME_GLOB="\*\.{sml,ml}"/) { }
   285     elsif (m/NAME="javacc"/) {
   286       print qq,<MODE NAME="isabelle" FILE="isabelle.xml" FILE_NAME_GLOB="*.thy"/>\n\n,;
   287       print qq,<MODE NAME="isabelle-ml" FILE="isabelle-ml.xml" FILE_NAME_GLOB="*.ML"/>\n\n,;
   288       print qq,<MODE NAME="isabelle-news" FILE="isabelle-news.xml"/>\n\n,;
   289       print qq,<MODE NAME="isabelle-options" FILE="isabelle-options.xml"/>\n\n,;
   290       print qq,<MODE NAME="isabelle-root" FILE="isabelle-root.xml" FILE_NAME_GLOB="ROOT"/>\n\n,;
   291       print;
   292     }
   293     elsif (m/NAME="sqr"/) {
   294       print qq!<MODE NAME="sml" FILE="sml.xml" FILE_NAME_GLOB="*.{sml,sig}"/>\n\n!;
   295       print;
   296     }
   297     else { print; }
   298   }' dist/modes/catalog
   299 
   300   cd dist
   301   isabelle_jdk jar xf jedit.jar
   302   cp "$ISABELLE_HOME/lib/logo/isabelle_transparent-32.gif" \
   303     "org/gjt/sp/jedit/icons/themes/classic/32x32/apps/isabelle.gif" || failed
   304   cp "$ISABELLE_HOME/lib/logo/isabelle_transparent-32.gif" \
   305     "org/gjt/sp/jedit/icons/themes/tango/32x32/apps/isabelle.gif" || failed
   306   isabelle_jdk jar cfe jedit.jar org.gjt.sp.jedit.jEdit org || failed
   307   rm -rf META-INF org
   308   cd ..
   309 
   310   cp -p -R -f "${JEDIT_JARS[@]}" dist/jars/. || failed
   311   (
   312     #FIXME workarounds for scalac 2.11.0
   313     export CYGWIN="nodosfilewarning"
   314     function stty() { :; }
   315     export -f stty
   316 
   317     for JAR in "$JEDIT_JAR" "${JEDIT_JARS[@]}" "$PURE_JAR"
   318     do
   319       classpath "$JAR"
   320     done
   321     export CLASSPATH="$(jvmpath "$ISABELLE_CLASSPATH")"
   322     exec "$SCALA_HOME/bin/scalac" $ISABELLE_SCALA_BUILD_OPTIONS -d dist/classes "${SOURCES[@]}"
   323   ) || fail "Failed to compile sources"
   324 
   325   cd dist/classes
   326   isabelle_jdk jar cf "../jars/Isabelle-jEdit.jar" * || failed
   327   cd ../..
   328   rm -rf dist/classes
   329 
   330   cp "$ISABELLE_JEDIT_BUILD_HOME/doc/jedit5.1.0manual-a4.pdf" dist/doc/jedit-manual.pdf
   331   cp dist/doc/CHANGES.txt dist/doc/jedit-changes
   332   cat > dist/doc/Contents <<EOF
   333 Original jEdit Documentation
   334   jedit-manual    jEdit 5.1 User's Guide
   335   jedit-changes   jEdit 5.1 Version History
   336 
   337 EOF
   338 
   339 fi
   340 
   341 popd >/dev/null
   342 
   343 
   344 ## main
   345 
   346 if [ "$BUILD_ONLY" = false ]
   347 then
   348   export JEDIT_SESSION_DIRS JEDIT_LOGIC JEDIT_PRINT_MODE JEDIT_BUILD_MODE
   349   classpath "$JEDIT_HOME/dist/jedit.jar"
   350   exec "$ISABELLE_TOOL" java "${JAVA_ARGS[@]}" isabelle.Main "${ARGS[@]}"
   351 fi