src/Tools/jEdit/lib/Tools/jedit
author wenzelm
Wed Dec 04 18:59:20 2013 +0100 (2013-12-04)
changeset 54667 4dd08fe126ba
parent 54666 391ba1e12360
child 54676 6b2ca4850b71
permissions -rwxr-xr-x
remove junk;
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@43285
    31
  "src/output_dockable.scala"
wenzelm@43285
    32
  "src/plugin.scala"
wenzelm@49398
    33
  "src/pretty_text_area.scala"
wenzelm@49702
    34
  "src/pretty_tooltip.scala"
wenzelm@52934
    35
  "src/process_indicator.scala"
wenzelm@43285
    36
  "src/protocol_dockable.scala"
wenzelm@43285
    37
  "src/raw_output_dockable.scala"
wenzelm@50202
    38
  "src/rendering.scala"
wenzelm@49411
    39
  "src/rich_text_area.scala"
wenzelm@43285
    40
  "src/scala_console.scala"
wenzelm@52908
    41
  "src/sledgehammer_dockable.scala"
immler@50143
    42
  "src/symbols_dockable.scala"
wenzelm@48021
    43
  "src/syslog_dockable.scala"
wenzelm@46572
    44
  "src/text_overview.scala"
wenzelm@50299
    45
  "src/theories_dockable.scala"
wenzelm@51533
    46
  "src/timing_dockable.scala"
wenzelm@43414
    47
  "src/token_markup.scala"
wenzelm@43285
    48
)
wenzelm@43285
    49
wenzelm@43320
    50
declare -a RESOURCES=(
wenzelm@43286
    51
  "src/actions.xml"
wenzelm@43286
    52
  "src/dockables.xml"
wenzelm@43286
    53
  "src/Isabelle.props"
wenzelm@50306
    54
  "src/jEdit.props"
wenzelm@43286
    55
  "src/services.xml"
wenzelm@52540
    56
  "src/modes/isabelle-news.xml"
wenzelm@52540
    57
  "src/modes/isabelle-options.xml"
wenzelm@52540
    58
  "src/modes/isabelle-root.xml"
wenzelm@52540
    59
  "src/modes/isabelle.xml"
wenzelm@43285
    60
)
wenzelm@43285
    61
wenzelm@43285
    62
wenzelm@34333
    63
## diagnostics
wenzelm@34333
    64
wenzelm@34664
    65
PRG="$(basename "$0")"
wenzelm@34664
    66
wenzelm@43284
    67
function usage()
wenzelm@34333
    68
{
wenzelm@34333
    69
  echo
wenzelm@34664
    70
  echo "Usage: isabelle $PRG [OPTIONS] [FILES ...]"
wenzelm@34333
    71
  echo
wenzelm@34333
    72
  echo "  Options are:"
wenzelm@34333
    73
  echo "    -J OPTION    add JVM runtime option"
wenzelm@34409
    74
  echo "                 (default JEDIT_JAVA_OPTIONS=$JEDIT_JAVA_OPTIONS)"
wenzelm@43285
    75
  echo "    -b           build only"
wenzelm@48791
    76
  echo "    -d DIR       include session directory"
wenzelm@43285
    77
  echo "    -f           fresh build"
wenzelm@34333
    78
  echo "    -j OPTION    add jEdit runtime option"
wenzelm@34333
    79
  echo "                 (default JEDIT_OPTIONS=$JEDIT_OPTIONS)"
wenzelm@50403
    80
  echo "    -l NAME      logic session name"
wenzelm@34333
    81
  echo "    -m MODE      add print mode for output"
wenzelm@50405
    82
  echo "    -n           no build dialog for session image on startup"
wenzelm@50373
    83
  echo "    -s           system build mode for session image"
wenzelm@34333
    84
  echo
wenzelm@50550
    85
  echo "Start jEdit with Isabelle plugin setup and open theory FILES"
wenzelm@50114
    86
  echo "(default \"$USER_HOME/Scratch.thy\")."
wenzelm@34333
    87
  echo
wenzelm@34333
    88
  exit 1
wenzelm@34333
    89
}
wenzelm@34333
    90
wenzelm@43284
    91
function fail()
wenzelm@34333
    92
{
wenzelm@34333
    93
  echo "$1" >&2
wenzelm@34333
    94
  exit 2
wenzelm@34333
    95
}
wenzelm@34333
    96
wenzelm@43284
    97
function failed()
wenzelm@43284
    98
{
wenzelm@43284
    99
  fail "Failed!"
wenzelm@43284
   100
}
wenzelm@43284
   101
wenzelm@34333
   102
wenzelm@34333
   103
## process command line
wenzelm@34333
   104
wenzelm@34333
   105
# options
wenzelm@34333
   106
wenzelm@43285
   107
BUILD_ONLY=false
wenzelm@43285
   108
