src/Tools/jEdit/lib/Tools/jedit
author wenzelm
Wed Sep 25 15:26:19 2013 +0200 (2013-09-25)
changeset 53882 da57c4912987
parent 53783 f5e9d182f645
child 53883 f1c5f857df3d
permissions -rwxr-xr-x
removed obsolete cobra.jar, js.jar (see also 30de372ca56f);
added MacOSX.jar based on SVN 23208 (essentially plugin version 1.3);
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@53023
    12
  "src/completion_popup.scala"
wenzelm@43285
    13
  "src/dockable.scala"
wenzelm@43285
    14
  "src/document_model.scala"
wenzelm@43285
    15
  "src/document_view.scala"
wenzelm@52445
    16
  "src/documentation_dockable.scala"
wenzelm@52846
    17
  "src/find_dockable.scala"
wenzelm@50542
    18
  "src/fold_handling.scala"
wenzelm@49570
    19
  "src/graphview_dockable.scala"
wenzelm@49726
    20
  "src/info_dockable.scala"
wenzelm@50208
    21
  "src/isabelle.scala"
wenzelm@43285
    22
  "src/isabelle_encoding.scala"
wenzelm@49246
    23
  "src/isabelle_logic.scala"
wenzelm@43285
    24
  "src/isabelle_options.scala"
wenzelm@43285
    25
  "src/isabelle_sidekick.scala"
wenzelm@52971
    26
  "src/jedit_editor.scala"
wenzelm@49406
    27
  "src/jedit_lib.scala"
wenzelm@50202
    28
  "src/jedit_options.scala"
wenzelm@44577
    29
  "src/jedit_thy_load.scala"
wenzelm@50433
    30
  "src/monitor_dockable.scala"
wenzelm@51071
    31
  "src/osx_adapter.scala"
wenzelm@43285
    32
  "src/output_dockable.scala"
wenzelm@43285
    33
  "src/plugin.scala"
wenzelm@49398
    34
  "src/pretty_text_area.scala"
wenzelm@49702
    35
  "src/pretty_tooltip.scala"
wenzelm@52934
    36
  "src/process_indicator.scala"
wenzelm@43285
    37
  "src/protocol_dockable.scala"
wenzelm@43285
    38
  "src/raw_output_dockable.scala"
wenzelm@50202
    39
  "src/rendering.scala"
wenzelm@49411
    40
  "src/rich_text_area.scala"
wenzelm@43285
    41
  "src/scala_console.scala"
wenzelm@52908
    42
  "src/sledgehammer_dockable.scala"
immler@50143
    43
  "src/symbols_dockable.scala"
wenzelm@48021
    44
  "src/syslog_dockable.scala"
wenzelm@46572
    45
  "src/text_overview.scala"
wenzelm@50299
    46
  "src/theories_dockable.scala"
wenzelm@51533
    47
  "src/timing_dockable.scala"
wenzelm@43414
    48
  "src/token_markup.scala"
wenzelm@43285
    49
)
wenzelm@43285
    50
wenzelm@43320
    51
declare -a RESOURCES=(
wenzelm@43286
    52
  "src/actions.xml"
wenzelm@43286
    53
  "src/dockables.xml"
wenzelm@43286
    54
  "src/Isabelle.props"
wenzelm@50306
    55
  "src/jEdit.props"
wenzelm@43286
    56
  "src/services.xml"
wenzelm@52540
    57
  "src/modes/isabelle-news.xml"
wenzelm@52540
    58
  "src/modes/isabelle-options.xml"
wenzelm@52540
    59
  "src/modes/isabelle-root.xml"
wenzelm@52540
    60
  "src/modes/isabelle.xml"
wenzelm@43285
    61
)
wenzelm@43285
    62
wenzelm@43285
    63
wenzelm@34333
    64
## diagnostics
wenzelm@34333
    65
wenzelm@34664
    66
PRG="$(basename "$0")"
wenzelm@34664
    67
wenzelm@43284
    68
