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