BUILD_JARS="jars"
wenzelm@48791
   109
JEDIT_SESSION_DIRS=""
wenzelm@50403
   110
JEDIT_LOGIC=""
wenzelm@34333
   111
JEDIT_PRINT_MODE=""
wenzelm@53449
   112
JEDIT_BUILD_MODE="normal"
wenzelm@34333
   113
wenzelm@43284
   114
function getoptions()
wenzelm@34780
   115
{
wenzelm@34780
   116
  OPTIND=1
wenzelm@50405
   117
  while getopts "J:bd:fj:l:m:ns" OPT
wenzelm@34780
   118
  do
wenzelm@34780
   119
    case "$OPT" in
wenzelm@34780
   120
      J)
wenzelm@34780
   121
        JAVA_ARGS["${#JAVA_ARGS[@]}"]="$OPTARG"
wenzelm@34780
   122
        ;;
wenzelm@43285
   123
      b)
wenzelm@43285
   124
        BUILD_ONLY=true
wenzelm@43285
   125
        ;;
wenzelm@48791
   126
      d)
wenzelm@48791
   127
        if [ -z "$JEDIT_SESSION_DIRS" ]; then
wenzelm@48791
   128
          JEDIT_SESSION_DIRS="$OPTARG"
wenzelm@48791
   129
        else
wenzelm@48791
   130
          JEDIT_SESSION_DIRS="$JEDIT_SESSION_DIRS:$OPTARG"
wenzelm@48791
   131
        fi
wenzelm@48791
   132
        ;;
wenzelm@43285
   133
      f)
wenzelm@43285
   134
        BUILD_JARS="jars_fresh"
wenzelm@43285
   135
        ;;
wenzelm@34780
   136
      j)
wenzelm@34780
   137
        ARGS["${#ARGS[@]}"]="$OPTARG"
wenzelm@34780
   138
        ;;
wenzelm@34780
   139
      l)
wenzelm@34780
   140
        JEDIT_LOGIC="$OPTARG"
wenzelm@34780
   141
        ;;
wenzelm@34780
   142
      m)
wenzelm@34780
   143
        if [ -z "$JEDIT_PRINT_MODE" ]; then
wenzelm@34780
   144
          JEDIT_PRINT_MODE="$OPTARG"
wenzelm@34780
   145
        else
wenzelm@34780
   146
          JEDIT_PRINT_MODE="$JEDIT_PRINT_MODE,$OPTARG"
wenzelm@34780
   147
        fi
wenzelm@34780
   148
        ;;
wenzelm@50405
   149
      n)
wenzelm@53449
   150
        JEDIT_BUILD_MODE="none"
wenzelm@50405
   151
        ;;
wenzelm@50373
   152
      s)
wenzelm@53449
   153
        JEDIT_BUILD_MODE="system"
wenzelm@50373
   154
        ;;
wenzelm@34780
   155
      \?)
wenzelm@34780
   156
        usage
wenzelm@34780
   157
        ;;
wenzelm@34780
   158
    esac
wenzelm@34780
   159
  done
wenzelm@34780
   160
}
wenzelm@34581
   161
wenzelm@38257
   162
declare -a JAVA_ARGS; eval "JAVA_ARGS=($JEDIT_JAVA_OPTIONS $JEDIT_SYSTEM_OPTIONS)"
wenzelm@34843
   163
wenzelm@53446
   164
declare -a ARGS=()
wenzelm@34333
   165
wenzelm@34780
   166
declare -a OPTIONS; eval "OPTIONS=($ISABELLE_JEDIT_OPTIONS)"
wenzelm@34780
   167
getoptions "${OPTIONS[@]}"
wenzelm@34780
   168
wenzelm@34780
   169
getoptions "$@"
wenzelm@34333
   170
shift $(($OPTIND - 1))
wenzelm@34333
   171
wenzelm@34333
   172
wenzelm@34333
   173
# args
wenzelm@34333
   174
wenzelm@44485
   175
if [ "$#" -eq 0 ]; then
wenzelm@50120
   176
  ARGS["${#ARGS[@]}"]="$(jvmpath "$USER_HOME/Scratch.thy")"
wenzelm@44485
   177
else
wenzelm@44485
   178
  while [ "$#" -gt 0 ]; do
wenzelm@44485
   179
    ARGS["${#ARGS[@]}"]="$(jvmpath "$1")"
wenzelm@44485
   180
    shift
wenzelm@44485
   181
  done
wenzelm@44485
   182
fi
wenzelm@34333
   183
wenzelm@34333
   184
wenzelm@43284
   185
## dependencies
wenzelm@43284
   186
wenzelm@49953
   187
if [ -e "$ISABELLE_HOME/Admin/build" ]; then
wenzelm@50782
   188
  "$ISABELLE_TOOL" browser -b || exit $?