function usage()
wenzelm@34333
    69
{
wenzelm@34333
    70
  echo
wenzelm@34664
    71
  echo "Usage: isabelle $PRG [OPTIONS] [FILES ...]"
wenzelm@34333
    72
  echo
wenzelm@34333
    73
  echo "  Options are:"
wenzelm@34333
    74
  echo "    -J OPTION    add JVM runtime option"
wenzelm@34409
    75
  echo "                 (default JEDIT_JAVA_OPTIONS=$JEDIT_JAVA_OPTIONS)"
wenzelm@43285
    76
  echo "    -b           build only"
wenzelm@48791
    77
  echo "    -d DIR       include session directory"
wenzelm@43285
    78
  echo "    -f           fresh build"
wenzelm@34333
    79
  echo "    -j OPTION    add jEdit runtime option"
wenzelm@34333
    80
  echo "                 (default JEDIT_OPTIONS=$JEDIT_OPTIONS)"
wenzelm@50403
    81
  echo "    -l NAME      logic session name"
wenzelm@34333
    82
  echo "    -m MODE      add print mode for output"
wenzelm@50405
    83
  echo "    -n           no build dialog for session image on startup"
wenzelm@50373
    84
  echo "    -s           system build mode for session image"
wenzelm@34333
    85
  echo
wenzelm@50550
    86
  echo "Start jEdit with Isabelle plugin setup and open theory FILES"
wenzelm@50114
    87
  echo "(default \"$USER_HOME/Scratch.thy\")."
wenzelm@34333
    88
  echo
wenzelm@34333
    89
  exit 1
wenzelm@34333
    90
}
wenzelm@34333
    91
wenzelm@43284
    92
function fail()
wenzelm@34333
    93
{
wenzelm@34333
    94
  echo "$1" >&2
wenzelm@34333
    95
  exit 2
wenzelm@34333
    96
}
wenzelm@34333
    97
wenzelm@43284
    98
function failed()
wenzelm@43284
    99
{
wenzelm@43284
   100
  fail "Failed!"
wenzelm@43284
   101
}
wenzelm@43284
   102
wenzelm@34333
   103
wenzelm@34333
   104
## process command line
wenzelm@34333
   105
wenzelm@34333
   106
# options
wenzelm@34333
   107
wenzelm@43285
   108
BUILD_ONLY=false
wenzelm@43285
   109
BUILD_JARS="jars"
wenzelm@48791
   110
JEDIT_SESSION_DIRS=""
wenzelm@50403
   111
JEDIT_LOGIC=""
wenzelm@34333
   112
JEDIT_PRINT_MODE=""
wenzelm@53449
   113
JEDIT_BUILD_MODE="normal"
wenzelm@34333
   114
wenzelm@43284
   115
function getoptions()
wenzelm@34780
   116
{
wenzelm@34780
   117
  OPTIND=1
wenzelm@50405
   118
  while getopts "J:bd:fj:l:m:ns" OPT
wenzelm@34780
   119
  do
wenzelm@34780
   120
    case "$OPT" in
wenzelm@34780
   121
      J)
wenzelm@34780
   122
        JAVA_ARGS["${#JAVA_ARGS[@]}"]="$OPTARG"
wenzelm@34780
   123
        ;;
wenzelm@43285
   124
      b)
wenzelm@43285
   125
        BUILD_ONLY=true
wenzelm@43285
   126
        ;;
wenzelm@48791
   127
      d)
wenzelm@48791
   128
        if [ -z "$JEDIT_SESSION_DIRS" ]; then
wenzelm@48791
   129
          JEDIT_SESSION_DIRS="$OPTARG"
wenzelm@48791
   130
        else
wenzelm@48791
   131
          JEDIT_SESSION_DIRS="$JEDIT_SESSION_DIRS:$OPTARG"
wenzelm@48791
   132
        fi
wenzelm@48791
   133
        ;;
wenzelm@43285
   134
      f)
wenzelm@43285
   135
        BUILD_JARS="jars_fresh"
wenzelm@43285
   136
        ;;
wenzelm@34780
   137
      j)
wenzelm@34780
   138
        ARGS["${#ARGS[@]}"]="$OPTARG"
