src/Pure/System/isabelle_system.scala
changeset 48409 0d2114eb412a
parent 48373 527e2bad7cca
child 48411 5b3440850d36
equal deleted inserted replaced
48374:623607c5a40f 48409:0d2114eb412a
     8 package isabelle
     8 package isabelle
     9 
     9 
    10 import java.lang.System
    10 import java.lang.System
    11 import java.util.regex.Pattern
    11 import java.util.regex.Pattern
    12 import java.util.Locale
    12 import java.util.Locale
    13 import java.io.{InputStream, OutputStream, File, BufferedReader, InputStreamReader,
    13 import java.io.{InputStream, OutputStream, File => JFile, BufferedReader, InputStreamReader,
    14   BufferedWriter, OutputStreamWriter, IOException}
    14   BufferedWriter, OutputStreamWriter, IOException}
    15 import java.awt.{GraphicsEnvironment, Font}
    15 import java.awt.{GraphicsEnvironment, Font}
    16 import java.awt.font.TextAttribute
    16 import java.awt.font.TextAttribute
    17 
    17 
    18 import scala.io.Source
    18 import scala.io.Source
   107   /* path specifications */
   107   /* path specifications */
   108 
   108 
   109   def standard_path(path: Path): String = path.expand.implode
   109   def standard_path(path: Path): String = path.expand.implode
   110 
   110 
   111   def platform_path(path: Path): String = standard_system.jvm_path(standard_path(path))
   111   def platform_path(path: Path): String = standard_system.jvm_path(standard_path(path))
   112   def platform_file(path: Path): File = new File(platform_path(path))
   112   def platform_file(path: Path): JFile = new JFile(platform_path(path))
   113 
   113 
   114   def platform_file_url(raw_path: Path): String =
   114   def platform_file_url(raw_path: Path): String =
   115   {
   115   {
   116     val path = raw_path.expand
   116     val path = raw_path.expand
   117     require(path.is_absolute)
   117     require(path.is_absolute)
   137   }
   137   }
   138 
   138 
   139 
   139 
   140   /* source files */
   140   /* source files */
   141 
   141 
   142   private def try_file(file: File) = if (file.isFile) Some(file) else None
   142   private def try_file(file: JFile) = if (file.isFile) Some(file) else None
   143 
   143 
   144   def source_file(path: Path): Option[File] =
   144   def source_file(path: Path): Option[JFile] =
   145   {
   145   {
   146     if (path.is_absolute || path.is_current)
   146     if (path.is_absolute || path.is_current)
   147       try_file(platform_file(path))
   147       try_file(platform_file(path))
   148     else {
   148     else {
   149       val pure_file = (Path.explode("~~/src/Pure") + path).file
   149       val pure_file = (Path.explode("~~/src/Pure") + path).file
   157 
   157 
   158   /** external processes **/
   158   /** external processes **/
   159 
   159 
   160   /* plain execute */
   160   /* plain execute */
   161 
   161 
   162   def execute_env(cwd: File, env: Map[String, String], redirect: Boolean, args: String*): Process =
   162   def execute_env(cwd: JFile, env: Map[String, String], redirect: Boolean, args: String*): Process =
   163   {
   163   {
   164     val cmdline =
   164     val cmdline =
   165       if (Platform.is_windows) List(standard_system.platform_root + "\\bin\\env.exe") ++ args
   165       if (Platform.is_windows) List(standard_system.platform_root + "\\bin\\env.exe") ++ args
   166       else args
   166       else args
   167     val env1 = if (env == null) settings else settings ++ env
   167     val env1 = if (env == null) settings else settings ++ env
   172     execute_env(null, null, redirect, args: _*)
   172     execute_env(null, null, redirect, args: _*)
   173 
   173 
   174 
   174 
   175   /* managed process */
   175   /* managed process */
   176 
   176 
   177   class Managed_Process(cwd: File, env: Map[String, String], redirect: Boolean, args: String*)
   177   class Managed_Process(cwd: JFile, env: Map[String, String], redirect: Boolean, args: String*)
   178   {
   178   {
   179     private val params =
   179     private val params =
   180       List(standard_path(Path.explode("~~/lib/scripts/process")), "group", "-", "no_script")
   180       List(standard_path(Path.explode("~~/lib/scripts/process")), "group", "-", "no_script")
   181     private val proc = execute_env(cwd, env, redirect, (params ++ args):_*)
   181     private val proc = execute_env(cwd, env, redirect, (params ++ args):_*)
   182 
   182 
   239   }
   239   }
   240 
   240 
   241 
   241 
   242   /* bash */
   242   /* bash */
   243 
   243 
   244   def bash_env(cwd: File, env: Map[String, String], script: String): (String, String, Int) =
   244   def bash_env(cwd: JFile, env: Map[String, String], script: String): (String, String, Int) =
   245   {
   245   {
   246     Standard_System.with_tmp_file("isabelle_script") { script_file =>
   246     Standard_System.with_tmp_file("isabelle_script") { script_file =>
   247       Standard_System.write_file(script_file, script)
   247       Standard_System.write_file(script_file, script)
   248       val proc = new Managed_Process(cwd, env, false, "bash", posix_path(script_file.getPath))
   248       val proc = new Managed_Process(cwd, env, false, "bash", posix_path(script_file.getPath))
   249 
   249 
   258     }
   258     }
   259   }
   259   }
   260 
   260 
   261   def bash(script: String): (String, String, Int) = bash_env(null, null, script)
   261   def bash(script: String): (String, String, Int) = bash_env(null, null, script)
   262 
   262 
   263   class Bash_Job(cwd: File, env: Map[String, String], script: String)
   263   class Bash_Job(cwd: JFile, env: Map[String, String], script: String)
   264   {
   264   {
   265     private val (thread, result) = Simple_Thread.future("bash_job") { bash_env(cwd, env, script) }
   265     private val (thread, result) = Simple_Thread.future("bash_job") { bash_env(cwd, env, script) }
   266 
   266 
   267     def terminate: Unit = thread.interrupt
   267     def terminate: Unit = thread.interrupt
   268     def is_finished: Boolean = result.is_finished
   268     def is_finished: Boolean = result.is_finished