wenzelm@49953
   189
  if [ "$BUILD_JARS" = jars_fresh ]; then
wenzelm@49953
   190
    "$ISABELLE_TOOL" graphview -b -f || exit $?
wenzelm@49953
   191
  else
wenzelm@49566
   192
    "$ISABELLE_HOME/Admin/build" "$BUILD_JARS" || exit $?
wenzelm@49953
   193
    "$ISABELLE_TOOL" graphview -b || exit $?
wenzelm@49953
   194
  fi
wenzelm@49953
   195
fi
wenzelm@43413
   196
wenzelm@53577
   197
PURE_JAR="$ISABELLE_HOME/lib/classes/Pure.jar"
wenzelm@53577
   198
GRAPHVIEW_JAR="$ISABELLE_HOME/lib/classes/Graphview.jar"
wenzelm@43413
   199
wenzelm@43285
   200
pushd "$JEDIT_HOME" >/dev/null || failed
wenzelm@43284
   201
wenzelm@43284
   202
JEDIT_JAR="$ISABELLE_JEDIT_BUILD_HOME/contrib/$ISABELLE_JEDIT_BUILD_VERSION/jedit.jar"
wenzelm@43284
   203
wenzelm@43284
   204
JEDIT_JARS=(
wenzelm@53445
   205
  "$ISABELLE_JEDIT_BUILD_HOME/contrib/Console.jar"
wenzelm@53445
   206
  "$ISABELLE_JEDIT_BUILD_HOME/contrib/ErrorList.jar"
wenzelm@53445
   207
  "$ISABELLE_JEDIT_BUILD_HOME/contrib/Highlight.jar"
wenzelm@53883
   208
  "$ISABELLE_JEDIT_BUILD_HOME/contrib/MacOSX.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@54660
   283
  cd dist
wenzelm@54660
   284
  isabelle_jdk jar xf jedit.jar
wenzelm@54660
   285
  cp "$ISABELLE_HOME/lib/logo/isabelle-32.gif" \
wenzelm@54660
   286
    "org/gjt/sp/jedit/icons/themes/classic/32x32/apps/isabelle.gif" || failed
wenzelm@54660
   287
  cp "$ISABELLE_HOME/lib/logo/isabelle-32.gif" \
wenzelm@54660
   288
    "org/gjt/sp/jedit/icons/themes/tango/32x32/apps/isabelle.gif" || failed
wenzelm@54666
   289
  isabelle_jdk jar cfe jedit.jar org.gjt.sp.jedit.jEdit org || failed
wenzelm@54667
   290
  rm -rf META-INF org
wenzelm@54660
   291
  cd ..
wenzelm@54660
   292
wenzelm@53445
   293
  cp -p -R -f "${JEDIT_JARS[@]}" dist/jars/. || failed
wenzelm@43284
   294
  (
wenzelm@53578
   295
    #workaround for scalac 2.10.2
wenzelm@53451
   296
    function stty() { :; }
wenzelm@53451
   297
    export -f stty
wenzelm@53451
   298
wenzelm@53576
   299
    for JAR in "$JEDIT_JAR" "${JEDIT_JARS[@]}" "$PURE_JAR" "$GRAPHVIEW_JAR"
wenzelm@43284
   300
    do
wenzelm@53576
   301
      classpath "$JAR"
wenzelm@43284
   302
    done
wenzelm@53576
   303
    export CLASSPATH="$(jvmpath "$ISABELLE_CLASSPATH")"
wenzelm@47009
   304
    exec "$SCALA_HOME/bin/scalac" $ISABELLE_SCALA_BUILD_OPTIONS -d dist/classes "${SOURCES[@]}"
wenzelm@43284
   305
  ) || fail "Failed to compile sources"
wenzelm@43284
   306
wenzelm@43284
   307
  cd dist/classes
wenzelm@47115
   308
  isabelle_jdk jar cf "../jars/Isabelle-jEdit.jar" * || failed
wenzelm@43284
   309
  cd ../..
wenzelm@43284
   310
  rm -rf dist/classes
wenzelm@43284
   311
fi
wenzelm@43284
   312
wenzelm@43284
   313
popd >/dev/null
wenzelm@43284
   314
wenzelm@43284
   315
wenzelm@43284
   316
## main
wenzelm@43284
   317
wenzelm@53576
   318
if [ "$BUILD_ONLY" = false ]
wenzelm@53576
   319
then
wenzelm@53449
   320
  export JEDIT_SESSION_DIRS JEDIT_LOGIC JEDIT_PRINT_MODE JEDIT_BUILD_MODE
wenzelm@53576
   321
  classpath "$JEDIT_HOME/dist/jedit.jar"
wenzelm@53576
   322
  exec "$ISABELLE_TOOL" java "${JAVA_ARGS[@]}" isabelle.Main "${ARGS[@]}"
wenzelm@50416
   323
fi