wenzelm@34780
   139
        ;;
wenzelm@34780
   140
      l)
wenzelm@34780
   141
        JEDIT_LOGIC="$OPTARG"
wenzelm@34780
   142
        ;;
wenzelm@34780
   143
      m)
wenzelm@34780
   144
        if [ -z "$JEDIT_PRINT_MODE" ]; then
wenzelm@34780
   145
          JEDIT_PRINT_MODE="$OPTARG"
wenzelm@34780
   146
        else
wenzelm@34780
   147
          JEDIT_PRINT_MODE="$JEDIT_PRINT_MODE,$OPTARG"
wenzelm@34780
   148
        fi
wenzelm@34780
   149
        ;;
wenzelm@50405
   150
      n)
wenzelm@53449
   151
        JEDIT_BUILD_MODE="none"
wenzelm@50405
   152
        ;;
wenzelm@50373
   153
      s)
wenzelm@53449
   154
        JEDIT_BUILD_MODE="system"
wenzelm@50373
   155
        ;;
wenzelm@34780
   156
      \?)
wenzelm@34780
   157
        usage
wenzelm@34780
   158
        ;;
wenzelm@34780
   159
    esac
wenzelm@34780
   160
  done
wenzelm@34780
   161
}
wenzelm@34581
   162
wenzelm@38257
   163
declare -a JAVA_ARGS; eval "JAVA_ARGS=($JEDIT_JAVA_OPTIONS $JEDIT_SYSTEM_OPTIONS)"
wenzelm@34843
   164
wenzelm@53446
   165
declare -a ARGS=()
wenzelm@34333
   166
wenzelm@34780
   167
declare -a OPTIONS; eval "OPTIONS=($ISABELLE_JEDIT_OPTIONS)"
wenzelm@34780
   168
getoptions "${OPTIONS[@]}"
wenzelm@34780
   169
wenzelm@34780
   170
getoptions "$@"
wenzelm@34333
   171
shift $(($OPTIND - 1))
wenzelm@34333
   172
wenzelm@34333
   173
wenzelm@34333
   174
# args
wenzelm@34333
   175
wenzelm@44485
   176
if [ "$#" -eq 0 ]; then
wenzelm@50120
   177
  ARGS["${#ARGS[@]}"]="$(jvmpath "$USER_HOME/Scratch.thy")"
wenzelm@44485
   178
else
wenzelm@44485
   179
  while [ "$#" -gt 0 ]; do
wenzelm@44485
   180
    ARGS["${#ARGS[@]}"]="$(jvmpath "$1")"
wenzelm@44485
   181
    shift
wenzelm@44485
   182
  done
wenzelm@44485
   183
fi
wenzelm@34333
   184
wenzelm@34333
   185
wenzelm@43284
   186
## dependencies
wenzelm@43284
   187
wenzelm@49953
   188
if [ -e "$ISABELLE_HOME/Admin/build" ]; then
wenzelm@50782
   189
  "$ISABELLE_TOOL" browser -b || exit $?
wenzelm@49953
   190
  if [ "$BUILD_JARS" = jars_fresh ]; then
wenzelm@49953
   191
    "$ISABELLE_TOOL" graphview -b -f || exit $?
wenzelm@49953
   192
  else
wenzelm@49566
   193
    "$ISABELLE_HOME/Admin/build" "$BUILD_JARS" || exit $?
wenzelm@49953
   194
    "$ISABELLE_TOOL" graphview -b || exit $?
wenzelm@49953
   195
  fi
wenzelm@49953
   196
fi
wenzelm@43413
   197
wenzelm@53577
   198
PURE_JAR="$ISABELLE_HOME/lib/classes/Pure.jar"
wenzelm@53577
   199
GRAPHVIEW_JAR="$ISABELLE_HOME/lib/classes/Graphview.jar"
wenzelm@43413
   200
wenzelm@43285
   201
pushd "$JEDIT_HOME" >/dev/null || failed
wenzelm@43284
   202
wenzelm@43284
   203
