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