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