JEDIT_JAR="$ISABELLE_JEDIT_BUILD_HOME/contrib/$ISABELLE_JEDIT_BUILD_VERSION/jedit.jar"
wenzelm@43284
   204
wenzelm@43284
   205
JEDIT_JARS=(
wenzelm@53445
   206
  "$ISABELLE_JEDIT_BUILD_HOME/contrib/Console.jar"
wenzelm@53445
   207
  "$ISABELLE_JEDIT_BUILD_HOME/contrib/ErrorList.jar"
wenzelm@53445
   208
  "$ISABELLE_JEDIT_BUILD_HOME/contrib/Highlight.jar"
wenzelm@53445
   209
  "$ISABELLE_JEDIT_BUILD_HOME/contrib/SideKick.jar"
wenzelm@53445
   210
  "$ISABELLE_JEDIT_BUILD_HOME/contrib/idea-icons.jar"
wenzelm@53445
   211
  "$ISABELLE_JEDIT_BUILD_HOME/contrib/jsr305-2.0.0.jar"
wenzelm@43284
   212
)
wenzelm@43284
   213
wenzelm@43284
   214
wenzelm@43284
   215
# target
wenzelm@43284
   216
wenzelm@43284
   217
TARGET="dist/jars/Isabelle-jEdit.jar"
wenzelm@43284
   218
wenzelm@43384
   219
declare -a UPDATED=()
wenzelm@43384
   220
wenzelm@43285
   221
if [ "$BUILD_JARS" = jars_fresh ]; then
wenzelm@43285
   222
  OUTDATED=true
wenzelm@43285
   223
else
wenzelm@43285
   224
  OUTDATED=false
wenzelm@43368
   225
  if [ ! -e "$TARGET" ]; then
wenzelm@43368
   226
    OUTDATED=true
wenzelm@43384
   227
  else
wenzelm@43384
   228
    if [ -n "$ISABELLE_JEDIT_BUILD_HOME" ]; then
wenzelm@49566
   229
      declare -a DEPS=(
wenzelm@53576
   230
        "$JEDIT_JAR" "${JEDIT_JARS[@]}" "$PURE_JAR" "$GRAPHVIEW_JAR"
wenzelm@53576
   231
        "${SOURCES[@]}" "${RESOURCES[@]}"
wenzelm@49566
   232
      )
wenzelm@47666
   233
    elif [ -e "$ISABELLE_HOME/Admin/build" ]; then
wenzelm@49566
   234
      declare -a DEPS=("$PURE_JAR" "$GRAPHVIEW_JAR" "${SOURCES[@]}" "${RESOURCES[@]}")
wenzelm@43384
   235
    else
wenzelm@47666
   236
      declare -a DEPS=()
wenzelm@43384
   237
    fi
wenzelm@43384
   238
    for DEP in "${DEPS[@]}"
wenzelm@43368
   239
    do
wenzelm@43384
   240
      [ ! -e "$DEP" ] && fail "Missing file: $DEP"
wenzelm@43384
   241
      [ "$DEP" -nt "$TARGET" ] && {
wenzelm@43384
   242
        OUTDATED=true
wenzelm@43384
   243
        UPDATED["${#UPDATED[@]}"]="$DEP"
wenzelm@43384
   244
      }
wenzelm@43368
   245
    done
wenzelm@43368
   246
  fi
wenzelm@43285
   247
fi
wenzelm@43284
   248
wenzelm@43284
   249
wenzelm@43284
   250
# build
wenzelm@43284
   251
wenzelm@43284
   252
if [ "$OUTDATED" = true ]
wenzelm@43284
   253
then
wenzelm@43405
   254
  echo "### Building Isabelle/jEdit ..."
wenzelm@43405
   255
wenzelm@43384
   256
  [ "${#UPDATED[@]}" -gt 0 ] && {
wenzelm@43405
   257
    echo "Changed files:"
wenzelm@43384
   258
    for FILE in "${UPDATED[@]}"
wenzelm@43384
   259
    do
wenzelm@43384
   260
      echo "  $FILE"
wenzelm@43384
   261
    done
wenzelm@43384
   262
  }
