src/Pure/Tools/main.scala
author wenzelm
Thu, 05 Sep 2013 21:37:32 +0200
changeset 53423 b5a279c7d7f3
parent 53422 ec97451fdf2e
child 53445 811db2b751ed
permissions -rw-r--r--
more explicit cygwin_root (again) -- do not rely on isabelle_home as cwd;
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
1c87e79bb838 main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents: 52675
diff changeset
    10
import java.lang.System
1c87e79bb838 main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents: 52675
diff changeset
    11
import java.io.{File => JFile}
47663
20e0865ae9e7 default Isabelle application wrapper -- JVM entry point for Isabelle.exe;
wenzelm
parents:
diff changeset
    12
20e0865ae9e7 default Isabelle application wrapper -- JVM entry point for Isabelle.exe;
wenzelm
parents:
diff changeset
    13
20e0865ae9e7 default Isabelle application wrapper -- JVM entry point for Isabelle.exe;
wenzelm
parents:
diff changeset
    14
object Main
20e0865ae9e7 default Isabelle application wrapper -- JVM entry point for Isabelle.exe;
wenzelm
parents:
diff changeset
    15
{
48275
31daac3a85ea more standard main method;
wenzelm
parents: 48192
diff changeset
    16
  def main(args: Array[String])
47663
20e0865ae9e7 default Isabelle application wrapper -- JVM entry point for Isabelle.exe;
wenzelm
parents:
diff changeset
    17
  {
53419
1c87e79bb838 main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents: 52675
diff changeset
    18
    def start: Unit =
1c87e79bb838 main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents: 52675
diff changeset
    19
    {
1c87e79bb838 main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents: 52675
diff changeset
    20
      val (out, rc) =
1c87e79bb838 main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents: 52675
diff changeset
    21
        try {
1c87e79bb838 main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents: 52675
diff changeset
    22
          GUI.init_laf()
1c87e79bb838 main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents: 52675
diff changeset
    23
          Isabelle_System.init()
1c87e79bb838 main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents: 52675
diff changeset
    24
          Isabelle_System.isabelle_tool("jedit", ("-s" :: "--" :: args.toList): _*)
1c87e79bb838 main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents: 52675
diff changeset
    25
        }
1c87e79bb838 main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents: 52675
diff changeset
    26
        catch { case exn: Throwable => (Exn.message(exn), 2) }
1c87e79bb838 main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents: 52675
diff changeset
    27
1c87e79bb838 main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents: 52675
diff changeset
    28
      if (rc != 0)
1c87e79bb838 main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents: 52675
diff changeset
    29
        GUI.dialog(null, "Isabelle", "Isabelle output",
1c87e79bb838 main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents: 52675
diff changeset
    30
          GUI.scrollable_text(out + "\nReturn code: " + rc))
1c87e79bb838 main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents: 52675
diff changeset
    31
1c87e79bb838 main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents: 52675
diff changeset
    32
      sys.exit(rc)
1c87e79bb838 main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents: 52675
diff changeset
    33
    }
1c87e79bb838 main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents: 52675
diff changeset
    34
1c87e79bb838 main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents: 52675
diff changeset
    35
    if (Platform.is_windows) {
1c87e79bb838 main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents: 52675
diff changeset
    36
      val init_isabelle_home =
1c87e79bb838 main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents: 52675
diff changeset
    37
        try {
1c87e79bb838 main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents: 52675
diff changeset
    38
          GUI.init_laf()
1c87e79bb838 main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents: 52675
diff changeset
    39
1c87e79bb838 main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents: 52675
diff changeset
    40
          val isabelle_home0 = System.getenv("ISABELLE_HOME_WINDOWS")
1c87e79bb838 main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents: 52675
diff changeset
    41
          val isabelle_home = System.getProperty("isabelle.home")
47663
20e0865ae9e7 default Isabelle application wrapper -- JVM entry point for Isabelle.exe;
wenzelm
parents:
diff changeset
    42
53419
1c87e79bb838 main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents: 52675
diff changeset
    43
          if (isabelle_home0 != null && isabelle_home0 != "") None
1c87e79bb838 main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents: 52675
diff changeset
    44
          else {
1c87e79bb838 main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents: 52675
diff changeset
    45
            if (isabelle_home == null || isabelle_home == "")
1c87e79bb838 main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents: 52675
diff changeset
    46
              error("Unknown Isabelle home directory")
1c87e79bb838 main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents: 52675
diff changeset
    47
            if (!(new JFile(isabelle_home)).isDirectory)
1c87e79bb838 main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents: 52675
diff changeset
    48
              error("Bad Isabelle home directory: " + quote(isabelle_home))
1c87e79bb838 main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents: 52675
diff changeset
    49
53423
b5a279c7d7f3 more explicit cygwin_root (again) -- do not rely on isabelle_home as cwd;
wenzelm
parents: 53422
diff changeset
    50
            val cygwin_root = isabelle_home + "\\contrib\\cygwin"
b5a279c7d7f3 more explicit cygwin_root (again) -- do not rely on isabelle_home as cwd;
wenzelm
parents: 53422
diff changeset
    51
            if ((new JFile(cygwin_root)).isDirectory)
b5a279c7d7f3 more explicit cygwin_root (again) -- do not rely on isabelle_home as cwd;
wenzelm
parents: 53422
diff changeset
    52
              System.setProperty("cygwin.root", cygwin_root)
53422
ec97451fdf2e recovered cygwin.root from 1c87e79bb838;
wenzelm
parents: 53419
diff changeset
    53
53423
b5a279c7d7f3 more explicit cygwin_root (again) -- do not rely on isabelle_home as cwd;
wenzelm
parents: 53422
diff changeset
    54
            val uninitialized_file = new JFile(cygwin_root, "isabelle\\uninitialized")
53419
1c87e79bb838 main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents: 52675
diff changeset
    55
            val uninitialized = uninitialized_file.isFile && uninitialized_file.delete
1c87e79bb838 main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents: 52675
diff changeset
    56
1c87e79bb838 main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents: 52675
diff changeset
    57
            if (uninitialized) Some(isabelle_home) else None
52675
f3a6b1d0915e more self-contained application, with side-entry for init;
wenzelm
parents: 51617
diff changeset
    58
          }
53419
1c87e79bb838 main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents: 52675
diff changeset
    59
        }
1c87e79bb838 main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents: 52675
diff changeset
    60
        catch {
1c87e79bb838 main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents: 52675
diff changeset
    61
          case exn: Throwable =>
1c87e79bb838 main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents: 52675
diff changeset
    62
            GUI.dialog(null, "Isabelle", GUI.scrollable_text(Exn.message(exn)))
1c87e79bb838 main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents: 52675
diff changeset
    63
            sys.exit(2)
1c87e79bb838 main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents: 52675
diff changeset
    64
        }
1c87e79bb838 main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents: 52675
diff changeset
    65
      init_isabelle_home match {
1c87e79bb838 main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents: 52675
diff changeset
    66
        case Some(isabelle_home) =>
1c87e79bb838 main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents: 52675
diff changeset
    67
          Swing_Thread.later { Cygwin_Init.main_frame(isabelle_home, start) }
1c87e79bb838 main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents: 52675
diff changeset
    68
        case None => start
1c87e79bb838 main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents: 52675
diff changeset
    69
      }
52675
f3a6b1d0915e more self-contained application, with side-entry for init;
wenzelm
parents: 51617
diff changeset
    70
    }
53419
1c87e79bb838 main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents: 52675
diff changeset
    71
    else start
47663
20e0865ae9e7 default Isabelle application wrapper -- JVM entry point for Isabelle.exe;
wenzelm
parents:
diff changeset
    72
  }
20e0865ae9e7 default Isabelle application wrapper -- JVM entry point for Isabelle.exe;
wenzelm
parents:
diff changeset
    73
}
20e0865ae9e7 default Isabelle application wrapper -- JVM entry point for Isabelle.exe;
wenzelm
parents:
diff changeset
    74