author | bulwahn |
Wed, 04 Apr 2012 10:17:54 +0200 | |
changeset 47330 | 8fe04753a210 |
parent 47113 | b5a5662528fb |
child 47998 | 969457d93f75 |
permissions | -rw-r--r-- |
34201
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
1 |
/* Title: Pure/System/standard_system.scala |
45673
cd41e3903fbf
separate compilation of PIDE vs. Pure sources, which enables independent Scala library;
wenzelm
parents:
45667
diff
changeset
|
2 |
Module: PIDE |
34201
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
3 |
Author: Makarius |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
4 |
|
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
5 |
Standard system operations, with basic Cygwin/Posix compatibility. |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
6 |
*/ |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
7 |
|
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
8 |
package isabelle |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
9 |
|
43520
cec9b95fa35d
explicit import java.lang.System to prevent odd scope problems;
wenzelm
parents:
43516
diff
changeset
|
10 |
import java.lang.System |
39732
4dbc72759706
added Standard_System.unzip (for platform file-system);
wenzelm
parents:
39709
diff
changeset
|
11 |
import java.util.zip.{ZipEntry, ZipInputStream} |
34201
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
12 |
import java.util.regex.Pattern |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
13 |
import java.util.Locale |
39705 | 14 |
import java.net.URL |
15 |
import java.io.{BufferedWriter, OutputStreamWriter, FileOutputStream, BufferedOutputStream, |
|
39578 | 16 |
BufferedInputStream, InputStream, FileInputStream, BufferedReader, InputStreamReader, |
34298 | 17 |
File, FileFilter, IOException} |
43516 | 18 |
import java.nio.charset.Charset |
34201
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
19 |
|
36011
3ff725ac13a4
adapted to Scala 2.8.0 Beta1 -- with notable changes to scala.collection;
wenzelm
parents:
34300
diff
changeset
|
20 |
import scala.io.{Source, Codec} |
34201
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
21 |
import scala.util.matching.Regex |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
22 |
import scala.collection.mutable |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
23 |
|
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
24 |
|
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
25 |
object Standard_System |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
26 |
{ |
38264 | 27 |
/* UTF-8 charset */ |
28 |
||
43516 | 29 |
val charset_name: String = "UTF-8" |
30 |
val charset: Charset = Charset.forName(charset_name) |
|
36015 | 31 |
def codec(): Codec = Codec(charset) |
34201
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
32 |
|
38264 | 33 |
def string_bytes(s: String): Array[Byte] = s.getBytes(charset) |
34 |
||
34201
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
35 |
|
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
36 |
/* permissive UTF-8 decoding */ |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
37 |
|
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
38 |
// see also http://en.wikipedia.org/wiki/UTF-8#Description |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
39 |
// overlong encodings enable byte-stuffing |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
40 |
|
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
41 |
def decode_permissive_utf8(text: CharSequence): String = |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
42 |
{ |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
43 |
val buf = new java.lang.StringBuilder(text.length) |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
44 |
var code = -1 |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
45 |
var rest = 0 |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
46 |
def flush() |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
47 |
{ |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
48 |
if (code != -1) { |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
49 |
if (rest == 0 && Character.isValidCodePoint(code)) |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
50 |
buf.appendCodePoint(code) |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
51 |
else buf.append('\uFFFD') |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
52 |
code = -1 |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
53 |
rest = 0 |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
54 |
} |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
55 |
} |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
56 |
def init(x: Int, n: Int) |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
57 |
{ |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
58 |
flush() |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
59 |
code = x |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
60 |
rest = n |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
61 |
} |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
62 |
def push(x: Int) |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
63 |
{ |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
64 |
if (rest <= 0) init(x, -1) |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
65 |
else { |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
66 |
code <<= 6 |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
67 |
code += x |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
68 |
rest -= 1 |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
69 |
} |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
70 |
} |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
71 |
for (i <- 0 until text.length) { |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
72 |
val c = text.charAt(i) |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
73 |
if (c < 128) { flush(); buf.append(c) } |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
74 |
else if ((c & 0xC0) == 0x80) push(c & 0x3F) |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
75 |
else if ((c & 0xE0) == 0xC0) init(c & 0x1F, 1) |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
76 |
else if ((c & 0xF0) == 0xE0) init(c & 0x0F, 2) |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
77 |
else if ((c & 0xF8) == 0xF0) init(c & 0x07, 3) |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
78 |
} |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
79 |
flush() |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
80 |
buf.toString |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
81 |
} |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
82 |
|
43746
a41f618c641d
some support for raw messages, which bypass standard Symbol/YXML decoding;
wenzelm
parents:
43695
diff
changeset
|
83 |
private class Decode_Chars(decode: String => String, |
a41f618c641d
some support for raw messages, which bypass standard Symbol/YXML decoding;
wenzelm
parents:
43695
diff
changeset
|
84 |
buffer: Array[Byte], start: Int, end: Int) extends CharSequence |
a41f618c641d
some support for raw messages, which bypass standard Symbol/YXML decoding;
wenzelm
parents:
43695
diff
changeset
|
85 |
{ |
a41f618c641d
some support for raw messages, which bypass standard Symbol/YXML decoding;
wenzelm
parents:
43695
diff
changeset
|
86 |
def length: Int = end - start |
a41f618c641d
some support for raw messages, which bypass standard Symbol/YXML decoding;
wenzelm
parents:
43695
diff
changeset
|
87 |
def charAt(i: Int): Char = (buffer(start + i).asInstanceOf[Int] & 0xFF).asInstanceOf[Char] |
a41f618c641d
some support for raw messages, which bypass standard Symbol/YXML decoding;
wenzelm
parents:
43695
diff
changeset
|
88 |
def subSequence(i: Int, j: Int): CharSequence = |
a41f618c641d
some support for raw messages, which bypass standard Symbol/YXML decoding;
wenzelm
parents:
43695
diff
changeset
|
89 |
new Decode_Chars(decode, buffer, start + i, start + j) |
a41f618c641d
some support for raw messages, which bypass standard Symbol/YXML decoding;
wenzelm
parents:
43695
diff
changeset
|
90 |
|
a41f618c641d
some support for raw messages, which bypass standard Symbol/YXML decoding;
wenzelm
parents:
43695
diff
changeset
|
91 |
// toString with adhoc decoding: abuse of CharSequence interface |
a41f618c641d
some support for raw messages, which bypass standard Symbol/YXML decoding;
wenzelm
parents:
43695
diff
changeset
|
92 |
override def toString: String = decode(decode_permissive_utf8(this)) |
a41f618c641d
some support for raw messages, which bypass standard Symbol/YXML decoding;
wenzelm
parents:
43695
diff
changeset
|
93 |
} |
a41f618c641d
some support for raw messages, which bypass standard Symbol/YXML decoding;
wenzelm
parents:
43695
diff
changeset
|
94 |
|
a41f618c641d
some support for raw messages, which bypass standard Symbol/YXML decoding;
wenzelm
parents:
43695
diff
changeset
|
95 |
def decode_chars(decode: String => String, |
a41f618c641d
some support for raw messages, which bypass standard Symbol/YXML decoding;
wenzelm
parents:
43695
diff
changeset
|
96 |
buffer: Array[Byte], start: Int, end: Int): CharSequence = |
a41f618c641d
some support for raw messages, which bypass standard Symbol/YXML decoding;
wenzelm
parents:
43695
diff
changeset
|
97 |
{ |
a41f618c641d
some support for raw messages, which bypass standard Symbol/YXML decoding;
wenzelm
parents:
43695
diff
changeset
|
98 |
require(0 <= start && start <= end && end <= buffer.length) |
a41f618c641d
some support for raw messages, which bypass standard Symbol/YXML decoding;
wenzelm
parents:
43695
diff
changeset
|
99 |
new Decode_Chars(decode, buffer, start, end) |
a41f618c641d
some support for raw messages, which bypass standard Symbol/YXML decoding;
wenzelm
parents:
43695
diff
changeset
|
100 |
} |
a41f618c641d
some support for raw messages, which bypass standard Symbol/YXML decoding;
wenzelm
parents:
43695
diff
changeset
|
101 |
|
34201
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
102 |
|
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
103 |
/* basic file operations */ |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
104 |
|
39578 | 105 |
def slurp(reader: BufferedReader): String = |
34201
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
106 |
{ |
39578 | 107 |
val output = new StringBuilder(100) |
108 |
var c = -1 |
|
109 |
while ({ c = reader.read; c != -1 }) output += c.toChar |
|
110 |
reader.close |
|
111 |
output.toString |
|
34201
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
112 |
} |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
113 |
|
39578 | 114 |
def slurp(stream: InputStream): String = |
115 |
slurp(new BufferedReader(new InputStreamReader(stream, charset))) |
|
116 |
||
117 |
def read_file(file: File): String = slurp(new FileInputStream(file)) |
|
34201
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
118 |
|
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
119 |
def write_file(file: File, text: CharSequence) |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
120 |
{ |
43516 | 121 |
val writer = |
122 |
new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), charset)) |
|
34201
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
123 |
try { writer.append(text) } |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
124 |
finally { writer.close } |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
125 |
} |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
126 |
|
39578 | 127 |
def with_tmp_file[A](prefix: String)(body: File => A): A = |
128 |
{ |
|
129 |
val file = File.createTempFile(prefix, null) |
|
39582
a873158542d0
Standard_System.with_tmp_file: deleteOnExit to make double sure;
wenzelm
parents:
39578
diff
changeset
|
130 |
file.deleteOnExit |
39578 | 131 |
try { body(file) } finally { file.delete } |
132 |
} |
|
133 |
||
34300 | 134 |
// FIXME handle (potentially cyclic) directory graph |
34298 | 135 |
def find_files(start: File, ok: File => Boolean): List[File] = |
136 |
{ |
|
137 |
val files = new mutable.ListBuffer[File] |
|
138 |
val filter = new FileFilter { def accept(entry: File) = entry.isDirectory || ok(entry) } |
|
139 |
def find_entry(entry: File) |
|
140 |
{ |
|
141 |
if (ok(entry)) files += entry |
|
142 |
if (entry.isDirectory) entry.listFiles(filter).foreach(find_entry) |
|
143 |
} |
|
144 |
find_entry(start) |
|
145 |
files.toList |
|
146 |
} |
|
147 |
||
34201
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
148 |
|
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
149 |
/* shell processes */ |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
150 |
|
34219 | 151 |
def raw_execute(cwd: File, env: Map[String, String], redirect: Boolean, args: String*): Process = |
34201
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
152 |
{ |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
153 |
val cmdline = new java.util.LinkedList[String] |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
154 |
for (s <- args) cmdline.add(s) |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
155 |
|
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
156 |
val proc = new ProcessBuilder(cmdline) |
34219 | 157 |
if (cwd != null) proc.directory(cwd) |
34202 | 158 |
if (env != null) { |
159 |
proc.environment.clear |
|
160 |
for ((x, y) <- env) proc.environment.put(x, y) |
|
161 |
} |
|
34201
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
162 |
proc.redirectErrorStream(redirect) |
39522
01aade784da9
raw_execute: let IOException pass-through unhindered (again);
wenzelm
parents:
38264
diff
changeset
|
163 |
proc.start |
34201
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
164 |
} |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
165 |
|
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
166 |
def process_output(proc: Process): (String, Int) = |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
167 |
{ |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
168 |
proc.getOutputStream.close |
39578 | 169 |
val output = slurp(proc.getInputStream) |
34201
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
170 |
val rc = |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
171 |
try { proc.waitFor } |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
172 |
finally { |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
173 |
proc.getInputStream.close |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
174 |
proc.getErrorStream.close |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
175 |
proc.destroy |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
176 |
Thread.interrupted |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
177 |
} |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
178 |
(output, rc) |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
179 |
} |
34258 | 180 |
|
39522
01aade784da9
raw_execute: let IOException pass-through unhindered (again);
wenzelm
parents:
38264
diff
changeset
|
181 |
def raw_exec(cwd: File, env: Map[String, String], redirect: Boolean, args: String*) |
01aade784da9
raw_execute: let IOException pass-through unhindered (again);
wenzelm
parents:
38264
diff
changeset
|
182 |
: (String, Int) = process_output(raw_execute(cwd, env, redirect, args: _*)) |
39705 | 183 |
|
184 |
||
39732
4dbc72759706
added Standard_System.unzip (for platform file-system);
wenzelm
parents:
39709
diff
changeset
|
185 |
/* unpack zip archive -- platform file-system */ |
4dbc72759706
added Standard_System.unzip (for platform file-system);
wenzelm
parents:
39709
diff
changeset
|
186 |
|
4dbc72759706
added Standard_System.unzip (for platform file-system);
wenzelm
parents:
39709
diff
changeset
|
187 |
def unzip(url: URL, root: File) |
4dbc72759706
added Standard_System.unzip (for platform file-system);
wenzelm
parents:
39709
diff
changeset
|
188 |
{ |
4dbc72759706
added Standard_System.unzip (for platform file-system);
wenzelm
parents:
39709
diff
changeset
|
189 |
import scala.collection.JavaConversions._ |
4dbc72759706
added Standard_System.unzip (for platform file-system);
wenzelm
parents:
39709
diff
changeset
|
190 |
|
4dbc72759706
added Standard_System.unzip (for platform file-system);
wenzelm
parents:
39709
diff
changeset
|
191 |
val buffer = new Array[Byte](4096) |
4dbc72759706
added Standard_System.unzip (for platform file-system);
wenzelm
parents:
39709
diff
changeset
|
192 |
|
4dbc72759706
added Standard_System.unzip (for platform file-system);
wenzelm
parents:
39709
diff
changeset
|
193 |
val zip_stream = new ZipInputStream(new BufferedInputStream(url.openStream)) |
4dbc72759706
added Standard_System.unzip (for platform file-system);
wenzelm
parents:
39709
diff
changeset
|
194 |
var entry: ZipEntry = null |
4dbc72759706
added Standard_System.unzip (for platform file-system);
wenzelm
parents:
39709
diff
changeset
|
195 |
try { |
4dbc72759706
added Standard_System.unzip (for platform file-system);
wenzelm
parents:
39709
diff
changeset
|
196 |
while ({ entry = zip_stream.getNextEntry; entry != null }) { |
4dbc72759706
added Standard_System.unzip (for platform file-system);
wenzelm
parents:
39709
diff
changeset
|
197 |
val file = new File(root, entry.getName.replace('/', File.separatorChar)) |
4dbc72759706
added Standard_System.unzip (for platform file-system);
wenzelm
parents:
39709
diff
changeset
|
198 |
val dir = file.getParentFile |
4dbc72759706
added Standard_System.unzip (for platform file-system);
wenzelm
parents:
39709
diff
changeset
|
199 |
if (dir != null && !dir.isDirectory && !dir.mkdirs) |
4dbc72759706
added Standard_System.unzip (for platform file-system);
wenzelm
parents:
39709
diff
changeset
|
200 |
error("Failed to create directory: " + dir) |
4dbc72759706
added Standard_System.unzip (for platform file-system);
wenzelm
parents:
39709
diff
changeset
|
201 |
|
4dbc72759706
added Standard_System.unzip (for platform file-system);
wenzelm
parents:
39709
diff
changeset
|
202 |
var len = 0 |
4dbc72759706
added Standard_System.unzip (for platform file-system);
wenzelm
parents:
39709
diff
changeset
|
203 |
val out_stream = new BufferedOutputStream(new FileOutputStream(file)) |
4dbc72759706
added Standard_System.unzip (for platform file-system);
wenzelm
parents:
39709
diff
changeset
|
204 |
try { |
4dbc72759706
added Standard_System.unzip (for platform file-system);
wenzelm
parents:
39709
diff
changeset
|
205 |
while ({ len = zip_stream.read(buffer); len != -1 }) |
4dbc72759706
added Standard_System.unzip (for platform file-system);
wenzelm
parents:
39709
diff
changeset
|
206 |
out_stream.write(buffer, 0, len) |
4dbc72759706
added Standard_System.unzip (for platform file-system);
wenzelm
parents:
39709
diff
changeset
|
207 |
} |
4dbc72759706
added Standard_System.unzip (for platform file-system);
wenzelm
parents:
39709
diff
changeset
|
208 |
finally { out_stream.close } |
4dbc72759706
added Standard_System.unzip (for platform file-system);
wenzelm
parents:
39709
diff
changeset
|
209 |
} |
4dbc72759706
added Standard_System.unzip (for platform file-system);
wenzelm
parents:
39709
diff
changeset
|
210 |
} |
4dbc72759706
added Standard_System.unzip (for platform file-system);
wenzelm
parents:
39709
diff
changeset
|
211 |
finally { zip_stream.close } |
4dbc72759706
added Standard_System.unzip (for platform file-system);
wenzelm
parents:
39709
diff
changeset
|
212 |
} |
4dbc72759706
added Standard_System.unzip (for platform file-system);
wenzelm
parents:
39709
diff
changeset
|
213 |
|
4dbc72759706
added Standard_System.unzip (for platform file-system);
wenzelm
parents:
39709
diff
changeset
|
214 |
|
4dbc72759706
added Standard_System.unzip (for platform file-system);
wenzelm
parents:
39709
diff
changeset
|
215 |
/* unpack tar archive -- POSIX file-system */ |
39705 | 216 |
|
39708
c3239be617f4
more efficient posix_untar -- avoid really slow java.util.zip.GZIPInputStream;
wenzelm
parents:
39706
diff
changeset
|
217 |
def posix_untar(url: URL, root: File, gunzip: Boolean = false, |
39709 | 218 |
tar: String = "tar", gzip: String = "", progress: Int => Unit = _ => ()): String = |
39705 | 219 |
{ |
39708
c3239be617f4
more efficient posix_untar -- avoid really slow java.util.zip.GZIPInputStream;
wenzelm
parents:
39706
diff
changeset
|
220 |
if (!root.isDirectory && !root.mkdirs) |
c3239be617f4
more efficient posix_untar -- avoid really slow java.util.zip.GZIPInputStream;
wenzelm
parents:
39706
diff
changeset
|
221 |
error("Failed to create root directory: " + root) |
39705 | 222 |
|
223 |
val connection = url.openConnection |
|
224 |
||
225 |
val length = connection.getContentLength.toLong |
|
226 |
require(length >= 0L) |
|
227 |
||
39708
c3239be617f4
more efficient posix_untar -- avoid really slow java.util.zip.GZIPInputStream;
wenzelm
parents:
39706
diff
changeset
|
228 |
val stream = new BufferedInputStream(connection.getInputStream) |
39705 | 229 |
val progress_stream = new InputStream { |
230 |
private val total = length max 1L |
|
231 |
private var index = 0L |
|
232 |
private var percentage = 0L |
|
233 |
override def read(): Int = |
|
234 |
{ |
|
39708
c3239be617f4
more efficient posix_untar -- avoid really slow java.util.zip.GZIPInputStream;
wenzelm
parents:
39706
diff
changeset
|
235 |
val c = stream.read |
39705 | 236 |
if (c != -1) { |
237 |
index += 100 |
|
238 |
val p = index / total |
|
239 |
if (percentage != p) { percentage = p; progress(percentage.toInt) } |
|
240 |
} |
|
241 |
c |
|
242 |
} |
|
39708
c3239be617f4
more efficient posix_untar -- avoid really slow java.util.zip.GZIPInputStream;
wenzelm
parents:
39706
diff
changeset
|
243 |
override def available(): Int = stream.available |
c3239be617f4
more efficient posix_untar -- avoid really slow java.util.zip.GZIPInputStream;
wenzelm
parents:
39706
diff
changeset
|
244 |
override def close() { stream.close } |
39705 | 245 |
} |
246 |
||
39709 | 247 |
val cmdline = |
248 |
List(tar, "-o", "-x", "-f-") ::: |
|
249 |
(if (!gunzip) Nil else if (gzip == "") List("-z") else List("-I", gzip)) |
|
250 |
||
251 |
val proc = raw_execute(root, null, false, cmdline:_*) |
|
39705 | 252 |
val stdout = Simple_Thread.future("tar_stdout") { slurp(proc.getInputStream) } |
253 |
val stderr = Simple_Thread.future("tar_stderr") { slurp(proc.getErrorStream) } |
|
254 |
val stdin = new BufferedOutputStream(proc.getOutputStream) |
|
255 |
||
256 |
try { |
|
257 |
var c = -1 |
|
39706
6e74fb2d4374
raw_untar.raw_execute with native cwd, to avoid cross-platform complications;
wenzelm
parents:
39705
diff
changeset
|
258 |
val io_err = |
39708
c3239be617f4
more efficient posix_untar -- avoid really slow java.util.zip.GZIPInputStream;
wenzelm
parents:
39706
diff
changeset
|
259 |
try { while ({ c = progress_stream.read; c != -1 }) stdin.write(c); false } |
39706
6e74fb2d4374
raw_untar.raw_execute with native cwd, to avoid cross-platform complications;
wenzelm
parents:
39705
diff
changeset
|
260 |
catch { case e: IOException => true } |
39705 | 261 |
stdin.close |
262 |
||
263 |
val rc = try { proc.waitFor } finally { Thread.interrupted } |
|
39706
6e74fb2d4374
raw_untar.raw_execute with native cwd, to avoid cross-platform complications;
wenzelm
parents:
39705
diff
changeset
|
264 |
if (io_err || rc != 0) error(stderr.join.trim) else stdout.join |
39705 | 265 |
} |
266 |
finally { |
|
39708
c3239be617f4
more efficient posix_untar -- avoid really slow java.util.zip.GZIPInputStream;
wenzelm
parents:
39706
diff
changeset
|
267 |
progress_stream.close |
39705 | 268 |
stdin.close |
269 |
proc.destroy |
|
270 |
} |
|
271 |
} |
|
34201
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
272 |
} |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
273 |
|
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
274 |
|
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
275 |
class Standard_System |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
276 |
{ |
43664 | 277 |
/* platform_root */ |
278 |
||
34201
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
279 |
val platform_root = if (Platform.is_windows) Cygwin.check_root() else "/" |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
280 |
|
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
281 |
|
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
282 |
/* jvm_path */ |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
283 |
|
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
284 |
private val Cygdrive = new Regex("/cygdrive/([a-zA-Z])($|/.*)") |
36136
89b1a136edef
more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents:
36015
diff
changeset
|
285 |
private val Named_Root = new Regex("//+([^/]*)(.*)") |
34201
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
286 |
|
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
287 |
def jvm_path(posix_path: String): String = |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
288 |
if (Platform.is_windows) { |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
289 |
val result_path = new StringBuilder |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
290 |
val rest = |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
291 |
posix_path match { |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
292 |
case Cygdrive(drive, rest) => |
45072
e30442a2b3b2
standardize drive letters -- important for proper document node identification;
wenzelm
parents:
43746
diff
changeset
|
293 |
result_path ++= (drive.toUpperCase(Locale.ENGLISH) + ":" + File.separator) |
34201
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
294 |
rest |
36136
89b1a136edef
more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents:
36015
diff
changeset
|
295 |
case Named_Root(root, rest) => |
89b1a136edef
more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents:
36015
diff
changeset
|
296 |
result_path ++= File.separator |
89b1a136edef
more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents:
36015
diff
changeset
|
297 |
result_path ++= File.separator |
89b1a136edef
more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents:
36015
diff
changeset
|
298 |
result_path ++= root |
89b1a136edef
more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents:
36015
diff
changeset
|
299 |
rest |
34201
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
300 |
case path if path.startsWith("/") => |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
301 |
result_path ++= platform_root |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
302 |
path |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
303 |
case path => path |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
304 |
} |
43670
7f933761764b
prefer space_explode/split_lines as in Isabelle/ML;
wenzelm
parents:
43664
diff
changeset
|
305 |
for (p <- space_explode('/', rest) if p != "") { |
34201
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
306 |
val len = result_path.length |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
307 |
if (len > 0 && result_path(len - 1) != File.separatorChar) |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
308 |
result_path += File.separatorChar |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
309 |
result_path ++= p |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
310 |
} |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
311 |
result_path.toString |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
312 |
} |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
313 |
else posix_path |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
314 |
|
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
315 |
|
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
316 |
/* posix_path */ |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
317 |
|
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
318 |
private val Platform_Root = new Regex("(?i)" + |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
319 |
Pattern.quote(platform_root) + """(?:\\+|\z)(.*)""") |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
320 |
|
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
321 |
private val Drive = new Regex("""([a-zA-Z]):\\*(.*)""") |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
322 |
|
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
323 |
def posix_path(jvm_path: String): String = |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
324 |
if (Platform.is_windows) { |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
325 |
jvm_path.replace('/', '\\') match { |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
326 |
case Platform_Root(rest) => "/" + rest.replace('\\', '/') |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
327 |
case Drive(letter, rest) => |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
328 |
"/cygdrive/" + letter.toLowerCase(Locale.ENGLISH) + |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
329 |
(if (rest == "") "" else "/" + rest.replace('\\', '/')) |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
330 |
case path => path.replace('\\', '/') |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
331 |
} |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
332 |
} |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
333 |
else jvm_path |
36193
067a01827fca
improved ISABELLE_JAVA, based on THIS_JAVA of the actually running JVM;
wenzelm
parents:
36136
diff
changeset
|
334 |
|
067a01827fca
improved ISABELLE_JAVA, based on THIS_JAVA of the actually running JVM;
wenzelm
parents:
36136
diff
changeset
|
335 |
|
47113
b5a5662528fb
ISABELLE_JDK_HOME settings variable points to JDK with javac and jar (not just JRE);
wenzelm
parents:
45673
diff
changeset
|
336 |
/* JDK home of running JVM */ |
36193
067a01827fca
improved ISABELLE_JAVA, based on THIS_JAVA of the actually running JVM;
wenzelm
parents:
36136
diff
changeset
|
337 |
|
47113
b5a5662528fb
ISABELLE_JDK_HOME settings variable points to JDK with javac and jar (not just JRE);
wenzelm
parents:
45673
diff
changeset
|
338 |
def this_jdk_home(): String = |
36193
067a01827fca
improved ISABELLE_JAVA, based on THIS_JAVA of the actually running JVM;
wenzelm
parents:
36136
diff
changeset
|
339 |
{ |
067a01827fca
improved ISABELLE_JAVA, based on THIS_JAVA of the actually running JVM;
wenzelm
parents:
36136
diff
changeset
|
340 |
val java_home = System.getProperty("java.home") |
47113
b5a5662528fb
ISABELLE_JDK_HOME settings variable points to JDK with javac and jar (not just JRE);
wenzelm
parents:
45673
diff
changeset
|
341 |
val home = new File(java_home) |
b5a5662528fb
ISABELLE_JDK_HOME settings variable points to JDK with javac and jar (not just JRE);
wenzelm
parents:
45673
diff
changeset
|
342 |
val parent = home.getParent |
b5a5662528fb
ISABELLE_JDK_HOME settings variable points to JDK with javac and jar (not just JRE);
wenzelm
parents:
45673
diff
changeset
|
343 |
val jdk_home = |
b5a5662528fb
ISABELLE_JDK_HOME settings variable points to JDK with javac and jar (not just JRE);
wenzelm
parents:
45673
diff
changeset
|
344 |
if (home.getName == "jre" && parent != null && |
b5a5662528fb
ISABELLE_JDK_HOME settings variable points to JDK with javac and jar (not just JRE);
wenzelm
parents:
45673
diff
changeset
|
345 |
(new File(new File(parent, "bin"), "javac")).exists) parent |
b5a5662528fb
ISABELLE_JDK_HOME settings variable points to JDK with javac and jar (not just JRE);
wenzelm
parents:
45673
diff
changeset
|
346 |
else java_home |
b5a5662528fb
ISABELLE_JDK_HOME settings variable points to JDK with javac and jar (not just JRE);
wenzelm
parents:
45673
diff
changeset
|
347 |
posix_path(jdk_home) |
36193
067a01827fca
improved ISABELLE_JAVA, based on THIS_JAVA of the actually running JVM;
wenzelm
parents:
36136
diff
changeset
|
348 |
} |
34201
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff
changeset
|
349 |
} |