src/Pure/Tools/main.scala
author wenzelm
Sat, 28 Sep 2013 13:40:33 +0200
changeset 53966 5a546a881f90
parent 53965 cca95e9055ba
child 53967 bfaae48b0ce0
permissions -rw-r--r--
update second environment that is used for System.getenv(String);
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50687
a8db4bf70e90 moved files;
wenzelm
parents: 48275
diff changeset
     1
/*  Title:      Pure/Tools/main.scala
47663
20e0865ae9e7 default Isabelle application wrapper -- JVM entry point for Isabelle.exe;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
20e0865ae9e7 default Isabelle application wrapper -- JVM entry point for Isabelle.exe;
wenzelm
parents:
diff changeset
     3
53419
1c87e79bb838 main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents: 52675
diff changeset
     4
Main Isabelle application entry point.
47663
20e0865ae9e7 default Isabelle application wrapper -- JVM entry point for Isabelle.exe;
wenzelm
parents:
diff changeset
     5
*/
20e0865ae9e7 default Isabelle application wrapper -- JVM entry point for Isabelle.exe;
wenzelm
parents:
diff changeset
     6
20e0865ae9e7 default Isabelle application wrapper -- JVM entry point for Isabelle.exe;
wenzelm
parents:
diff changeset
     7
package isabelle
20e0865ae9e7 default Isabelle application wrapper -- JVM entry point for Isabelle.exe;
wenzelm
parents:
diff changeset
     8
53419
1c87e79bb838 main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents: 52675
diff changeset
     9
53912
f6fb8ca4517f initialize class immediately (potentially more robust);
wenzelm
parents: 53772
diff changeset
    10
import java.lang.{System, Class, ClassLoader}
53461
26c609ada983 clarified modules;
wenzelm
parents: 53460
diff changeset
    11
import java.io.{File => JFile, BufferedReader, InputStreamReader}
26c609ada983 clarified modules;
wenzelm
parents: 53460
diff changeset
    12
import java.nio.file.Files
26c609ada983 clarified modules;
wenzelm
parents: 53460
diff changeset
    13
26c609ada983 clarified modules;
wenzelm
parents: 53460
diff changeset
    14
import scala.annotation.tailrec
47663
20e0865ae9e7 default Isabelle application wrapper -- JVM entry point for Isabelle.exe;
wenzelm
parents:
diff changeset
    15
20e0865ae9e7 default Isabelle application wrapper -- JVM entry point for Isabelle.exe;
wenzelm
parents:
diff changeset
    16
20e0865ae9e7 default Isabelle application wrapper -- JVM entry point for Isabelle.exe;
wenzelm
parents:
diff changeset
    17