wenzelm@43384
   263
wenzelm@43284
   264
  [ -z "$ISABELLE_JEDIT_BUILD_HOME" ] && \
wenzelm@43284
   265
    fail "Unknown ISABELLE_JEDIT_BUILD_HOME -- missing auxiliary component"
wenzelm@43284
   266
wenzelm@43284
   267
  rm -rf dist || failed
wenzelm@43284
   268
  mkdir -p dist dist/classes || failed
wenzelm@43287
   269
wenzelm@46502
   270
  cp -p -R -f "$ISABELLE_JEDIT_BUILD_HOME/contrib/$ISABELLE_JEDIT_BUILD_VERSION/." dist/.
wenzelm@46502
   271
  cp -p -R -f "${RESOURCES[@]}" dist/classes/.
wenzelm@43287
   272
  cp src/jEdit.props dist/properties/.
wenzelm@46502
   273
  cp -p -R -f src/modes/. dist/modes/.
wenzelm@43284
   274
wenzelm@43391
   275
  perl -i -e 'while (<>) {
wenzelm@43391
   276
    if (m/NAME="javacc"/) {
wenzelm@43391
   277
      print qq,<MODE NAME="isabelle" FILE="isabelle.xml" FILE_NAME_GLOB="*.thy"/>\n\n,;
wenzelm@52539
   278
      print qq,<MODE NAME="isabelle-news" FILE="isabelle-news.xml"/>\n\n,;
wenzelm@48366
   279
      print qq,<MODE NAME="isabelle-options" FILE="isabelle-options.xml"/>\n\n,;
wenzelm@48575
   280
      print qq,<MODE NAME="isabelle-root" FILE="isabelle-root.xml" FILE_NAME_GLOB="ROOT"/>\n\n,; }
wenzelm@43284
   281
    print; }' dist/modes/catalog
wenzelm@43284
   282
wenzelm@53445
   283
  cp -p -R -f "${JEDIT_JARS[@]}" dist/jars/. || failed
wenzelm@43284
   284
  (
wenzelm@53578
   285
    #workaround for scalac 2.10.2
wenzelm@53451
   286
    function stty() { :; }
wenzelm@53451
   287
    export -f stty
wenzelm@53451
   288
wenzelm@53576
   289
    for JAR in "$JEDIT_JAR" "${JEDIT_JARS[@]}" "$PURE_JAR" "$GRAPHVIEW_JAR"
wenzelm@43284
   290
    do
wenzelm@53576
   291
      classpath "$JAR"
wenzelm@43284
   292
    done
wenzelm@53576
   293
    export CLASSPATH="$(jvmpath "$ISABELLE_CLASSPATH")"
wenzelm@47009
   294
    exec "$SCALA_HOME/bin/scalac" $ISABELLE_SCALA_BUILD_OPTIONS -d dist/classes "${SOURCES[@]}"
wenzelm@43284
   295
  ) || fail "Failed to compile sources"
wenzelm@43284
   296
wenzelm@43284
   297
  cd dist/classes
wenzelm@47115
   298
  isabelle_jdk jar cf "../jars/Isabelle-jEdit.jar" * || failed
wenzelm@43284
   299
  cd ../..
wenzelm@43284
   300
  rm -rf dist/classes
wenzelm@43284
   301
fi
wenzelm@43284
   302
wenzelm@43284
   303
popd >/dev/null
wenzelm@43284
   304
wenzelm@43284
   305
wenzelm@43284
   306
## main
wenzelm@43284
   307
wenzelm@53576
   308
if [ "$BUILD_ONLY" = false ]
wenzelm@53576
   309
then
wenzelm@53449
   310
  export JEDIT_SESSION_DIRS JEDIT_LOGIC JEDIT_PRINT_MODE JEDIT_BUILD_MODE
wenzelm@53576
   311
  classpath "$JEDIT_HOME/dist/jedit.jar"
wenzelm@53576
   312
  exec "$ISABELLE_TOOL" java "${JAVA_ARGS[@]}" isabelle.Main "${ARGS[@]}"
wenzelm@50416
   313
fi