author | wenzelm |
Tue, 29 Sep 2015 15:37:37 +0200 | |
changeset 61277 | c9152a195899 |
parent 61186 | d48da797a056 |
child 61278 | 4d2ea32e0f75 |
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 |
|
55618 | 10 |
import java.lang.{Class, ClassLoader} |
53461 | 11 |
import java.io.{File => JFile, BufferedReader, InputStreamReader} |
12 |
import java.nio.file.Files |
|
13 |
||
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 | 19 |
/** main entry point **/ |
20 |
||
53456 | 21 |
def main(args: Array[String]) |
53449 | 22 |
{ |
53456 | 23 |
val system_dialog = new System_Dialog |
24 |
||
25 |
def exit_error(exn: Throwable): Nothing = |
|
26 |
{ |
|
27 |
GUI.dialog(null, "Isabelle", GUI.scrollable_text(Exn.message(exn))) |
|
56667
65e84b0ef974
more abstract Exn.Interrupt and POSIX return code;
wenzelm
parents:
56661
diff
changeset
|
28 |
system_dialog.return_code(Exn.return_code(exn, 2)) |
53460 | 29 |
system_dialog.join_exit |
53456 | 30 |
} |
31 |
||
53419
1c87e79bb838
main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents:
52675
diff
changeset
|
32 |
if (Platform.is_windows) { |
53459 | 33 |
try { |
34 |
GUI.init_laf() |
|
53419
1c87e79bb838
main application entry point involves implicit Cygwin init, depending on "uninitialized" file indicator;
wenzelm
parents:
52675
diff
changeset
|
35 |
|
53967
bfaae48b0ce0
simplified ISABELLE_HOME on Windows (see also 9c8a1b9c0630, 5a7903ba2dac);
wenzelm
parents:
53966
diff
changeset
|
36 |
val isabelle_home0 = System.getenv("ISABELLE_HOME") |
53459 | 37 |
val isabelle_home = System.getProperty("isabelle.home") |
47663
20e0865ae9e7
default Isabelle application wrapper -- JVM entry point for Isabelle.exe;
wenzelm
parents:
diff
changeset
|
38 |
|
53459 | 39 |
if (isabelle_home0 == null || isabelle_home0 == "") { |
40 |
if (isabelle_home == null || isabelle_home == "") |
|
41 |
error("Unknown Isabelle home directory") |
|
42 |
if (!(new JFile(isabelle_home)).isDirectory) |
|
43 |
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
|
44 |
|
53459 | 45 |
val cygwin_root = isabelle_home + "\\contrib\\cygwin" |
46 |
if ((new JFile(cygwin_root)).isDirectory) |
|
47 |
System.setProperty("cygwin.root", cygwin_root) |
|
53422 | 48 |
|
53459 | 49 |
val uninitialized_file = new JFile(cygwin_root, "isabelle\\uninitialized") |
50 |
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
|
51 |
|
53461 | 52 |
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
|
53 |
} |
53459 | 54 |
} |
55 |
catch { case exn: Throwable => exit_error(exn) } |
|
53462
c531db093680
observe "stopped" after Cygwin init (which is itself uninterruptible);
wenzelm
parents:
53461
diff
changeset
|
56 |
|
c531db093680
observe "stopped" after Cygwin init (which is itself uninterruptible);
wenzelm
parents:
53461
diff
changeset
|
57 |
if (system_dialog.stopped) { |
56667
65e84b0ef974
more abstract Exn.Interrupt and POSIX return code;
wenzelm
parents:
56661
diff
changeset
|
58 |
system_dialog.return_code(Exn.Interrupt.return_code) |
53462
c531db093680
observe "stopped" after Cygwin init (which is itself uninterruptible);
wenzelm
parents:
53461
diff
changeset
|
59 |
system_dialog.join_exit |
c531db093680
observe "stopped" after Cygwin init (which is itself uninterruptible);
wenzelm
parents:
53461
diff
changeset
|
60 |
} |
53459 | 61 |
} |
53445
811db2b751ed
warm start of Isabelle/jEdit from Isabelle/Scala;
wenzelm
parents:
53423
diff
changeset
|
62 |
|
61277 | 63 |
system_dialog.return_code(0) |
64 |
system_dialog.join |
|
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="isabelle-documentation" BOTTOM="" 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 |
} |
|
86 |
||
87 |
||
88 |
/* args */ |
|
89 |
||
90 |
val jedit_options = |
|
91 |
Isabelle_System.getenv_strict("JEDIT_OPTIONS").split(" +") |
|
92 |
||
93 |
val jedit_settings = |
|
94 |
Array("-settings=" + File.platform_path(Path.explode("$JEDIT_SETTINGS"))) |
|
95 |
||
96 |
val more_args = |
|
97 |
if (args.isEmpty) |
|
98 |
Array(File.platform_path(Path.explode("$USER_HOME/Scratch.thy"))) |
|
99 |
else args |
|
100 |
||
101 |
||
102 |
/* main startup */ |
|
103 |
||
104 |
update_environment() |
|
105 |
||
106 |
System.setProperty("jedit.home", File.platform_path(Path.explode("$JEDIT_HOME/dist"))) |
|
107 |
System.setProperty("scala.home", File.platform_path(Path.explode("$SCALA_HOME"))) |
|
108 |
||
109 |
val jedit = |
|
110 |
Class.forName("org.gjt.sp.jedit.jEdit", true, ClassLoader.getSystemClassLoader) |
|
111 |
val jedit_main = jedit.getMethod("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 |
||
118 |
do_start() |
|
53445
811db2b751ed
warm start of Isabelle/jEdit from Isabelle/Scala;
wenzelm
parents:
53423
diff
changeset
|
119 |
} |
53461 | 120 |
|
121 |
||
122 |
||
123 |
/** Cygwin init (e.g. after extraction via 7zip) **/ |
|
124 |
||
125 |
private def cygwin_init(system_dialog: System_Dialog, isabelle_home: String, cygwin_root: String) |
|
126 |
{ |
|
127 |
system_dialog.title("Isabelle system initialization") |
|
53466 | 128 |
system_dialog.echo("Initializing Cygwin ...") |
53461 | 129 |
|
130 |
def execute(args: String*): Int = |
|
131 |
{ |
|
132 |
val cwd = new JFile(isabelle_home) |
|
133 |
val env = Map("CYGWIN" -> "nodosfilewarning") |
|
134 |
system_dialog.execute(cwd, env, args: _*) |
|
135 |
} |
|
136 |
||
137 |
system_dialog.echo("symlinks ...") |
|
138 |
val symlinks = |
|
139 |
{ |
|
140 |
val path = (new JFile(cygwin_root + "\\isabelle\\symlinks")).toPath |
|
141 |
Files.readAllLines(path, UTF8.charset).toArray.toList.asInstanceOf[List[String]] |
|
142 |
} |
|
143 |
@tailrec def recover_symlinks(list: List[String]): Unit = |
|
144 |
{ |
|
145 |
list match { |
|
146 |
case Nil | List("") => |
|
147 |
case link :: content :: rest => |
|
148 |
val path = (new JFile(isabelle_home, link)).toPath |
|
149 |
||
150 |
val writer = Files.newBufferedWriter(path, UTF8.charset) |
|
56661
ef623f6f036b
avoid octal escape literals -- deprecated in scala-2.11.0;
wenzelm
parents:
55618
diff
changeset
|
151 |
try { writer.write("!<symlink>" + content + "\u0000") } |
53461 | 152 |
finally { writer.close } |
153 |
||
154 |
Files.setAttribute(path, "dos:system", true) |
|
155 |
||
156 |
recover_symlinks(rest) |
|
157 |
case _ => error("Unbalanced symlinks list") |
|
158 |
} |
|
159 |
} |
|
160 |
recover_symlinks(symlinks) |
|
161 |
||
162 |
system_dialog.echo("rebaseall ...") |
|
163 |
execute(cygwin_root + "\\bin\\dash.exe", "/isabelle/rebaseall") |
|
164 |
||
165 |
system_dialog.echo("postinstall ...") |
|
166 |
execute(cygwin_root + "\\bin\\bash.exe", "/isabelle/postinstall") |
|
167 |
||
168 |
system_dialog.echo("init ...") |
|
169 |
Isabelle_System.init() |
|
170 |
} |
|
53965
cca95e9055ba
adhoc update of JVM environment variables, which is relevant for cold start of jEdit;
wenzelm
parents:
53912
diff
changeset
|
171 |
|
cca95e9055ba
adhoc update of JVM environment variables, which is relevant for cold start of jEdit;
wenzelm
parents:
53912
diff
changeset
|
172 |
|
cca95e9055ba
adhoc update of JVM environment variables, which is relevant for cold start of jEdit;
wenzelm
parents:
53912
diff
changeset
|
173 |
|
cca95e9055ba
adhoc update of JVM environment variables, which is relevant for cold start of jEdit;
wenzelm
parents:
53912
diff
changeset
|
174 |
/** 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
|
175 |
|
cca95e9055ba
adhoc update of JVM environment variables, which is relevant for cold start of jEdit;
wenzelm
parents:
53912
diff
changeset
|
176 |
def update_environment() |
cca95e9055ba
adhoc update of JVM environment variables, which is relevant for cold start of jEdit;
wenzelm
parents:
53912
diff
changeset
|
177 |
{ |
cca95e9055ba
adhoc update of JVM environment variables, which is relevant for cold start of jEdit;
wenzelm
parents:
53912
diff
changeset
|
178 |
val update = |
53966
5a546a881f90
update second environment that is used for System.getenv(String);
wenzelm
parents:
53965
diff
changeset
|
179 |
{ |
5a546a881f90
update second environment that is used for System.getenv(String);
wenzelm
parents:
53965
diff
changeset
|
180 |
val isabelle_home = Isabelle_System.getenv("ISABELLE_HOME") |
54351 | 181 |
val isabelle_home_user = Isabelle_System.getenv("ISABELLE_HOME_USER") |
53965
cca95e9055ba
adhoc update of JVM environment variables, which is relevant for cold start of jEdit;
wenzelm
parents:
53912
diff
changeset
|
182 |
|
53966
5a546a881f90
update second environment that is used for System.getenv(String);
wenzelm
parents:
53965
diff
changeset
|
183 |
(env0: Any) => { |
5a546a881f90
update second environment that is used for System.getenv(String);
wenzelm
parents:
53965
diff
changeset
|
184 |
val env = env0.asInstanceOf[java.util.Map[String, String]] |
60997 | 185 |
env.put("ISABELLE_HOME", File.platform_path(isabelle_home)) |
186 |
env.put("ISABELLE_HOME_USER", File.platform_path(isabelle_home_user)) |
|
53966
5a546a881f90
update second environment that is used for System.getenv(String);
wenzelm
parents:
53965
diff
changeset
|
187 |
} |
5a546a881f90
update second environment that is used for System.getenv(String);
wenzelm
parents:
53965
diff
changeset
|
188 |
} |
53965
cca95e9055ba
adhoc update of JVM environment variables, which is relevant for cold start of jEdit;
wenzelm
parents:
53912
diff
changeset
|
189 |
|
cca95e9055ba
adhoc update of JVM environment variables, which is relevant for cold start of jEdit;
wenzelm
parents:
53912
diff
changeset
|
190 |
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
|
191 |
.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
|
192 |
{ |
cca95e9055ba
adhoc update of JVM environment variables, which is relevant for cold start of jEdit;
wenzelm
parents:
53912
diff
changeset
|
193 |
case Some(c) => |
cca95e9055ba
adhoc update of JVM environment variables, which is relevant for cold start of jEdit;
wenzelm
parents:
53912
diff
changeset
|
194 |
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
|
195 |
m.setAccessible(true) |
53966
5a546a881f90
update second environment that is used for System.getenv(String);
wenzelm
parents:
53965
diff
changeset
|
196 |
update(m.get(System.getenv())) |
5a546a881f90
update second environment that is used for System.getenv(String);
wenzelm
parents:
53965
diff
changeset
|
197 |
|
5a546a881f90
update second environment that is used for System.getenv(String);
wenzelm
parents:
53965
diff
changeset
|
198 |
if (Platform.is_windows) { |
5a546a881f90
update second environment that is used for System.getenv(String);
wenzelm
parents:
53965
diff
changeset
|
199 |
val ProcessEnvironment = Class.forName("java.lang.ProcessEnvironment") |
5a546a881f90
update second environment that is used for System.getenv(String);
wenzelm
parents:
53965
diff
changeset
|
200 |
val field = ProcessEnvironment.getDeclaredField("theCaseInsensitiveEnvironment") |
5a546a881f90
update second environment that is used for System.getenv(String);
wenzelm
parents:
53965
diff
changeset
|
201 |
field.setAccessible(true) |
5a546a881f90
update second environment that is used for System.getenv(String);
wenzelm
parents:
53965
diff
changeset
|
202 |
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
|
203 |
} |
53966
5a546a881f90
update second environment that is used for System.getenv(String);
wenzelm
parents:
53965
diff
changeset
|
204 |
|
5a546a881f90
update second environment that is used for System.getenv(String);
wenzelm
parents:
53965
diff
changeset
|
205 |
case None => |
5a546a881f90
update second environment that is used for System.getenv(String);
wenzelm
parents:
53965
diff
changeset
|
206 |
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
|
207 |
} |
cca95e9055ba
adhoc update of JVM environment variables, which is relevant for cold start of jEdit;
wenzelm
parents:
53912
diff
changeset
|
208 |
} |
47663
20e0865ae9e7
default Isabelle application wrapper -- JVM entry point for Isabelle.exe;
wenzelm
parents:
diff
changeset
|
209 |
} |