src/Pure/System/standard_system.scala
author wenzelm
Fri, 30 Nov 2012 21:30:24 +0100
changeset 50299 f70b3712040f
parent 50203 00d8ad713e32
child 50650 8922afc54b3d
permissions -rw-r--r--
renamed dockable "Prover Session" to "Theories"; more uniform Library.lowercase/uppercase;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
34201
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    11
import java.util.regex.Pattern
39705
41e9f69c553d added Standard_System.raw_untar;
wenzelm
parents: 39582
diff changeset
    12
import java.net.URL
48411
5b3440850d36 more abstract file system operations in Scala, corresponding to ML version;
wenzelm
parents: 48409
diff changeset
    13
import java.io.{File => JFile}
34201
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    14
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    15
import scala.util.matching.Regex
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    16
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    17
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    18
object Standard_System
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    19
{
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    20
  /* shell processes */
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    21
48409
0d2114eb412a more explicit java.io.{File => JFile};
wenzelm
parents: 48373
diff changeset
    22
  def raw_execute(cwd: JFile, 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
    23
  {
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    24
    val cmdline = new java.util.LinkedList[String]
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    25
    for (s <- args) cmdline.add(s)
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    26
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    27
    val proc = new ProcessBuilder(cmdline)
34219
d37cfca69887 Standard_System.raw_execute: optional cwd;
wenzelm
parents: 34202
diff changeset
    28
    if (cwd != null) proc.directory(cwd)
34202
99241daf807d ignore undefined environment;
wenzelm
parents: 34201
diff changeset
    29
    if (env != null) {
99241daf807d ignore undefined environment;
wenzelm
parents: 34201
diff changeset
    30
      proc.environment.clear
99241daf807d ignore undefined environment;
wenzelm
parents: 34201
diff changeset
    31
      for ((x, y) <- env) proc.environment.put(x, y)
99241daf807d ignore undefined environment;
wenzelm
parents: 34201
diff changeset
    32
    }
34201
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    33
    proc.redirectErrorStream(redirect)
39522
01aade784da9 raw_execute: let IOException pass-through unhindered (again);
wenzelm
parents: 38264
diff changeset
    34
    proc.start
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
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    37
  def process_output(proc: Process): (String, Int) =
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    38
  {
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    39
    proc.getOutputStream.close
48411
5b3440850d36 more abstract file system operations in Scala, corresponding to ML version;
wenzelm
parents: 48409
diff changeset
    40
    val output = File.read(proc.getInputStream)
34201
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    41
    val rc =
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    42
      try { proc.waitFor }
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    43
      finally {
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    44
        proc.getInputStream.close
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    45
        proc.getErrorStream.close
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    46
        proc.destroy
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    47
        Thread.interrupted
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    48
      }
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    49
    (output, rc)
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    50
  }
34258
e936d3c35ce0 Standard_System.raw_exec;
wenzelm
parents: 34219
diff changeset
    51
48409
0d2114eb412a more explicit java.io.{File => JFile};
wenzelm
parents: 48373
diff changeset
    52
  def raw_exec(cwd: JFile, env: Map[String, String], redirect: Boolean, args: String*)
39522
01aade784da9 raw_execute: let IOException pass-through unhindered (again);
wenzelm
parents: 38264
diff changeset
    53
    : (String, Int) = process_output(raw_execute(cwd, env, redirect, args: _*))
39705
41e9f69c553d added Standard_System.raw_untar;
wenzelm
parents: 39582
diff changeset
    54
41e9f69c553d added Standard_System.raw_untar;
wenzelm
parents: 39582
diff changeset
    55
47998
969457d93f75 discontinued obsolete Cygwin module;
wenzelm
parents: 47113
diff changeset
    56
  /* cygwin_root */
969457d93f75 discontinued obsolete Cygwin module;
wenzelm
parents: 47113
diff changeset
    57
969457d93f75 discontinued obsolete Cygwin module;
wenzelm
parents: 47113
diff changeset
    58
  def cygwin_root(): String =
969457d93f75 discontinued obsolete Cygwin module;
wenzelm
parents: 47113
diff changeset
    59
  {
969457d93f75 discontinued obsolete Cygwin module;
wenzelm
parents: 47113
diff changeset
    60
    val cygwin_root1 = System.getenv("CYGWIN_ROOT")
969457d93f75 discontinued obsolete Cygwin module;
wenzelm
parents: 47113
diff changeset
    61
    val cygwin_root2 = System.getProperty("cygwin.root")
969457d93f75 discontinued obsolete Cygwin module;
wenzelm
parents: 47113
diff changeset
    62
    val root =
969457d93f75 discontinued obsolete Cygwin module;
wenzelm
parents: 47113
diff changeset
    63
      if (cygwin_root1 != null && cygwin_root1 != "") cygwin_root1
969457d93f75 discontinued obsolete Cygwin module;
wenzelm
parents: 47113
diff changeset
    64
      else if (cygwin_root2 != null && cygwin_root2 != "") cygwin_root2
969457d93f75 discontinued obsolete Cygwin module;
wenzelm
parents: 47113
diff changeset
    65
      else error("Bad Cygwin installation: unknown root")
969457d93f75 discontinued obsolete Cygwin module;
wenzelm
parents: 47113
diff changeset
    66
48409
0d2114eb412a more explicit java.io.{File => JFile};
wenzelm
parents: 48373
diff changeset
    67
    val root_file = new JFile(root)
0d2114eb412a more explicit java.io.{File => JFile};
wenzelm
parents: 48373
diff changeset
    68
    if (!new JFile(root_file, "bin\\bash.exe").isFile ||
0d2114eb412a more explicit java.io.{File => JFile};
wenzelm
parents: 48373
diff changeset
    69
        !new JFile(root_file, "bin\\env.exe").isFile ||
0d2114eb412a more explicit java.io.{File => JFile};
wenzelm
parents: 48373
diff changeset
    70
        !new JFile(root_file, "bin\\tar.exe").isFile)
47998
969457d93f75 discontinued obsolete Cygwin module;
wenzelm
parents: 47113
diff changeset
    71
      error("Bad Cygwin installation: " + quote(root))
969457d93f75 discontinued obsolete Cygwin module;
wenzelm
parents: 47113
diff changeset
    72
969457d93f75 discontinued obsolete Cygwin module;
wenzelm
parents: 47113
diff changeset
    73
    root
969457d93f75 discontinued obsolete Cygwin module;
wenzelm
parents: 47113
diff changeset
    74
  }
34201
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    75
}
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    76
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
class Standard_System
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    79
{
43664
wenzelm
parents: 43661
diff changeset
    80
  /* platform_root */
wenzelm
parents: 43661
diff changeset
    81
47998
969457d93f75 discontinued obsolete Cygwin module;
wenzelm
parents: 47113
diff changeset
    82
  val platform_root = if (Platform.is_windows) Standard_System.cygwin_root() else "/"
34201
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    83
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    84
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    85
  /* jvm_path */
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    86
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    87
  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
    88
  private val Named_Root = new Regex("//+([^/]*)(.*)")
34201
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    89
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    90
  def jvm_path(posix_path: String): String =
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    91
    if (Platform.is_windows) {
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    92
      val result_path = new StringBuilder
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    93
      val rest =
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    94
        posix_path match {
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    95
          case Cygdrive(drive, rest) =>
50299
f70b3712040f renamed dockable "Prover Session" to "Theories";
wenzelm
parents: 50203
diff changeset
    96
            result_path ++= (Library.uppercase(drive) + ":" + JFile.separator)
34201
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    97
            rest
36136
89b1a136edef more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents: 36015
diff changeset
    98
          case Named_Root(root, rest) =>
48409
0d2114eb412a more explicit java.io.{File => JFile};
wenzelm
parents: 48373
diff changeset
    99
            result_path ++= JFile.separator
0d2114eb412a more explicit java.io.{File => JFile};
wenzelm
parents: 48373
diff changeset
   100
            result_path ++= JFile.separator
36136
89b1a136edef more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents: 36015
diff changeset
   101
            result_path ++= root
89b1a136edef more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents: 36015
diff changeset
   102
            rest
34201
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   103
          case path if path.startsWith("/") =>
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   104
            result_path ++= platform_root
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   105
            path
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   106
          case path => path
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   107
        }
43670
7f933761764b prefer space_explode/split_lines as in Isabelle/ML;
wenzelm
parents: 43664
diff changeset
   108
      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
   109
        val len = result_path.length
48409
0d2114eb412a more explicit java.io.{File => JFile};
wenzelm
parents: 48373
diff changeset
   110
        if (len > 0 && result_path(len - 1) != JFile.separatorChar)
0d2114eb412a more explicit java.io.{File => JFile};
wenzelm
parents: 48373
diff changeset
   111
          result_path += JFile.separatorChar
34201
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   112
        result_path ++= p
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   113
      }
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   114
      result_path.toString
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   115
    }
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   116
    else posix_path
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
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   119
  /* posix_path */
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   120
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   121
  private val Platform_Root = new Regex("(?i)" +
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   122
    Pattern.quote(platform_root) + """(?:\\+|\z)(.*)""")
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   123
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   124
  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
   125
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   126
  def posix_path(jvm_path: String): String =
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   127
    if (Platform.is_windows) {
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   128
      jvm_path.replace('/', '\\') match {
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   129
        case Platform_Root(rest) => "/" + rest.replace('\\', '/')
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   130
        case Drive(letter, rest) =>
50299
f70b3712040f renamed dockable "Prover Session" to "Theories";
wenzelm
parents: 50203
diff changeset
   131
          "/cygdrive/" + Library.lowercase(letter) +
34201
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   132
            (if (rest == "") "" else "/" + rest.replace('\\', '/'))
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   133
        case path => path.replace('\\', '/')
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   134
      }
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   135
    }
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   136
    else jvm_path
36193
067a01827fca improved ISABELLE_JAVA, based on THIS_JAVA of the actually running JVM;
wenzelm
parents: 36136
diff changeset
   137
067a01827fca improved ISABELLE_JAVA, based on THIS_JAVA of the actually running JVM;
wenzelm
parents: 36136
diff changeset
   138
47113
b5a5662528fb ISABELLE_JDK_HOME settings variable points to JDK with javac and jar (not just JRE);
wenzelm
parents: 45673
diff changeset
   139
  /* JDK home of running JVM */
36193
067a01827fca improved ISABELLE_JAVA, based on THIS_JAVA of the actually running JVM;
wenzelm
parents: 36136
diff changeset
   140
47113
b5a5662528fb ISABELLE_JDK_HOME settings variable points to JDK with javac and jar (not just JRE);
wenzelm
parents: 45673
diff changeset
   141
  def this_jdk_home(): String =
36193
067a01827fca improved ISABELLE_JAVA, based on THIS_JAVA of the actually running JVM;
wenzelm
parents: 36136
diff changeset
   142
  {
067a01827fca improved ISABELLE_JAVA, based on THIS_JAVA of the actually running JVM;
wenzelm
parents: 36136
diff changeset
   143
    val java_home = System.getProperty("java.home")
48409
0d2114eb412a more explicit java.io.{File => JFile};
wenzelm
parents: 48373
diff changeset
   144
    val home = new JFile(java_home)
47113
b5a5662528fb ISABELLE_JDK_HOME settings variable points to JDK with javac and jar (not just JRE);
wenzelm
parents: 45673
diff changeset
   145
    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
   146
    val jdk_home =
b5a5662528fb ISABELLE_JDK_HOME settings variable points to JDK with javac and jar (not just JRE);
wenzelm
parents: 45673
diff changeset
   147
      if (home.getName == "jre" && parent != null &&
48409
0d2114eb412a more explicit java.io.{File => JFile};
wenzelm
parents: 48373
diff changeset
   148
          (new JFile(new JFile(parent, "bin"), "javac")).exists) parent
47113
b5a5662528fb ISABELLE_JDK_HOME settings variable points to JDK with javac and jar (not just JRE);
wenzelm
parents: 45673
diff changeset
   149
      else java_home
b5a5662528fb ISABELLE_JDK_HOME settings variable points to JDK with javac and jar (not just JRE);
wenzelm
parents: 45673
diff changeset
   150
    posix_path(jdk_home)
36193
067a01827fca improved ISABELLE_JAVA, based on THIS_JAVA of the actually running JVM;
wenzelm
parents: 36136
diff changeset
   151
  }
34201
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   152
}