author | wenzelm |
Sat, 07 Sep 2013 15:10:33 +0200 | |
changeset 53456 | d12be8f62285 |
parent 53449 | 913df2adc99c |
child 53457 | b7c15885fd1e |
permissions | -rw-r--r-- |
50687 | 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 |
|
53449 | 10 |
import javax.swing.SwingUtilities |
53445
811db2b751ed
warm start of Isabelle/jEdit from Isabelle/Scala;
wenzelm
parents:
53423
diff
changeset
|
11 |
import java.lang.{System, ClassLoader} |
53419
1c87e79bb838
main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents:
52675
diff
changeset
|
12 |
import java.io.{File => JFile} |
47663
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 |
|
20e0865ae9e7
default Isabelle application wrapper -- JVM entry point for Isabelle.exe;
wenzelm
parents:
diff
changeset
|
15 |
object Main |
20e0865ae9e7
default Isabelle application wrapper -- JVM entry point for Isabelle.exe;
wenzelm
parents:
diff
changeset
|
16 |
{ |
53449 | 17 |
private def continue(body: => Unit)(rc: Int) |
18 |
{ |
|
19 |
if (rc != 0) sys.exit(rc) |
|
20 |
else if (SwingUtilities.isEventDispatchThread()) |
|
21 |
Simple_Thread.fork("Isabelle") { body } |
|
22 |
else body |
|
23 |
} |
|
53445
811db2b751ed
warm start of Isabelle/jEdit from Isabelle/Scala;
wenzelm
parents:
53423
diff
changeset
|
24 |
|
53456 | 25 |
def main(args: Array[String]) |
53449 | 26 |
{ |
53456 | 27 |
val system_dialog = new System_Dialog |
28 |
||
29 |
def exit_error(exn: Throwable): Nothing = |
|
30 |
{ |
|
31 |
GUI.dialog(null, "Isabelle", GUI.scrollable_text(Exn.message(exn))) |
|
32 |
system_dialog.return_code(2) |
|
33 |
sys.exit(system_dialog.join) |
|
34 |
} |
|
35 |
||
36 |
def run |
|
37 |
{ |
|
38 |
build |
|
39 |
if (system_dialog.join == 0) start |
|
40 |
} |
|
41 |
||
42 |
def build |
|
43 |
{ |
|
44 |
try { |
|
45 |
GUI.init_laf() |
|
46 |
Isabelle_System.init() |
|
53449 | 47 |
|
53456 | 48 |
val mode = Isabelle_System.getenv("JEDIT_BUILD_MODE") |
49 |
if (mode == "none") |
|
50 |
system_dialog.return_code(0) |
|
51 |
else { |
|
52 |
val system_mode = mode == "" || mode == "system" |
|
53 |
val dirs = Path.split(Isabelle_System.getenv("JEDIT_SESSION_DIRS")) |
|
54 |
val options = Options.init() |
|
55 |
val session = Isabelle_System.default_logic( |
|
56 |
Isabelle_System.getenv("JEDIT_LOGIC"), |
|
57 |
options.string("jedit_logic")) |
|
58 |
Build_Dialog.dialog(options, system_dialog, system_mode, dirs, session) |
|
59 |
} |
|
60 |
} |
|
61 |
catch { case exn: Throwable => exit_error(exn) } |
|
62 |
} |
|
53449 | 63 |
|
53456 | 64 |
def start |
65 |
{ |
|
66 |
val do_start = |
|
67 |
{ |
|
68 |
try { |
|
69 |
/* settings directory */ |
|
70 |
||
71 |
val settings_dir = Path.explode("$JEDIT_SETTINGS") |
|
72 |
Isabelle_System.mkdirs(settings_dir + Path.explode("DockableWindowManager")) |
|
73 |
||
74 |
if (!(settings_dir + Path.explode("perspective.xml")).is_file) { |
|
75 |
File.write(settings_dir + Path.explode("DockableWindowManager/perspective-view0.xml"), |
|
76 |
"""<DOCKING LEFT="" TOP="" RIGHT="" BOTTOM="isabelle-readme" LEFT_POS="0" TOP_POS="0" RIGHT_POS="250" BOTTOM_POS="250" />""") |
|
77 |
File.write(settings_dir + Path.explode("perspective.xml"), |
|
78 |
"""<?xml version="1.0" encoding="UTF-8" ?> |
|
79 |
<!DOCTYPE PERSPECTIVE SYSTEM "perspective.dtd"> |
|
80 |
<PERSPECTIVE> |
|
81 |
<VIEW PLAIN="FALSE"> |
|
82 |
<GEOMETRY X="0" Y="35" WIDTH="1072" HEIGHT="787" EXT_STATE="0" /> |
|
83 |
</VIEW> |
|
84 |
</PERSPECTIVE>""") |
|
85 |
} |
|
53449 | 86 |
|
87 |
||
53456 | 88 |
/* args */ |
89 |
||
90 |
val jedit_options = |
|
91 |
Isabelle_System.getenv_strict("JEDIT_OPTIONS").split(" +") |
|
92 |
||
93 |
val jedit_settings = |
|
94 |
Array("-settings=" + Isabelle_System.platform_path(Path.explode("$JEDIT_SETTINGS"))) |
|
95 |
||
96 |
val more_args = |
|
97 |
if (args.isEmpty) |
|
98 |
Array(Isabelle_System.platform_path(Path.explode("$USER_HOME/Scratch.thy"))) |
|
99 |
else args |
|
100 |
||
101 |
||
102 |
/* startup */ |
|
53445
811db2b751ed
warm start of Isabelle/jEdit from Isabelle/Scala;
wenzelm
parents:
53423
diff
changeset
|
103 |
|
53456 | 104 |
System.setProperty("jedit.home", |
105 |
Isabelle_System.platform_path(Path.explode("$JEDIT_HOME/dist"))) |
|
106 |
||
107 |
System.setProperty("scala.home", |
|
108 |
Isabelle_System.platform_path(Path.explode("$SCALA_HOME"))) |
|
109 |
||
110 |
val jedit = ClassLoader.getSystemClassLoader.loadClass("org.gjt.sp.jedit.jEdit") |
|
111 |
val jedit_main = jedit.getDeclaredMethod("main", classOf[Array[String]]) |
|
112 |
||
113 |
() => jedit_main.invoke(null, jedit_options ++ jedit_settings ++ more_args) |
|
114 |
} |
|
115 |
catch { case exn: Throwable => exit_error(exn) } |
|
116 |
} |
|
117 |
do_start() |
|
118 |
} |
|
53419
1c87e79bb838
main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents:
52675
diff
changeset
|
119 |
|
1c87e79bb838
main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents:
52675
diff
changeset
|
120 |
if (Platform.is_windows) { |
1c87e79bb838
main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents:
52675
diff
changeset
|
121 |
val init_isabelle_home = |
1c87e79bb838
main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents:
52675
diff
changeset
|
122 |
try { |
1c87e79bb838
main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents:
52675
diff
changeset
|
123 |
GUI.init_laf() |
1c87e79bb838
main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents:
52675
diff
changeset
|
124 |
|
1c87e79bb838
main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents:
52675
diff
changeset
|
125 |
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
|
126 |
val isabelle_home = System.getProperty("isabelle.home") |
47663
20e0865ae9e7
default Isabelle application wrapper -- JVM entry point for Isabelle.exe;
wenzelm
parents:
diff
changeset
|
127 |
|
53419
1c87e79bb838
main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents:
52675
diff
changeset
|
128 |
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
|
129 |
else { |
1c87e79bb838
main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents:
52675
diff
changeset
|
130 |
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
|
131 |
error("Unknown Isabelle home directory") |
1c87e79bb838
main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents:
52675
diff
changeset
|
132 |
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
|
133 |
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
|
134 |
|
53423
b5a279c7d7f3
more explicit cygwin_root (again) -- do not rely on isabelle_home as cwd;
wenzelm
parents:
53422
diff
changeset
|
135 |
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
|
136 |
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
|
137 |
System.setProperty("cygwin.root", cygwin_root) |
53422 | 138 |
|
53423
b5a279c7d7f3
more explicit cygwin_root (again) -- do not rely on isabelle_home as cwd;
wenzelm
parents:
53422
diff
changeset
|
139 |
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
|
140 |
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
|
141 |
|
1c87e79bb838
main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents:
52675
diff
changeset
|
142 |
if (uninitialized) Some(isabelle_home) else None |
52675
f3a6b1d0915e
more self-contained application, with side-entry for init;
wenzelm
parents:
51617
diff
changeset
|
143 |
} |
53419
1c87e79bb838
main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents:
52675
diff
changeset
|
144 |
} |
53445
811db2b751ed
warm start of Isabelle/jEdit from Isabelle/Scala;
wenzelm
parents:
53423
diff
changeset
|
145 |
catch { case exn: Throwable => exit_error(exn) } |
811db2b751ed
warm start of Isabelle/jEdit from Isabelle/Scala;
wenzelm
parents:
53423
diff
changeset
|
146 |
|
53419
1c87e79bb838
main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents:
52675
diff
changeset
|
147 |
init_isabelle_home match { |
1c87e79bb838
main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents:
52675
diff
changeset
|
148 |
case Some(isabelle_home) => |
53456 | 149 |
Swing_Thread.later { Cygwin_Init.main_frame(isabelle_home, continue(run)) } |
150 |
case None => run |
|
53419
1c87e79bb838
main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents:
52675
diff
changeset
|
151 |
} |
52675
f3a6b1d0915e
more self-contained application, with side-entry for init;
wenzelm
parents:
51617
diff
changeset
|
152 |
} |
53456 | 153 |
else run |
53445
811db2b751ed
warm start of Isabelle/jEdit from Isabelle/Scala;
wenzelm
parents:
53423
diff
changeset
|
154 |
} |
47663
20e0865ae9e7
default Isabelle application wrapper -- JVM entry point for Isabelle.exe;
wenzelm
parents:
diff
changeset
|
155 |
} |
20e0865ae9e7
default Isabelle application wrapper -- JVM entry point for Isabelle.exe;
wenzelm
parents:
diff
changeset
|
156 |