object Main
20e0865ae9e7 default Isabelle application wrapper -- JVM entry point for Isabelle.exe;
wenzelm
parents:
diff changeset
    18
{
53461
26c609ada983 clarified modules;
wenzelm
parents: 53460
diff changeset
    19
  /** main entry point **/
26c609ada983 clarified modules;
wenzelm
parents: 53460
diff changeset
    20
53456
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
    21
  def main(args: Array[String])
53449
913df2adc99c build session before start of jedit;
wenzelm
parents: 53445
diff changeset
    22
  {
53456
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
    23
    val system_dialog = new System_Dialog
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
    24
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
    25
    def exit_error(exn: Throwable): Nothing =
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
    26
    {
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
    27
      GUI.dialog(null, "Isabelle", GUI.scrollable_text(Exn.message(exn)))
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
    28
      system_dialog.return_code(2)
53460
6015a663b889 tuned signature;
wenzelm
parents: 53459
diff changeset
    29
      system_dialog.join_exit
53456
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
    30
    }
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
    31
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
    32
    def build
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
    33
    {
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
    34
      try {
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
    35
        GUI.init_laf()
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
    36
        Isabelle_System.init()
53449
913df2adc99c build session before start of jedit;
wenzelm
parents: 53445
diff changeset
    37
53456
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
    38
        val mode = Isabelle_System.getenv("JEDIT_BUILD_MODE")
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
    39
        if (mode == "none")
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
    40
          system_dialog.return_code(0)
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
    41
        else {
53519
3c977c570e20 discontinued obsolete command-line tool "isabelle build_dialog";
wenzelm
parents: 53466
diff changeset
    42
          val options = Options.init()
53456
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
    43
          val system_mode = mode == "" || mode == "system"
53519
3c977c570e20 discontinued obsolete command-line tool "isabelle build_dialog";
wenzelm
parents: 53466
diff changeset
    44
          val more_dirs = Path.split(Isabelle_System.getenv("JEDIT_SESSION_DIRS")).map((false, _))
53456
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
    45
          val session = Isabelle_System.default_logic(
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
    46
            Isabelle_System.getenv("JEDIT_LOGIC"),
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
    47
            options.string("jedit_logic"))
53519
3c977c570e20 discontinued obsolete command-line tool "isabelle build_dialog";
wenzelm
parents: 53466
diff changeset
    48
3c977c570e20 discontinued obsolete command-line tool "isabelle build_dialog";
wenzelm
parents: 53466
diff changeset
    49
          if (Build.build(options = options, build_heap = true, no_build = true,
3c977c570e20 discontinued obsolete command-line tool "isabelle build_dialog";
wenzelm
parents: 53466
diff changeset
    50
              more_dirs = more_dirs, sessions = List(session)) == 0)
3c977c570e20 discontinued obsolete command-line tool "isabelle build_dialog";
wenzelm
parents: 53466
diff changeset
    51
            system_dialog.return_code(0)
3c977c570e20 discontinued obsolete command-line tool "isabelle build_dialog";
wenzelm
parents: 53466
diff changeset
    52
          else {
3c977c570e20 discontinued obsolete command-line tool "isabelle build_dialog";
wenzelm
parents: 53466
diff changeset
    53
            system_dialog.title("Isabelle build (" + Isabelle_System.getenv("ML_IDENTIFIER") + ")")
3c977c570e20 discontinued obsolete command-line tool "isabelle build_dialog";
wenzelm
parents: 53466
diff changeset
    54
            system_dialog.echo("Build started for Isabelle/" + session + " ...")
3c977c570e20 discontinued obsolete command-line tool "isabelle build_dialog";
wenzelm
parents: 53466
diff changeset
    55
3c977c570e20 discontinued obsolete command-line tool "isabelle build_dialog";
wenzelm
parents: 53466
diff changeset
    56
            val (out, rc) =
3c977c570e20 discontinued obsolete command-line tool "isabelle build_dialog";
wenzelm
parents: 53466
diff changeset
    57
              try {
3c977c570e20 discontinued obsolete command-line tool "isabelle build_dialog";
wenzelm
parents: 53466
diff changeset
    58
                ("",
3c977c570e20 discontinued obsolete command-line tool "isabelle build_dialog";
wenzelm
parents: 53466
diff changeset
    59
                  Build.build(options = options, progress = system_dialog,
3c977c570e20 discontinued obsolete command-line tool "isabelle build_dialog";
wenzelm
parents: 53466
diff changeset
    60
                    build_heap = true, more_dirs = more_dirs,
3c977c570e20 discontinued obsolete command-line tool "isabelle build_dialog";
wenzelm
parents: 53466
diff changeset
    61
                    system_mode = system_mode, sessions = List(session)))
3c977c570e20 discontinued obsolete command-line tool "isabelle build_dialog";
wenzelm
parents: 53466
diff changeset
    62
              }
3c977c570e20 discontinued obsolete command-line tool "isabelle build_dialog";
wenzelm
parents: 53466
diff changeset
    63
              catch { case exn: Throwable => (Exn.message(exn) + "\n", 2) }
3c977c570e20 discontinued obsolete command-line tool "isabelle build_dialog";
wenzelm
parents: 53466
diff changeset
    64
3c977c570e20 discontinued obsolete command-line tool "isabelle build_dialog";
wenzelm
parents: 53466
diff changeset
    65
            system_dialog.echo(out + (if (rc == 0) "OK\n" else "Return code: " + rc + "\n"))
3c977c570e20 discontinued obsolete command-line tool "isabelle build_dialog";
wenzelm
parents: 53466
diff changeset
    66
            system_dialog.return_code(rc)
3c977c570e20 discontinued obsolete command-line tool "isabelle build_dialog";
wenzelm
parents: 53466
diff changeset
    67
          }
53456
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
    68
        }
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
    69
      }
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
    70
      catch { case exn: Throwable => exit_error(exn) }
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
    71
    }
53449
913df2adc99c build session before start of jedit;
wenzelm
parents: 53445
diff changeset
    72
53456
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
    73
    def start
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
    74
    {
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
    75
      val do_start =
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
    76
      {
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
    77
        try {
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
    78
          /* settings directory */
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
    79
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
    80
          val settings_dir = Path.explode("$JEDIT_SETTINGS")
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
    81
          Isabelle_System.mkdirs(settings_dir + Path.explode("DockableWindowManager"))
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
    82
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
    83
          if (!(settings_dir + Path.explode("perspective.xml")).is_file) {
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
    84
            File.write(settings_dir + Path.explode("DockableWindowManager/perspective-view0.xml"),
53772
30de372ca56f removed obsolete README;
wenzelm
parents: 53575
diff changeset
    85
              """<DOCKING LEFT="" TOP="" RIGHT="isabelle-documentation" BOTTOM="" LEFT_POS="0" TOP_POS="0" RIGHT_POS="250" BOTTOM_POS="250" />""")
53456
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
    86
            File.write(settings_dir + Path.explode("perspective.xml"),
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
    87
              """<?xml version="1.0" encoding="UTF-8" ?>
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
    88
<!DOCTYPE PERSPECTIVE SYSTEM "perspective.dtd">
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
    89
<PERSPECTIVE>
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
    90
<VIEW PLAIN="FALSE">
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
    91
<GEOMETRY X="0" Y="35" WIDTH="1072" HEIGHT="787" EXT_STATE="0" />
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
    92
</VIEW>
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
    93
</PERSPECTIVE>""")
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
    94
          }
53449
913df2adc99c build session before start of jedit;
wenzelm
parents: 53445
diff changeset
    95
913df2adc99c build session before start of jedit;
wenzelm
parents: 53445
diff changeset
    96
53456
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
    97
          /* args */
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
    98
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
    99
          val jedit_options =
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
   100
            Isabelle_System.getenv_strict("JEDIT_OPTIONS").split(" +")
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
   101
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
   102
          val jedit_settings =
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
   103
            Array("-settings=" + Isabelle_System.platform_path(Path.explode("$JEDIT_SETTINGS")))
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
   104
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
   105
          val more_args =
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
   106
            if (args.isEmpty)
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
   107
              Array(Isabelle_System.platform_path(Path.explode("$USER_HOME/Scratch.thy")))
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
   108
            else args
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
   109
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
   110
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
   111
          /* startup */
53445
811db2b751ed warm start of Isabelle/jEdit from Isabelle/Scala;
wenzelm
parents: 53423
diff changeset
   112
53965
cca95e9055ba adhoc update of JVM environment variables, which is relevant for cold start of jEdit;
wenzelm
parents: 53912
diff changeset
   113
          update_environment()
cca95e9055ba adhoc update of JVM environment variables, which is relevant for cold start of jEdit;
wenzelm
parents: 53912
diff changeset
   114
53456
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
   115
          System.setProperty("jedit.home",
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
   116
            Isabelle_System.platform_path(Path.explode("$JEDIT_HOME/dist")))
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
   117
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
   118
          System.setProperty("scala.home",
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
   119
            Isabelle_System.platform_path(Path.explode("$SCALA_HOME")))
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
   120
53912
f6fb8ca4517f initialize class immediately (potentially more robust);
wenzelm
parents: 53772
diff changeset
   121
          val jedit =
f6fb8ca4517f initialize class immediately (potentially more robust);
wenzelm
parents: 53772
diff changeset
   122
            Class.forName("org.gjt.sp.jedit.jEdit", true, ClassLoader.getSystemClassLoader)
53456
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
   123
          val jedit_main = jedit.getDeclaredMethod("main", classOf[Array[String]])
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
   124
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
   125
          () => jedit_main.invoke(null, jedit_options ++ jedit_settings ++ more_args)
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
   126
        }
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
   127
        catch { case exn: Throwable => exit_error(exn) }
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
   128
      }
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
   129
      do_start()
d12be8f62285 Build_Dialog based on System_Dialog;
wenzelm
parents: 53449
diff changeset
   130
    }
53419
1c87e79bb838 main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents: 52675
diff changeset
   131
1c87e79bb838 main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents: 52675
diff changeset
   132
    if (Platform.is_windows) {
53459
33f773731f0c Cygwin_Init based on System_Dialog;
wenzelm
parents: 53457
diff changeset
   133
      try {
33f773731f0c Cygwin_Init based on System_Dialog;
wenzelm
parents: 53457
diff changeset
   134
        GUI.init_laf()
53419
1c87e79bb838 main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents: 52675
diff changeset
   135
53459
33f773731f0c Cygwin_Init based on System_Dialog;
wenzelm
parents: 53457
diff changeset
   136
        val isabelle_home0 = System.getenv("ISABELLE_HOME_WINDOWS")
33f773731f0c Cygwin_Init based on System_Dialog;
wenzelm
parents: 53457
diff changeset
   137
        val isabelle_home = System.getProperty("isabelle.home")
47663
20e0865ae9e7 default Isabelle application wrapper -- JVM entry point for Isabelle.exe;
wenzelm
parents:
diff changeset
   138
53459
33f773731f0c Cygwin_Init based on System_Dialog;
wenzelm
parents: 53457
diff changeset
   139
        if (isabelle_home0 == null || isabelle_home0 == "") {
33f773731f0c Cygwin_Init based on System_Dialog;
wenzelm
parents: 53457
diff changeset
   140
          if (isabelle_home == null || isabelle_home == "")
33f773731f0c Cygwin_Init based on System_Dialog;
wenzelm
parents: 53457
diff changeset
   141
            error("Unknown Isabelle home directory")
33f773731f0c Cygwin_Init based on System_Dialog;
wenzelm
parents: 53457
diff changeset
   142
          if (!(new JFile(isabelle_home)).isDirectory)
33f773731f0c Cygwin_Init based on System_Dialog;
wenzelm
parents: 53457
diff changeset
   143
            error("Bad Isabelle home directory: " + quote(isabelle_home))
53419
1c87e79bb838 main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents: 52675
diff changeset
   144
53459
33f773731f0c Cygwin_Init based on System_Dialog;
wenzelm
parents: 53457
diff changeset
   145
          val cygwin_root = isabelle_home + "\\contrib\\cygwin"
33f773731f0c Cygwin_Init based on System_Dialog;
wenzelm
parents: 53457
diff changeset
   146
          if ((new JFile(cygwin_root)).isDirectory)
33f773731f0c Cygwin_Init based on System_Dialog;
wenzelm
parents: 53457
diff changeset
   147
            System.setProperty("cygwin.root", cygwin_root)
53422
ec97451fdf2e recovered cygwin.root from 1c87e79bb838;
wenzelm
parents: 53419
diff changeset
   148
53459
33f773731f0c Cygwin_Init based on System_Dialog;
wenzelm
parents: 53457
diff changeset
   149
          val uninitialized_file = new JFile(cygwin_root, "isabelle\\uninitialized")
33f773731f0c Cygwin_Init based on System_Dialog;
wenzelm
parents: 53457
diff changeset
   150
          val uninitialized = uninitialized_file.isFile && uninitialized_file.delete
53419
1c87e79bb838 main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents: 52675
diff changeset
   151
53461
26c609ada983 clarified modules;
wenzelm
parents: 53460
diff changeset
   152
          if (uninitialized) cygwin_init(system_dialog, isabelle_home, cygwin_root)
53419
1c87e79bb838 main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents: 52675
diff changeset
   153
        }
53459
33f773731f0c Cygwin_Init based on System_Dialog;
wenzelm
parents: 53457
diff changeset
   154
      }
33f773731f0c Cygwin_Init based on System_Dialog;
wenzelm
parents: 53457
diff changeset
   155
      catch { case exn: Throwable => exit_error(exn) }
53462
c531db093680 observe "stopped" after Cygwin init (which is itself uninterruptible);
wenzelm
parents: 53461
diff changeset
   156
c531db093680 observe "stopped" after Cygwin init (which is itself uninterruptible);
wenzelm
parents: 53461
diff changeset
   157
      if (system_dialog.stopped) {
c531db093680 observe "stopped" after Cygwin init (which is itself uninterruptible);
wenzelm
parents: 53461
diff changeset
   158
        system_dialog.return_code(130)
c531db093680 observe "stopped" after Cygwin init (which is itself uninterruptible);
wenzelm
parents: 53461
diff changeset
   159
        system_dialog.join_exit
c531db093680 observe "stopped" after Cygwin init (which is itself uninterruptible);
wenzelm
parents: 53461
diff changeset
   160
      }
53459
33f773731f0c Cygwin_Init based on System_Dialog;
wenzelm
parents: 53457
diff changeset
   161
    }
53445
811db2b751ed warm start of Isabelle/jEdit from Isabelle/Scala;
wenzelm
parents: 53423
diff changeset
   162
53459
33f773731f0c Cygwin_Init based on System_Dialog;
wenzelm
parents: 53457
diff changeset
   163
    build
33f773731f0c Cygwin_Init based on System_Dialog;
wenzelm
parents: 53457
diff changeset
   164
    val rc = system_dialog.join
33f773731f0c Cygwin_Init based on System_Dialog;
wenzelm
parents: 53457
diff changeset
   165
    if (rc == 0) start else sys.exit(rc)
53445
811db2b751ed warm start of Isabelle/jEdit from Isabelle/Scala;
wenzelm
parents: 53423
diff changeset
   166
  }
53461
26c609ada983 clarified modules;
wenzelm
parents: 53460
diff changeset
   167
26c609ada983 clarified modules;
wenzelm
parents: 53460
diff changeset
   168
26c609ada983 clarified modules;
wenzelm
parents: 53460
diff changeset
   169
26c609ada983 clarified modules;
wenzelm
parents: 53460
diff changeset
   170
  /** Cygwin init (e.g. after extraction via 7zip) **/
26c609ada983 clarified modules;
wenzelm
parents: 53460
diff changeset
   171
26c609ada983 clarified modules;
wenzelm
parents: 53460
diff changeset
   172
  private def cygwin_init(system_dialog: System_Dialog, isabelle_home: String, cygwin_root: String)
26c609ada983 clarified modules;
wenzelm
parents: 53460
diff changeset
   173
  {
26c609ada983 clarified modules;
wenzelm
parents: 53460
diff changeset
   174
    system_dialog.title("Isabelle system initialization")
53466
19e7d5044617 tuned message;
wenzelm
parents: 53465
diff changeset
   175
    system_dialog.echo("Initializing Cygwin ...")
53461
26c609ada983 clarified modules;
wenzelm
parents: 53460
diff changeset
   176
26c609ada983 clarified modules;
wenzelm
parents: 53460
diff changeset
   177
    def execute(args: String*): Int =
26c609ada983 clarified modules;
wenzelm
parents: 53460
diff changeset
   178
    {
26c609ada983 clarified modules;
wenzelm
parents: 53460
diff changeset
   179
      val cwd = new JFile(isabelle_home)
26c609ada983 clarified modules;
wenzelm
parents: 53460
diff changeset
   180
      val env = Map("CYGWIN" -> "nodosfilewarning")
26c609ada983 clarified modules;
wenzelm
parents: 53460
diff changeset
   181
      system_dialog.execute(cwd, env, args: _*)
26c609ada983 clarified modules;
wenzelm
parents: 53460
diff changeset
   182
    }
26c609ada983 clarified modules;
wenzelm
parents: 53460
diff changeset
   183
26c609ada983 clarified modules;
wenzelm
parents: 53460
diff changeset
   184
    system_dialog.echo("symlinks ...")
26c609ada983 clarified modules;
wenzelm
parents: 53460
diff changeset
   185
    val symlinks =
26c609ada983 clarified modules;
wenzelm
parents: 53460
diff changeset
   186
    {
26c609ada983 clarified modules;
wenzelm
parents: 53460
diff changeset
   187
      val path = (new JFile(cygwin_root + "\\isabelle\\symlinks")).toPath
26c609ada983 clarified modules;
wenzelm
parents: 53460
diff changeset
   188
      Files.readAllLines(path, UTF8.charset).toArray.toList.asInstanceOf[List[String]]
26c609ada983 clarified modules;
wenzelm
parents: 53460
diff changeset
   189
    }
26c609ada983 clarified modules;
wenzelm
parents: 53460
diff changeset
   190
    @tailrec def recover_symlinks(list: List[String]): Unit =
26c609ada983 clarified modules;
wenzelm
parents: 53460
diff changeset
   191
    {
26c609ada983 clarified modules;
wenzelm
parents: 53460
diff changeset
   192
      list match {
26c609ada983 clarified modules;
wenzelm
parents: 53460
diff changeset
   193
        case Nil | List("") =>
26c609ada983 clarified modules;
wenzelm
parents: 53460
diff changeset
   194
        case link :: content :: rest =>
26c609ada983 clarified modules;
wenzelm
parents: 53460
diff changeset
   195
          val path = (new JFile(isabelle_home, link)).toPath
26c609ada983 clarified modules;
wenzelm
parents: 53460
diff changeset
   196
26c609ada983 clarified modules;
wenzelm
parents: 53460
diff changeset
   197
          val writer = Files.newBufferedWriter(path, UTF8.charset)
26c609ada983 clarified modules;
wenzelm
parents: 53460
diff changeset
   198
          try { writer.write("!<symlink>" + content + "\0") }
26c609ada983 clarified modules;
wenzelm
parents: 53460
diff changeset
   199
          finally { writer.close }
26c609ada983 clarified modules;
wenzelm
parents: 53460
diff changeset
   200
26c609ada983 clarified modules;
wenzelm
parents: 53460
diff changeset
   201
          Files.setAttribute(path, "dos:system", true)
26c609ada983 clarified modules;
wenzelm
parents: 53460
diff changeset
   202
26c609ada983 clarified modules;
wenzelm
parents: 53460
diff changeset
   203
          recover_symlinks(rest)
26c609ada983 clarified modules;
wenzelm
parents: 53460
diff changeset
   204
        case _ => error("Unbalanced symlinks list")
26c609ada983 clarified modules;
wenzelm
parents: 53460
diff changeset
   205
      }
26c609ada983 clarified modules;
wenzelm
parents: 53460
diff changeset
   206
    }
26c609ada983 clarified modules;
wenzelm
parents: 53460
diff changeset
   207
    recover_symlinks(symlinks)
26c609ada983 clarified modules;
wenzelm
parents: 53460
diff changeset
   208
26c609ada983 clarified modules;
wenzelm
parents: 53460
diff changeset
   209
    system_dialog.echo("rebaseall ...")
26c609ada983 clarified modules;
wenzelm
parents: 53460
diff changeset
   210
    execute(cygwin_root + "\\bin\\dash.exe", "/isabelle/rebaseall")
26c609ada983 clarified modules;
wenzelm
parents: 53460
diff changeset
   211
26c609ada983 clarified modules;
wenzelm
parents: 53460
diff changeset
   212
    system_dialog.echo("postinstall ...")
26c609ada983 clarified modules;
wenzelm
parents: 53460
diff changeset
   213
    execute(cygwin_root + "\\bin\\bash.exe", "/isabelle/postinstall")
26c609ada983 clarified modules;
wenzelm
parents: 53460
diff changeset
   214
26c609ada983 clarified modules;
wenzelm
parents: 53460
diff changeset
   215
    system_dialog.echo("init ...")
26c609ada983 clarified modules;
wenzelm
parents: 53460
diff changeset
   216
    Isabelle_System.init()
26c609ada983 clarified modules;
wenzelm
parents: 53460
diff changeset
   217
  }
53965
cca95e9055ba adhoc update of JVM environment variables, which is relevant for cold start of jEdit;
wenzelm
parents: 53912
diff changeset
   218
cca95e9055ba adhoc update of JVM environment variables, which is relevant for cold start of jEdit;
wenzelm
parents: 53912
diff changeset
   219
cca95e9055ba adhoc update of JVM environment variables, which is relevant for cold start of jEdit;
wenzelm
parents: 53912
diff changeset
   220
cca95e9055ba adhoc update of JVM environment variables, which is relevant for cold start of jEdit;
wenzelm
parents: 53912
diff changeset
   221
  /** adhoc update of JVM environment variables **/
cca95e9055ba adhoc update of JVM environment variables, which is relevant for cold start of jEdit;
wenzelm
parents: 53912
diff changeset
   222
cca95e9055ba adhoc update of JVM environment variables, which is relevant for cold start of jEdit;
wenzelm
parents: 53912
diff changeset
   223
  def update_environment()
cca95e9055ba adhoc update of JVM environment variables, which is relevant for cold start of jEdit;
wenzelm
parents: 53912
diff changeset
   224
  {
cca95e9055ba adhoc update of JVM environment variables, which is relevant for cold start of jEdit;
wenzelm
parents: 53912
diff changeset
   225
    val update =
53966
5a546a881f90 update second environment that is used for System.getenv(String);
wenzelm
parents: 53965
diff changeset
   226
    {
5a546a881f90 update second environment that is used for System.getenv(String);
wenzelm
parents: 53965
diff changeset
   227
      val isabelle_home = Isabelle_System.getenv("ISABELLE_HOME")
5a546a881f90 update second environment that is used for System.getenv(String);
wenzelm
parents: 53965
diff changeset
   228
      val upd =
5a546a881f90 update second environment that is used for System.getenv(String);
wenzelm
parents: 53965
diff changeset
   229
        if (Platform.is_windows)
5a546a881f90 update second environment that is used for System.getenv(String);
wenzelm
parents: 53965
diff changeset
   230
          List("ISABELLE_HOME" -> Isabelle_System.jvm_path(isabelle_home), "INI_DIR" -> "")
5a546a881f90 update second environment that is used for System.getenv(String);
wenzelm
parents: 53965
diff changeset
   231
        else
5a546a881f90 update second environment that is used for System.getenv(String);
wenzelm
parents: 53965
diff changeset
   232
          List("ISABELLE_HOME" -> isabelle_home)
53965
cca95e9055ba adhoc update of JVM environment variables, which is relevant for cold start of jEdit;
wenzelm
parents: 53912
diff changeset
   233
53966
5a546a881f90 update second environment that is used for System.getenv(String);
wenzelm
parents: 53965
diff changeset
   234
      (env0: Any) => {
5a546a881f90 update second environment that is used for System.getenv(String);
wenzelm
parents: 53965
diff changeset
   235
        val env = env0.asInstanceOf[java.util.Map[String, String]]
5a546a881f90 update second environment that is used for System.getenv(String);
wenzelm
parents: 53965
diff changeset
   236
        upd.foreach {
5a546a881f90 update second environment that is used for System.getenv(String);
wenzelm
parents: 53965
diff changeset
   237
          case (x, "") => env.remove(x)
5a546a881f90 update second environment that is used for System.getenv(String);
wenzelm
parents: 53965
diff changeset
   238
          case (x, y) => env.put(x, y)
5a546a881f90 update second environment that is used for System.getenv(String);
wenzelm
parents: 53965
diff changeset
   239
        }
5a546a881f90 update second environment that is used for System.getenv(String);
wenzelm
parents: 53965
diff changeset
   240
      }
5a546a881f90 update second environment that is used for System.getenv(String);
wenzelm
parents: 53965
diff changeset
   241
    }
53965
cca95e9055ba adhoc update of JVM environment variables, which is relevant for cold start of jEdit;
wenzelm
parents: 53912
diff changeset
   242
cca95e9055ba adhoc update of JVM environment variables, which is relevant for cold start of jEdit;
wenzelm
parents: 53912
diff changeset
   243
    classOf[java.util.Collections].getDeclaredClasses
cca95e9055ba adhoc update of JVM environment variables, which is relevant for cold start of jEdit;
wenzelm
parents: 53912
diff changeset
   244
      .find(c => c.getName == "java.util.Collections$UnmodifiableMap") match
cca95e9055ba adhoc update of JVM environment variables, which is relevant for cold start of jEdit;
wenzelm
parents: 53912
diff changeset
   245
    {
cca95e9055ba adhoc update of JVM environment variables, which is relevant for cold start of jEdit;
wenzelm
parents: 53912
diff changeset
   246
      case Some(c) =>
cca95e9055ba adhoc update of JVM environment variables, which is relevant for cold start of jEdit;
wenzelm
parents: 53912
diff changeset
   247
        val m = c.getDeclaredField("m")
cca95e9055ba adhoc update of JVM environment variables, which is relevant for cold start of jEdit;
wenzelm
parents: 53912
diff changeset
   248
        m.setAccessible(true)
53966
5a546a881f90 update second environment that is used for System.getenv(String);
wenzelm
parents: 53965
diff changeset
   249
        update(m.get(System.getenv()))
5a546a881f90 update second environment that is used for System.getenv(String);
wenzelm
parents: 53965
diff changeset
   250
5a546a881f90 update second environment that is used for System.getenv(String);
wenzelm
parents: 53965
diff changeset
   251
        if (Platform.is_windows) {
5a546a881f90 update second environment that is used for System.getenv(String);
wenzelm
parents: 53965
diff changeset
   252
          val ProcessEnvironment = Class.forName("java.lang.ProcessEnvironment")
5a546a881f90 update second environment that is used for System.getenv(String);
wenzelm
parents: 53965
diff changeset
   253
          val field = ProcessEnvironment.getDeclaredField("theCaseInsensitiveEnvironment")
5a546a881f90 update second environment that is used for System.getenv(String);
wenzelm
parents: 53965
diff changeset
   254
          field.setAccessible(true)
5a546a881f90 update second environment that is used for System.getenv(String);
wenzelm
parents: 53965
diff changeset
   255
          update(field.get(null))
53965
cca95e9055ba adhoc update of JVM environment variables, which is relevant for cold start of jEdit;
wenzelm
parents: 53912
diff changeset
   256
        }
53966
5a546a881f90 update second environment that is used for System.getenv(String);
wenzelm
parents: 53965
diff changeset
   257
5a546a881f90 update second environment that is used for System.getenv(String);
wenzelm
parents: 53965
diff changeset
   258
      case None =>
5a546a881f90 update second environment that is used for System.getenv(String);
wenzelm
parents: 53965
diff changeset
   259
        error("Failed to update JVM environment -- platform incompatibility")
53965
cca95e9055ba adhoc update of JVM environment variables, which is relevant for cold start of jEdit;
wenzelm
parents: 53912
diff changeset
   260
    }
cca95e9055ba adhoc update of JVM environment variables, which is relevant for cold start of jEdit;
wenzelm
parents: 53912
diff changeset
   261
  }
47663
20e0865ae9e7 default Isabelle application wrapper -- JVM entry point for Isabelle.exe;
wenzelm
parents:
diff changeset
   262
}
20e0865ae9e7 default Isabelle application wrapper -- JVM entry point for Isabelle.exe;
wenzelm
parents:
diff changeset
   263