separate base plugin for important services that should be always available, despite startup errors of the main plugin;
authorwenzelm
Sun, 20 Aug 2017 14:03:23 +0200
changeset 66457 9098c36abd1a
parent 66455 158c513a39f5
child 66458 42d0d5c77c78
separate base plugin for important services that should be always available, despite startup errors of the main plugin;
src/Tools/jEdit/lib/Tools/jedit
src/Tools/jEdit/src-base/isabelle_encoding.scala
src/Tools/jEdit/src-base/plugin.scala
src/Tools/jEdit/src-base/services.xml
src/Tools/jEdit/src/Isabelle.props
src/Tools/jEdit/src/isabelle_encoding.scala
src/Tools/jEdit/src/services.xml
--- a/src/Tools/jEdit/lib/Tools/jedit	Fri Aug 18 22:55:54 2017 +0200
+++ b/src/Tools/jEdit/lib/Tools/jedit	Sun Aug 20 14:03:23 2017 +0200
@@ -19,6 +19,16 @@
 
 ## sources
 
+declare -a SOURCES_BASE=(
+  "src-base/isabelle_encoding.scala"
+  "src-base/plugin.scala"
+)
+
+declare -a RESOURCES_BASE=(
+  "src-base/Isabelle_Base.props"
+  "src-base/services.xml"
+)
+
 declare -a SOURCES=(
   "src/active.scala"
   "src/completion_popup.scala"
@@ -248,6 +258,7 @@
 
 # target
 
+TARGET_BASE="dist/jars/Isabelle-jEdit-base.jar"
 TARGET="dist/jars/Isabelle-jEdit.jar"
 
 declare -a UPDATED=()
@@ -256,23 +267,28 @@
   OUTDATED=true
 else
   OUTDATED=false
-  if [ ! -e "$TARGET" ]; then
+  if [ ! -e "$TARGET_BASE" -a ! -e "$TARGET" ]; then
     OUTDATED=true
   else
     if [ -n "$ISABELLE_JEDIT_BUILD_HOME" ]; then
       declare -a DEPS=(
         "$JEDIT_JAR" "${JEDIT_JARS[@]}" "$PURE_JAR"
+        "${SOURCES_BASE[@]}" "${RESOURCES_BASE[@]}"
         "${SOURCES[@]}" "${RESOURCES[@]}"
       )
     elif [ -e "$ISABELLE_HOME/Admin/build" ]; then
-      declare -a DEPS=("$PURE_JAR" "${SOURCES[@]}" "${RESOURCES[@]}")
+      declare -a DEPS=(
+        "$PURE_JAR"
+        "${SOURCES_BASE[@]}" "${RESOURCES_BASE[@]}"
+        "${SOURCES[@]}" "${RESOURCES[@]}"
+      )
     else
       declare -a DEPS=()
     fi
     for DEP in "${DEPS[@]}"
     do
       [ ! -e "$DEP" ] && fail "Missing file: $DEP"
-      [ "$DEP" -nt "$TARGET" ] && {
+      [ "$DEP" -nt "$TARGET_BASE" -o "$DEP" -nt "$TARGET" ] && {
         OUTDATED=true
         UPDATED["${#UPDATED[@]}"]="$DEP"
       }
@@ -283,6 +299,37 @@
 
 # build
 
+function init_resources ()
+{
+  mkdir -p dist/classes || failed
+  cp -p -R -f "$@" dist/classes/.
+}
+
+function compile_sources ()
+{
+  (
+    #FIXME workarounds for scalac 2.11.0
+    export CYGWIN="nodosfilewarning"
+    function stty() { :; }
+    export -f stty
+
+    for JAR in "$JEDIT_JAR" "${JEDIT_JARS[@]}" "$PURE_JAR"
+    do
+      classpath "$JAR"
+    done
+    export CLASSPATH="$(platform_path "$ISABELLE_CLASSPATH")"
+    isabelle_scala scalac $ISABELLE_SCALAC_OPTIONS -d dist/classes "$@"
+  ) || fail "Failed to compile sources"
+}
+
+function make_jar ()
+{
+  cd dist/classes
+  isabelle_jdk jar cf "../../$1" * || failed
+  cd ../..
+  rm -rf dist/classes
+}
+
 if [ "$OUTDATED" = true ]
 then
   echo "### Building Isabelle/jEdit ..."
@@ -299,10 +346,15 @@
     fail "Unknown ISABELLE_JEDIT_BUILD_HOME -- missing auxiliary component"
 
   rm -rf dist || failed
-  mkdir -p dist dist/classes || failed
+  mkdir -p dist || failed
 
   cp -p -R -f "$ISABELLE_JEDIT_BUILD_HOME/contrib/$ISABELLE_JEDIT_BUILD_VERSION/." dist/.
-  cp -p -R -f "${RESOURCES[@]}" dist/classes/.
+
+  init_resources "${RESOURCES_BASE[@]}"
+  compile_sources "${SOURCES_BASE[@]}"
+  make_jar "$TARGET_BASE"
+
+  init_resources "${RESOURCES[@]}"
   cp src/jEdit.props dist/properties/.
   cp -p -R -f src/modes/. dist/modes/.
 
@@ -334,24 +386,8 @@
   cd ..
 
   cp -p -R -f "${JEDIT_JARS[@]}" dist/jars/. || failed
-  (
-    #FIXME workarounds for scalac 2.11.0
-    export CYGWIN="nodosfilewarning"
-    function stty() { :; }
-    export -f stty
-
-    for JAR in "$JEDIT_JAR" "${JEDIT_JARS[@]}" "$PURE_JAR"
-    do
-      classpath "$JAR"
-    done
-    export CLASSPATH="$(platform_path "$ISABELLE_CLASSPATH")"
-    isabelle_scala scalac $ISABELLE_SCALAC_OPTIONS -d dist/classes "${SOURCES[@]}"
-  ) || fail "Failed to compile sources"
-
-  cd dist/classes
-  isabelle_jdk jar cf "../jars/Isabelle-jEdit.jar" * || failed
-  cd ../..
-  rm -rf dist/classes
+  compile_sources "${SOURCES[@]}"
+  make_jar "$TARGET"
 
   cp "$ISABELLE_JEDIT_BUILD_HOME/doc/jedit5.4.0manual-a4.pdf" dist/doc/jedit-manual.pdf
   cp dist/doc/CHANGES.txt dist/doc/jedit-changes
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/Tools/jEdit/src-base/isabelle_encoding.scala	Sun Aug 20 14:03:23 2017 +0200
@@ -0,0 +1,54 @@
+/*  Title:      Tools/jEdit/src-base/isabelle_encoding.scala
+    Author:     Makarius
+
+Isabelle encoding -- based on UTF-8.
+*/
+
+package isabelle.jedit_base
+
+
+import isabelle._
+
+import org.gjt.sp.jedit.io.Encoding
+
+import java.nio.charset.{Charset, CodingErrorAction}
+import java.io.{InputStream, OutputStream, Reader, Writer, InputStreamReader, OutputStreamWriter,
+  CharArrayReader, ByteArrayOutputStream}
+
+import scala.io.{Codec, BufferedSource}
+
+
+class Isabelle_Encoding extends Encoding
+{
+  private val BUFSIZE = 32768
+
+  private def text_reader(in: InputStream, codec: Codec): Reader =
+  {
+    val source = new BufferedSource(in)(codec)
+    new CharArrayReader(Symbol.decode(source.mkString).toArray)
+  }
+
+  override def getTextReader(in: InputStream): Reader = text_reader(in, UTF8.codec())
+
+  override def getPermissiveTextReader(in: InputStream): Reader =
+  {
+    val codec = UTF8.codec()
+    codec.onMalformedInput(CodingErrorAction.REPLACE)
+    codec.onUnmappableCharacter(CodingErrorAction.REPLACE)
+    text_reader(in, codec)
+  }
+
+  override def getTextWriter(out: OutputStream): Writer =
+  {
+    val buffer = new ByteArrayOutputStream(BUFSIZE) {
+      override def flush()
+      {
+        val text = Symbol.encode(toString(UTF8.charset_name))
+        out.write(UTF8.bytes(text))
+        out.flush()
+      }
+      override def close() { out.close() }
+    }
+    new OutputStreamWriter(buffer, UTF8.charset.newEncoder())
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/Tools/jEdit/src-base/plugin.scala	Sun Aug 20 14:03:23 2017 +0200
@@ -0,0 +1,21 @@
+/*  Title:      Tools/jEdit/src-base/plugin.scala
+    Author:     Makarius
+
+Isabelle base environment for jEdit.
+*/
+
+package isabelle.jedit_base
+
+
+import isabelle._
+
+import org.gjt.sp.jedit.EBPlugin
+
+
+class Plugin extends EBPlugin
+{
+  override def start()
+  {
+    Isabelle_System.init()
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/Tools/jEdit/src-base/services.xml	Sun Aug 20 14:03:23 2017 +0200
@@ -0,0 +1,8 @@
+<?xml version="1.0"?>
+<!DOCTYPE SERVICES SYSTEM "services.dtd">
+
+<SERVICES>
+  <SERVICE NAME="UTF-8-Isabelle" CLASS="org.gjt.sp.jedit.io.Encoding">
+    new isabelle.jedit_base.Isabelle_Encoding();
+  </SERVICE>
+</SERVICES>
--- a/src/Tools/jEdit/src/Isabelle.props	Fri Aug 18 22:55:54 2017 +0200
+++ b/src/Tools/jEdit/src/Isabelle.props	Sun Aug 20 14:03:23 2017 +0200
@@ -18,6 +18,7 @@
 plugin.isabelle.jedit.Plugin.depend.2=plugin console.ConsolePlugin 5.1.4
 plugin.isabelle.jedit.Plugin.depend.3=plugin errorlist.ErrorListPlugin 2.3
 plugin.isabelle.jedit.Plugin.depend.4=plugin sidekick.SideKickPlugin 1.8
+plugin.isabelle.jedit.Plugin.depend.5=plugin isabelle.jedit_base.Plugin 1.0
 
 #options
 plugin.isabelle.jedit.Plugin.option-group=isabelle-general isabelle-rendering
--- a/src/Tools/jEdit/src/isabelle_encoding.scala	Fri Aug 18 22:55:54 2017 +0200
+++ b/src/Tools/jEdit/src/isabelle_encoding.scala	Sun Aug 20 14:03:23 2017 +0200
@@ -9,58 +9,14 @@
 
 import isabelle._
 
-import org.gjt.sp.jedit.io.Encoding
 import org.gjt.sp.jedit.buffer.JEditBuffer
 
-import java.nio.charset.{Charset, CodingErrorAction}
-import java.io.{InputStream, OutputStream, Reader, Writer, InputStreamReader, OutputStreamWriter,
-  CharArrayReader, ByteArrayOutputStream}
-
-import scala.io.{Codec, BufferedSource}
-
 
 object Isabelle_Encoding
 {
-  val NAME = "UTF-8-Isabelle"
-
   def is_active(buffer: JEditBuffer): Boolean =
-    buffer.getStringProperty(JEditBuffer.ENCODING).asInstanceOf[String] == NAME
+    buffer.getStringProperty(JEditBuffer.ENCODING).asInstanceOf[String] == "UTF-8-Isabelle"
 
   def maybe_decode(buffer: JEditBuffer, s: String): String =
     if (is_active(buffer)) Symbol.decode(s) else s
 }
-
-class Isabelle_Encoding extends Encoding
-{
-  private val BUFSIZE = 32768
-
-  private def text_reader(in: InputStream, codec: Codec): Reader =
-  {
-    val source = new BufferedSource(in)(codec)
-    new CharArrayReader(Symbol.decode(source.mkString).toArray)
-  }
-
-  override def getTextReader(in: InputStream): Reader = text_reader(in, UTF8.codec())
-
-  override def getPermissiveTextReader(in: InputStream): Reader =
-  {
-    val codec = UTF8.codec()
-    codec.onMalformedInput(CodingErrorAction.REPLACE)
-    codec.onUnmappableCharacter(CodingErrorAction.REPLACE)
-    text_reader(in, codec)
-  }
-
-  override def getTextWriter(out: OutputStream): Writer =
-  {
-    val buffer = new ByteArrayOutputStream(BUFSIZE) {
-      override def flush()
-      {
-        val text = Symbol.encode(toString(UTF8.charset_name))
-        out.write(UTF8.bytes(text))
-        out.flush()
-      }
-      override def close() { out.close() }
-    }
-    new OutputStreamWriter(buffer, UTF8.charset.newEncoder())
-  }
-}
--- a/src/Tools/jEdit/src/services.xml	Fri Aug 18 22:55:54 2017 +0200
+++ b/src/Tools/jEdit/src/services.xml	Sun Aug 20 14:03:23 2017 +0200
@@ -11,9 +11,6 @@
   <SERVICE CLASS="org.gjt.sp.jedit.gui.DockingFrameworkProvider" NAME="PIDE">
     new isabelle.jedit.PIDE_Docking_Framework();
   </SERVICE>
-  <SERVICE NAME="UTF-8-Isabelle" CLASS="org.gjt.sp.jedit.io.Encoding">
-    new isabelle.jedit.Isabelle_Encoding();
-  </SERVICE>
   <SERVICE NAME="isabelle" CLASS="sidekick.SideKickParser">
     new isabelle.jedit.Isabelle_Sidekick_Default();
   </SERVICE>